edac_device.c
来自「linux 内核源代码」· C语言 代码 · 共 747 行 · 第 1/2 页
C
747 行
* edac_device_find * Search for a edac_device_ctl_info structure whose index is 'idx'. * * If found, return a pointer to the structure. * Else return NULL. * * Caller must hold device_ctls_mutex. */struct edac_device_ctl_info *edac_device_find(int idx){ struct list_head *item; struct edac_device_ctl_info *edac_dev; /* Iterate over list, looking for exact match of ID */ list_for_each(item, &edac_device_list) { edac_dev = list_entry(item, struct edac_device_ctl_info, link); if (edac_dev->dev_idx >= idx) { if (edac_dev->dev_idx == idx) return edac_dev; /* not on list, so terminate early */ break; } } return NULL;}EXPORT_SYMBOL_GPL(edac_device_find);/* * edac_device_workq_function * performs the operation scheduled by a workq request * * this workq is embedded within an edac_device_ctl_info * structure, that needs to be polled for possible error events. * * This operation is to acquire the list mutex lock * (thus preventing insertation or deletion) * and then call the device's poll function IFF this device is * running polled and there is a poll function defined. */static void edac_device_workq_function(struct work_struct *work_req){ struct delayed_work *d_work = (struct delayed_work *)work_req; struct edac_device_ctl_info *edac_dev = to_edac_device_ctl_work(d_work); mutex_lock(&device_ctls_mutex); /* Only poll controllers that are running polled and have a check */ if ((edac_dev->op_state == OP_RUNNING_POLL) && (edac_dev->edac_check != NULL)) { edac_dev->edac_check(edac_dev); } mutex_unlock(&device_ctls_mutex); /* Reschedule the workq for the next time period to start again * if the number of msec is for 1 sec, then adjust to the next * whole one second to save timers fireing all over the period * between integral seconds */ if (edac_dev->poll_msec == 1000) queue_delayed_work(edac_workqueue, &edac_dev->work, round_jiffies(edac_dev->delay)); else queue_delayed_work(edac_workqueue, &edac_dev->work, edac_dev->delay);}/* * edac_device_workq_setup * initialize a workq item for this edac_device instance * passing in the new delay period in msec */void edac_device_workq_setup(struct edac_device_ctl_info *edac_dev, unsigned msec){ debugf0("%s()\n", __func__); /* take the arg 'msec' and set it into the control structure * to used in the time period calculation * then calc the number of jiffies that represents */ edac_dev->poll_msec = msec; edac_dev->delay = msecs_to_jiffies(msec); INIT_DELAYED_WORK(&edac_dev->work, edac_device_workq_function); /* optimize here for the 1 second case, which will be normal value, to * fire ON the 1 second time event. This helps reduce all sorts of * timers firing on sub-second basis, while they are happy * to fire together on the 1 second exactly */ if (edac_dev->poll_msec == 1000) queue_delayed_work(edac_workqueue, &edac_dev->work, round_jiffies(edac_dev->delay)); else queue_delayed_work(edac_workqueue, &edac_dev->work, edac_dev->delay);}/* * edac_device_workq_teardown * stop the workq processing on this edac_dev */void edac_device_workq_teardown(struct edac_device_ctl_info *edac_dev){ int status; status = cancel_delayed_work(&edac_dev->work); if (status == 0) { /* workq instance might be running, wait for it */ flush_workqueue(edac_workqueue); }}/* * edac_device_reset_delay_period * * need to stop any outstanding workq queued up at this time * because we will be resetting the sleep time. * Then restart the workq on the new delay */void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev, unsigned long value){ /* cancel the current workq request, without the mutex lock */ edac_device_workq_teardown(edac_dev); /* acquire the mutex before doing the workq setup */ mutex_lock(&device_ctls_mutex); /* restart the workq request, with new delay value */ edac_device_workq_setup(edac_dev, value); mutex_unlock(&device_ctls_mutex);}/** * edac_device_add_device: Insert the 'edac_dev' structure into the * edac_device global list and create sysfs entries associated with * edac_device structure. * @edac_device: pointer to the edac_device structure to be added to the list * 'edac_device' structure. * * Return: * 0 Success * !0 Failure */int edac_device_add_device(struct edac_device_ctl_info *edac_dev){ debugf0("%s()\n", __func__);#ifdef CONFIG_EDAC_DEBUG if (edac_debug_level >= 3) edac_device_dump_device(edac_dev);#endif mutex_lock(&device_ctls_mutex); if (add_edac_dev_to_global_list(edac_dev)) goto fail0; /* set load time so that error rate can be tracked */ edac_dev->start_time = jiffies; /* create this instance's sysfs entries */ if (edac_device_create_sysfs(edac_dev)) { edac_device_printk(edac_dev, KERN_WARNING, "failed to create sysfs device\n"); goto fail1; } /* If there IS a check routine, then we are running POLLED */ if (edac_dev->edac_check != NULL) { /* This instance is NOW RUNNING */ edac_dev->op_state = OP_RUNNING_POLL; /* * enable workq processing on this instance, * default = 1000 msec */ edac_device_workq_setup(edac_dev, 1000); } else { edac_dev->op_state = OP_RUNNING_INTERRUPT; } /* Report action taken */ edac_device_printk(edac_dev, KERN_INFO, "Giving out device to module '%s' controller " "'%s': DEV '%s' (%s)\n", edac_dev->mod_name, edac_dev->ctl_name, dev_name(edac_dev), edac_op_state_to_string(edac_dev->op_state)); mutex_unlock(&device_ctls_mutex); return 0;fail1: /* Some error, so remove the entry from the lsit */ del_edac_device_from_global_list(edac_dev);fail0: mutex_unlock(&device_ctls_mutex); return 1;}EXPORT_SYMBOL_GPL(edac_device_add_device);/** * edac_device_del_device: * Remove sysfs entries for specified edac_device structure and * then remove edac_device structure from global list * * @pdev: * Pointer to 'struct device' representing edac_device * structure to remove. * * Return: * Pointer to removed edac_device structure, * OR NULL if device not found. */struct edac_device_ctl_info *edac_device_del_device(struct device *dev){ struct edac_device_ctl_info *edac_dev; debugf0("%s()\n", __func__); mutex_lock(&device_ctls_mutex); /* Find the structure on the list, if not there, then leave */ edac_dev = find_edac_device_by_dev(dev); if (edac_dev == NULL) { mutex_unlock(&device_ctls_mutex); return NULL; } /* mark this instance as OFFLINE */ edac_dev->op_state = OP_OFFLINE; /* clear workq processing on this instance */ edac_device_workq_teardown(edac_dev); /* deregister from global list */ del_edac_device_from_global_list(edac_dev); mutex_unlock(&device_ctls_mutex); /* Tear down the sysfs entries for this instance */ edac_device_remove_sysfs(edac_dev); edac_printk(KERN_INFO, EDAC_MC, "Removed device %d for %s %s: DEV %s\n", edac_dev->dev_idx, edac_dev->mod_name, edac_dev->ctl_name, dev_name(edac_dev)); return edac_dev;}EXPORT_SYMBOL_GPL(edac_device_del_device);static inline int edac_device_get_log_ce(struct edac_device_ctl_info *edac_dev){ return edac_dev->log_ce;}static inline int edac_device_get_log_ue(struct edac_device_ctl_info *edac_dev){ return edac_dev->log_ue;}static inline int edac_device_get_panic_on_ue(struct edac_device_ctl_info *edac_dev){ return edac_dev->panic_on_ue;}/* * edac_device_handle_ce * perform a common output and handling of an 'edac_dev' CE event */void edac_device_handle_ce(struct edac_device_ctl_info *edac_dev, int inst_nr, int block_nr, const char *msg){ struct edac_device_instance *instance; struct edac_device_block *block = NULL; if ((inst_nr >= edac_dev->nr_instances) || (inst_nr < 0)) { edac_device_printk(edac_dev, KERN_ERR, "INTERNAL ERROR: 'instance' out of range " "(%d >= %d)\n", inst_nr, edac_dev->nr_instances); return; } instance = edac_dev->instances + inst_nr; if ((block_nr >= instance->nr_blocks) || (block_nr < 0)) { edac_device_printk(edac_dev, KERN_ERR, "INTERNAL ERROR: instance %d 'block' " "out of range (%d >= %d)\n", inst_nr, block_nr, instance->nr_blocks); return; } if (instance->nr_blocks > 0) { block = instance->blocks + block_nr; block->counters.ce_count++; } /* Propogate the count up the 'totals' tree */ instance->counters.ce_count++; edac_dev->counters.ce_count++; if (edac_device_get_log_ce(edac_dev)) edac_device_printk(edac_dev, KERN_WARNING, "CE: %s instance: %s block: %s '%s'\n", edac_dev->ctl_name, instance->name, block ? block->name : "N/A", msg);}EXPORT_SYMBOL_GPL(edac_device_handle_ce);/* * edac_device_handle_ue * perform a common output and handling of an 'edac_dev' UE event */void edac_device_handle_ue(struct edac_device_ctl_info *edac_dev, int inst_nr, int block_nr, const char *msg){ struct edac_device_instance *instance; struct edac_device_block *block = NULL; if ((inst_nr >= edac_dev->nr_instances) || (inst_nr < 0)) { edac_device_printk(edac_dev, KERN_ERR, "INTERNAL ERROR: 'instance' out of range " "(%d >= %d)\n", inst_nr, edac_dev->nr_instances); return; } instance = edac_dev->instances + inst_nr; if ((block_nr >= instance->nr_blocks) || (block_nr < 0)) { edac_device_printk(edac_dev, KERN_ERR, "INTERNAL ERROR: instance %d 'block' " "out of range (%d >= %d)\n", inst_nr, block_nr, instance->nr_blocks); return; } if (instance->nr_blocks > 0) { block = instance->blocks + block_nr; block->counters.ue_count++; } /* Propogate the count up the 'totals' tree */ instance->counters.ue_count++; edac_dev->counters.ue_count++; if (edac_device_get_log_ue(edac_dev)) edac_device_printk(edac_dev, KERN_EMERG, "UE: %s instance: %s block: %s '%s'\n", edac_dev->ctl_name, instance->name, block ? block->name : "N/A", msg); if (edac_device_get_panic_on_ue(edac_dev)) panic("EDAC %s: UE instance: %s block %s '%s'\n", edac_dev->ctl_name, instance->name, block ? block->name : "N/A", msg);}EXPORT_SYMBOL_GPL(edac_device_handle_ue);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?