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