Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
scom.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Benjamin Herrenschmidt, IBM Corp
4  * and David Gibson, IBM Corporation.
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #ifndef _ASM_POWERPC_SCOM_H
22 #define _ASM_POWERPC_SCOM_H
23 
24 #ifdef __KERNEL__
25 #ifndef __ASSEMBLY__
26 #ifdef CONFIG_PPC_SCOM
27 
28 /*
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.
33  *
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
38  *
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.
42  */
43 
44 typedef void *scom_map_t;
45 
46 /* Value for an invalid SCOM map */
47 #define SCOM_MAP_INVALID (NULL)
48 
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
52  */
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);
56 
57  u64 (*read)(scom_map_t map, u32 reg);
58  void (*write)(scom_map_t map, u32 reg, u64 value);
59 };
60 
61 extern const struct scom_controller *scom_controller;
62 
67 static inline void scom_init(const struct scom_controller *controller)
68 {
69  scom_controller = controller;
70 }
71 
76 static inline int scom_map_ok(scom_map_t map)
77 {
78  return map != SCOM_MAP_INVALID;
79 }
80 
89 static inline scom_map_t scom_map(struct device_node *ctrl_dev,
90  u64 reg, u64 count)
91 {
92  return scom_controller->map(ctrl_dev, reg, count);
93 }
94 
105 
106 
119 extern scom_map_t scom_map_device(struct device_node *dev, int index);
120 
121 
126 static inline void scom_unmap(scom_map_t map)
127 {
128  if (scom_map_ok(map))
129  scom_controller->unmap(map);
130 }
131 
137 static inline u64 scom_read(scom_map_t map, u32 reg)
138 {
139  return scom_controller->read(map, reg);
140 }
141 
148 static inline void scom_write(scom_map_t map, u32 reg, u64 value)
149 {
150  scom_controller->write(map, reg, value);
151 }
152 
153 #endif /* CONFIG_PPC_SCOM */
154 #endif /* __ASSEMBLY__ */
155 #endif /* __KERNEL__ */
156 #endif /* _ASM_POWERPC_SCOM_H */