1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright 2010 Benjamin Herrenschmidt, IBM Corp
4 * <benh@kernel.crashing.org>
5 * and David Gibson, IBM Corporation.
8 #ifndef _ASM_POWERPC_SCOM_H
9 #define _ASM_POWERPC_SCOM_H
13 #ifdef CONFIG_PPC_SCOM
16 * The SCOM bus is a sideband bus used for accessing various internal
17 * registers of the processor or the chipset. The implementation details
18 * differ between processors and platforms, and the access method as
21 * This API allows to "map" ranges of SCOM register numbers associated
22 * with a given SCOM controller. The later must be represented by a
23 * device node, though some implementations might support NULL if there
24 * is no possible ambiguity
26 * Then, scom_read/scom_write can be used to accesses registers inside
27 * that range. The argument passed is a register number relative to
28 * the beginning of the range mapped.
31 typedef void *scom_map_t;
33 /* Value for an invalid SCOM map */
34 #define SCOM_MAP_INVALID (NULL)
36 /* The scom_controller data structure is what the platform passes
37 * to the core code in scom_init, it provides the actual implementation
38 * of all the SCOM functions
40 struct scom_controller {
41 scom_map_t (*map)(struct device_node *ctrl_dev, u64 reg, u64 count);
42 void (*unmap)(scom_map_t map);
44 int (*read)(scom_map_t map, u64 reg, u64 *value);
45 int (*write)(scom_map_t map, u64 reg, u64 value);
48 extern const struct scom_controller *scom_controller;
51 * scom_init - Initialize the SCOM backend, called by the platform
52 * @controller: The platform SCOM controller
54 static inline void scom_init(const struct scom_controller *controller)
56 scom_controller = controller;
60 * scom_map_ok - Test is a SCOM mapping is successful
61 * @map: The result of scom_map to test
63 static inline int scom_map_ok(scom_map_t map)
65 return map != SCOM_MAP_INVALID;
69 * scom_map - Map a block of SCOM registers
70 * @ctrl_dev: Device node of the SCOM controller
71 * some implementations allow NULL here
72 * @reg: first SCOM register to map
73 * @count: Number of SCOM registers to map
76 static inline scom_map_t scom_map(struct device_node *ctrl_dev,
79 return scom_controller->map(ctrl_dev, reg, count);
83 * scom_find_parent - Find the SCOM controller for a device
84 * @dev: OF node of the device
86 * This is not meant for general usage, but in combination with
87 * scom_map() allows to map registers not represented by the
88 * device own scom-reg property. Useful for applying HW workarounds
89 * on things not properly represented in the device-tree for example.
91 struct device_node *scom_find_parent(struct device_node *dev);
95 * scom_map_device - Map a device's block of SCOM registers
96 * @dev: OF node of the device
97 * @index: Register bank index (index in "scom-reg" property)
99 * This function will use the device-tree binding for SCOM which
100 * is to follow "scom-parent" properties until it finds a node with
101 * a "scom-controller" property to find the controller. It will then
102 * use the "scom-reg" property which is made of reg/count pairs,
103 * each of them having a size defined by the controller's #scom-cells
106 extern scom_map_t scom_map_device(struct device_node *dev, int index);
110 * scom_unmap - Unmap a block of SCOM registers
111 * @map: Result of scom_map is to be unmapped
113 static inline void scom_unmap(scom_map_t map)
115 if (scom_map_ok(map))
116 scom_controller->unmap(map);
120 * scom_read - Read a SCOM register
121 * @map: Result of scom_map
122 * @reg: Register index within that map
123 * @value: Updated with the value read
125 * Returns 0 (success) or a negative error code
127 static inline int scom_read(scom_map_t map, u64 reg, u64 *value)
131 rc = scom_controller->read(map, reg, value);
133 *value = 0xfffffffffffffffful;
138 * scom_write - Write to a SCOM register
139 * @map: Result of scom_map
140 * @reg: Register index within that map
141 * @value: Value to write
143 * Returns 0 (success) or a negative error code
145 static inline int scom_write(scom_map_t map, u64 reg, u64 value)
147 return scom_controller->write(map, reg, value);
151 #endif /* CONFIG_PPC_SCOM */
152 #endif /* __ASSEMBLY__ */
153 #endif /* __KERNEL__ */
154 #endif /* _ASM_POWERPC_SCOM_H */