Sam Ravnborg | a00736e | 2008-06-19 20:26:19 +0200 | [diff] [blame] | 1 | #ifndef _SPARC64_MDESC_H |
| 2 | #define _SPARC64_MDESC_H |
| 3 | |
| 4 | #include <linux/types.h> |
| 5 | #include <linux/cpumask.h> |
| 6 | #include <asm/prom.h> |
| 7 | |
| 8 | struct mdesc_handle; |
| 9 | |
| 10 | /* Machine description operations are to be surrounded by grab and |
| 11 | * release calls. The mdesc_handle returned from the grab is |
| 12 | * the first argument to all of the operational calls that work |
| 13 | * on mdescs. |
| 14 | */ |
Sam Ravnborg | f05a686 | 2014-05-16 23:25:50 +0200 | [diff] [blame] | 15 | struct mdesc_handle *mdesc_grab(void); |
| 16 | void mdesc_release(struct mdesc_handle *); |
Sam Ravnborg | a00736e | 2008-06-19 20:26:19 +0200 | [diff] [blame] | 17 | |
| 18 | #define MDESC_NODE_NULL (~(u64)0) |
Jag Raman | 411cb4a | 2017-06-23 14:58:32 -0400 | [diff] [blame] | 19 | #define MDESC_MAX_STR_LEN 256 |
Sam Ravnborg | a00736e | 2008-06-19 20:26:19 +0200 | [diff] [blame] | 20 | |
Sam Ravnborg | f05a686 | 2014-05-16 23:25:50 +0200 | [diff] [blame] | 21 | u64 mdesc_node_by_name(struct mdesc_handle *handle, |
| 22 | u64 from_node, const char *name); |
Sam Ravnborg | a00736e | 2008-06-19 20:26:19 +0200 | [diff] [blame] | 23 | #define mdesc_for_each_node_by_name(__hdl, __node, __name) \ |
| 24 | for (__node = mdesc_node_by_name(__hdl, MDESC_NODE_NULL, __name); \ |
| 25 | (__node) != MDESC_NODE_NULL; \ |
| 26 | __node = mdesc_node_by_name(__hdl, __node, __name)) |
| 27 | |
| 28 | /* Access to property values returned from mdesc_get_property() are |
| 29 | * only valid inside of a mdesc_grab()/mdesc_release() sequence. |
| 30 | * Once mdesc_release() is called, the memory backed up by these |
| 31 | * pointers may reference freed up memory. |
| 32 | * |
| 33 | * Therefore callers must make copies of any property values |
| 34 | * they need. |
| 35 | * |
| 36 | * These same rules apply to mdesc_node_name(). |
| 37 | */ |
Sam Ravnborg | f05a686 | 2014-05-16 23:25:50 +0200 | [diff] [blame] | 38 | const void *mdesc_get_property(struct mdesc_handle *handle, |
| 39 | u64 node, const char *name, int *lenp); |
| 40 | const char *mdesc_node_name(struct mdesc_handle *hp, u64 node); |
Sam Ravnborg | a00736e | 2008-06-19 20:26:19 +0200 | [diff] [blame] | 41 | |
| 42 | /* MD arc iteration, the standard sequence is: |
| 43 | * |
| 44 | * unsigned long arc; |
| 45 | * mdesc_for_each_arc(arc, handle, node, MDESC_ARC_TYPE_{FWD,BACK}) { |
| 46 | * unsigned long target = mdesc_arc_target(handle, arc); |
| 47 | * ... |
| 48 | * } |
| 49 | */ |
| 50 | |
| 51 | #define MDESC_ARC_TYPE_FWD "fwd" |
| 52 | #define MDESC_ARC_TYPE_BACK "back" |
| 53 | |
Sam Ravnborg | f05a686 | 2014-05-16 23:25:50 +0200 | [diff] [blame] | 54 | u64 mdesc_next_arc(struct mdesc_handle *handle, u64 from, |
| 55 | const char *arc_type); |
Sam Ravnborg | a00736e | 2008-06-19 20:26:19 +0200 | [diff] [blame] | 56 | #define mdesc_for_each_arc(__arc, __hdl, __node, __type) \ |
| 57 | for (__arc = mdesc_next_arc(__hdl, __node, __type); \ |
| 58 | (__arc) != MDESC_NODE_NULL; \ |
| 59 | __arc = mdesc_next_arc(__hdl, __arc, __type)) |
| 60 | |
Sam Ravnborg | f05a686 | 2014-05-16 23:25:50 +0200 | [diff] [blame] | 61 | u64 mdesc_arc_target(struct mdesc_handle *hp, u64 arc); |
Sam Ravnborg | a00736e | 2008-06-19 20:26:19 +0200 | [diff] [blame] | 62 | |
Sam Ravnborg | f05a686 | 2014-05-16 23:25:50 +0200 | [diff] [blame] | 63 | void mdesc_update(void); |
Sam Ravnborg | a00736e | 2008-06-19 20:26:19 +0200 | [diff] [blame] | 64 | |
| 65 | struct mdesc_notifier_client { |
Jag Raman | 06f3c3a | 2017-06-23 14:58:34 -0400 | [diff] [blame] | 66 | void (*add)(struct mdesc_handle *handle, u64 node, |
| 67 | const char *node_name); |
| 68 | void (*remove)(struct mdesc_handle *handle, u64 node, |
| 69 | const char *node_name); |
Sam Ravnborg | a00736e | 2008-06-19 20:26:19 +0200 | [diff] [blame] | 70 | const char *node_name; |
| 71 | struct mdesc_notifier_client *next; |
| 72 | }; |
| 73 | |
Sam Ravnborg | f05a686 | 2014-05-16 23:25:50 +0200 | [diff] [blame] | 74 | void mdesc_register_notifier(struct mdesc_notifier_client *client); |
Sam Ravnborg | a00736e | 2008-06-19 20:26:19 +0200 | [diff] [blame] | 75 | |
Jag Raman | 411cb4a | 2017-06-23 14:58:32 -0400 | [diff] [blame] | 76 | union md_node_info { |
| 77 | struct vdev_port { |
| 78 | u64 id; /* id */ |
| 79 | u64 parent_cfg_hdl; /* parent config handle */ |
| 80 | const char *name; /* name (property) */ |
| 81 | } vdev_port; |
| 82 | struct ds_port { |
| 83 | u64 id; /* id */ |
| 84 | } ds_port; |
| 85 | }; |
| 86 | |
| 87 | u64 mdesc_get_node(struct mdesc_handle *hp, const char *node_name, |
| 88 | union md_node_info *node_info); |
| 89 | int mdesc_get_node_info(struct mdesc_handle *hp, u64 node, |
| 90 | const char *node_name, union md_node_info *node_info); |
| 91 | |
Sam Ravnborg | f05a686 | 2014-05-16 23:25:50 +0200 | [diff] [blame] | 92 | void mdesc_fill_in_cpu_data(cpumask_t *mask); |
| 93 | void mdesc_populate_present_mask(cpumask_t *mask); |
| 94 | void mdesc_get_page_sizes(cpumask_t *mask, unsigned long *pgsz_mask); |
Sam Ravnborg | a00736e | 2008-06-19 20:26:19 +0200 | [diff] [blame] | 95 | |
Sam Ravnborg | f05a686 | 2014-05-16 23:25:50 +0200 | [diff] [blame] | 96 | void sun4v_mdesc_init(void); |
Sam Ravnborg | a00736e | 2008-06-19 20:26:19 +0200 | [diff] [blame] | 97 | |
| 98 | #endif |