powerpc: Add SCOM infrastructure
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / powerpc / include / asm / scom.h
blob0cabfd7bc2d1e5603d1cfa64e49c3cbd4557224e
1 /*
2 * Copyright 2010 Benjamin Herrenschmidt, IBM Corp
3 * <benh@kernel.crashing.org>
4 * and David Gibson, IBM Corporation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 * the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef _ASM_POWERPC_SCOM_H
22 #define _ASM_POWERPC_SCOM_H
24 #ifdef __KERNEL__
25 #ifndef __ASSEMBLY__
26 #ifdef CONFIG_PPC_SCOM
29 * The SCOM bus is a sideband bus used for accessing various internal
30 * registers of the processor or the chipset. The implementation details
31 * differ between processors and platforms, and the access method as
32 * well.
34 * This API allows to "map" ranges of SCOM register numbers associated
35 * with a given SCOM controller. The later must be represented by a
36 * device node, though some implementations might support NULL if there
37 * is no possible ambiguity
39 * Then, scom_read/scom_write can be used to accesses registers inside
40 * that range. The argument passed is a register number relative to
41 * the beginning of the range mapped.
44 typedef void *scom_map_t;
46 /* Value for an invalid SCOM map */
47 #define SCOM_MAP_INVALID (NULL)
49 /* The scom_controller data structure is what the platform passes
50 * to the core code in scom_init, it provides the actual implementation
51 * of all the SCOM functions
53 struct scom_controller {
54 scom_map_t (*map)(struct device_node *ctrl_dev, u64 reg, u64 count);
55 void (*unmap)(scom_map_t map);
57 u64 (*read)(scom_map_t map, u32 reg);
58 void (*write)(scom_map_t map, u32 reg, u64 value);
61 extern const struct scom_controller *scom_controller;
63 /**
64 * scom_init - Initialize the SCOM backend, called by the platform
65 * @controller: The platform SCOM controller
67 static inline void scom_init(const struct scom_controller *controller)
69 scom_controller = controller;
72 /**
73 * scom_map_ok - Test is a SCOM mapping is successful
74 * @map: The result of scom_map to test
76 static inline int scom_map_ok(scom_map_t map)
78 return map != SCOM_MAP_INVALID;
81 /**
82 * scom_map - Map a block of SCOM registers
83 * @ctrl_dev: Device node of the SCOM controller
84 * some implementations allow NULL here
85 * @reg: first SCOM register to map
86 * @count: Number of SCOM registers to map
89 static inline scom_map_t scom_map(struct device_node *ctrl_dev,
90 u64 reg, u64 count)
92 return scom_controller->map(ctrl_dev, reg, count);
95 /**
96 * scom_find_parent - Find the SCOM controller for a device
97 * @dev: OF node of the device
99 * This is not meant for general usage, but in combination with
100 * scom_map() allows to map registers not represented by the
101 * device own scom-reg property. Useful for applying HW workarounds
102 * on things not properly represented in the device-tree for example.
104 struct device_node *scom_find_parent(struct device_node *dev);
108 * scom_map_device - Map a device's block of SCOM registers
109 * @dev: OF node of the device
110 * @index: Register bank index (index in "scom-reg" property)
112 * This function will use the device-tree binding for SCOM which
113 * is to follow "scom-parent" properties until it finds a node with
114 * a "scom-controller" property to find the controller. It will then
115 * use the "scom-reg" property which is made of reg/count pairs,
116 * each of them having a size defined by the controller's #scom-cells
117 * property
119 extern scom_map_t scom_map_device(struct device_node *dev, int index);
123 * scom_unmap - Unmap a block of SCOM registers
124 * @map: Result of scom_map is to be unmapped
126 static inline void scom_unmap(scom_map_t map)
128 if (scom_map_ok(map))
129 scom_controller->unmap(map);
133 * scom_read - Read a SCOM register
134 * @map: Result of scom_map
135 * @reg: Register index within that map
137 static inline u64 scom_read(scom_map_t map, u32 reg)
139 return scom_controller->read(map, reg);
143 * scom_write - Write to a SCOM register
144 * @map: Result of scom_map
145 * @reg: Register index within that map
146 * @value: Value to write
148 static inline void scom_write(scom_map_t map, u32 reg, u64 value)
150 scom_controller->write(map, reg, value);
153 #endif /* CONFIG_PPC_SCOM */
154 #endif /* __ASSEMBLY__ */
155 #endif /* __KERNEL__ */
156 #endif /* _ASM_POWERPC_SCOM_H */