David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 1 | /* mdesc.c: Sun4V machine description handling. |
| 2 | * |
| 3 | * Copyright (C) 2007 David S. Miller <davem@davemloft.net> |
| 4 | */ |
| 5 | #include <linux/kernel.h> |
| 6 | #include <linux/types.h> |
| 7 | #include <linux/bootmem.h> |
| 8 | #include <linux/log2.h> |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 9 | #include <linux/list.h> |
| 10 | #include <linux/slab.h> |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 11 | |
| 12 | #include <asm/hypervisor.h> |
| 13 | #include <asm/mdesc.h> |
| 14 | #include <asm/prom.h> |
| 15 | #include <asm/oplib.h> |
| 16 | #include <asm/smp.h> |
| 17 | |
| 18 | /* Unlike the OBP device tree, the machine description is a full-on |
| 19 | * DAG. An arbitrary number of ARCs are possible from one |
| 20 | * node to other nodes and thus we can't use the OBP device_node |
| 21 | * data structure to represent these nodes inside of the kernel. |
| 22 | * |
| 23 | * Actually, it isn't even a DAG, because there are back pointers |
| 24 | * which create cycles in the graph. |
| 25 | * |
| 26 | * mdesc_hdr and mdesc_elem describe the layout of the data structure |
| 27 | * we get from the Hypervisor. |
| 28 | */ |
| 29 | struct mdesc_hdr { |
| 30 | u32 version; /* Transport version */ |
| 31 | u32 node_sz; /* node block size */ |
| 32 | u32 name_sz; /* name block size */ |
| 33 | u32 data_sz; /* data block size */ |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 34 | } __attribute__((aligned(16))); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 35 | |
| 36 | struct mdesc_elem { |
| 37 | u8 tag; |
| 38 | #define MD_LIST_END 0x00 |
| 39 | #define MD_NODE 0x4e |
| 40 | #define MD_NODE_END 0x45 |
| 41 | #define MD_NOOP 0x20 |
| 42 | #define MD_PROP_ARC 0x61 |
| 43 | #define MD_PROP_VAL 0x76 |
| 44 | #define MD_PROP_STR 0x73 |
| 45 | #define MD_PROP_DATA 0x64 |
| 46 | u8 name_len; |
| 47 | u16 resv; |
| 48 | u32 name_offset; |
| 49 | union { |
| 50 | struct { |
| 51 | u32 data_len; |
| 52 | u32 data_offset; |
| 53 | } data; |
| 54 | u64 val; |
| 55 | } d; |
| 56 | }; |
| 57 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 58 | struct mdesc_mem_ops { |
| 59 | struct mdesc_handle *(*alloc)(unsigned int mdesc_size); |
| 60 | void (*free)(struct mdesc_handle *handle); |
| 61 | }; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 62 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 63 | struct mdesc_handle { |
| 64 | struct list_head list; |
| 65 | struct mdesc_mem_ops *mops; |
| 66 | void *self_base; |
| 67 | atomic_t refcnt; |
| 68 | unsigned int handle_size; |
| 69 | struct mdesc_hdr mdesc; |
| 70 | }; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 71 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 72 | static void mdesc_handle_init(struct mdesc_handle *hp, |
| 73 | unsigned int handle_size, |
| 74 | void *base) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 75 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 76 | BUG_ON(((unsigned long)&hp->mdesc) & (16UL - 1)); |
| 77 | |
| 78 | memset(hp, 0, handle_size); |
| 79 | INIT_LIST_HEAD(&hp->list); |
| 80 | hp->self_base = base; |
| 81 | atomic_set(&hp->refcnt, 1); |
| 82 | hp->handle_size = handle_size; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 83 | } |
| 84 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 85 | static struct mdesc_handle *mdesc_bootmem_alloc(unsigned int mdesc_size) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 86 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 87 | struct mdesc_handle *hp; |
| 88 | unsigned int handle_size, alloc_size; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 89 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 90 | handle_size = (sizeof(struct mdesc_handle) - |
| 91 | sizeof(struct mdesc_hdr) + |
| 92 | mdesc_size); |
| 93 | alloc_size = PAGE_ALIGN(handle_size); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 94 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 95 | hp = __alloc_bootmem(alloc_size, PAGE_SIZE, 0UL); |
| 96 | if (hp) |
| 97 | mdesc_handle_init(hp, handle_size, hp); |
| 98 | |
| 99 | return hp; |
| 100 | } |
| 101 | |
| 102 | static void mdesc_bootmem_free(struct mdesc_handle *hp) |
| 103 | { |
| 104 | unsigned int alloc_size, handle_size = hp->handle_size; |
| 105 | unsigned long start, end; |
| 106 | |
| 107 | BUG_ON(atomic_read(&hp->refcnt) != 0); |
| 108 | BUG_ON(!list_empty(&hp->list)); |
| 109 | |
| 110 | alloc_size = PAGE_ALIGN(handle_size); |
| 111 | |
| 112 | start = (unsigned long) hp; |
| 113 | end = start + alloc_size; |
| 114 | |
| 115 | while (start < end) { |
| 116 | struct page *p; |
| 117 | |
| 118 | p = virt_to_page(start); |
| 119 | ClearPageReserved(p); |
| 120 | __free_page(p); |
| 121 | start += PAGE_SIZE; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 125 | static struct mdesc_mem_ops bootmem_mdesc_memops = { |
| 126 | .alloc = mdesc_bootmem_alloc, |
| 127 | .free = mdesc_bootmem_free, |
| 128 | }; |
| 129 | |
| 130 | static struct mdesc_handle *mdesc_kmalloc(unsigned int mdesc_size) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 131 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 132 | unsigned int handle_size; |
| 133 | void *base; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 134 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 135 | handle_size = (sizeof(struct mdesc_handle) - |
| 136 | sizeof(struct mdesc_hdr) + |
| 137 | mdesc_size); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 138 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 139 | base = kmalloc(handle_size + 15, GFP_KERNEL); |
| 140 | if (base) { |
| 141 | struct mdesc_handle *hp; |
| 142 | unsigned long addr; |
| 143 | |
| 144 | addr = (unsigned long)base; |
| 145 | addr = (addr + 15UL) & ~15UL; |
| 146 | hp = (struct mdesc_handle *) addr; |
| 147 | |
| 148 | mdesc_handle_init(hp, handle_size, base); |
| 149 | return hp; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 150 | } |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 151 | |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 152 | return NULL; |
| 153 | } |
| 154 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 155 | static void mdesc_kfree(struct mdesc_handle *hp) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 156 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 157 | BUG_ON(atomic_read(&hp->refcnt) != 0); |
| 158 | BUG_ON(!list_empty(&hp->list)); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 159 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 160 | kfree(hp->self_base); |
| 161 | } |
| 162 | |
| 163 | static struct mdesc_mem_ops kmalloc_mdesc_memops = { |
| 164 | .alloc = mdesc_kmalloc, |
| 165 | .free = mdesc_kfree, |
| 166 | }; |
| 167 | |
| 168 | static struct mdesc_handle *mdesc_alloc(unsigned int mdesc_size, |
| 169 | struct mdesc_mem_ops *mops) |
| 170 | { |
| 171 | struct mdesc_handle *hp = mops->alloc(mdesc_size); |
| 172 | |
| 173 | if (hp) |
| 174 | hp->mops = mops; |
| 175 | |
| 176 | return hp; |
| 177 | } |
| 178 | |
| 179 | static void mdesc_free(struct mdesc_handle *hp) |
| 180 | { |
| 181 | hp->mops->free(hp); |
| 182 | } |
| 183 | |
| 184 | static struct mdesc_handle *cur_mdesc; |
| 185 | static LIST_HEAD(mdesc_zombie_list); |
| 186 | static DEFINE_SPINLOCK(mdesc_lock); |
| 187 | |
| 188 | struct mdesc_handle *mdesc_grab(void) |
| 189 | { |
| 190 | struct mdesc_handle *hp; |
| 191 | unsigned long flags; |
| 192 | |
| 193 | spin_lock_irqsave(&mdesc_lock, flags); |
| 194 | hp = cur_mdesc; |
| 195 | if (hp) |
| 196 | atomic_inc(&hp->refcnt); |
| 197 | spin_unlock_irqrestore(&mdesc_lock, flags); |
| 198 | |
| 199 | return hp; |
| 200 | } |
| 201 | EXPORT_SYMBOL(mdesc_grab); |
| 202 | |
| 203 | void mdesc_release(struct mdesc_handle *hp) |
| 204 | { |
| 205 | unsigned long flags; |
| 206 | |
| 207 | spin_lock_irqsave(&mdesc_lock, flags); |
| 208 | if (atomic_dec_and_test(&hp->refcnt)) { |
| 209 | list_del_init(&hp->list); |
| 210 | hp->mops->free(hp); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 211 | } |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 212 | spin_unlock_irqrestore(&mdesc_lock, flags); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 213 | } |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 214 | EXPORT_SYMBOL(mdesc_release); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 215 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 216 | static void do_mdesc_update(struct work_struct *work) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 217 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 218 | unsigned long len, real_len, status; |
| 219 | struct mdesc_handle *hp, *orig_hp; |
| 220 | unsigned long flags; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 221 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 222 | (void) sun4v_mach_desc(0UL, 0UL, &len); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 223 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 224 | hp = mdesc_alloc(len, &kmalloc_mdesc_memops); |
| 225 | if (!hp) { |
| 226 | printk(KERN_ERR "MD: mdesc alloc fails\n"); |
| 227 | return; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 228 | } |
| 229 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 230 | status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len); |
| 231 | if (status != HV_EOK || real_len > len) { |
| 232 | printk(KERN_ERR "MD: mdesc reread fails with %lu\n", |
| 233 | status); |
| 234 | atomic_dec(&hp->refcnt); |
| 235 | mdesc_free(hp); |
| 236 | return; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 237 | } |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 238 | |
| 239 | spin_lock_irqsave(&mdesc_lock, flags); |
| 240 | orig_hp = cur_mdesc; |
| 241 | cur_mdesc = hp; |
| 242 | |
| 243 | if (atomic_dec_and_test(&orig_hp->refcnt)) |
| 244 | mdesc_free(orig_hp); |
| 245 | else |
| 246 | list_add(&orig_hp->list, &mdesc_zombie_list); |
| 247 | spin_unlock_irqrestore(&mdesc_lock, flags); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 248 | } |
| 249 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 250 | static DECLARE_WORK(mdesc_update_work, do_mdesc_update); |
| 251 | |
| 252 | void mdesc_update(void) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 253 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 254 | schedule_work(&mdesc_update_work); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 255 | } |
| 256 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 257 | static struct mdesc_elem *node_block(struct mdesc_hdr *mdesc) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 258 | { |
| 259 | return (struct mdesc_elem *) (mdesc + 1); |
| 260 | } |
| 261 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 262 | static void *name_block(struct mdesc_hdr *mdesc) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 263 | { |
| 264 | return ((void *) node_block(mdesc)) + mdesc->node_sz; |
| 265 | } |
| 266 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 267 | static void *data_block(struct mdesc_hdr *mdesc) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 268 | { |
| 269 | return ((void *) name_block(mdesc)) + mdesc->name_sz; |
| 270 | } |
| 271 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 272 | u64 mdesc_node_by_name(struct mdesc_handle *hp, |
| 273 | u64 from_node, const char *name) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 274 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 275 | struct mdesc_elem *ep = node_block(&hp->mdesc); |
| 276 | const char *names = name_block(&hp->mdesc); |
| 277 | u64 last_node = hp->mdesc.node_sz / 16; |
| 278 | u64 ret; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 279 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 280 | if (from_node == MDESC_NODE_NULL) |
| 281 | from_node = 0; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 282 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 283 | if (from_node >= last_node) |
| 284 | return MDESC_NODE_NULL; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 285 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 286 | ret = ep[from_node].d.val; |
| 287 | while (ret < last_node) { |
| 288 | if (ep[ret].tag != MD_NODE) |
| 289 | return MDESC_NODE_NULL; |
| 290 | if (!strcmp(names + ep[ret].name_offset, name)) |
| 291 | break; |
| 292 | ret = ep[ret].d.val; |
| 293 | } |
| 294 | if (ret >= last_node) |
| 295 | ret = MDESC_NODE_NULL; |
| 296 | return ret; |
| 297 | } |
| 298 | EXPORT_SYMBOL(mdesc_node_by_name); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 299 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 300 | const void *mdesc_get_property(struct mdesc_handle *hp, u64 node, |
| 301 | const char *name, int *lenp) |
| 302 | { |
| 303 | const char *names = name_block(&hp->mdesc); |
| 304 | u64 last_node = hp->mdesc.node_sz / 16; |
| 305 | void *data = data_block(&hp->mdesc); |
| 306 | struct mdesc_elem *ep; |
| 307 | |
| 308 | if (node == MDESC_NODE_NULL || node >= last_node) |
| 309 | return NULL; |
| 310 | |
| 311 | ep = node_block(&hp->mdesc) + node; |
| 312 | ep++; |
| 313 | for (; ep->tag != MD_NODE_END; ep++) { |
| 314 | void *val = NULL; |
| 315 | int len = 0; |
| 316 | |
| 317 | switch (ep->tag) { |
| 318 | case MD_PROP_VAL: |
| 319 | val = &ep->d.val; |
| 320 | len = 8; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 321 | break; |
| 322 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 323 | case MD_PROP_STR: |
| 324 | case MD_PROP_DATA: |
| 325 | val = data + ep->d.data.data_offset; |
| 326 | len = ep->d.data.data_len; |
| 327 | break; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 328 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 329 | default: |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 330 | break; |
| 331 | } |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 332 | if (!val) |
| 333 | continue; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 334 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 335 | if (!strcmp(names + ep->name_offset, name)) { |
| 336 | if (lenp) |
| 337 | *lenp = len; |
| 338 | return val; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 339 | } |
| 340 | } |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 341 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 342 | return NULL; |
| 343 | } |
| 344 | EXPORT_SYMBOL(mdesc_get_property); |
| 345 | |
| 346 | u64 mdesc_next_arc(struct mdesc_handle *hp, u64 from, const char *arc_type) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 347 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 348 | struct mdesc_elem *ep, *base = node_block(&hp->mdesc); |
| 349 | const char *names = name_block(&hp->mdesc); |
| 350 | u64 last_node = hp->mdesc.node_sz / 16; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 351 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 352 | if (from == MDESC_NODE_NULL || from >= last_node) |
| 353 | return MDESC_NODE_NULL; |
| 354 | |
| 355 | ep = base + from; |
| 356 | |
| 357 | ep++; |
| 358 | for (; ep->tag != MD_NODE_END; ep++) { |
| 359 | if (ep->tag != MD_PROP_ARC) |
| 360 | continue; |
| 361 | |
| 362 | if (strcmp(names + ep->name_offset, arc_type)) |
| 363 | continue; |
| 364 | |
| 365 | return ep - base; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 366 | } |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 367 | |
| 368 | return MDESC_NODE_NULL; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 369 | } |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 370 | EXPORT_SYMBOL(mdesc_next_arc); |
| 371 | |
| 372 | u64 mdesc_arc_target(struct mdesc_handle *hp, u64 arc) |
| 373 | { |
| 374 | struct mdesc_elem *ep, *base = node_block(&hp->mdesc); |
| 375 | |
| 376 | ep = base + arc; |
| 377 | |
| 378 | return ep->d.val; |
| 379 | } |
| 380 | EXPORT_SYMBOL(mdesc_arc_target); |
| 381 | |
| 382 | const char *mdesc_node_name(struct mdesc_handle *hp, u64 node) |
| 383 | { |
| 384 | struct mdesc_elem *ep, *base = node_block(&hp->mdesc); |
| 385 | const char *names = name_block(&hp->mdesc); |
| 386 | u64 last_node = hp->mdesc.node_sz / 16; |
| 387 | |
| 388 | if (node == MDESC_NODE_NULL || node >= last_node) |
| 389 | return NULL; |
| 390 | |
| 391 | ep = base + node; |
| 392 | if (ep->tag != MD_NODE) |
| 393 | return NULL; |
| 394 | |
| 395 | return names + ep->name_offset; |
| 396 | } |
| 397 | EXPORT_SYMBOL(mdesc_node_name); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 398 | |
| 399 | static void __init report_platform_properties(void) |
| 400 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 401 | struct mdesc_handle *hp = mdesc_grab(); |
| 402 | u64 pn = mdesc_node_by_name(hp, MDESC_NODE_NULL, "platform"); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 403 | const char *s; |
| 404 | const u64 *v; |
| 405 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 406 | if (pn == MDESC_NODE_NULL) { |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 407 | prom_printf("No platform node in machine-description.\n"); |
| 408 | prom_halt(); |
| 409 | } |
| 410 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 411 | s = mdesc_get_property(hp, pn, "banner-name", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 412 | printk("PLATFORM: banner-name [%s]\n", s); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 413 | s = mdesc_get_property(hp, pn, "name", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 414 | printk("PLATFORM: name [%s]\n", s); |
| 415 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 416 | v = mdesc_get_property(hp, pn, "hostid", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 417 | if (v) |
| 418 | printk("PLATFORM: hostid [%08lx]\n", *v); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 419 | v = mdesc_get_property(hp, pn, "serial#", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 420 | if (v) |
| 421 | printk("PLATFORM: serial# [%08lx]\n", *v); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 422 | v = mdesc_get_property(hp, pn, "stick-frequency", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 423 | printk("PLATFORM: stick-frequency [%08lx]\n", *v); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 424 | v = mdesc_get_property(hp, pn, "mac-address", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 425 | if (v) |
| 426 | printk("PLATFORM: mac-address [%lx]\n", *v); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 427 | v = mdesc_get_property(hp, pn, "watchdog-resolution", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 428 | if (v) |
| 429 | printk("PLATFORM: watchdog-resolution [%lu ms]\n", *v); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 430 | v = mdesc_get_property(hp, pn, "watchdog-max-timeout", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 431 | if (v) |
| 432 | printk("PLATFORM: watchdog-max-timeout [%lu ms]\n", *v); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 433 | v = mdesc_get_property(hp, pn, "max-cpus", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 434 | if (v) |
| 435 | printk("PLATFORM: max-cpus [%lu]\n", *v); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 436 | |
| 437 | mdesc_release(hp); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | static int inline find_in_proplist(const char *list, const char *match, int len) |
| 441 | { |
| 442 | while (len > 0) { |
| 443 | int l; |
| 444 | |
| 445 | if (!strcmp(list, match)) |
| 446 | return 1; |
| 447 | l = strlen(list) + 1; |
| 448 | list += l; |
| 449 | len -= l; |
| 450 | } |
| 451 | return 0; |
| 452 | } |
| 453 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 454 | static void __init fill_in_one_cache(cpuinfo_sparc *c, |
| 455 | struct mdesc_handle *hp, |
| 456 | u64 mp) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 457 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 458 | const u64 *level = mdesc_get_property(hp, mp, "level", NULL); |
| 459 | const u64 *size = mdesc_get_property(hp, mp, "size", NULL); |
| 460 | const u64 *line_size = mdesc_get_property(hp, mp, "line-size", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 461 | const char *type; |
| 462 | int type_len; |
| 463 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 464 | type = mdesc_get_property(hp, mp, "type", &type_len); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 465 | |
| 466 | switch (*level) { |
| 467 | case 1: |
| 468 | if (find_in_proplist(type, "instn", type_len)) { |
| 469 | c->icache_size = *size; |
| 470 | c->icache_line_size = *line_size; |
| 471 | } else if (find_in_proplist(type, "data", type_len)) { |
| 472 | c->dcache_size = *size; |
| 473 | c->dcache_line_size = *line_size; |
| 474 | } |
| 475 | break; |
| 476 | |
| 477 | case 2: |
| 478 | c->ecache_size = *size; |
| 479 | c->ecache_line_size = *line_size; |
| 480 | break; |
| 481 | |
| 482 | default: |
| 483 | break; |
| 484 | } |
| 485 | |
| 486 | if (*level == 1) { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 487 | u64 a; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 488 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 489 | mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) { |
| 490 | u64 target = mdesc_arc_target(hp, a); |
| 491 | const char *name = mdesc_node_name(hp, target); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 492 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 493 | if (!strcmp(name, "cache")) |
| 494 | fill_in_one_cache(c, hp, target); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 499 | static void __init mark_core_ids(struct mdesc_handle *hp, u64 mp, int core_id) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 500 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 501 | u64 a; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 502 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 503 | mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_BACK) { |
| 504 | u64 t = mdesc_arc_target(hp, a); |
| 505 | const char *name; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 506 | const u64 *id; |
| 507 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 508 | name = mdesc_node_name(hp, t); |
| 509 | if (!strcmp(name, "cpu")) { |
| 510 | id = mdesc_get_property(hp, t, "id", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 511 | if (*id < NR_CPUS) |
| 512 | cpu_data(*id).core_id = core_id; |
| 513 | } else { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 514 | u64 j; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 515 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 516 | mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_BACK) { |
| 517 | u64 n = mdesc_arc_target(hp, j); |
| 518 | const char *n_name; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 519 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 520 | n_name = mdesc_node_name(hp, n); |
| 521 | if (strcmp(n_name, "cpu")) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 522 | continue; |
| 523 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 524 | id = mdesc_get_property(hp, n, "id", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 525 | if (*id < NR_CPUS) |
| 526 | cpu_data(*id).core_id = core_id; |
| 527 | } |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 532 | static void __init set_core_ids(struct mdesc_handle *hp) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 533 | { |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 534 | int idx; |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 535 | u64 mp; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 536 | |
| 537 | idx = 1; |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 538 | mdesc_for_each_node_by_name(hp, mp, "cache") { |
| 539 | const u64 *level; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 540 | const char *type; |
| 541 | int len; |
| 542 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 543 | level = mdesc_get_property(hp, mp, "level", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 544 | if (*level != 1) |
| 545 | continue; |
| 546 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 547 | type = mdesc_get_property(hp, mp, "type", &len); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 548 | if (!find_in_proplist(type, "instn", len)) |
| 549 | continue; |
| 550 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 551 | mark_core_ids(hp, mp, idx); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 552 | |
| 553 | idx++; |
| 554 | } |
| 555 | } |
| 556 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 557 | static void __init mark_proc_ids(struct mdesc_handle *hp, u64 mp, int proc_id) |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 558 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 559 | u64 a; |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 560 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 561 | mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_BACK) { |
| 562 | u64 t = mdesc_arc_target(hp, a); |
| 563 | const char *name; |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 564 | const u64 *id; |
| 565 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 566 | name = mdesc_node_name(hp, t); |
| 567 | if (strcmp(name, "cpu")) |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 568 | continue; |
| 569 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 570 | id = mdesc_get_property(hp, t, "id", NULL); |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 571 | if (*id < NR_CPUS) |
| 572 | cpu_data(*id).proc_id = proc_id; |
| 573 | } |
| 574 | } |
| 575 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 576 | static void __init __set_proc_ids(struct mdesc_handle *hp, |
| 577 | const char *exec_unit_name) |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 578 | { |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 579 | int idx; |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 580 | u64 mp; |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 581 | |
| 582 | idx = 0; |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 583 | mdesc_for_each_node_by_name(hp, mp, exec_unit_name) { |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 584 | const char *type; |
| 585 | int len; |
| 586 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 587 | type = mdesc_get_property(hp, mp, "type", &len); |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 588 | if (!find_in_proplist(type, "int", len) && |
| 589 | !find_in_proplist(type, "integer", len)) |
| 590 | continue; |
| 591 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 592 | mark_proc_ids(hp, mp, idx); |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 593 | |
| 594 | idx++; |
| 595 | } |
| 596 | } |
| 597 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 598 | static void __init set_proc_ids(struct mdesc_handle *hp) |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 599 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 600 | __set_proc_ids(hp, "exec_unit"); |
| 601 | __set_proc_ids(hp, "exec-unit"); |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 602 | } |
| 603 | |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 604 | static void __init get_one_mondo_bits(const u64 *p, unsigned int *mask, unsigned char def) |
| 605 | { |
| 606 | u64 val; |
| 607 | |
| 608 | if (!p) |
| 609 | goto use_default; |
| 610 | val = *p; |
| 611 | |
| 612 | if (!val || val >= 64) |
| 613 | goto use_default; |
| 614 | |
| 615 | *mask = ((1U << val) * 64U) - 1U; |
| 616 | return; |
| 617 | |
| 618 | use_default: |
| 619 | *mask = ((1U << def) * 64U) - 1U; |
| 620 | } |
| 621 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 622 | static void __init get_mondo_data(struct mdesc_handle *hp, u64 mp, |
| 623 | struct trap_per_cpu *tb) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 624 | { |
| 625 | const u64 *val; |
| 626 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 627 | val = mdesc_get_property(hp, mp, "q-cpu-mondo-#bits", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 628 | get_one_mondo_bits(val, &tb->cpu_mondo_qmask, 7); |
| 629 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 630 | val = mdesc_get_property(hp, mp, "q-dev-mondo-#bits", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 631 | get_one_mondo_bits(val, &tb->dev_mondo_qmask, 7); |
| 632 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 633 | val = mdesc_get_property(hp, mp, "q-resumable-#bits", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 634 | get_one_mondo_bits(val, &tb->resum_qmask, 6); |
| 635 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 636 | val = mdesc_get_property(hp, mp, "q-nonresumable-#bits", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 637 | get_one_mondo_bits(val, &tb->nonresum_qmask, 2); |
| 638 | } |
| 639 | |
| 640 | static void __init mdesc_fill_in_cpu_data(void) |
| 641 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 642 | struct mdesc_handle *hp = mdesc_grab(); |
| 643 | u64 mp; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 644 | |
| 645 | ncpus_probed = 0; |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 646 | mdesc_for_each_node_by_name(hp, mp, "cpu") { |
| 647 | const u64 *id = mdesc_get_property(hp, mp, "id", NULL); |
| 648 | const u64 *cfreq = mdesc_get_property(hp, mp, "clock-frequency", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 649 | struct trap_per_cpu *tb; |
| 650 | cpuinfo_sparc *c; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 651 | int cpuid; |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 652 | u64 a; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 653 | |
| 654 | ncpus_probed++; |
| 655 | |
| 656 | cpuid = *id; |
| 657 | |
| 658 | #ifdef CONFIG_SMP |
| 659 | if (cpuid >= NR_CPUS) |
| 660 | continue; |
| 661 | #else |
| 662 | /* On uniprocessor we only want the values for the |
| 663 | * real physical cpu the kernel booted onto, however |
| 664 | * cpu_data() only has one entry at index 0. |
| 665 | */ |
| 666 | if (cpuid != real_hard_smp_processor_id()) |
| 667 | continue; |
| 668 | cpuid = 0; |
| 669 | #endif |
| 670 | |
| 671 | c = &cpu_data(cpuid); |
| 672 | c->clock_tick = *cfreq; |
| 673 | |
| 674 | tb = &trap_block[cpuid]; |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 675 | get_mondo_data(hp, mp, tb); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 676 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 677 | mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) { |
| 678 | u64 j, t = mdesc_arc_target(hp, a); |
| 679 | const char *t_name; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 680 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 681 | t_name = mdesc_node_name(hp, t); |
| 682 | if (!strcmp(t_name, "cache")) { |
| 683 | fill_in_one_cache(c, hp, t); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 684 | continue; |
| 685 | } |
| 686 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 687 | mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_FWD) { |
| 688 | u64 n = mdesc_arc_target(hp, j); |
| 689 | const char *n_name; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 690 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 691 | n_name = mdesc_node_name(hp, n); |
| 692 | if (!strcmp(n_name, "cache")) |
| 693 | fill_in_one_cache(c, hp, n); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | |
| 697 | #ifdef CONFIG_SMP |
| 698 | cpu_set(cpuid, cpu_present_map); |
| 699 | cpu_set(cpuid, phys_cpu_present_map); |
| 700 | #endif |
| 701 | |
| 702 | c->core_id = 0; |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 703 | c->proc_id = -1; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 704 | } |
| 705 | |
David S. Miller | a2f9f6b | 2007-06-04 21:48:33 -0700 | [diff] [blame] | 706 | #ifdef CONFIG_SMP |
| 707 | sparc64_multi_core = 1; |
| 708 | #endif |
| 709 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 710 | set_core_ids(hp); |
| 711 | set_proc_ids(hp); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 712 | |
| 713 | smp_fill_in_sib_core_maps(); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 714 | |
| 715 | mdesc_release(hp); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | void __init sun4v_mdesc_init(void) |
| 719 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 720 | struct mdesc_handle *hp; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 721 | unsigned long len, real_len, status; |
| 722 | |
| 723 | (void) sun4v_mach_desc(0UL, 0UL, &len); |
| 724 | |
| 725 | printk("MDESC: Size is %lu bytes.\n", len); |
| 726 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 727 | hp = mdesc_alloc(len, &bootmem_mdesc_memops); |
| 728 | if (hp == NULL) { |
| 729 | prom_printf("MDESC: alloc of %lu bytes failed.\n", len); |
| 730 | prom_halt(); |
| 731 | } |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 732 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 733 | status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 734 | if (status != HV_EOK || real_len > len) { |
| 735 | prom_printf("sun4v_mach_desc fails, err(%lu), " |
| 736 | "len(%lu), real_len(%lu)\n", |
| 737 | status, len, real_len); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 738 | mdesc_free(hp); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 739 | prom_halt(); |
| 740 | } |
| 741 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame^] | 742 | cur_mdesc = hp; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 743 | |
| 744 | report_platform_properties(); |
| 745 | mdesc_fill_in_cpu_data(); |
| 746 | } |