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