zongfan-shao / linux

1 stars 1 forks source link

devm_xxx机制 #29

Open zongfan-shao opened 5 years ago

zongfan-shao commented 5 years ago

devm是内核提供的基础机制,用于方便驱动开发者所分配资源的自动回收。参考内核文档devres.txt。总的来说,就是驱动开发者只需要调用这类接口分配期望的资源,不用关心释放问题。这些资源的释放会在device对象销毁时自动释放。

devres使用   不同的内核模块提供了对应的devm_xxx接口,如下(不仅仅这些): MEM devm_kmalloc()
devm_kzalloc() devm_kcalloc() devm_kmalloc_array() devm_kstrdup() devm_kfree()

IIO devm_iio_device_alloc() devm_iio_device_free() devm_iio_trigger_alloc() devm_iio_trigger_free() devm_iio_device_register() devm_iio_device_unregister()

IO region devm_request_region() devm_request_mem_region() devm_release_region() devm_release_mem_region()

IRQ devm_request_irq() devm_free_irq()

DMA dmam_alloc_coherent() dmam_free_coherent() dmam_alloc_noncoherent() dmam_free_noncoherent() dmam_declare_coherent_memory() dmam_pool_create() dmam_pool_destroy()

PCI pcim_enable_device() : after success, all PCI ops become managed pcim_pin_device() : keep PCI device enabled after release

IOMAP devm_ioport_map() devm_ioport_unmap() devm_ioremap() devm_ioremap_nocache() devm_iounmap() devm_ioremap_resource() : checks resource, requests memory region, ioremaps devm_request_and_ioremap() : obsoleted by devm_ioremap_resource() pcim_iomap() pcim_iounmap() pcim_iomap_table() : array of mapped addresses indexed by BAR pcim_iomap_regions() : do request_region() and iomap() on multiple BARs

REGULATOR devm_regulator_get() devm_regulator_put() devm_regulator_bulk_get() devm_regulator_register()

CLOCK devm_clk_get() devm_clk_put()

PINCTRL devm_pinctrl_get() devm_pinctrl_put()

PWM devm_pwm_get() devm_pwm_put()

PHY devm_usb_get_phy() devm_usb_put_phy()

SLAVE DMA ENGINE devm_acpi_dma_controller_register()

SPI devm_spi_register_master()