aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/mei/hw-me.c
diff options
context:
space:
mode:
authorTomas Winkler <tomas.winkler@intel.com>2013-02-06 07:06:41 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-02-06 14:23:47 -0500
commit827eef51f8dd9a4ab62b4ad270c15472f46938f2 (patch)
tree15798db67af269512bdb4ae54f36e0a26d178d4a /drivers/misc/mei/hw-me.c
parent52c34561415b420301f1580413a9d1891d079494 (diff)
mei: separate compilation of the ME hardware specifics
We add struct mei_hw_ops to virtualize access to hw specific configurations. This allows us to separate the compilation of the ME interface from the ME hardware specifics Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc/mei/hw-me.c')
-rw-r--r--drivers/misc/mei/hw-me.c87
1 files changed, 60 insertions, 27 deletions
diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c
index 3bdf22848a91..6300943497ae 100644
--- a/drivers/misc/mei/hw-me.c
+++ b/drivers/misc/mei/hw-me.c
@@ -56,7 +56,7 @@ static inline void mei_reg_write(const struct mei_me_hw *hw,
56 * 56 *
57 * returns ME_CB_RW register value (u32) 57 * returns ME_CB_RW register value (u32)
58 */ 58 */
59u32 mei_mecbrw_read(const struct mei_device *dev) 59static u32 mei_me_mecbrw_read(const struct mei_device *dev)
60{ 60{
61 return mei_reg_read(to_me_hw(dev), ME_CB_RW); 61 return mei_reg_read(to_me_hw(dev), ME_CB_RW);
62} 62}
@@ -102,7 +102,7 @@ static inline void mei_hcsr_set(struct mei_me_hw *hw, u32 hcsr)
102 * 102 *
103 * @dev: mei device 103 * @dev: mei device
104 */ 104 */
105void mei_hw_config(struct mei_device *dev) 105static void mei_me_hw_config(struct mei_device *dev)
106{ 106{
107 u32 hcsr = mei_hcsr_read(to_me_hw(dev)); 107 u32 hcsr = mei_hcsr_read(to_me_hw(dev));
108 /* Doesn't change in runtime */ 108 /* Doesn't change in runtime */
@@ -113,20 +113,19 @@ void mei_hw_config(struct mei_device *dev)
113 * 113 *
114 * @dev: the device structure 114 * @dev: the device structure
115 */ 115 */
116void mei_clear_interrupts(struct mei_device *dev) 116static void mei_me_intr_clear(struct mei_device *dev)
117{ 117{
118 struct mei_me_hw *hw = to_me_hw(dev); 118 struct mei_me_hw *hw = to_me_hw(dev);
119 u32 hcsr = mei_hcsr_read(hw); 119 u32 hcsr = mei_hcsr_read(hw);
120 if ((hcsr & H_IS) == H_IS) 120 if ((hcsr & H_IS) == H_IS)
121 mei_reg_write(hw, H_CSR, hcsr); 121 mei_reg_write(hw, H_CSR, hcsr);
122} 122}
123
124/** 123/**
125 * mei_enable_interrupts - enables mei device interrupts 124 * mei_me_intr_enable - enables mei device interrupts
126 * 125 *
127 * @dev: the device structure 126 * @dev: the device structure
128 */ 127 */
129void mei_enable_interrupts(struct mei_device *dev) 128static void mei_me_intr_enable(struct mei_device *dev)
130{ 129{
131 struct mei_me_hw *hw = to_me_hw(dev); 130 struct mei_me_hw *hw = to_me_hw(dev);
132 u32 hcsr = mei_hcsr_read(hw); 131 u32 hcsr = mei_hcsr_read(hw);
@@ -139,7 +138,7 @@ void mei_enable_interrupts(struct mei_device *dev)
139 * 138 *
140 * @dev: the device structure 139 * @dev: the device structure
141 */ 140 */
142void mei_disable_interrupts(struct mei_device *dev) 141static void mei_me_intr_disable(struct mei_device *dev)
143{ 142{
144 struct mei_me_hw *hw = to_me_hw(dev); 143 struct mei_me_hw *hw = to_me_hw(dev);
145 u32 hcsr = mei_hcsr_read(hw); 144 u32 hcsr = mei_hcsr_read(hw);
@@ -148,12 +147,12 @@ void mei_disable_interrupts(struct mei_device *dev)
148} 147}
149 148
150/** 149/**
151 * mei_hw_reset - resets fw via mei csr register. 150 * mei_me_hw_reset - resets fw via mei csr register.
152 * 151 *
153 * @dev: the device structure 152 * @dev: the device structure
154 * @interrupts_enabled: if interrupt should be enabled after reset. 153 * @interrupts_enabled: if interrupt should be enabled after reset.
155 */ 154 */
156void mei_hw_reset(struct mei_device *dev, bool intr_enable) 155static void mei_me_hw_reset(struct mei_device *dev, bool intr_enable)
157{ 156{
158 struct mei_me_hw *hw = to_me_hw(dev); 157 struct mei_me_hw *hw = to_me_hw(dev);
159 u32 hcsr = mei_hcsr_read(hw); 158 u32 hcsr = mei_hcsr_read(hw);
@@ -180,25 +179,25 @@ void mei_hw_reset(struct mei_device *dev, bool intr_enable)
180} 179}
181 180
182/** 181/**
183 * mei_host_set_ready - enable device 182 * mei_me_host_set_ready - enable device
184 * 183 *
185 * @dev - mei device 184 * @dev - mei device
186 * returns bool 185 * returns bool
187 */ 186 */
188 187
189void mei_host_set_ready(struct mei_device *dev) 188static void mei_me_host_set_ready(struct mei_device *dev)
190{ 189{
191 struct mei_me_hw *hw = to_me_hw(dev); 190 struct mei_me_hw *hw = to_me_hw(dev);
192 hw->host_hw_state |= H_IE | H_IG | H_RDY; 191 hw->host_hw_state |= H_IE | H_IG | H_RDY;
193 mei_hcsr_set(hw, hw->host_hw_state); 192 mei_hcsr_set(hw, hw->host_hw_state);
194} 193}
195/** 194/**
196 * mei_host_is_ready - check whether the host has turned ready 195 * mei_me_host_is_ready - check whether the host has turned ready
197 * 196 *
198 * @dev - mei device 197 * @dev - mei device
199 * returns bool 198 * returns bool
200 */ 199 */
201bool mei_host_is_ready(struct mei_device *dev) 200static bool mei_me_host_is_ready(struct mei_device *dev)
202{ 201{
203 struct mei_me_hw *hw = to_me_hw(dev); 202 struct mei_me_hw *hw = to_me_hw(dev);
204 hw->host_hw_state = mei_hcsr_read(hw); 203 hw->host_hw_state = mei_hcsr_read(hw);
@@ -206,12 +205,12 @@ bool mei_host_is_ready(struct mei_device *dev)
206} 205}
207 206
208/** 207/**
209 * mei_me_is_ready - check whether the me has turned ready 208 * mei_me_hw_is_ready - check whether the me(hw) has turned ready
210 * 209 *
211 * @dev - mei device 210 * @dev - mei device
212 * returns bool 211 * returns bool
213 */ 212 */
214bool mei_me_is_ready(struct mei_device *dev) 213static bool mei_me_hw_is_ready(struct mei_device *dev)
215{ 214{
216 struct mei_me_hw *hw = to_me_hw(dev); 215 struct mei_me_hw *hw = to_me_hw(dev);
217 hw->me_hw_state = mei_mecsr_read(hw); 216 hw->me_hw_state = mei_mecsr_read(hw);
@@ -268,19 +267,19 @@ static unsigned char mei_hbuf_filled_slots(struct mei_device *dev)
268 * 267 *
269 * returns true if empty, false - otherwise. 268 * returns true if empty, false - otherwise.
270 */ 269 */
271bool mei_hbuf_is_empty(struct mei_device *dev) 270static bool mei_me_hbuf_is_empty(struct mei_device *dev)
272{ 271{
273 return mei_hbuf_filled_slots(dev) == 0; 272 return mei_hbuf_filled_slots(dev) == 0;
274} 273}
275 274
276/** 275/**
277 * mei_hbuf_empty_slots - counts write empty slots. 276 * mei_me_hbuf_empty_slots - counts write empty slots.
278 * 277 *
279 * @dev: the device structure 278 * @dev: the device structure
280 * 279 *
281 * returns -1(ESLOTS_OVERFLOW) if overflow, otherwise empty slots count 280 * returns -1(ESLOTS_OVERFLOW) if overflow, otherwise empty slots count
282 */ 281 */
283int mei_hbuf_empty_slots(struct mei_device *dev) 282static int mei_me_hbuf_empty_slots(struct mei_device *dev)
284{ 283{
285 unsigned char filled_slots, empty_slots; 284 unsigned char filled_slots, empty_slots;
286 285
@@ -294,6 +293,12 @@ int mei_hbuf_empty_slots(struct mei_device *dev)
294 return empty_slots; 293 return empty_slots;
295} 294}
296 295
296static size_t mei_me_hbuf_max_len(const struct mei_device *dev)
297{
298 return dev->hbuf_depth * sizeof(u32) - sizeof(struct mei_msg_hdr);
299}
300
301
297/** 302/**
298 * mei_write_message - writes a message to mei device. 303 * mei_write_message - writes a message to mei device.
299 * 304 *
@@ -303,8 +308,9 @@ int mei_hbuf_empty_slots(struct mei_device *dev)
303 * 308 *
304 * This function returns -EIO if write has failed 309 * This function returns -EIO if write has failed
305 */ 310 */
306int mei_write_message(struct mei_device *dev, struct mei_msg_hdr *header, 311static int mei_me_write_message(struct mei_device *dev,
307 unsigned char *buf) 312 struct mei_msg_hdr *header,
313 unsigned char *buf)
308{ 314{
309 struct mei_me_hw *hw = to_me_hw(dev); 315 struct mei_me_hw *hw = to_me_hw(dev);
310 unsigned long rem, dw_cnt; 316 unsigned long rem, dw_cnt;
@@ -337,20 +343,20 @@ int mei_write_message(struct mei_device *dev, struct mei_msg_hdr *header,
337 343
338 hcsr = mei_hcsr_read(hw) | H_IG; 344 hcsr = mei_hcsr_read(hw) | H_IG;
339 mei_hcsr_set(hw, hcsr); 345 mei_hcsr_set(hw, hcsr);
340 if (!mei_me_is_ready(dev)) 346 if (!mei_me_hw_is_ready(dev))
341 return -EIO; 347 return -EIO;
342 348
343 return 0; 349 return 0;
344} 350}
345 351
346/** 352/**
347 * mei_count_full_read_slots - counts read full slots. 353 * mei_me_count_full_read_slots - counts read full slots.
348 * 354 *
349 * @dev: the device structure 355 * @dev: the device structure
350 * 356 *
351 * returns -1(ESLOTS_OVERFLOW) if overflow, otherwise filled slots count 357 * returns -1(ESLOTS_OVERFLOW) if overflow, otherwise filled slots count
352 */ 358 */
353int mei_count_full_read_slots(struct mei_device *dev) 359static int mei_me_count_full_read_slots(struct mei_device *dev)
354{ 360{
355 struct mei_me_hw *hw = to_me_hw(dev); 361 struct mei_me_hw *hw = to_me_hw(dev);
356 char read_ptr, write_ptr; 362 char read_ptr, write_ptr;
@@ -371,13 +377,13 @@ int mei_count_full_read_slots(struct mei_device *dev)
371} 377}
372 378
373/** 379/**
374 * mei_read_slots - reads a message from mei device. 380 * mei_me_read_slots - reads a message from mei device.
375 * 381 *
376 * @dev: the device structure 382 * @dev: the device structure
377 * @buffer: message buffer will be written 383 * @buffer: message buffer will be written
378 * @buffer_length: message size will be read 384 * @buffer_length: message size will be read
379 */ 385 */
380void mei_read_slots(struct mei_device *dev, unsigned char *buffer, 386static int mei_me_read_slots(struct mei_device *dev, unsigned char *buffer,
381 unsigned long buffer_length) 387 unsigned long buffer_length)
382{ 388{
383 struct mei_me_hw *hw = to_me_hw(dev); 389 struct mei_me_hw *hw = to_me_hw(dev);
@@ -385,17 +391,42 @@ void mei_read_slots(struct mei_device *dev, unsigned char *buffer,
385 u32 hcsr; 391 u32 hcsr;
386 392
387 for (; buffer_length >= sizeof(u32); buffer_length -= sizeof(u32)) 393 for (; buffer_length >= sizeof(u32); buffer_length -= sizeof(u32))
388 *reg_buf++ = mei_mecbrw_read(dev); 394 *reg_buf++ = mei_me_mecbrw_read(dev);
389 395
390 if (buffer_length > 0) { 396 if (buffer_length > 0) {
391 u32 reg = mei_mecbrw_read(dev); 397 u32 reg = mei_me_mecbrw_read(dev);
392 memcpy(reg_buf, &reg, buffer_length); 398 memcpy(reg_buf, &reg, buffer_length);
393 } 399 }
394 400
395 hcsr = mei_hcsr_read(hw) | H_IG; 401 hcsr = mei_hcsr_read(hw) | H_IG;
396 mei_hcsr_set(hw, hcsr); 402 mei_hcsr_set(hw, hcsr);
403 return 0;
397} 404}
398 405
406static const struct mei_hw_ops mei_me_hw_ops = {
407
408 .host_set_ready = mei_me_host_set_ready,
409 .host_is_ready = mei_me_host_is_ready,
410
411 .hw_is_ready = mei_me_hw_is_ready,
412 .hw_reset = mei_me_hw_reset,
413 .hw_config = mei_me_hw_config,
414
415 .intr_clear = mei_me_intr_clear,
416 .intr_enable = mei_me_intr_enable,
417 .intr_disable = mei_me_intr_disable,
418
419 .hbuf_free_slots = mei_me_hbuf_empty_slots,
420 .hbuf_is_ready = mei_me_hbuf_is_empty,
421 .hbuf_max_len = mei_me_hbuf_max_len,
422
423 .write = mei_me_write_message,
424
425 .rdbuf_full_slots = mei_me_count_full_read_slots,
426 .read_hdr = mei_me_mecbrw_read,
427 .read = mei_me_read_slots
428};
429
399/** 430/**
400 * init_mei_device - allocates and initializes the mei device structure 431 * init_mei_device - allocates and initializes the mei device structure
401 * 432 *
@@ -422,6 +453,8 @@ struct mei_device *mei_me_dev_init(struct pci_dev *pdev)
422 INIT_DELAYED_WORK(&dev->timer_work, mei_timer); 453 INIT_DELAYED_WORK(&dev->timer_work, mei_timer);
423 INIT_WORK(&dev->init_work, mei_host_client_init); 454 INIT_WORK(&dev->init_work, mei_host_client_init);
424 455
456 dev->ops = &mei_me_hw_ops;
457
425 dev->pdev = pdev; 458 dev->pdev = pdev;
426 return dev; 459 return dev;
427} 460}