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 | 920c3ed | 2007-07-17 21:37:35 -0700 | [diff] [blame^] | 140 | base = kmalloc(handle_size + 15, GFP_KERNEL | __GFP_NOFAIL); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 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 | 920c3ed | 2007-07-17 21:37:35 -0700 | [diff] [blame^] | 217 | static DEFINE_MUTEX(mdesc_mutex); |
| 218 | static struct mdesc_notifier_client *client_list; |
| 219 | |
| 220 | void mdesc_register_notifier(struct mdesc_notifier_client *client) |
| 221 | { |
| 222 | u64 node; |
| 223 | |
| 224 | mutex_lock(&mdesc_mutex); |
| 225 | client->next = client_list; |
| 226 | client_list = client; |
| 227 | |
| 228 | mdesc_for_each_node_by_name(cur_mdesc, node, client->node_name) |
| 229 | client->add(cur_mdesc, node); |
| 230 | |
| 231 | mutex_unlock(&mdesc_mutex); |
| 232 | } |
| 233 | |
| 234 | /* Run 'func' on nodes which are in A but not in B. */ |
| 235 | static void invoke_on_missing(const char *name, |
| 236 | struct mdesc_handle *a, |
| 237 | struct mdesc_handle *b, |
| 238 | void (*func)(struct mdesc_handle *, u64)) |
| 239 | { |
| 240 | u64 node; |
| 241 | |
| 242 | mdesc_for_each_node_by_name(a, node, name) { |
| 243 | const u64 *id = mdesc_get_property(a, node, "id", NULL); |
| 244 | int found = 0; |
| 245 | u64 fnode; |
| 246 | |
| 247 | mdesc_for_each_node_by_name(b, fnode, name) { |
| 248 | const u64 *fid = mdesc_get_property(b, fnode, |
| 249 | "id", NULL); |
| 250 | |
| 251 | if (*id == *fid) { |
| 252 | found = 1; |
| 253 | break; |
| 254 | } |
| 255 | } |
| 256 | if (!found) |
| 257 | func(a, node); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | static void notify_one(struct mdesc_notifier_client *p, |
| 262 | struct mdesc_handle *old_hp, |
| 263 | struct mdesc_handle *new_hp) |
| 264 | { |
| 265 | invoke_on_missing(p->node_name, old_hp, new_hp, p->remove); |
| 266 | invoke_on_missing(p->node_name, new_hp, old_hp, p->add); |
| 267 | } |
| 268 | |
| 269 | static void mdesc_notify_clients(struct mdesc_handle *old_hp, |
| 270 | struct mdesc_handle *new_hp) |
| 271 | { |
| 272 | struct mdesc_notifier_client *p = client_list; |
| 273 | |
| 274 | while (p) { |
| 275 | notify_one(p, old_hp, new_hp); |
| 276 | p = p->next; |
| 277 | } |
| 278 | } |
| 279 | |
David S. Miller | 778feeb | 2007-07-16 16:50:36 -0700 | [diff] [blame] | 280 | void mdesc_update(void) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 281 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 282 | unsigned long len, real_len, status; |
| 283 | struct mdesc_handle *hp, *orig_hp; |
| 284 | unsigned long flags; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 285 | |
David S. Miller | 920c3ed | 2007-07-17 21:37:35 -0700 | [diff] [blame^] | 286 | mutex_lock(&mdesc_mutex); |
| 287 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 288 | (void) sun4v_mach_desc(0UL, 0UL, &len); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 289 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 290 | hp = mdesc_alloc(len, &kmalloc_mdesc_memops); |
| 291 | if (!hp) { |
| 292 | printk(KERN_ERR "MD: mdesc alloc fails\n"); |
David S. Miller | 920c3ed | 2007-07-17 21:37:35 -0700 | [diff] [blame^] | 293 | goto out; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 294 | } |
| 295 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 296 | status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len); |
| 297 | if (status != HV_EOK || real_len > len) { |
| 298 | printk(KERN_ERR "MD: mdesc reread fails with %lu\n", |
| 299 | status); |
| 300 | atomic_dec(&hp->refcnt); |
| 301 | mdesc_free(hp); |
David S. Miller | 920c3ed | 2007-07-17 21:37:35 -0700 | [diff] [blame^] | 302 | goto out; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 303 | } |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 304 | |
| 305 | spin_lock_irqsave(&mdesc_lock, flags); |
| 306 | orig_hp = cur_mdesc; |
| 307 | cur_mdesc = hp; |
David S. Miller | 920c3ed | 2007-07-17 21:37:35 -0700 | [diff] [blame^] | 308 | spin_unlock_irqrestore(&mdesc_lock, flags); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 309 | |
David S. Miller | 920c3ed | 2007-07-17 21:37:35 -0700 | [diff] [blame^] | 310 | mdesc_notify_clients(orig_hp, hp); |
| 311 | |
| 312 | spin_lock_irqsave(&mdesc_lock, flags); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 313 | if (atomic_dec_and_test(&orig_hp->refcnt)) |
| 314 | mdesc_free(orig_hp); |
| 315 | else |
| 316 | list_add(&orig_hp->list, &mdesc_zombie_list); |
| 317 | spin_unlock_irqrestore(&mdesc_lock, flags); |
David S. Miller | 920c3ed | 2007-07-17 21:37:35 -0700 | [diff] [blame^] | 318 | |
| 319 | out: |
| 320 | mutex_unlock(&mdesc_mutex); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 321 | } |
| 322 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 323 | static struct mdesc_elem *node_block(struct mdesc_hdr *mdesc) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 324 | { |
| 325 | return (struct mdesc_elem *) (mdesc + 1); |
| 326 | } |
| 327 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 328 | static void *name_block(struct mdesc_hdr *mdesc) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 329 | { |
| 330 | return ((void *) node_block(mdesc)) + mdesc->node_sz; |
| 331 | } |
| 332 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 333 | static void *data_block(struct mdesc_hdr *mdesc) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 334 | { |
| 335 | return ((void *) name_block(mdesc)) + mdesc->name_sz; |
| 336 | } |
| 337 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 338 | u64 mdesc_node_by_name(struct mdesc_handle *hp, |
| 339 | u64 from_node, const char *name) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 340 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 341 | struct mdesc_elem *ep = node_block(&hp->mdesc); |
| 342 | const char *names = name_block(&hp->mdesc); |
| 343 | u64 last_node = hp->mdesc.node_sz / 16; |
| 344 | u64 ret; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 345 | |
David S. Miller | 778feeb | 2007-07-16 16:50:36 -0700 | [diff] [blame] | 346 | if (from_node == MDESC_NODE_NULL) { |
| 347 | ret = from_node = 0; |
| 348 | } else if (from_node >= last_node) { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 349 | return MDESC_NODE_NULL; |
David S. Miller | 778feeb | 2007-07-16 16:50:36 -0700 | [diff] [blame] | 350 | } else { |
| 351 | ret = ep[from_node].d.val; |
| 352 | } |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 353 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 354 | while (ret < last_node) { |
| 355 | if (ep[ret].tag != MD_NODE) |
| 356 | return MDESC_NODE_NULL; |
| 357 | if (!strcmp(names + ep[ret].name_offset, name)) |
| 358 | break; |
| 359 | ret = ep[ret].d.val; |
| 360 | } |
| 361 | if (ret >= last_node) |
| 362 | ret = MDESC_NODE_NULL; |
| 363 | return ret; |
| 364 | } |
| 365 | EXPORT_SYMBOL(mdesc_node_by_name); |
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 | const void *mdesc_get_property(struct mdesc_handle *hp, u64 node, |
| 368 | const char *name, int *lenp) |
| 369 | { |
| 370 | const char *names = name_block(&hp->mdesc); |
| 371 | u64 last_node = hp->mdesc.node_sz / 16; |
| 372 | void *data = data_block(&hp->mdesc); |
| 373 | struct mdesc_elem *ep; |
| 374 | |
| 375 | if (node == MDESC_NODE_NULL || node >= last_node) |
| 376 | return NULL; |
| 377 | |
| 378 | ep = node_block(&hp->mdesc) + node; |
| 379 | ep++; |
| 380 | for (; ep->tag != MD_NODE_END; ep++) { |
| 381 | void *val = NULL; |
| 382 | int len = 0; |
| 383 | |
| 384 | switch (ep->tag) { |
| 385 | case MD_PROP_VAL: |
| 386 | val = &ep->d.val; |
| 387 | len = 8; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 388 | break; |
| 389 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 390 | case MD_PROP_STR: |
| 391 | case MD_PROP_DATA: |
| 392 | val = data + ep->d.data.data_offset; |
| 393 | len = ep->d.data.data_len; |
| 394 | break; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 395 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 396 | default: |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 397 | break; |
| 398 | } |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 399 | if (!val) |
| 400 | continue; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 401 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 402 | if (!strcmp(names + ep->name_offset, name)) { |
| 403 | if (lenp) |
| 404 | *lenp = len; |
| 405 | return val; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 406 | } |
| 407 | } |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 408 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 409 | return NULL; |
| 410 | } |
| 411 | EXPORT_SYMBOL(mdesc_get_property); |
| 412 | |
| 413 | 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] | 414 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 415 | struct mdesc_elem *ep, *base = node_block(&hp->mdesc); |
| 416 | const char *names = name_block(&hp->mdesc); |
| 417 | u64 last_node = hp->mdesc.node_sz / 16; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 418 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 419 | if (from == MDESC_NODE_NULL || from >= last_node) |
| 420 | return MDESC_NODE_NULL; |
| 421 | |
| 422 | ep = base + from; |
| 423 | |
| 424 | ep++; |
| 425 | for (; ep->tag != MD_NODE_END; ep++) { |
| 426 | if (ep->tag != MD_PROP_ARC) |
| 427 | continue; |
| 428 | |
| 429 | if (strcmp(names + ep->name_offset, arc_type)) |
| 430 | continue; |
| 431 | |
| 432 | return ep - base; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 433 | } |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 434 | |
| 435 | return MDESC_NODE_NULL; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 436 | } |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 437 | EXPORT_SYMBOL(mdesc_next_arc); |
| 438 | |
| 439 | u64 mdesc_arc_target(struct mdesc_handle *hp, u64 arc) |
| 440 | { |
| 441 | struct mdesc_elem *ep, *base = node_block(&hp->mdesc); |
| 442 | |
| 443 | ep = base + arc; |
| 444 | |
| 445 | return ep->d.val; |
| 446 | } |
| 447 | EXPORT_SYMBOL(mdesc_arc_target); |
| 448 | |
| 449 | const char *mdesc_node_name(struct mdesc_handle *hp, u64 node) |
| 450 | { |
| 451 | struct mdesc_elem *ep, *base = node_block(&hp->mdesc); |
| 452 | const char *names = name_block(&hp->mdesc); |
| 453 | u64 last_node = hp->mdesc.node_sz / 16; |
| 454 | |
| 455 | if (node == MDESC_NODE_NULL || node >= last_node) |
| 456 | return NULL; |
| 457 | |
| 458 | ep = base + node; |
| 459 | if (ep->tag != MD_NODE) |
| 460 | return NULL; |
| 461 | |
| 462 | return names + ep->name_offset; |
| 463 | } |
| 464 | EXPORT_SYMBOL(mdesc_node_name); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 465 | |
| 466 | static void __init report_platform_properties(void) |
| 467 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 468 | struct mdesc_handle *hp = mdesc_grab(); |
| 469 | u64 pn = mdesc_node_by_name(hp, MDESC_NODE_NULL, "platform"); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 470 | const char *s; |
| 471 | const u64 *v; |
| 472 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 473 | if (pn == MDESC_NODE_NULL) { |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 474 | prom_printf("No platform node in machine-description.\n"); |
| 475 | prom_halt(); |
| 476 | } |
| 477 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 478 | s = mdesc_get_property(hp, pn, "banner-name", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 479 | printk("PLATFORM: banner-name [%s]\n", s); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 480 | s = mdesc_get_property(hp, pn, "name", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 481 | printk("PLATFORM: name [%s]\n", s); |
| 482 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 483 | v = mdesc_get_property(hp, pn, "hostid", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 484 | if (v) |
| 485 | printk("PLATFORM: hostid [%08lx]\n", *v); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 486 | v = mdesc_get_property(hp, pn, "serial#", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 487 | if (v) |
| 488 | printk("PLATFORM: serial# [%08lx]\n", *v); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 489 | v = mdesc_get_property(hp, pn, "stick-frequency", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 490 | printk("PLATFORM: stick-frequency [%08lx]\n", *v); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 491 | v = mdesc_get_property(hp, pn, "mac-address", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 492 | if (v) |
| 493 | printk("PLATFORM: mac-address [%lx]\n", *v); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 494 | v = mdesc_get_property(hp, pn, "watchdog-resolution", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 495 | if (v) |
| 496 | printk("PLATFORM: watchdog-resolution [%lu ms]\n", *v); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 497 | v = mdesc_get_property(hp, pn, "watchdog-max-timeout", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 498 | if (v) |
| 499 | printk("PLATFORM: watchdog-max-timeout [%lu ms]\n", *v); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 500 | v = mdesc_get_property(hp, pn, "max-cpus", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 501 | if (v) |
| 502 | printk("PLATFORM: max-cpus [%lu]\n", *v); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 503 | |
David S. Miller | 4f0234f | 2007-07-13 16:03:42 -0700 | [diff] [blame] | 504 | #ifdef CONFIG_SMP |
| 505 | { |
| 506 | int max_cpu, i; |
| 507 | |
| 508 | if (v) { |
| 509 | max_cpu = *v; |
| 510 | if (max_cpu > NR_CPUS) |
| 511 | max_cpu = NR_CPUS; |
| 512 | } else { |
| 513 | max_cpu = NR_CPUS; |
| 514 | } |
| 515 | for (i = 0; i < max_cpu; i++) |
| 516 | cpu_set(i, cpu_possible_map); |
| 517 | } |
| 518 | #endif |
| 519 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 520 | mdesc_release(hp); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | static int inline find_in_proplist(const char *list, const char *match, int len) |
| 524 | { |
| 525 | while (len > 0) { |
| 526 | int l; |
| 527 | |
| 528 | if (!strcmp(list, match)) |
| 529 | return 1; |
| 530 | l = strlen(list) + 1; |
| 531 | list += l; |
| 532 | len -= l; |
| 533 | } |
| 534 | return 0; |
| 535 | } |
| 536 | |
David S. Miller | 4f0234f | 2007-07-13 16:03:42 -0700 | [diff] [blame] | 537 | static void __devinit fill_in_one_cache(cpuinfo_sparc *c, |
| 538 | struct mdesc_handle *hp, |
| 539 | u64 mp) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 540 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 541 | const u64 *level = mdesc_get_property(hp, mp, "level", NULL); |
| 542 | const u64 *size = mdesc_get_property(hp, mp, "size", NULL); |
| 543 | 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] | 544 | const char *type; |
| 545 | int type_len; |
| 546 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 547 | type = mdesc_get_property(hp, mp, "type", &type_len); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 548 | |
| 549 | switch (*level) { |
| 550 | case 1: |
| 551 | if (find_in_proplist(type, "instn", type_len)) { |
| 552 | c->icache_size = *size; |
| 553 | c->icache_line_size = *line_size; |
| 554 | } else if (find_in_proplist(type, "data", type_len)) { |
| 555 | c->dcache_size = *size; |
| 556 | c->dcache_line_size = *line_size; |
| 557 | } |
| 558 | break; |
| 559 | |
| 560 | case 2: |
| 561 | c->ecache_size = *size; |
| 562 | c->ecache_line_size = *line_size; |
| 563 | break; |
| 564 | |
| 565 | default: |
| 566 | break; |
| 567 | } |
| 568 | |
| 569 | if (*level == 1) { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 570 | u64 a; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 571 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 572 | mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) { |
| 573 | u64 target = mdesc_arc_target(hp, a); |
| 574 | const char *name = mdesc_node_name(hp, target); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 575 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 576 | if (!strcmp(name, "cache")) |
| 577 | fill_in_one_cache(c, hp, target); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | } |
| 581 | |
David S. Miller | 4f0234f | 2007-07-13 16:03:42 -0700 | [diff] [blame] | 582 | static void __devinit mark_core_ids(struct mdesc_handle *hp, u64 mp, |
| 583 | int core_id) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 584 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 585 | u64 a; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 586 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 587 | mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_BACK) { |
| 588 | u64 t = mdesc_arc_target(hp, a); |
| 589 | const char *name; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 590 | const u64 *id; |
| 591 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 592 | name = mdesc_node_name(hp, t); |
| 593 | if (!strcmp(name, "cpu")) { |
| 594 | id = mdesc_get_property(hp, t, "id", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 595 | if (*id < NR_CPUS) |
| 596 | cpu_data(*id).core_id = core_id; |
| 597 | } else { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 598 | u64 j; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 599 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 600 | mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_BACK) { |
| 601 | u64 n = mdesc_arc_target(hp, j); |
| 602 | const char *n_name; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 603 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 604 | n_name = mdesc_node_name(hp, n); |
| 605 | if (strcmp(n_name, "cpu")) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 606 | continue; |
| 607 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 608 | id = mdesc_get_property(hp, n, "id", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 609 | if (*id < NR_CPUS) |
| 610 | cpu_data(*id).core_id = core_id; |
| 611 | } |
| 612 | } |
| 613 | } |
| 614 | } |
| 615 | |
David S. Miller | 4f0234f | 2007-07-13 16:03:42 -0700 | [diff] [blame] | 616 | static void __devinit set_core_ids(struct mdesc_handle *hp) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 617 | { |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 618 | int idx; |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 619 | u64 mp; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 620 | |
| 621 | idx = 1; |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 622 | mdesc_for_each_node_by_name(hp, mp, "cache") { |
| 623 | const u64 *level; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 624 | const char *type; |
| 625 | int len; |
| 626 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 627 | level = mdesc_get_property(hp, mp, "level", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 628 | if (*level != 1) |
| 629 | continue; |
| 630 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 631 | type = mdesc_get_property(hp, mp, "type", &len); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 632 | if (!find_in_proplist(type, "instn", len)) |
| 633 | continue; |
| 634 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 635 | mark_core_ids(hp, mp, idx); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 636 | |
| 637 | idx++; |
| 638 | } |
| 639 | } |
| 640 | |
David S. Miller | 4f0234f | 2007-07-13 16:03:42 -0700 | [diff] [blame] | 641 | static void __devinit mark_proc_ids(struct mdesc_handle *hp, u64 mp, |
| 642 | int proc_id) |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 643 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 644 | u64 a; |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 645 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 646 | mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_BACK) { |
| 647 | u64 t = mdesc_arc_target(hp, a); |
| 648 | const char *name; |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 649 | const u64 *id; |
| 650 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 651 | name = mdesc_node_name(hp, t); |
| 652 | if (strcmp(name, "cpu")) |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 653 | continue; |
| 654 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 655 | id = mdesc_get_property(hp, t, "id", NULL); |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 656 | if (*id < NR_CPUS) |
| 657 | cpu_data(*id).proc_id = proc_id; |
| 658 | } |
| 659 | } |
| 660 | |
David S. Miller | 4f0234f | 2007-07-13 16:03:42 -0700 | [diff] [blame] | 661 | static void __devinit __set_proc_ids(struct mdesc_handle *hp, |
| 662 | const char *exec_unit_name) |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 663 | { |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 664 | int idx; |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 665 | u64 mp; |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 666 | |
| 667 | idx = 0; |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 668 | mdesc_for_each_node_by_name(hp, mp, exec_unit_name) { |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 669 | const char *type; |
| 670 | int len; |
| 671 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 672 | type = mdesc_get_property(hp, mp, "type", &len); |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 673 | if (!find_in_proplist(type, "int", len) && |
| 674 | !find_in_proplist(type, "integer", len)) |
| 675 | continue; |
| 676 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 677 | mark_proc_ids(hp, mp, idx); |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 678 | |
| 679 | idx++; |
| 680 | } |
| 681 | } |
| 682 | |
David S. Miller | 4f0234f | 2007-07-13 16:03:42 -0700 | [diff] [blame] | 683 | static void __devinit set_proc_ids(struct mdesc_handle *hp) |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 684 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 685 | __set_proc_ids(hp, "exec_unit"); |
| 686 | __set_proc_ids(hp, "exec-unit"); |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 687 | } |
| 688 | |
David S. Miller | 4f0234f | 2007-07-13 16:03:42 -0700 | [diff] [blame] | 689 | static void __devinit get_one_mondo_bits(const u64 *p, unsigned int *mask, |
| 690 | unsigned char def) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 691 | { |
| 692 | u64 val; |
| 693 | |
| 694 | if (!p) |
| 695 | goto use_default; |
| 696 | val = *p; |
| 697 | |
| 698 | if (!val || val >= 64) |
| 699 | goto use_default; |
| 700 | |
| 701 | *mask = ((1U << val) * 64U) - 1U; |
| 702 | return; |
| 703 | |
| 704 | use_default: |
| 705 | *mask = ((1U << def) * 64U) - 1U; |
| 706 | } |
| 707 | |
David S. Miller | 4f0234f | 2007-07-13 16:03:42 -0700 | [diff] [blame] | 708 | static void __devinit get_mondo_data(struct mdesc_handle *hp, u64 mp, |
| 709 | struct trap_per_cpu *tb) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 710 | { |
| 711 | const u64 *val; |
| 712 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 713 | val = mdesc_get_property(hp, mp, "q-cpu-mondo-#bits", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 714 | get_one_mondo_bits(val, &tb->cpu_mondo_qmask, 7); |
| 715 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 716 | val = mdesc_get_property(hp, mp, "q-dev-mondo-#bits", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 717 | get_one_mondo_bits(val, &tb->dev_mondo_qmask, 7); |
| 718 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 719 | val = mdesc_get_property(hp, mp, "q-resumable-#bits", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 720 | get_one_mondo_bits(val, &tb->resum_qmask, 6); |
| 721 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 722 | val = mdesc_get_property(hp, mp, "q-nonresumable-#bits", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 723 | get_one_mondo_bits(val, &tb->nonresum_qmask, 2); |
| 724 | } |
| 725 | |
David S. Miller | 4f0234f | 2007-07-13 16:03:42 -0700 | [diff] [blame] | 726 | void __devinit mdesc_fill_in_cpu_data(cpumask_t mask) |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 727 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 728 | struct mdesc_handle *hp = mdesc_grab(); |
| 729 | u64 mp; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 730 | |
| 731 | ncpus_probed = 0; |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 732 | mdesc_for_each_node_by_name(hp, mp, "cpu") { |
| 733 | const u64 *id = mdesc_get_property(hp, mp, "id", NULL); |
| 734 | const u64 *cfreq = mdesc_get_property(hp, mp, "clock-frequency", NULL); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 735 | struct trap_per_cpu *tb; |
| 736 | cpuinfo_sparc *c; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 737 | int cpuid; |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 738 | u64 a; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 739 | |
| 740 | ncpus_probed++; |
| 741 | |
| 742 | cpuid = *id; |
| 743 | |
| 744 | #ifdef CONFIG_SMP |
| 745 | if (cpuid >= NR_CPUS) |
| 746 | continue; |
David S. Miller | 4f0234f | 2007-07-13 16:03:42 -0700 | [diff] [blame] | 747 | if (!cpu_isset(cpuid, mask)) |
| 748 | continue; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 749 | #else |
| 750 | /* On uniprocessor we only want the values for the |
| 751 | * real physical cpu the kernel booted onto, however |
| 752 | * cpu_data() only has one entry at index 0. |
| 753 | */ |
| 754 | if (cpuid != real_hard_smp_processor_id()) |
| 755 | continue; |
| 756 | cpuid = 0; |
| 757 | #endif |
| 758 | |
| 759 | c = &cpu_data(cpuid); |
| 760 | c->clock_tick = *cfreq; |
| 761 | |
| 762 | tb = &trap_block[cpuid]; |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 763 | get_mondo_data(hp, mp, tb); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 764 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 765 | mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) { |
| 766 | u64 j, t = mdesc_arc_target(hp, a); |
| 767 | const char *t_name; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 768 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 769 | t_name = mdesc_node_name(hp, t); |
| 770 | if (!strcmp(t_name, "cache")) { |
| 771 | fill_in_one_cache(c, hp, t); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 772 | continue; |
| 773 | } |
| 774 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 775 | mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_FWD) { |
| 776 | u64 n = mdesc_arc_target(hp, j); |
| 777 | const char *n_name; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 778 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 779 | n_name = mdesc_node_name(hp, n); |
| 780 | if (!strcmp(n_name, "cache")) |
| 781 | fill_in_one_cache(c, hp, n); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 782 | } |
| 783 | } |
| 784 | |
| 785 | #ifdef CONFIG_SMP |
| 786 | cpu_set(cpuid, cpu_present_map); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 787 | #endif |
| 788 | |
| 789 | c->core_id = 0; |
David S. Miller | f78eae2 | 2007-06-04 17:01:39 -0700 | [diff] [blame] | 790 | c->proc_id = -1; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 791 | } |
| 792 | |
David S. Miller | a2f9f6b | 2007-06-04 21:48:33 -0700 | [diff] [blame] | 793 | #ifdef CONFIG_SMP |
| 794 | sparc64_multi_core = 1; |
| 795 | #endif |
| 796 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 797 | set_core_ids(hp); |
| 798 | set_proc_ids(hp); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 799 | |
| 800 | smp_fill_in_sib_core_maps(); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 801 | |
| 802 | mdesc_release(hp); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | void __init sun4v_mdesc_init(void) |
| 806 | { |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 807 | struct mdesc_handle *hp; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 808 | unsigned long len, real_len, status; |
David S. Miller | 4f0234f | 2007-07-13 16:03:42 -0700 | [diff] [blame] | 809 | cpumask_t mask; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 810 | |
| 811 | (void) sun4v_mach_desc(0UL, 0UL, &len); |
| 812 | |
| 813 | printk("MDESC: Size is %lu bytes.\n", len); |
| 814 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 815 | hp = mdesc_alloc(len, &bootmem_mdesc_memops); |
| 816 | if (hp == NULL) { |
| 817 | prom_printf("MDESC: alloc of %lu bytes failed.\n", len); |
| 818 | prom_halt(); |
| 819 | } |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 820 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 821 | status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 822 | if (status != HV_EOK || real_len > len) { |
| 823 | prom_printf("sun4v_mach_desc fails, err(%lu), " |
| 824 | "len(%lu), real_len(%lu)\n", |
| 825 | status, len, real_len); |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 826 | mdesc_free(hp); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 827 | prom_halt(); |
| 828 | } |
| 829 | |
David S. Miller | 43fdf27 | 2007-07-12 13:47:50 -0700 | [diff] [blame] | 830 | cur_mdesc = hp; |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 831 | |
| 832 | report_platform_properties(); |
David S. Miller | 4f0234f | 2007-07-13 16:03:42 -0700 | [diff] [blame] | 833 | |
| 834 | cpus_setall(mask); |
| 835 | mdesc_fill_in_cpu_data(mask); |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 836 | } |