diff --git a/Software/Development/OperatingSystem/Linux/Kernel/API/Linux_Kernel_Devm_APIs.md b/Software/Development/OperatingSystem/Linux/Kernel/API/Linux_Kernel_Devm_APIs.md index 86ae5a8..b51a073 100644 --- a/Software/Development/OperatingSystem/Linux/Kernel/API/Linux_Kernel_Devm_APIs.md +++ b/Software/Development/OperatingSystem/Linux/Kernel/API/Linux_Kernel_Devm_APIs.md @@ -2,7 +2,9 @@ Devm APIs 是一组便捷易用的接口,通过该接口申请的内核资源是跟设备(device)有关的,在设备(device)被detached或者驱动(driver)卸载(unloaded)时,会被自动释放。 -## devm_kmalloc 函数 +## Memory + +### devm_kmalloc 函数 **函数原型:** @@ -26,7 +28,7 @@ size:要分配的内存大小,以字节为单位; 申请成功返回有效的内存首地址,失败返回 NULL。 -## devm_kzalloc 函数 +### devm_kzalloc 函数 **函数原型:** @@ -50,7 +52,9 @@ size:要分配的内存大小,以字节为单位; 申请成功返回有效的内存首地址,失败返回 NULL。 -## devm_ioremap_resource 函数 +## IOMEM + +### devm_ioremap_resource 函数 **函数原型:** @@ -83,7 +87,7 @@ res:resource to be handled。 Returns a pointer to the remapped memory or an ERR_PTR() encoded error code on failure. -## devm_request_mem_region 函数 +### devm_request_mem_region 函数 **函数原型:** @@ -109,7 +113,7 @@ name:该 mmio 空间的名称。 成功返回非 0 值,失败返回 NULL。 -## devm_ioremap 函数 +### devm_ioremap 函数 **函数原型:** @@ -134,7 +138,7 @@ size:Size of map. 成功则返回映射内存首地址,失败返回 NULL。 -## devm_ioremap_nocache 函数 +### devm_ioremap_nocache 函数 **函数原型:** @@ -161,7 +165,9 @@ size:Size of map. 成功则返回映射内存首地址,失败返回 NULL。 -## devm_request_irq 函数 +## Interrupt + +### devm_request_irq 函数 **头文件:** @@ -172,6 +178,7 @@ size:Size of map. **函数原型:** ```c +static inline int __must_check devm_request_irq(struct device *dev, unsigned int irq, irq_handler_t handler, unsigned long irqflags, const char *devname, void *dev_id); ``` @@ -200,3 +207,107 @@ dev_id:该参数将会传递给 handler 所对应的回调函数。 -INVAL:表示中断号无效或处理函数指针为NULL; -EBUSY:表示中断已经被占用且不能共享。 + +## GPIO + +### devm_gpiod_get_index 函数 + +**头文件:** + +```cpp +#include +``` + +**函数原型:** + +```cpp +struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, + const char *con_id, + unsigned int idx, + enum gpiod_flags flags); +``` + +**说明:** + +Managed gpiod_get_index(). GPIO descriptors returned from this function are automatically disposed on driver detach. See gpiod_get_index() for detailed information about behavior and return values。 + +**参数:** + +dev:GPIO consumer; + +con_id:function within the GPIO consumer; + +idx:index of the GPIO to obtain in the consumer; + +flags:optional GPIO initialization flags。 + +**返回值:** + +See gpiod_get_index() for detailed information about behavior and return values。 + +### devm_gpiod_get_index_optional 函数 + +**头文件:** + +```cpp +#include +``` + +**函数原型:** + +```cpp +struct gpio_desc *__must_check devm_gpiod_get_index_optional(struct device *dev, + const char *con_id, + unsigned int index, + enum gpiod_flags flags); +``` + +**说明:** + +Managed gpiod_get_index_optional(). GPIO descriptors returned from this function are automatically disposed on driver detach. See gpiod_get_index_optional() for detailed information about behavior and return values。 + +**参数:** + +dev:GPIO consumer; + +con_id:function within the GPIO consumer; + +index:index of the GPIO to obtain in the consumer; + +flags:optional GPIO initialization flags。 + +**返回值:** + +See gpiod_get_index_optional() for detailed information about behavior and return values。 + +### devm_gpiod_get_optional 函数 + +**头文件:** + +```cpp +#include +``` + +**函数原型:** + +```cpp +struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev, + const char *con_id, + enum gpiod_flags flags); +``` + +**说明:** + +Managed gpiod_get_optional(). GPIO descriptors returned from this function are automatically disposed on driver detach. See gpiod_get_optional() for detailed information about behavior and return values。 + +**参数:** + +dev:GPIO consumer; + +con_id:function within the GPIO consumer; + +flags:optional GPIO initialization flags。 + +**返回值:** + +See gpiod_get_optional() for detailed information about behavior and return values。