aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/edac/edac_device.c
diff options
context:
space:
mode:
authorDouglas Thompson <dougthompson@xmission.com>2007-07-19 04:50:20 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-19 13:04:55 -0400
commit52490c8d07680a7ecc3c1a70a16841455d37e96a (patch)
treeacebfdd53c8512bbda09fee32347828a0d0ed368 /drivers/edac/edac_device.c
parentb2ccaecad2b00bf7bc72d5b864425daf43a4080d (diff)
drivers/edac: edac_device code tidying
For the file edac_device.c perform some coding style enhancements Add some function header comments Made for better readability commands Signed-off-by: Douglas Thompson <dougthompson@xmission.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/edac/edac_device.c')
-rw-r--r--drivers/edac/edac_device.c105
1 files changed, 54 insertions, 51 deletions
diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
index 258e146efcbd..3ccadda3e723 100644
--- a/drivers/edac/edac_device.c
+++ b/drivers/edac/edac_device.c
@@ -20,6 +20,7 @@
20#include <linux/highmem.h> 20#include <linux/highmem.h>
21#include <linux/timer.h> 21#include <linux/timer.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/jiffies.h>
23#include <linux/spinlock.h> 24#include <linux/spinlock.h>
24#include <linux/list.h> 25#include <linux/list.h>
25#include <linux/sysdev.h> 26#include <linux/sysdev.h>
@@ -31,20 +32,10 @@
31#include "edac_core.h" 32#include "edac_core.h"
32#include "edac_module.h" 33#include "edac_module.h"
33 34
34/* lock to memory controller's control array */ 35/* lock to memory controller's control array 'edac_device_list' */
35static DECLARE_MUTEX(device_ctls_mutex); 36static DECLARE_MUTEX(device_ctls_mutex);
36static struct list_head edac_device_list = LIST_HEAD_INIT(edac_device_list); 37static struct list_head edac_device_list = LIST_HEAD_INIT(edac_device_list);
37 38
38static inline void lock_device_list(void)
39{
40 down(&device_ctls_mutex);
41}
42
43static inline void unlock_device_list(void)
44{
45 up(&device_ctls_mutex);
46}
47
48#ifdef CONFIG_EDAC_DEBUG 39#ifdef CONFIG_EDAC_DEBUG
49static void edac_device_dump_device(struct edac_device_ctl_info *edac_dev) 40static void edac_device_dump_device(struct edac_device_ctl_info *edac_dev)
50{ 41{
@@ -58,20 +49,25 @@ static void edac_device_dump_device(struct edac_device_ctl_info *edac_dev)
58#endif /* CONFIG_EDAC_DEBUG */ 49#endif /* CONFIG_EDAC_DEBUG */
59 50
60/* 51/*
61 * The alloc() and free() functions for the 'edac_device' control info 52 * edac_device_alloc_ctl_info()
62 * structure. A MC driver will allocate one of these for each edac_device 53 * Allocate a new edac device control info structure
63 * it is going to control/register with the EDAC CORE. 54 *
55 * The control structure is allocated in complete chunk
56 * from the OS. It is in turn sub allocated to the
57 * various objects that compose the struture
58 *
59 * The structure has a 'nr_instance' array within itself.
60 * Each instance represents a major component
61 * Example: L1 cache and L2 cache are 2 instance components
62 *
63 * Within each instance is an array of 'nr_blocks' blockoffsets
64 */ 64 */
65struct edac_device_ctl_info *edac_device_alloc_ctl_info( 65struct edac_device_ctl_info *edac_device_alloc_ctl_info(
66 unsigned sz_private, 66 unsigned sz_private,
67 char *edac_device_name, 67 char *edac_device_name, unsigned nr_instances,
68 unsigned nr_instances, 68 char *edac_block_name, unsigned nr_blocks,
69 char *edac_block_name, 69 unsigned offset_value, /* zero, 1, or other based offset */
70 unsigned nr_blocks, 70 struct edac_attrib_spec *attrib_spec, unsigned nr_attribs)
71 unsigned offset_value,
72 struct edac_attrib_spec
73 *attrib_spec,
74 unsigned nr_attribs)
75{ 71{
76 struct edac_device_ctl_info *dev_ctl; 72 struct edac_device_ctl_info *dev_ctl;
77 struct edac_device_instance *dev_inst, *inst; 73 struct edac_device_instance *dev_inst, *inst;
@@ -90,7 +86,7 @@ struct edac_device_ctl_info *edac_device_alloc_ctl_info(
90 * to be at least as stringent as what the compiler would 86 * to be at least as stringent as what the compiler would
91 * provide if we could simply hardcode everything into a single struct. 87 * provide if we could simply hardcode everything into a single struct.
92 */ 88 */
93 dev_ctl = (struct edac_device_ctl_info *)0; 89 dev_ctl = (struct edac_device_ctl_info *)NULL;
94 90
95 /* Calc the 'end' offset past the ctl_info structure */ 91 /* Calc the 'end' offset past the ctl_info structure */
96 dev_inst = (struct edac_device_instance *) 92 dev_inst = (struct edac_device_instance *)
@@ -114,7 +110,8 @@ struct edac_device_ctl_info *edac_device_alloc_ctl_info(
114 total_size = ((unsigned long)pvt) + sz_private; 110 total_size = ((unsigned long)pvt) + sz_private;
115 111
116 /* Allocate the amount of memory for the set of control structures */ 112 /* Allocate the amount of memory for the set of control structures */
117 if ((dev_ctl = kmalloc(total_size, GFP_KERNEL)) == NULL) 113 dev_ctl = kzalloc(total_size, GFP_KERNEL);
114 if (dev_ctl == NULL)
118 return NULL; 115 return NULL;
119 116
120 /* Adjust pointers so they point within the memory we just allocated 117 /* Adjust pointers so they point within the memory we just allocated
@@ -128,14 +125,12 @@ struct edac_device_ctl_info *edac_device_alloc_ctl_info(
128 (((char *)dev_ctl) + ((unsigned long)dev_attrib)); 125 (((char *)dev_ctl) + ((unsigned long)dev_attrib));
129 pvt = sz_private ? (((char *)dev_ctl) + ((unsigned long)pvt)) : NULL; 126 pvt = sz_private ? (((char *)dev_ctl) + ((unsigned long)pvt)) : NULL;
130 127
131 memset(dev_ctl, 0, total_size); /* clear all fields */
132 dev_ctl->nr_instances = nr_instances; 128 dev_ctl->nr_instances = nr_instances;
133 dev_ctl->instances = dev_inst; 129 dev_ctl->instances = dev_inst;
134 dev_ctl->pvt_info = pvt; 130 dev_ctl->pvt_info = pvt;
135 131
136 /* Name of this edac device, ensure null terminated */ 132 /* Name of this edac device */
137 snprintf(dev_ctl->name, sizeof(dev_ctl->name), "%s", edac_device_name); 133 snprintf(dev_ctl->name,sizeof(dev_ctl->name),"%s",edac_device_name);
138 dev_ctl->name[sizeof(dev_ctl->name) - 1] = '\0';
139 134
140 /* Initialize every Instance */ 135 /* Initialize every Instance */
141 for (instance = 0; instance < nr_instances; instance++) { 136 for (instance = 0; instance < nr_instances; instance++) {
@@ -148,7 +143,6 @@ struct edac_device_ctl_info *edac_device_alloc_ctl_info(
148 /* name of this instance */ 143 /* name of this instance */
149 snprintf(inst->name, sizeof(inst->name), 144 snprintf(inst->name, sizeof(inst->name),
150 "%s%u", edac_device_name, instance); 145 "%s%u", edac_device_name, instance);
151 inst->name[sizeof(inst->name) - 1] = '\0';
152 146
153 /* Initialize every block in each instance */ 147 /* Initialize every block in each instance */
154 for (block = 0; block < nr_blocks; block++) { 148 for (block = 0; block < nr_blocks; block++) {
@@ -159,7 +153,6 @@ struct edac_device_ctl_info *edac_device_alloc_ctl_info(
159 blk->attribs = attrib_p; 153 blk->attribs = attrib_p;
160 snprintf(blk->name, sizeof(blk->name), 154 snprintf(blk->name, sizeof(blk->name),
161 "%s%d", edac_block_name, block+offset_value); 155 "%s%d", edac_block_name, block+offset_value);
162 blk->name[sizeof(blk->name) - 1] = '\0';
163 156
164 debugf1("%s() instance=%d block=%d name=%s\n", 157 debugf1("%s() instance=%d block=%d name=%s\n",
165 __func__, instance, block, blk->name); 158 __func__, instance, block, blk->name);
@@ -186,7 +179,6 @@ struct edac_device_ctl_info *edac_device_alloc_ctl_info(
186 179
187 return dev_ctl; 180 return dev_ctl;
188} 181}
189
190EXPORT_SYMBOL_GPL(edac_device_alloc_ctl_info); 182EXPORT_SYMBOL_GPL(edac_device_alloc_ctl_info);
191 183
192/* 184/*
@@ -198,12 +190,17 @@ void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info)
198{ 190{
199 kfree(ctl_info); 191 kfree(ctl_info);
200} 192}
201
202EXPORT_SYMBOL_GPL(edac_device_free_ctl_info); 193EXPORT_SYMBOL_GPL(edac_device_free_ctl_info);
203 194
204/* 195/*
205 * find_edac_device_by_dev 196 * find_edac_device_by_dev
206 * scans the edac_device list for a specific 'struct device *' 197 * scans the edac_device list for a specific 'struct device *'
198 *
199 * lock to be held prior to call: device_ctls_mutex
200 *
201 * Return:
202 * pointer to control structure managing 'dev'
203 * NULL if not found on list
207 */ 204 */
208static struct edac_device_ctl_info *find_edac_device_by_dev(struct device *dev) 205static struct edac_device_ctl_info *find_edac_device_by_dev(struct device *dev)
209{ 206{
@@ -226,6 +223,9 @@ static struct edac_device_ctl_info *find_edac_device_by_dev(struct device *dev)
226 * add_edac_dev_to_global_list 223 * add_edac_dev_to_global_list
227 * Before calling this function, caller must 224 * Before calling this function, caller must
228 * assign a unique value to edac_dev->dev_idx. 225 * assign a unique value to edac_dev->dev_idx.
226 *
227 * lock to be held prior to call: device_ctls_mutex
228 *
229 * Return: 229 * Return:
230 * 0 on success 230 * 0 on success
231 * 1 on failure. 231 * 1 on failure.
@@ -238,7 +238,8 @@ static int add_edac_dev_to_global_list(struct edac_device_ctl_info *edac_dev)
238 insert_before = &edac_device_list; 238 insert_before = &edac_device_list;
239 239
240 /* Determine if already on the list */ 240 /* Determine if already on the list */
241 if (unlikely((rover = find_edac_device_by_dev(edac_dev->dev)) != NULL)) 241 rover = find_edac_device_by_dev(edac_dev->dev);
242 if (unlikely(rover != NULL))
242 goto fail0; 243 goto fail0;
243 244
244 /* Insert in ascending order by 'dev_idx', so find position */ 245 /* Insert in ascending order by 'dev_idx', so find position */
@@ -274,6 +275,8 @@ fail1:
274 275
275/* 276/*
276 * complete_edac_device_list_del 277 * complete_edac_device_list_del
278 *
279 * callback function when reference count is zero
277 */ 280 */
278static void complete_edac_device_list_del(struct rcu_head *head) 281static void complete_edac_device_list_del(struct rcu_head *head)
279{ 282{
@@ -286,6 +289,9 @@ static void complete_edac_device_list_del(struct rcu_head *head)
286 289
287/* 290/*
288 * del_edac_device_from_global_list 291 * del_edac_device_from_global_list
292 *
293 * remove the RCU, setup for a callback call, then wait for the
294 * callback to occur
289 */ 295 */
290static void del_edac_device_from_global_list(struct edac_device_ctl_info 296static void del_edac_device_from_global_list(struct edac_device_ctl_info
291 *edac_device) 297 *edac_device)
@@ -325,8 +331,7 @@ struct edac_device_ctl_info *edac_device_find(int idx)
325 331
326 return NULL; 332 return NULL;
327} 333}
328 334EXPORT_SYMBOL_GPL(edac_device_find);
329EXPORT_SYMBOL(edac_device_find);
330 335
331/* 336/*
332 * edac_device_workq_function 337 * edac_device_workq_function
@@ -338,7 +343,7 @@ static void edac_device_workq_function(struct work_struct *work_req)
338 struct edac_device_ctl_info *edac_dev = to_edac_device_ctl_work(d_work); 343 struct edac_device_ctl_info *edac_dev = to_edac_device_ctl_work(d_work);
339 344
340 //debugf0("%s() here and running\n", __func__); 345 //debugf0("%s() here and running\n", __func__);
341 lock_device_list(); 346 down(&device_ctls_mutex);
342 347
343 /* Only poll controllers that are running polled and have a check */ 348 /* Only poll controllers that are running polled and have a check */
344 if ((edac_dev->op_state == OP_RUNNING_POLL) && 349 if ((edac_dev->op_state == OP_RUNNING_POLL) &&
@@ -346,7 +351,7 @@ static void edac_device_workq_function(struct work_struct *work_req)
346 edac_dev->edac_check(edac_dev); 351 edac_dev->edac_check(edac_dev);
347 } 352 }
348 353
349 unlock_device_list(); 354 up(&device_ctls_mutex);
350 355
351 /* Reschedule */ 356 /* Reschedule */
352 queue_delayed_work(edac_workqueue, &edac_dev->work, edac_dev->delay); 357 queue_delayed_work(edac_workqueue, &edac_dev->work, edac_dev->delay);
@@ -363,7 +368,7 @@ void edac_device_workq_setup(struct edac_device_ctl_info *edac_dev,
363 debugf0("%s()\n", __func__); 368 debugf0("%s()\n", __func__);
364 369
365 edac_dev->poll_msec = msec; 370 edac_dev->poll_msec = msec;
366 edac_calc_delay(edac_dev); /* Calc delay jiffies */ 371 edac_dev->delay = msecs_to_jiffies(msec); /* Calc delay jiffies */
367 372
368 INIT_DELAYED_WORK(&edac_dev->work, edac_device_workq_function); 373 INIT_DELAYED_WORK(&edac_dev->work, edac_device_workq_function);
369 queue_delayed_work(edac_workqueue, &edac_dev->work, edac_dev->delay); 374 queue_delayed_work(edac_workqueue, &edac_dev->work, edac_dev->delay);
@@ -391,7 +396,7 @@ void edac_device_workq_teardown(struct edac_device_ctl_info *edac_dev)
391void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev, 396void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
392 unsigned long value) 397 unsigned long value)
393{ 398{
394 lock_device_list(); 399 down(&device_ctls_mutex);
395 400
396 /* cancel the current workq request */ 401 /* cancel the current workq request */
397 edac_device_workq_teardown(edac_dev); 402 edac_device_workq_teardown(edac_dev);
@@ -399,7 +404,7 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
399 /* restart the workq request, with new delay value */ 404 /* restart the workq request, with new delay value */
400 edac_device_workq_setup(edac_dev, value); 405 edac_device_workq_setup(edac_dev, value);
401 406
402 unlock_device_list(); 407 up(&device_ctls_mutex);
403} 408}
404 409
405/** 410/**
@@ -423,7 +428,7 @@ int edac_device_add_device(struct edac_device_ctl_info *edac_dev, int edac_idx)
423 if (edac_debug_level >= 3) 428 if (edac_debug_level >= 3)
424 edac_device_dump_device(edac_dev); 429 edac_device_dump_device(edac_dev);
425#endif 430#endif
426 lock_device_list(); 431 down(&device_ctls_mutex);
427 432
428 if (add_edac_dev_to_global_list(edac_dev)) 433 if (add_edac_dev_to_global_list(edac_dev))
429 goto fail0; 434 goto fail0;
@@ -461,7 +466,7 @@ int edac_device_add_device(struct edac_device_ctl_info *edac_dev, int edac_idx)
461 dev_name(edac_dev), 466 dev_name(edac_dev),
462 edac_op_state_toString(edac_dev->op_state)); 467 edac_op_state_toString(edac_dev->op_state));
463 468
464 unlock_device_list(); 469 up(&device_ctls_mutex);
465 return 0; 470 return 0;
466 471
467fail1: 472fail1:
@@ -469,10 +474,9 @@ fail1:
469 del_edac_device_from_global_list(edac_dev); 474 del_edac_device_from_global_list(edac_dev);
470 475
471fail0: 476fail0:
472 unlock_device_list(); 477 up(&device_ctls_mutex);
473 return 1; 478 return 1;
474} 479}
475
476EXPORT_SYMBOL_GPL(edac_device_add_device); 480EXPORT_SYMBOL_GPL(edac_device_add_device);
477 481
478/** 482/**
@@ -494,10 +498,12 @@ struct edac_device_ctl_info *edac_device_del_device(struct device *dev)
494 498
495 debugf0("MC: %s()\n", __func__); 499 debugf0("MC: %s()\n", __func__);
496 500
497 lock_device_list(); 501 down(&device_ctls_mutex);
498 502
499 if ((edac_dev = find_edac_device_by_dev(dev)) == NULL) { 503 /* Find the structure on the list, if not there, then leave */
500 unlock_device_list(); 504 edac_dev = find_edac_device_by_dev(dev);
505 if (edac_dev == NULL) {
506 up(&device_ctls_mutex);
501 return NULL; 507 return NULL;
502 } 508 }
503 509
@@ -513,7 +519,7 @@ struct edac_device_ctl_info *edac_device_del_device(struct device *dev)
513 /* deregister from global list */ 519 /* deregister from global list */
514 del_edac_device_from_global_list(edac_dev); 520 del_edac_device_from_global_list(edac_dev);
515 521
516 unlock_device_list(); 522 up(&device_ctls_mutex);
517 523
518 edac_printk(KERN_INFO, EDAC_MC, 524 edac_printk(KERN_INFO, EDAC_MC,
519 "Removed device %d for %s %s: DEV %s\n", 525 "Removed device %d for %s %s: DEV %s\n",
@@ -522,7 +528,6 @@ struct edac_device_ctl_info *edac_device_del_device(struct device *dev)
522 528
523 return edac_dev; 529 return edac_dev;
524} 530}
525
526EXPORT_SYMBOL_GPL(edac_device_del_device); 531EXPORT_SYMBOL_GPL(edac_device_del_device);
527 532
528static inline int edac_device_get_log_ce(struct edac_device_ctl_info *edac_dev) 533static inline int edac_device_get_log_ce(struct edac_device_ctl_info *edac_dev)
@@ -585,7 +590,6 @@ void edac_device_handle_ce(struct edac_device_ctl_info *edac_dev,
585 edac_dev->ctl_name, instance->name, 590 edac_dev->ctl_name, instance->name,
586 block ? block->name : "N/A", msg); 591 block ? block->name : "N/A", msg);
587} 592}
588
589EXPORT_SYMBOL_GPL(edac_device_handle_ce); 593EXPORT_SYMBOL_GPL(edac_device_handle_ce);
590 594
591/* 595/*
@@ -637,5 +641,4 @@ void edac_device_handle_ue(struct edac_device_ctl_info *edac_dev,
637 edac_dev->ctl_name, instance->name, 641 edac_dev->ctl_name, instance->name,
638 block ? block->name : "N/A", msg); 642 block ? block->name : "N/A", msg);
639} 643}
640
641EXPORT_SYMBOL_GPL(edac_device_handle_ue); 644EXPORT_SYMBOL_GPL(edac_device_handle_ue);