blob: ec31a06d04cc17c56f4d437e082bdc1bb238d639 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Sam Ravnborga00736e2008-06-19 20:26:19 +02002#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
9struct 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 */
Sam Ravnborgf05a6862014-05-16 23:25:50 +020016struct mdesc_handle *mdesc_grab(void);
17void mdesc_release(struct mdesc_handle *);
Sam Ravnborga00736e2008-06-19 20:26:19 +020018
19#define MDESC_NODE_NULL (~(u64)0)
Jag Raman411cb4a2017-06-23 14:58:32 -040020#define MDESC_MAX_STR_LEN 256
Sam Ravnborga00736e2008-06-19 20:26:19 +020021
Sam Ravnborgf05a6862014-05-16 23:25:50 +020022u64 mdesc_node_by_name(struct mdesc_handle *handle,
23 u64 from_node, const char *name);
Sam Ravnborga00736e2008-06-19 20:26:19 +020024#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 */
Sam Ravnborgf05a6862014-05-16 23:25:50 +020039const void *mdesc_get_property(struct mdesc_handle *handle,
40 u64 node, const char *name, int *lenp);
41const char *mdesc_node_name(struct mdesc_handle *hp, u64 node);
Sam Ravnborga00736e2008-06-19 20:26:19 +020042
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
Sam Ravnborgf05a6862014-05-16 23:25:50 +020055u64 mdesc_next_arc(struct mdesc_handle *handle, u64 from,
56 const char *arc_type);
Sam Ravnborga00736e2008-06-19 20:26:19 +020057#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
Sam Ravnborgf05a6862014-05-16 23:25:50 +020062u64 mdesc_arc_target(struct mdesc_handle *hp, u64 arc);
Sam Ravnborga00736e2008-06-19 20:26:19 +020063
Sam Ravnborgf05a6862014-05-16 23:25:50 +020064void mdesc_update(void);
Sam Ravnborga00736e2008-06-19 20:26:19 +020065
66struct mdesc_notifier_client {
Jag Raman06f3c3a2017-06-23 14:58:34 -040067 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);
Sam Ravnborga00736e2008-06-19 20:26:19 +020071 const char *node_name;
72 struct mdesc_notifier_client *next;
73};
74
Sam Ravnborgf05a6862014-05-16 23:25:50 +020075void mdesc_register_notifier(struct mdesc_notifier_client *client);
Sam Ravnborga00736e2008-06-19 20:26:19 +020076
Jag Raman411cb4a2017-06-23 14:58:32 -040077union 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
88u64 mdesc_get_node(struct mdesc_handle *hp, const char *node_name,
89 union md_node_info *node_info);
90int mdesc_get_node_info(struct mdesc_handle *hp, u64 node,
91 const char *node_name, union md_node_info *node_info);
92
Sam Ravnborgf05a6862014-05-16 23:25:50 +020093void mdesc_fill_in_cpu_data(cpumask_t *mask);
94void mdesc_populate_present_mask(cpumask_t *mask);
95void mdesc_get_page_sizes(cpumask_t *mask, unsigned long *pgsz_mask);
Sam Ravnborga00736e2008-06-19 20:26:19 +020096
Sam Ravnborgf05a6862014-05-16 23:25:50 +020097void sun4v_mdesc_init(void);
Sam Ravnborga00736e2008-06-19 20:26:19 +020098
99#endif