Lines Matching +full:hp +full:- +full:cfg

1 // SPDX-License-Identifier: GPL-2.0
26 /* Unlike the OBP device tree, the machine description is a full-on
107 {"virtual-device-port", get_vdev_port_node_info,
109 {"domain-services-port", get_ds_port_node_info,
149 static void mdesc_handle_init(struct mdesc_handle *hp, in mdesc_handle_init() argument
153 BUG_ON(((unsigned long)&hp->mdesc) & (16UL - 1)); in mdesc_handle_init()
155 memset(hp, 0, handle_size); in mdesc_handle_init()
156 INIT_LIST_HEAD(&hp->list); in mdesc_handle_init()
157 hp->self_base = base; in mdesc_handle_init()
158 refcount_set(&hp->refcnt, 1); in mdesc_handle_init()
159 hp->handle_size = handle_size; in mdesc_handle_init()
165 struct mdesc_handle *hp; in mdesc_memblock_alloc() local
168 handle_size = (sizeof(struct mdesc_handle) - in mdesc_memblock_alloc()
175 hp = NULL; in mdesc_memblock_alloc()
177 hp = __va(paddr); in mdesc_memblock_alloc()
178 mdesc_handle_init(hp, handle_size, hp); in mdesc_memblock_alloc()
180 return hp; in mdesc_memblock_alloc()
183 static void __init mdesc_memblock_free(struct mdesc_handle *hp) in mdesc_memblock_free() argument
188 BUG_ON(refcount_read(&hp->refcnt) != 0); in mdesc_memblock_free()
189 BUG_ON(!list_empty(&hp->list)); in mdesc_memblock_free()
191 alloc_size = PAGE_ALIGN(hp->handle_size); in mdesc_memblock_free()
192 start = __pa(hp); in mdesc_memblock_free()
204 struct mdesc_handle *hp; in mdesc_kmalloc() local
208 handle_size = (sizeof(struct mdesc_handle) - in mdesc_kmalloc()
217 hp = (struct mdesc_handle *) addr; in mdesc_kmalloc()
219 mdesc_handle_init(hp, handle_size, base); in mdesc_kmalloc()
221 return hp; in mdesc_kmalloc()
224 static void mdesc_kfree(struct mdesc_handle *hp) in mdesc_kfree() argument
226 BUG_ON(refcount_read(&hp->refcnt) != 0); in mdesc_kfree()
227 BUG_ON(!list_empty(&hp->list)); in mdesc_kfree()
229 kfree(hp->self_base); in mdesc_kfree()
240 struct mdesc_handle *hp = mops->alloc(mdesc_size); in mdesc_alloc() local
242 if (hp) in mdesc_alloc()
243 hp->mops = mops; in mdesc_alloc()
245 return hp; in mdesc_alloc()
248 static void mdesc_free(struct mdesc_handle *hp) in mdesc_free() argument
250 hp->mops->free(hp); in mdesc_free()
259 struct mdesc_handle *hp; in mdesc_grab() local
263 hp = cur_mdesc; in mdesc_grab()
264 if (hp) in mdesc_grab()
265 refcount_inc(&hp->refcnt); in mdesc_grab()
268 return hp; in mdesc_grab()
272 void mdesc_release(struct mdesc_handle *hp) in mdesc_release() argument
277 if (refcount_dec_and_test(&hp->refcnt)) { in mdesc_release()
278 list_del_init(&hp->list); in mdesc_release()
279 hp->mops->free(hp); in mdesc_release()
298 if (strcmp(md_node_ops_table[i].name, client->node_name) == 0) { in mdesc_register_notifier()
305 pr_err("MD: %s node not supported\n", client->node_name); in mdesc_register_notifier()
310 client->next = client_list; in mdesc_register_notifier()
313 mdesc_for_each_node_by_name(cur_mdesc, node, client->node_name) in mdesc_register_notifier()
314 client->add(cur_mdesc, node, client->node_name); in mdesc_register_notifier()
319 static const u64 *parent_cfg_handle(struct mdesc_handle *hp, u64 node) in parent_cfg_handle() argument
325 mdesc_for_each_arc(a, hp, node, MDESC_ARC_TYPE_BACK) { in parent_cfg_handle()
328 target = mdesc_arc_target(hp, a); in parent_cfg_handle()
329 id = mdesc_get_property(hp, target, in parent_cfg_handle()
330 "cfg-handle", NULL); in parent_cfg_handle()
349 * 3. parent node "cfg-handle" property in get_vdev_port_node_info()
356 return -1; in get_vdev_port_node_info()
358 node_info->vdev_port.id = *idp; in get_vdev_port_node_info()
359 node_info->vdev_port.name = kstrdup_const(name, GFP_KERNEL); in get_vdev_port_node_info()
360 if (!node_info->vdev_port.name) in get_vdev_port_node_info()
361 return -1; in get_vdev_port_node_info()
362 node_info->vdev_port.parent_cfg_hdl = *parent_cfg_hdlp; in get_vdev_port_node_info()
369 if (node_info && node_info->vdev_port.name) { in rel_vdev_port_node_info()
370 kfree_const(node_info->vdev_port.name); in rel_vdev_port_node_info()
371 node_info->vdev_port.name = NULL; in rel_vdev_port_node_info()
378 if (a_node_info->vdev_port.id != b_node_info->vdev_port.id) in vdev_port_node_match()
381 if (a_node_info->vdev_port.parent_cfg_hdl != in vdev_port_node_match()
382 b_node_info->vdev_port.parent_cfg_hdl) in vdev_port_node_match()
385 if (strncmp(a_node_info->vdev_port.name, in vdev_port_node_match()
386 b_node_info->vdev_port.name, MDESC_MAX_STR_LEN) != 0) in vdev_port_node_match()
400 return -1; in get_ds_port_node_info()
402 node_info->ds_port.id = *idp; in get_ds_port_node_info()
414 if (a_node_info->ds_port.id != b_node_info->ds_port.id) in ds_port_node_match()
486 invoke_on_missing(p->node_name, old_hp, new_hp, p->remove); in notify_one()
487 invoke_on_missing(p->node_name, new_hp, old_hp, p->add); in notify_one()
497 p = p->next; in mdesc_notify_clients()
504 struct mdesc_handle *hp, *orig_hp; in mdesc_update() local
511 hp = mdesc_alloc(len, &kmalloc_mdesc_memops); in mdesc_update()
512 if (!hp) { in mdesc_update()
517 status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len); in mdesc_update()
521 refcount_dec(&hp->refcnt); in mdesc_update()
522 mdesc_free(hp); in mdesc_update()
528 cur_mdesc = hp; in mdesc_update()
531 mdesc_notify_clients(orig_hp, hp); in mdesc_update()
534 if (refcount_dec_and_test(&orig_hp->refcnt)) in mdesc_update()
537 list_add(&orig_hp->list, &mdesc_zombie_list); in mdesc_update()
544 u64 mdesc_get_node(struct mdesc_handle *hp, const char *node_name, in mdesc_get_node() argument
554 if (hp == NULL || node_name == NULL || node_info == NULL) in mdesc_get_node()
564 return -EINVAL; in mdesc_get_node()
567 mdesc_for_each_node_by_name(hp, hp_node, node_name) { in mdesc_get_node()
568 rv = get_info_func(hp, hp_node, &hp_node_info); in mdesc_get_node()
584 int mdesc_get_node_info(struct mdesc_handle *hp, u64 node, in mdesc_get_node_info() argument
590 if (hp == NULL || node == MDESC_NODE_NULL || in mdesc_get_node_info()
592 return -EINVAL; in mdesc_get_node_info()
600 return -EINVAL; in mdesc_get_node_info()
603 rv = get_info_func(hp, node, node_info); in mdesc_get_node_info()
607 return -1; in mdesc_get_node_info()
616 return (struct mdesc_elem *) mdesc->data; in node_block()
621 return ((void *) node_block(mdesc)) + mdesc->node_sz; in name_block()
626 return ((void *) name_block(mdesc)) + mdesc->name_sz; in data_block()
629 u64 mdesc_node_by_name(struct mdesc_handle *hp, in mdesc_node_by_name() argument
632 struct mdesc_elem *ep = node_block(&hp->mdesc); in mdesc_node_by_name()
633 const char *names = name_block(&hp->mdesc); in mdesc_node_by_name()
634 u64 last_node = hp->mdesc.node_sz / 16; in mdesc_node_by_name()
658 const void *mdesc_get_property(struct mdesc_handle *hp, u64 node, in mdesc_get_property() argument
661 const char *names = name_block(&hp->mdesc); in mdesc_get_property()
662 u64 last_node = hp->mdesc.node_sz / 16; in mdesc_get_property()
663 void *data = data_block(&hp->mdesc); in mdesc_get_property()
669 ep = node_block(&hp->mdesc) + node; in mdesc_get_property()
671 for (; ep->tag != MD_NODE_END; ep++) { in mdesc_get_property()
675 switch (ep->tag) { in mdesc_get_property()
677 val = &ep->d.val; in mdesc_get_property()
683 val = data + ep->d.data.data_offset; in mdesc_get_property()
684 len = ep->d.data.data_len; in mdesc_get_property()
693 if (!strcmp(names + ep->name_offset, name)) { in mdesc_get_property()
704 u64 mdesc_next_arc(struct mdesc_handle *hp, u64 from, const char *arc_type) in mdesc_next_arc() argument
706 struct mdesc_elem *ep, *base = node_block(&hp->mdesc); in mdesc_next_arc()
707 const char *names = name_block(&hp->mdesc); in mdesc_next_arc()
708 u64 last_node = hp->mdesc.node_sz / 16; in mdesc_next_arc()
716 for (; ep->tag != MD_NODE_END; ep++) { in mdesc_next_arc()
717 if (ep->tag != MD_PROP_ARC) in mdesc_next_arc()
720 if (strcmp(names + ep->name_offset, arc_type)) in mdesc_next_arc()
723 return ep - base; in mdesc_next_arc()
730 u64 mdesc_arc_target(struct mdesc_handle *hp, u64 arc) in mdesc_arc_target() argument
732 struct mdesc_elem *ep, *base = node_block(&hp->mdesc); in mdesc_arc_target()
736 return ep->d.val; in mdesc_arc_target()
740 const char *mdesc_node_name(struct mdesc_handle *hp, u64 node) in mdesc_node_name() argument
742 struct mdesc_elem *ep, *base = node_block(&hp->mdesc); in mdesc_node_name()
743 const char *names = name_block(&hp->mdesc); in mdesc_node_name()
744 u64 last_node = hp->mdesc.node_sz / 16; in mdesc_node_name()
750 if (ep->tag != MD_NODE) in mdesc_node_name()
753 return names + ep->name_offset; in mdesc_node_name()
761 struct mdesc_handle *hp = mdesc_grab(); in report_platform_properties() local
762 u64 pn = mdesc_node_by_name(hp, MDESC_NODE_NULL, "platform"); in report_platform_properties()
767 prom_printf("No platform node in machine-description.\n"); in report_platform_properties()
771 s = mdesc_get_property(hp, pn, "banner-name", NULL); in report_platform_properties()
772 printk("PLATFORM: banner-name [%s]\n", s); in report_platform_properties()
773 s = mdesc_get_property(hp, pn, "name", NULL); in report_platform_properties()
776 v = mdesc_get_property(hp, pn, "hostid", NULL); in report_platform_properties()
779 v = mdesc_get_property(hp, pn, "serial#", NULL); in report_platform_properties()
782 v = mdesc_get_property(hp, pn, "stick-frequency", NULL); in report_platform_properties()
783 printk("PLATFORM: stick-frequency [%08llx]\n", *v); in report_platform_properties()
784 v = mdesc_get_property(hp, pn, "mac-address", NULL); in report_platform_properties()
786 printk("PLATFORM: mac-address [%llx]\n", *v); in report_platform_properties()
787 v = mdesc_get_property(hp, pn, "watchdog-resolution", NULL); in report_platform_properties()
789 printk("PLATFORM: watchdog-resolution [%llu ms]\n", *v); in report_platform_properties()
790 v = mdesc_get_property(hp, pn, "watchdog-max-timeout", NULL); in report_platform_properties()
792 printk("PLATFORM: watchdog-max-timeout [%llu ms]\n", *v); in report_platform_properties()
793 v = mdesc_get_property(hp, pn, "max-cpus", NULL); in report_platform_properties()
796 printk("PLATFORM: max-cpus [%llu]\n", max_cpus); in report_platform_properties()
815 mdesc_release(hp); in report_platform_properties()
818 static void fill_in_one_cache(cpuinfo_sparc *c, struct mdesc_handle *hp, u64 mp) in fill_in_one_cache() argument
820 const u64 *level = mdesc_get_property(hp, mp, "level", NULL); in fill_in_one_cache()
821 const u64 *size = mdesc_get_property(hp, mp, "size", NULL); in fill_in_one_cache()
822 const u64 *line_size = mdesc_get_property(hp, mp, "line-size", NULL); in fill_in_one_cache()
826 type = mdesc_get_property(hp, mp, "type", &type_len); in fill_in_one_cache()
831 c->icache_size = *size; in fill_in_one_cache()
832 c->icache_line_size = *line_size; in fill_in_one_cache()
834 c->dcache_size = *size; in fill_in_one_cache()
835 c->dcache_line_size = *line_size; in fill_in_one_cache()
840 c->ecache_size = *size; in fill_in_one_cache()
841 c->ecache_line_size = *line_size; in fill_in_one_cache()
851 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) { in fill_in_one_cache()
852 u64 target = mdesc_arc_target(hp, a); in fill_in_one_cache()
853 const char *name = mdesc_node_name(hp, target); in fill_in_one_cache()
856 fill_in_one_cache(c, hp, target); in fill_in_one_cache()
861 static void find_back_node_value(struct mdesc_handle *hp, u64 node, in find_back_node_value() argument
872 mdesc_for_each_arc(arc, hp, node, MDESC_ARC_TYPE_BACK) { in find_back_node_value()
873 u64 n = mdesc_arc_target(hp, arc); in find_back_node_value()
874 const char *name = mdesc_node_name(hp, n); in find_back_node_value()
877 (*func)(hp, n, val); in find_back_node_value()
879 find_back_node_value(hp, n, srch_val, func, val, depth-1); in find_back_node_value()
883 static void __mark_core_id(struct mdesc_handle *hp, u64 node, in __mark_core_id() argument
886 const u64 *id = mdesc_get_property(hp, node, "id", NULL); in __mark_core_id()
892 static void __mark_max_cache_id(struct mdesc_handle *hp, u64 node, in __mark_max_cache_id() argument
895 const u64 *id = mdesc_get_property(hp, node, "id", NULL); in __mark_max_cache_id()
908 static void mark_core_ids(struct mdesc_handle *hp, u64 mp, in mark_core_ids() argument
911 find_back_node_value(hp, mp, "cpu", __mark_core_id, core_id, 10); in mark_core_ids()
914 static void mark_max_cache_ids(struct mdesc_handle *hp, u64 mp, in mark_max_cache_ids() argument
917 find_back_node_value(hp, mp, "cpu", __mark_max_cache_id, in mark_max_cache_ids()
921 static void set_core_ids(struct mdesc_handle *hp) in set_core_ids() argument
931 mdesc_for_each_node_by_name(hp, mp, "cache") { in set_core_ids()
936 level = mdesc_get_property(hp, mp, "level", NULL); in set_core_ids()
940 type = mdesc_get_property(hp, mp, "type", &len); in set_core_ids()
944 mark_core_ids(hp, mp, idx); in set_core_ids()
949 static int set_max_cache_ids_by_cache(struct mdesc_handle *hp, int level) in set_max_cache_ids_by_cache() argument
959 mdesc_for_each_node_by_name(hp, mp, "cache") { in set_max_cache_ids_by_cache()
962 cur_lvl = mdesc_get_property(hp, mp, "level", NULL); in set_max_cache_ids_by_cache()
965 mark_max_cache_ids(hp, mp, idx); in set_max_cache_ids_by_cache()
972 static void set_sock_ids_by_socket(struct mdesc_handle *hp, u64 mp) in set_sock_ids_by_socket() argument
976 mdesc_for_each_node_by_name(hp, mp, "socket") { in set_sock_ids_by_socket()
979 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) { in set_sock_ids_by_socket()
980 u64 t = mdesc_arc_target(hp, a); in set_sock_ids_by_socket()
984 name = mdesc_node_name(hp, t); in set_sock_ids_by_socket()
988 id = mdesc_get_property(hp, t, "id", NULL); in set_sock_ids_by_socket()
996 static void set_sock_ids(struct mdesc_handle *hp) in set_sock_ids() argument
1001 * Find the highest level of shared cache which pre-T7 is also in set_sock_ids()
1004 if (!set_max_cache_ids_by_cache(hp, 3)) in set_sock_ids()
1005 set_max_cache_ids_by_cache(hp, 2); in set_sock_ids()
1008 mp = mdesc_node_by_name(hp, MDESC_NODE_NULL, "sockets"); in set_sock_ids()
1010 set_sock_ids_by_socket(hp, mp); in set_sock_ids()
1013 static void mark_proc_ids(struct mdesc_handle *hp, u64 mp, int proc_id) in mark_proc_ids() argument
1017 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_BACK) { in mark_proc_ids()
1018 u64 t = mdesc_arc_target(hp, a); in mark_proc_ids()
1022 name = mdesc_node_name(hp, t); in mark_proc_ids()
1026 id = mdesc_get_property(hp, t, "id", NULL); in mark_proc_ids()
1032 static void __set_proc_ids(struct mdesc_handle *hp, const char *exec_unit_name) in __set_proc_ids() argument
1038 mdesc_for_each_node_by_name(hp, mp, exec_unit_name) { in __set_proc_ids()
1042 type = mdesc_get_property(hp, mp, "type", &len); in __set_proc_ids()
1047 mark_proc_ids(hp, mp, idx); in __set_proc_ids()
1052 static void set_proc_ids(struct mdesc_handle *hp) in set_proc_ids() argument
1054 __set_proc_ids(hp, "exec_unit"); in set_proc_ids()
1055 __set_proc_ids(hp, "exec-unit"); in set_proc_ids()
1073 *mask = ((1U << val) * 64U) - 1U; in get_one_mondo_bits()
1077 *mask = ((1U << def) * 64U) - 1U; in get_one_mondo_bits()
1080 static void get_mondo_data(struct mdesc_handle *hp, u64 mp, in get_mondo_data() argument
1086 val = mdesc_get_property(hp, mp, "q-cpu-mondo-#bits", NULL); in get_mondo_data()
1087 get_one_mondo_bits(val, &tb->cpu_mondo_qmask, 7, ilog2(max_cpus * 2)); in get_mondo_data()
1089 val = mdesc_get_property(hp, mp, "q-dev-mondo-#bits", NULL); in get_mondo_data()
1090 get_one_mondo_bits(val, &tb->dev_mondo_qmask, 7, 8); in get_mondo_data()
1092 val = mdesc_get_property(hp, mp, "q-resumable-#bits", NULL); in get_mondo_data()
1093 get_one_mondo_bits(val, &tb->resum_qmask, 6, 7); in get_mondo_data()
1095 val = mdesc_get_property(hp, mp, "q-nonresumable-#bits", NULL); in get_mondo_data()
1096 get_one_mondo_bits(val, &tb->nonresum_qmask, 2, 2); in get_mondo_data()
1100 tb->cpu_mondo_qmask + 1, in get_mondo_data()
1101 tb->dev_mondo_qmask + 1, in get_mondo_data()
1102 tb->resum_qmask + 1, in get_mondo_data()
1103 tb->nonresum_qmask + 1); in get_mondo_data()
1109 struct mdesc_handle *hp = mdesc_grab(); in mdesc_iterate_over_cpus() local
1113 mdesc_for_each_node_by_name(hp, mp, "cpu") { in mdesc_iterate_over_cpus()
1114 const u64 *id = mdesc_get_property(hp, mp, "id", NULL); in mdesc_iterate_over_cpus()
1128 ret = func(hp, mp, cpuid, arg); in mdesc_iterate_over_cpus()
1133 mdesc_release(hp); in mdesc_iterate_over_cpus()
1137 static void *record_one_cpu(struct mdesc_handle *hp, u64 mp, int cpuid, in record_one_cpu() argument
1156 static void * __init check_one_pgsz(struct mdesc_handle *hp, u64 mp, int cpuid, void *arg) in check_one_pgsz() argument
1158 const u64 *pgsz_prop = mdesc_get_property(hp, mp, "mmu-page-size-list", NULL); in check_one_pgsz()
1180 static void *fill_in_one_cpu(struct mdesc_handle *hp, u64 mp, int cpuid, in fill_in_one_cpu() argument
1183 const u64 *cfreq = mdesc_get_property(hp, mp, "clock-frequency", NULL); in fill_in_one_cpu()
1199 c->clock_tick = *cfreq; in fill_in_one_cpu()
1202 get_mondo_data(hp, mp, tb); in fill_in_one_cpu()
1204 mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) { in fill_in_one_cpu()
1205 u64 j, t = mdesc_arc_target(hp, a); in fill_in_one_cpu()
1208 t_name = mdesc_node_name(hp, t); in fill_in_one_cpu()
1210 fill_in_one_cache(c, hp, t); in fill_in_one_cpu()
1214 mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_FWD) { in fill_in_one_cpu()
1215 u64 n = mdesc_arc_target(hp, j); in fill_in_one_cpu()
1218 n_name = mdesc_node_name(hp, n); in fill_in_one_cpu()
1220 fill_in_one_cache(c, hp, n); in fill_in_one_cpu()
1224 c->core_id = 0; in fill_in_one_cpu()
1225 c->proc_id = -1; in fill_in_one_cpu()
1232 struct mdesc_handle *hp; in mdesc_fill_in_cpu_data() local
1236 hp = mdesc_grab(); in mdesc_fill_in_cpu_data()
1238 set_core_ids(hp); in mdesc_fill_in_cpu_data()
1239 set_proc_ids(hp); in mdesc_fill_in_cpu_data()
1240 set_sock_ids(hp); in mdesc_fill_in_cpu_data()
1242 mdesc_release(hp); in mdesc_fill_in_cpu_data()
1247 /* mdesc_open() - Grab a reference to mdesc_handle when /dev/mdesc is
1254 struct mdesc_handle *hp = mdesc_grab(); in mdesc_open() local
1256 if (!hp) in mdesc_open()
1257 return -ENODEV; in mdesc_open()
1259 file->private_data = hp; in mdesc_open()
1267 struct mdesc_handle *hp = file->private_data; in mdesc_read() local
1271 if (*offp >= hp->handle_size) in mdesc_read()
1274 bytes_left = hp->handle_size - *offp; in mdesc_read()
1278 mdesc = (unsigned char *)&hp->mdesc; in mdesc_read()
1284 return -EFAULT; in mdesc_read()
1290 struct mdesc_handle *hp = file->private_data; in mdesc_llseek() local
1292 return no_seek_end_llseek_size(file, offset, whence, hp->handle_size); in mdesc_llseek()
1295 /* mdesc_close() - /dev/mdesc is being closed, release the reference to
1300 mdesc_release(file->private_data); in mdesc_close()
1327 struct mdesc_handle *hp; in sun4v_mdesc_init() local
1334 hp = mdesc_alloc(len, &memblock_mdesc_ops); in sun4v_mdesc_init()
1335 if (hp == NULL) { in sun4v_mdesc_init()
1340 status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len); in sun4v_mdesc_init()
1345 mdesc_free(hp); in sun4v_mdesc_init()
1349 cur_mdesc = hp; in sun4v_mdesc_init()