]> asedeno.scripts.mit.edu Git - linux.git/blob - arch/x86/include/asm/iosf_mbi.h
eb959cd77994f1f3096bedf30518ff773b6ceeb8
[linux.git] / arch / x86 / include / asm / iosf_mbi.h
1 /*
2  * Intel OnChip System Fabric MailBox access support
3  */
4
5 #ifndef IOSF_MBI_SYMS_H
6 #define IOSF_MBI_SYMS_H
7
8 #include <linux/notifier.h>
9
10 #define MBI_MCR_OFFSET          0xD0
11 #define MBI_MDR_OFFSET          0xD4
12 #define MBI_MCRX_OFFSET         0xD8
13
14 #define MBI_RD_MASK             0xFEFFFFFF
15 #define MBI_WR_MASK             0X01000000
16
17 #define MBI_MASK_HI             0xFFFFFF00
18 #define MBI_MASK_LO             0x000000FF
19 #define MBI_ENABLE              0xF0
20
21 /* IOSF SB read/write opcodes */
22 #define MBI_MMIO_READ           0x00
23 #define MBI_MMIO_WRITE          0x01
24 #define MBI_CFG_READ            0x04
25 #define MBI_CFG_WRITE           0x05
26 #define MBI_CR_READ             0x06
27 #define MBI_CR_WRITE            0x07
28 #define MBI_REG_READ            0x10
29 #define MBI_REG_WRITE           0x11
30 #define MBI_ESRAM_READ          0x12
31 #define MBI_ESRAM_WRITE         0x13
32
33 /* Baytrail available units */
34 #define BT_MBI_UNIT_AUNIT       0x00
35 #define BT_MBI_UNIT_SMC         0x01
36 #define BT_MBI_UNIT_CPU         0x02
37 #define BT_MBI_UNIT_BUNIT       0x03
38 #define BT_MBI_UNIT_PMC         0x04
39 #define BT_MBI_UNIT_GFX         0x06
40 #define BT_MBI_UNIT_SMI         0x0C
41 #define BT_MBI_UNIT_USB         0x43
42 #define BT_MBI_UNIT_SATA        0xA3
43 #define BT_MBI_UNIT_PCIE        0xA6
44
45 /* Quark available units */
46 #define QRK_MBI_UNIT_HBA        0x00
47 #define QRK_MBI_UNIT_HB         0x03
48 #define QRK_MBI_UNIT_RMU        0x04
49 #define QRK_MBI_UNIT_MM         0x05
50 #define QRK_MBI_UNIT_SOC        0x31
51
52 /* Action values for the pmic_bus_access_notifier functions */
53 #define MBI_PMIC_BUS_ACCESS_BEGIN       1
54 #define MBI_PMIC_BUS_ACCESS_END         2
55
56 #if IS_ENABLED(CONFIG_IOSF_MBI)
57
58 bool iosf_mbi_available(void);
59
60 /**
61  * iosf_mbi_read() - MailBox Interface read command
62  * @port:       port indicating subunit being accessed
63  * @opcode:     port specific read or write opcode
64  * @offset:     register address offset
65  * @mdr:        register data to be read
66  *
67  * Locking is handled by spinlock - cannot sleep.
68  * Return: Nonzero on error
69  */
70 int iosf_mbi_read(u8 port, u8 opcode, u32 offset, u32 *mdr);
71
72 /**
73  * iosf_mbi_write() - MailBox unmasked write command
74  * @port:       port indicating subunit being accessed
75  * @opcode:     port specific read or write opcode
76  * @offset:     register address offset
77  * @mdr:        register data to be written
78  *
79  * Locking is handled by spinlock - cannot sleep.
80  * Return: Nonzero on error
81  */
82 int iosf_mbi_write(u8 port, u8 opcode, u32 offset, u32 mdr);
83
84 /**
85  * iosf_mbi_modify() - MailBox masked write command
86  * @port:       port indicating subunit being accessed
87  * @opcode:     port specific read or write opcode
88  * @offset:     register address offset
89  * @mdr:        register data being modified
90  * @mask:       mask indicating bits in mdr to be modified
91  *
92  * Locking is handled by spinlock - cannot sleep.
93  * Return: Nonzero on error
94  */
95 int iosf_mbi_modify(u8 port, u8 opcode, u32 offset, u32 mdr, u32 mask);
96
97 /**
98  * iosf_mbi_punit_acquire() - Acquire access to the P-Unit
99  *
100  * One some systems the P-Unit accesses the PMIC to change various voltages
101  * through the same bus as other kernel drivers use for e.g. battery monitoring.
102  *
103  * If a driver sends requests to the P-Unit which require the P-Unit to access
104  * the PMIC bus while another driver is also accessing the PMIC bus various bad
105  * things happen.
106  *
107  * To avoid these problems this function must be called before accessing the
108  * P-Unit or the PMIC, be it through iosf_mbi* functions or through other means.
109  *
110  * Note on these systems the i2c-bus driver will request a sempahore from the
111  * P-Unit for exclusive access to the PMIC bus when i2c drivers are accessing
112  * it, but this does not appear to be sufficient, we still need to avoid making
113  * certain P-Unit requests during the access window to avoid problems.
114  *
115  * This function locks a mutex, as such it may sleep.
116  */
117 void iosf_mbi_punit_acquire(void);
118
119 /**
120  * iosf_mbi_punit_release() - Release access to the P-Unit
121  */
122 void iosf_mbi_punit_release(void);
123
124 /**
125  * iosf_mbi_register_pmic_bus_access_notifier - Register PMIC bus notifier
126  *
127  * This function can be used by drivers which may need to acquire P-Unit
128  * managed resources from interrupt context, where iosf_mbi_punit_acquire()
129  * can not be used.
130  *
131  * This function allows a driver to register a notifier to get notified (in a
132  * process context) before other drivers start accessing the PMIC bus.
133  *
134  * This allows the driver to acquire any resources, which it may need during
135  * the window the other driver is accessing the PMIC, before hand.
136  *
137  * @nb: notifier_block to register
138  */
139 int iosf_mbi_register_pmic_bus_access_notifier(struct notifier_block *nb);
140
141 /**
142  * iosf_mbi_register_pmic_bus_access_notifier - Unregister PMIC bus notifier
143  *
144  * @nb: notifier_block to unregister
145  */
146 int iosf_mbi_unregister_pmic_bus_access_notifier(struct notifier_block *nb);
147
148 /**
149  * iosf_mbi_unregister_pmic_bus_access_notifier_unlocked - Unregister PMIC bus
150  *                                                         notifier, unlocked
151  *
152  * Like iosf_mbi_unregister_pmic_bus_access_notifier(), but for use when the
153  * caller has already called iosf_mbi_punit_acquire() itself.
154  *
155  * @nb: notifier_block to unregister
156  */
157 int iosf_mbi_unregister_pmic_bus_access_notifier_unlocked(
158         struct notifier_block *nb);
159
160 /**
161  * iosf_mbi_call_pmic_bus_access_notifier_chain - Call PMIC bus notifier chain
162  *
163  * @val: action to pass into listener's notifier_call function
164  * @v: data pointer to pass into listener's notifier_call function
165  */
166 int iosf_mbi_call_pmic_bus_access_notifier_chain(unsigned long val, void *v);
167
168 /**
169  * iosf_mbi_assert_punit_acquired - Assert that the P-Unit has been acquired.
170  */
171 void iosf_mbi_assert_punit_acquired(void);
172
173 #else /* CONFIG_IOSF_MBI is not enabled */
174 static inline
175 bool iosf_mbi_available(void)
176 {
177         return false;
178 }
179
180 static inline
181 int iosf_mbi_read(u8 port, u8 opcode, u32 offset, u32 *mdr)
182 {
183         WARN(1, "IOSF_MBI driver not available");
184         return -EPERM;
185 }
186
187 static inline
188 int iosf_mbi_write(u8 port, u8 opcode, u32 offset, u32 mdr)
189 {
190         WARN(1, "IOSF_MBI driver not available");
191         return -EPERM;
192 }
193
194 static inline
195 int iosf_mbi_modify(u8 port, u8 opcode, u32 offset, u32 mdr, u32 mask)
196 {
197         WARN(1, "IOSF_MBI driver not available");
198         return -EPERM;
199 }
200
201 static inline void iosf_mbi_punit_acquire(void) {}
202 static inline void iosf_mbi_punit_release(void) {}
203
204 static inline
205 int iosf_mbi_register_pmic_bus_access_notifier(struct notifier_block *nb)
206 {
207         return 0;
208 }
209
210 static inline
211 int iosf_mbi_unregister_pmic_bus_access_notifier(struct notifier_block *nb)
212 {
213         return 0;
214 }
215
216 static inline int
217 iosf_mbi_unregister_pmic_bus_access_notifier_unlocked(struct notifier_block *nb)
218 {
219         return 0;
220 }
221
222 static inline
223 int iosf_mbi_call_pmic_bus_access_notifier_chain(unsigned long val, void *v)
224 {
225         return 0;
226 }
227
228 static inline void iosf_mbi_assert_punit_acquired(void) {}
229
230 #endif /* CONFIG_IOSF_MBI */
231
232 #endif /* IOSF_MBI_SYMS_H */