1 /* mdesc.c: Sun4V machine description handling.
3 * Copyright (C) 2007, 2008 David S. Miller <davem@davemloft.net>
5 #include <linux/kernel.h>
6 #include <linux/types.h>
7 #include <linux/memblock.h>
8 #include <linux/log2.h>
9 #include <linux/list.h>
10 #include <linux/slab.h>
12 #include <linux/miscdevice.h>
13 #include <linux/bootmem.h>
14 #include <linux/export.h>
16 #include <asm/cpudata.h>
17 #include <asm/hypervisor.h>
18 #include <asm/mdesc.h>
20 #include <asm/uaccess.h>
21 #include <asm/oplib.h>
24 /* Unlike the OBP device tree, the machine description is a full-on
25 * DAG. An arbitrary number of ARCs are possible from one
26 * node to other nodes and thus we can't use the OBP device_node
27 * data structure to represent these nodes inside of the kernel.
29 * Actually, it isn't even a DAG, because there are back pointers
30 * which create cycles in the graph.
32 * mdesc_hdr and mdesc_elem describe the layout of the data structure
33 * we get from the Hypervisor.
36 u32 version; /* Transport version */
37 u32 node_sz; /* node block size */
38 u32 name_sz; /* name block size */
39 u32 data_sz; /* data block size */
41 } __attribute__((aligned(16)));
45 #define MD_LIST_END 0x00
47 #define MD_NODE_END 0x45
49 #define MD_PROP_ARC 0x61
50 #define MD_PROP_VAL 0x76
51 #define MD_PROP_STR 0x73
52 #define MD_PROP_DATA 0x64
65 struct mdesc_mem_ops {
66 struct mdesc_handle *(*alloc)(unsigned int mdesc_size);
67 void (*free)(struct mdesc_handle *handle);
71 struct list_head list;
72 struct mdesc_mem_ops *mops;
75 unsigned int handle_size;
76 struct mdesc_hdr mdesc;
79 static void mdesc_handle_init(struct mdesc_handle *hp,
80 unsigned int handle_size,
83 BUG_ON(((unsigned long)&hp->mdesc) & (16UL - 1));
85 memset(hp, 0, handle_size);
86 INIT_LIST_HEAD(&hp->list);
88 atomic_set(&hp->refcnt, 1);
89 hp->handle_size = handle_size;
92 static struct mdesc_handle * __init mdesc_memblock_alloc(unsigned int mdesc_size)
94 unsigned int handle_size, alloc_size;
95 struct mdesc_handle *hp;
98 handle_size = (sizeof(struct mdesc_handle) -
99 sizeof(struct mdesc_hdr) +
101 alloc_size = PAGE_ALIGN(handle_size);
103 paddr = memblock_alloc(alloc_size, PAGE_SIZE);
108 mdesc_handle_init(hp, handle_size, hp);
113 static void __init mdesc_memblock_free(struct mdesc_handle *hp)
115 unsigned int alloc_size;
118 BUG_ON(atomic_read(&hp->refcnt) != 0);
119 BUG_ON(!list_empty(&hp->list));
121 alloc_size = PAGE_ALIGN(hp->handle_size);
123 free_bootmem_late(start, alloc_size);
126 static struct mdesc_mem_ops memblock_mdesc_ops = {
127 .alloc = mdesc_memblock_alloc,
128 .free = mdesc_memblock_free,
131 static struct mdesc_handle *mdesc_kmalloc(unsigned int mdesc_size)
133 unsigned int handle_size;
134 struct mdesc_handle *hp;
138 handle_size = (sizeof(struct mdesc_handle) -
139 sizeof(struct mdesc_hdr) +
143 * Allocation has to succeed because mdesc update would be missed
144 * and such events are not retransmitted.
146 base = kmalloc(handle_size + 15, GFP_KERNEL | __GFP_NOFAIL);
147 addr = (unsigned long)base;
148 addr = (addr + 15UL) & ~15UL;
149 hp = (struct mdesc_handle *) addr;
151 mdesc_handle_init(hp, handle_size, base);
156 static void mdesc_kfree(struct mdesc_handle *hp)
158 BUG_ON(atomic_read(&hp->refcnt) != 0);
159 BUG_ON(!list_empty(&hp->list));
161 kfree(hp->self_base);
164 static struct mdesc_mem_ops kmalloc_mdesc_memops = {
165 .alloc = mdesc_kmalloc,
169 static struct mdesc_handle *mdesc_alloc(unsigned int mdesc_size,
170 struct mdesc_mem_ops *mops)
172 struct mdesc_handle *hp = mops->alloc(mdesc_size);
180 static void mdesc_free(struct mdesc_handle *hp)
185 static struct mdesc_handle *cur_mdesc;
186 static LIST_HEAD(mdesc_zombie_list);
187 static DEFINE_SPINLOCK(mdesc_lock);
189 struct mdesc_handle *mdesc_grab(void)
191 struct mdesc_handle *hp;
194 spin_lock_irqsave(&mdesc_lock, flags);
197 atomic_inc(&hp->refcnt);
198 spin_unlock_irqrestore(&mdesc_lock, flags);
202 EXPORT_SYMBOL(mdesc_grab);
204 void mdesc_release(struct mdesc_handle *hp)
208 spin_lock_irqsave(&mdesc_lock, flags);
209 if (atomic_dec_and_test(&hp->refcnt)) {
210 list_del_init(&hp->list);
213 spin_unlock_irqrestore(&mdesc_lock, flags);
215 EXPORT_SYMBOL(mdesc_release);
217 static DEFINE_MUTEX(mdesc_mutex);
218 static struct mdesc_notifier_client *client_list;
220 void mdesc_register_notifier(struct mdesc_notifier_client *client)
224 mutex_lock(&mdesc_mutex);
225 client->next = client_list;
226 client_list = client;
228 mdesc_for_each_node_by_name(cur_mdesc, node, client->node_name)
229 client->add(cur_mdesc, node);
231 mutex_unlock(&mdesc_mutex);
234 static const u64 *parent_cfg_handle(struct mdesc_handle *hp, u64 node)
240 mdesc_for_each_arc(a, hp, node, MDESC_ARC_TYPE_BACK) {
243 target = mdesc_arc_target(hp, a);
244 id = mdesc_get_property(hp, target,
253 /* Run 'func' on nodes which are in A but not in B. */
254 static void invoke_on_missing(const char *name,
255 struct mdesc_handle *a,
256 struct mdesc_handle *b,
257 void (*func)(struct mdesc_handle *, u64))
261 mdesc_for_each_node_by_name(a, node, name) {
262 int found = 0, is_vdc_port = 0;
263 const char *name_prop;
267 name_prop = mdesc_get_property(a, node, "name", NULL);
268 if (name_prop && !strcmp(name_prop, "vdc-port")) {
270 id = parent_cfg_handle(a, node);
272 id = mdesc_get_property(a, node, "id", NULL);
275 printk(KERN_ERR "MD: Cannot find ID for %s node.\n",
276 (name_prop ? name_prop : name));
280 mdesc_for_each_node_by_name(b, fnode, name) {
284 name_prop = mdesc_get_property(b, fnode,
287 strcmp(name_prop, "vdc-port"))
289 fid = parent_cfg_handle(b, fnode);
291 printk(KERN_ERR "MD: Cannot find ID "
292 "for vdc-port node.\n");
296 fid = mdesc_get_property(b, fnode,
309 static void notify_one(struct mdesc_notifier_client *p,
310 struct mdesc_handle *old_hp,
311 struct mdesc_handle *new_hp)
313 invoke_on_missing(p->node_name, old_hp, new_hp, p->remove);
314 invoke_on_missing(p->node_name, new_hp, old_hp, p->add);
317 static void mdesc_notify_clients(struct mdesc_handle *old_hp,
318 struct mdesc_handle *new_hp)
320 struct mdesc_notifier_client *p = client_list;
323 notify_one(p, old_hp, new_hp);
328 void mdesc_update(void)
330 unsigned long len, real_len, status;
331 struct mdesc_handle *hp, *orig_hp;
334 mutex_lock(&mdesc_mutex);
336 (void) sun4v_mach_desc(0UL, 0UL, &len);
338 hp = mdesc_alloc(len, &kmalloc_mdesc_memops);
340 printk(KERN_ERR "MD: mdesc alloc fails\n");
344 status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len);
345 if (status != HV_EOK || real_len > len) {
346 printk(KERN_ERR "MD: mdesc reread fails with %lu\n",
348 atomic_dec(&hp->refcnt);
353 spin_lock_irqsave(&mdesc_lock, flags);
356 spin_unlock_irqrestore(&mdesc_lock, flags);
358 mdesc_notify_clients(orig_hp, hp);
360 spin_lock_irqsave(&mdesc_lock, flags);
361 if (atomic_dec_and_test(&orig_hp->refcnt))
364 list_add(&orig_hp->list, &mdesc_zombie_list);
365 spin_unlock_irqrestore(&mdesc_lock, flags);
368 mutex_unlock(&mdesc_mutex);
371 static struct mdesc_elem *node_block(struct mdesc_hdr *mdesc)
373 return (struct mdesc_elem *) mdesc->data;
376 static void *name_block(struct mdesc_hdr *mdesc)
378 return ((void *) node_block(mdesc)) + mdesc->node_sz;
381 static void *data_block(struct mdesc_hdr *mdesc)
383 return ((void *) name_block(mdesc)) + mdesc->name_sz;
386 u64 mdesc_node_by_name(struct mdesc_handle *hp,
387 u64 from_node, const char *name)
389 struct mdesc_elem *ep = node_block(&hp->mdesc);
390 const char *names = name_block(&hp->mdesc);
391 u64 last_node = hp->mdesc.node_sz / 16;
394 if (from_node == MDESC_NODE_NULL) {
396 } else if (from_node >= last_node) {
397 return MDESC_NODE_NULL;
399 ret = ep[from_node].d.val;
402 while (ret < last_node) {
403 if (ep[ret].tag != MD_NODE)
404 return MDESC_NODE_NULL;
405 if (!strcmp(names + ep[ret].name_offset, name))
409 if (ret >= last_node)
410 ret = MDESC_NODE_NULL;
413 EXPORT_SYMBOL(mdesc_node_by_name);
415 const void *mdesc_get_property(struct mdesc_handle *hp, u64 node,
416 const char *name, int *lenp)
418 const char *names = name_block(&hp->mdesc);
419 u64 last_node = hp->mdesc.node_sz / 16;
420 void *data = data_block(&hp->mdesc);
421 struct mdesc_elem *ep;
423 if (node == MDESC_NODE_NULL || node >= last_node)
426 ep = node_block(&hp->mdesc) + node;
428 for (; ep->tag != MD_NODE_END; ep++) {
440 val = data + ep->d.data.data_offset;
441 len = ep->d.data.data_len;
450 if (!strcmp(names + ep->name_offset, name)) {
459 EXPORT_SYMBOL(mdesc_get_property);
461 u64 mdesc_next_arc(struct mdesc_handle *hp, u64 from, const char *arc_type)
463 struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
464 const char *names = name_block(&hp->mdesc);
465 u64 last_node = hp->mdesc.node_sz / 16;
467 if (from == MDESC_NODE_NULL || from >= last_node)
468 return MDESC_NODE_NULL;
473 for (; ep->tag != MD_NODE_END; ep++) {
474 if (ep->tag != MD_PROP_ARC)
477 if (strcmp(names + ep->name_offset, arc_type))
483 return MDESC_NODE_NULL;
485 EXPORT_SYMBOL(mdesc_next_arc);
487 u64 mdesc_arc_target(struct mdesc_handle *hp, u64 arc)
489 struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
495 EXPORT_SYMBOL(mdesc_arc_target);
497 const char *mdesc_node_name(struct mdesc_handle *hp, u64 node)
499 struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
500 const char *names = name_block(&hp->mdesc);
501 u64 last_node = hp->mdesc.node_sz / 16;
503 if (node == MDESC_NODE_NULL || node >= last_node)
507 if (ep->tag != MD_NODE)
510 return names + ep->name_offset;
512 EXPORT_SYMBOL(mdesc_node_name);
514 static u64 max_cpus = 64;
516 static void __init report_platform_properties(void)
518 struct mdesc_handle *hp = mdesc_grab();
519 u64 pn = mdesc_node_by_name(hp, MDESC_NODE_NULL, "platform");
523 if (pn == MDESC_NODE_NULL) {
524 prom_printf("No platform node in machine-description.\n");
528 s = mdesc_get_property(hp, pn, "banner-name", NULL);
529 printk("PLATFORM: banner-name [%s]\n", s);
530 s = mdesc_get_property(hp, pn, "name", NULL);
531 printk("PLATFORM: name [%s]\n", s);
533 v = mdesc_get_property(hp, pn, "hostid", NULL);
535 printk("PLATFORM: hostid [%08llx]\n", *v);
536 v = mdesc_get_property(hp, pn, "serial#", NULL);
538 printk("PLATFORM: serial# [%08llx]\n", *v);
539 v = mdesc_get_property(hp, pn, "stick-frequency", NULL);
540 printk("PLATFORM: stick-frequency [%08llx]\n", *v);
541 v = mdesc_get_property(hp, pn, "mac-address", NULL);
543 printk("PLATFORM: mac-address [%llx]\n", *v);
544 v = mdesc_get_property(hp, pn, "watchdog-resolution", NULL);
546 printk("PLATFORM: watchdog-resolution [%llu ms]\n", *v);
547 v = mdesc_get_property(hp, pn, "watchdog-max-timeout", NULL);
549 printk("PLATFORM: watchdog-max-timeout [%llu ms]\n", *v);
550 v = mdesc_get_property(hp, pn, "max-cpus", NULL);
553 printk("PLATFORM: max-cpus [%llu]\n", max_cpus);
562 if (max_cpu > NR_CPUS)
567 for (i = 0; i < max_cpu; i++)
568 set_cpu_possible(i, true);
575 static void fill_in_one_cache(cpuinfo_sparc *c, struct mdesc_handle *hp, u64 mp)
577 const u64 *level = mdesc_get_property(hp, mp, "level", NULL);
578 const u64 *size = mdesc_get_property(hp, mp, "size", NULL);
579 const u64 *line_size = mdesc_get_property(hp, mp, "line-size", NULL);
583 type = mdesc_get_property(hp, mp, "type", &type_len);
587 if (of_find_in_proplist(type, "instn", type_len)) {
588 c->icache_size = *size;
589 c->icache_line_size = *line_size;
590 } else if (of_find_in_proplist(type, "data", type_len)) {
591 c->dcache_size = *size;
592 c->dcache_line_size = *line_size;
597 c->ecache_size = *size;
598 c->ecache_line_size = *line_size;
608 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) {
609 u64 target = mdesc_arc_target(hp, a);
610 const char *name = mdesc_node_name(hp, target);
612 if (!strcmp(name, "cache"))
613 fill_in_one_cache(c, hp, target);
618 static void find_back_node_value(struct mdesc_handle *hp, u64 node,
620 void (*func)(struct mdesc_handle *, u64, int),
625 /* Since we have an estimate of recursion depth, do a sanity check. */
629 mdesc_for_each_arc(arc, hp, node, MDESC_ARC_TYPE_BACK) {
630 u64 n = mdesc_arc_target(hp, arc);
631 const char *name = mdesc_node_name(hp, n);
633 if (!strcmp(srch_val, name))
636 find_back_node_value(hp, n, srch_val, func, val, depth-1);
640 static void __mark_core_id(struct mdesc_handle *hp, u64 node,
643 const u64 *id = mdesc_get_property(hp, node, "id", NULL);
645 if (*id < num_possible_cpus())
646 cpu_data(*id).core_id = core_id;
649 static void __mark_max_cache_id(struct mdesc_handle *hp, u64 node,
652 const u64 *id = mdesc_get_property(hp, node, "id", NULL);
654 if (*id < num_possible_cpus()) {
655 cpu_data(*id).max_cache_id = max_cache_id;
658 * On systems without explicit socket descriptions socket
661 cpu_data(*id).sock_id = max_cache_id;
665 static void mark_core_ids(struct mdesc_handle *hp, u64 mp,
668 find_back_node_value(hp, mp, "cpu", __mark_core_id, core_id, 10);
671 static void mark_max_cache_ids(struct mdesc_handle *hp, u64 mp,
674 find_back_node_value(hp, mp, "cpu", __mark_max_cache_id,
678 static void set_core_ids(struct mdesc_handle *hp)
685 /* Identify unique cores by looking for cpus backpointed to by
686 * level 1 instruction caches.
688 mdesc_for_each_node_by_name(hp, mp, "cache") {
693 level = mdesc_get_property(hp, mp, "level", NULL);
697 type = mdesc_get_property(hp, mp, "type", &len);
698 if (!of_find_in_proplist(type, "instn", len))
701 mark_core_ids(hp, mp, idx);
706 static int set_max_cache_ids_by_cache(struct mdesc_handle *hp, int level)
713 * Identify unique highest level of shared cache by looking for cpus
714 * backpointed to by shared level N caches.
716 mdesc_for_each_node_by_name(hp, mp, "cache") {
719 cur_lvl = mdesc_get_property(hp, mp, "level", NULL);
720 if (*cur_lvl != level)
722 mark_max_cache_ids(hp, mp, idx);
729 static void set_sock_ids_by_socket(struct mdesc_handle *hp, u64 mp)
733 mdesc_for_each_node_by_name(hp, mp, "socket") {
736 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) {
737 u64 t = mdesc_arc_target(hp, a);
741 name = mdesc_node_name(hp, t);
742 if (strcmp(name, "cpu"))
745 id = mdesc_get_property(hp, t, "id", NULL);
746 if (*id < num_possible_cpus())
747 cpu_data(*id).sock_id = idx;
753 static void set_sock_ids(struct mdesc_handle *hp)
758 * Find the highest level of shared cache which pre-T7 is also
761 if (!set_max_cache_ids_by_cache(hp, 3))
762 set_max_cache_ids_by_cache(hp, 2);
764 /* If machine description exposes sockets data use it.*/
765 mp = mdesc_node_by_name(hp, MDESC_NODE_NULL, "sockets");
766 if (mp != MDESC_NODE_NULL)
767 set_sock_ids_by_socket(hp, mp);
770 static void mark_proc_ids(struct mdesc_handle *hp, u64 mp, int proc_id)
774 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_BACK) {
775 u64 t = mdesc_arc_target(hp, a);
779 name = mdesc_node_name(hp, t);
780 if (strcmp(name, "cpu"))
783 id = mdesc_get_property(hp, t, "id", NULL);
785 cpu_data(*id).proc_id = proc_id;
789 static void __set_proc_ids(struct mdesc_handle *hp, const char *exec_unit_name)
795 mdesc_for_each_node_by_name(hp, mp, exec_unit_name) {
799 type = mdesc_get_property(hp, mp, "type", &len);
800 if (!of_find_in_proplist(type, "int", len) &&
801 !of_find_in_proplist(type, "integer", len))
804 mark_proc_ids(hp, mp, idx);
809 static void set_proc_ids(struct mdesc_handle *hp)
811 __set_proc_ids(hp, "exec_unit");
812 __set_proc_ids(hp, "exec-unit");
815 static void get_one_mondo_bits(const u64 *p, unsigned int *mask,
816 unsigned long def, unsigned long max)
824 if (!val || val >= 64)
830 *mask = ((1U << val) * 64U) - 1U;
834 *mask = ((1U << def) * 64U) - 1U;
837 static void get_mondo_data(struct mdesc_handle *hp, u64 mp,
838 struct trap_per_cpu *tb)
843 val = mdesc_get_property(hp, mp, "q-cpu-mondo-#bits", NULL);
844 get_one_mondo_bits(val, &tb->cpu_mondo_qmask, 7, ilog2(max_cpus * 2));
846 val = mdesc_get_property(hp, mp, "q-dev-mondo-#bits", NULL);
847 get_one_mondo_bits(val, &tb->dev_mondo_qmask, 7, 8);
849 val = mdesc_get_property(hp, mp, "q-resumable-#bits", NULL);
850 get_one_mondo_bits(val, &tb->resum_qmask, 6, 7);
852 val = mdesc_get_property(hp, mp, "q-nonresumable-#bits", NULL);
853 get_one_mondo_bits(val, &tb->nonresum_qmask, 2, 2);
855 pr_info("SUN4V: Mondo queue sizes "
856 "[cpu(%u) dev(%u) r(%u) nr(%u)]\n",
857 tb->cpu_mondo_qmask + 1,
858 tb->dev_mondo_qmask + 1,
860 tb->nonresum_qmask + 1);
864 static void *mdesc_iterate_over_cpus(void *(*func)(struct mdesc_handle *, u64, int, void *), void *arg, cpumask_t *mask)
866 struct mdesc_handle *hp = mdesc_grab();
870 mdesc_for_each_node_by_name(hp, mp, "cpu") {
871 const u64 *id = mdesc_get_property(hp, mp, "id", NULL);
875 if (cpuid >= NR_CPUS) {
876 printk(KERN_WARNING "Ignoring CPU %d which is "
881 if (!cpumask_test_cpu(cpuid, mask))
885 ret = func(hp, mp, cpuid, arg);
894 static void *record_one_cpu(struct mdesc_handle *hp, u64 mp, int cpuid,
899 set_cpu_present(cpuid, true);
904 void mdesc_populate_present_mask(cpumask_t *mask)
906 if (tlb_type != hypervisor)
910 mdesc_iterate_over_cpus(record_one_cpu, NULL, mask);
913 static void * __init check_one_pgsz(struct mdesc_handle *hp, u64 mp, int cpuid, void *arg)
915 const u64 *pgsz_prop = mdesc_get_property(hp, mp, "mmu-page-size-list", NULL);
916 unsigned long *pgsz_mask = arg;
919 val = (HV_PGSZ_MASK_8K | HV_PGSZ_MASK_64K |
920 HV_PGSZ_MASK_512K | HV_PGSZ_MASK_4MB);
931 void __init mdesc_get_page_sizes(cpumask_t *mask, unsigned long *pgsz_mask)
934 mdesc_iterate_over_cpus(check_one_pgsz, pgsz_mask, mask);
937 static void *fill_in_one_cpu(struct mdesc_handle *hp, u64 mp, int cpuid,
940 const u64 *cfreq = mdesc_get_property(hp, mp, "clock-frequency", NULL);
941 struct trap_per_cpu *tb;
946 /* On uniprocessor we only want the values for the
947 * real physical cpu the kernel booted onto, however
948 * cpu_data() only has one entry at index 0.
950 if (cpuid != real_hard_smp_processor_id())
955 c = &cpu_data(cpuid);
956 c->clock_tick = *cfreq;
958 tb = &trap_block[cpuid];
959 get_mondo_data(hp, mp, tb);
961 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) {
962 u64 j, t = mdesc_arc_target(hp, a);
965 t_name = mdesc_node_name(hp, t);
966 if (!strcmp(t_name, "cache")) {
967 fill_in_one_cache(c, hp, t);
971 mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_FWD) {
972 u64 n = mdesc_arc_target(hp, j);
975 n_name = mdesc_node_name(hp, n);
976 if (!strcmp(n_name, "cache"))
977 fill_in_one_cache(c, hp, n);
987 void mdesc_fill_in_cpu_data(cpumask_t *mask)
989 struct mdesc_handle *hp;
991 mdesc_iterate_over_cpus(fill_in_one_cpu, NULL, mask);
1001 smp_fill_in_sib_core_maps();
1004 /* mdesc_open() - Grab a reference to mdesc_handle when /dev/mdesc is
1005 * opened. Hold this reference until /dev/mdesc is closed to ensure
1006 * mdesc data structure is not released underneath us. Store the
1007 * pointer to mdesc structure in private_data for read and seek to use
1009 static int mdesc_open(struct inode *inode, struct file *file)
1011 struct mdesc_handle *hp = mdesc_grab();
1016 file->private_data = hp;
1021 static ssize_t mdesc_read(struct file *file, char __user *buf,
1022 size_t len, loff_t *offp)
1024 struct mdesc_handle *hp = file->private_data;
1025 unsigned char *mdesc;
1026 int bytes_left, count = len;
1028 if (*offp >= hp->handle_size)
1031 bytes_left = hp->handle_size - *offp;
1032 if (count > bytes_left)
1035 mdesc = (unsigned char *)&hp->mdesc;
1037 if (!copy_to_user(buf, mdesc, count)) {
1045 static loff_t mdesc_llseek(struct file *file, loff_t offset, int whence)
1047 struct mdesc_handle *hp = file->private_data;
1049 return no_seek_end_llseek_size(file, offset, whence, hp->handle_size);
1052 /* mdesc_close() - /dev/mdesc is being closed, release the reference to
1055 static int mdesc_close(struct inode *inode, struct file *file)
1057 mdesc_release(file->private_data);
1061 static const struct file_operations mdesc_fops = {
1064 .llseek = mdesc_llseek,
1065 .release = mdesc_close,
1066 .owner = THIS_MODULE,
1069 static struct miscdevice mdesc_misc = {
1070 .minor = MISC_DYNAMIC_MINOR,
1072 .fops = &mdesc_fops,
1075 static int __init mdesc_misc_init(void)
1077 return misc_register(&mdesc_misc);
1080 __initcall(mdesc_misc_init);
1082 void __init sun4v_mdesc_init(void)
1084 struct mdesc_handle *hp;
1085 unsigned long len, real_len, status;
1087 (void) sun4v_mach_desc(0UL, 0UL, &len);
1089 printk("MDESC: Size is %lu bytes.\n", len);
1091 hp = mdesc_alloc(len, &memblock_mdesc_ops);
1093 prom_printf("MDESC: alloc of %lu bytes failed.\n", len);
1097 status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len);
1098 if (status != HV_EOK || real_len > len) {
1099 prom_printf("sun4v_mach_desc fails, err(%lu), "
1100 "len(%lu), real_len(%lu)\n",
1101 status, len, real_len);
1108 report_platform_properties();