aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/device.h
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2007-01-20 02:00:26 -0500
committerJeff Garzik <jeff@garzik.org>2007-02-09 17:39:36 -0500
commit9ac7849e35f705830f7b016ff272b0ff1f7ff759 (patch)
tree7f17cdff87e154937a15cc2ec8da9b4e6018ce8e /include/linux/device.h
parent77a527eadb425b60db3f5f0aae6a4c51c38e35e5 (diff)
devres: device resource management
Implement device resource management, in short, devres. A device driver can allocate arbirary size of devres data which is associated with a release function. On driver detach, release function is invoked on the devres data, then, devres data is freed. devreses are typed by associated release functions. Some devreses are better represented by single instance of the type while others need multiple instances sharing the same release function. Both usages are supported. devreses can be grouped using devres group such that a device driver can easily release acquired resources halfway through initialization or selectively release resources (e.g. resources for port 1 out of 4 ports). This patch adds devres core including documentation and the following managed interfaces. * alloc/free : devm_kzalloc(), devm_kzfree() * IO region : devm_request_region(), devm_release_region() * IRQ : devm_request_irq(), devm_free_irq() * DMA : dmam_alloc_coherent(), dmam_free_coherent(), dmam_declare_coherent_memory(), dmam_pool_create(), dmam_pool_destroy() * PCI : pcim_enable_device(), pcim_pin_device(), pci_is_managed() * iomap : devm_ioport_map(), devm_ioport_unmap(), devm_ioremap(), devm_ioremap_nocache(), devm_iounmap(), pcim_iomap_table(), pcim_iomap(), pcim_iounmap() Signed-off-by: Tejun Heo <htejun@gmail.com> Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'include/linux/device.h')
-rw-r--r--include/linux/device.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/include/linux/device.h b/include/linux/device.h
index 5ca1cdba563a..26e4692f2d1a 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -354,6 +354,41 @@ extern int __must_check device_create_bin_file(struct device *dev,
354 struct bin_attribute *attr); 354 struct bin_attribute *attr);
355extern void device_remove_bin_file(struct device *dev, 355extern void device_remove_bin_file(struct device *dev,
356 struct bin_attribute *attr); 356 struct bin_attribute *attr);
357
358/* device resource management */
359typedef void (*dr_release_t)(struct device *dev, void *res);
360typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data);
361
362#ifdef CONFIG_DEBUG_DEVRES
363extern void * __devres_alloc(dr_release_t release, size_t size, gfp_t gfp,
364 const char *name);
365#define devres_alloc(release, size, gfp) \
366 __devres_alloc(release, size, gfp, #release)
367#else
368extern void * devres_alloc(dr_release_t release, size_t size, gfp_t gfp);
369#endif
370extern void devres_free(void *res);
371extern void devres_add(struct device *dev, void *res);
372extern void * devres_find(struct device *dev, dr_release_t release,
373 dr_match_t match, void *match_data);
374extern void * devres_get(struct device *dev, void *new_res,
375 dr_match_t match, void *match_data);
376extern void * devres_remove(struct device *dev, dr_release_t release,
377 dr_match_t match, void *match_data);
378extern int devres_destroy(struct device *dev, dr_release_t release,
379 dr_match_t match, void *match_data);
380
381/* devres group */
382extern void * __must_check devres_open_group(struct device *dev, void *id,
383 gfp_t gfp);
384extern void devres_close_group(struct device *dev, void *id);
385extern void devres_remove_group(struct device *dev, void *id);
386extern int devres_release_group(struct device *dev, void *id);
387
388/* managed kzalloc/kfree for device drivers, no kmalloc, always use kzalloc */
389extern void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp);
390extern void devm_kfree(struct device *dev, void *p);
391
357struct device { 392struct device {
358 struct klist klist_children; 393 struct klist klist_children;
359 struct klist_node knode_parent; /* node in sibling list */ 394 struct klist_node knode_parent; /* node in sibling list */
@@ -397,6 +432,9 @@ struct device {
397 /* arch specific additions */ 432 /* arch specific additions */
398 struct dev_archdata archdata; 433 struct dev_archdata archdata;
399 434
435 spinlock_t devres_lock;
436 struct list_head devres_head;
437
400 /* class_device migration path */ 438 /* class_device migration path */
401 struct list_head node; 439 struct list_head node;
402 struct class *class; 440 struct class *class;