diff options
| author | fangjianzhou <[email protected]> | 2024-01-09 23:10:42 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-01-09 23:10:42 +0800 |
| commit | 10b16273b8b98a8c4ab1196aea211b0084dfb8de (patch) | |
| tree | 949e5c85972424a9ad91b68bfb8f3ea9a935a604 /components/drivers/include | |
| parent | cc157baf23b3757b1741ca06da4bad45b5ff8ddc (diff) | |
[drivers][core] 完善设备模型 (#8384)
Diffstat (limited to 'components/drivers/include')
| -rw-r--r-- | components/drivers/include/drivers/core/bus.h | 20 | ||||
| -rw-r--r-- | components/drivers/include/drivers/core/dm.h | 138 | ||||
| -rw-r--r-- | components/drivers/include/drivers/core/driver.h | 13 | ||||
| -rw-r--r-- | components/drivers/include/drivers/ofw.h | 4 | ||||
| -rwxr-xr-x | components/drivers/include/drivers/ofw_fdt.h | 3 | ||||
| -rwxr-xr-x | components/drivers/include/drivers/ofw_io.h | 1 | ||||
| -rw-r--r-- | components/drivers/include/drivers/platform.h | 6 |
7 files changed, 160 insertions, 25 deletions
diff --git a/components/drivers/include/drivers/core/bus.h b/components/drivers/include/drivers/core/bus.h index 4a010d797d..ab821240bb 100644 --- a/components/drivers/include/drivers/core/bus.h +++ b/components/drivers/include/drivers/core/bus.h @@ -21,32 +21,32 @@ struct rt_bus { struct rt_object parent; /**< inherit from rt_object */ - char *name; - struct rt_bus *bus; + const char *name; rt_list_t list; - rt_list_t children; rt_list_t dev_list; rt_list_t drv_list; - struct rt_spinlock spinlock; + struct rt_spinlock dev_lock; + struct rt_spinlock drv_lock; rt_bool_t (*match)(rt_driver_t drv, rt_device_t dev); rt_err_t (*probe)(rt_device_t dev); + rt_err_t (*remove)(rt_device_t dev); + rt_err_t (*shutdown)(rt_device_t dev); }; -rt_bus_t rt_bus_root(void); +rt_err_t rt_bus_for_each_dev(rt_bus_t bus, void *data, int (*fn)(rt_device_t dev, void *)); +rt_err_t rt_bus_for_each_drv(rt_bus_t bus, void *data, int (*fn)(rt_driver_t drv, void *)); -rt_err_t rt_bus_for_each_dev(rt_bus_t bus, rt_driver_t drv, int (*fn)(rt_driver_t drv, rt_device_t dev)); -rt_err_t rt_bus_for_each_drv(rt_bus_t bus, rt_device_t dev, int (*fn)(rt_driver_t drv, rt_device_t dev)); - -rt_err_t rt_bus_add(rt_bus_t bus); rt_err_t rt_bus_add_driver(rt_bus_t bus, rt_driver_t drv); rt_err_t rt_bus_add_device(rt_bus_t bus, rt_device_t dev); rt_err_t rt_bus_remove_driver(rt_driver_t drv); rt_err_t rt_bus_remove_device(rt_device_t dev); -rt_bus_t rt_bus_find_by_name(char *name); +rt_err_t rt_bus_shutdown(void); + +rt_bus_t rt_bus_find_by_name(const char *name); rt_err_t rt_bus_reload_driver_device(rt_bus_t new_bus, rt_device_t dev); rt_err_t rt_bus_register(rt_bus_t bus); diff --git a/components/drivers/include/drivers/core/dm.h b/components/drivers/include/drivers/core/dm.h index f016906499..94821fe395 100644 --- a/components/drivers/include/drivers/core/dm.h +++ b/components/drivers/include/drivers/core/dm.h @@ -13,6 +13,7 @@ #include <rthw.h> #include <rtdef.h> +#include <ioremap.h> #include <drivers/misc.h> #include <drivers/byteorder.h> @@ -26,10 +27,139 @@ extern int rt_hw_cpu_id(void); void rt_dm_secondary_cpu_init(void); -int rt_dm_set_dev_name_auto(rt_device_t dev, const char *prefix); -int rt_dm_get_dev_name_id(rt_device_t dev); +int rt_dm_dev_set_name_auto(rt_device_t dev, const char *prefix); +int rt_dm_dev_get_name_id(rt_device_t dev); -int rt_dm_set_dev_name(rt_device_t dev, const char *format, ...); -const char *rt_dm_get_dev_name(rt_device_t dev); +int rt_dm_dev_set_name(rt_device_t dev, const char *format, ...); +const char *rt_dm_dev_get_name(rt_device_t dev); + +int rt_dm_dev_get_address_count(rt_device_t dev); +rt_err_t rt_dm_dev_get_address(rt_device_t dev, int index, + rt_uint64_t *out_address, rt_uint64_t *out_size); +rt_err_t rt_dm_dev_get_address_by_name(rt_device_t dev, const char *name, + rt_uint64_t *out_address, rt_uint64_t *out_size); +int rt_dm_dev_get_address_array(rt_device_t dev, int nr, rt_uint64_t *out_regs); + +void *rt_dm_dev_iomap(rt_device_t dev, int index); +void *rt_dm_dev_iomap_by_name(rt_device_t dev, const char *name); + +int rt_dm_dev_get_irq_count(rt_device_t dev); +int rt_dm_dev_get_irq(rt_device_t dev, int index); +int rt_dm_dev_get_irq_by_name(rt_device_t dev, const char *name); + +void rt_dm_dev_bind_fwdata(rt_device_t dev, void *fw_np, void *data); +void rt_dm_dev_unbind_fwdata(rt_device_t dev, void *fw_np); + +int rt_dm_dev_prop_read_u8_array_index(rt_device_t dev, const char *propname, + int index, int nr, rt_uint8_t *out_values); +int rt_dm_dev_prop_read_u16_array_index(rt_device_t dev, const char *propname, + int index, int nr, rt_uint16_t *out_values); +int rt_dm_dev_prop_read_u32_array_index(rt_device_t dev, const char *propname, + int index, int nr, rt_uint32_t *out_values); +int rt_dm_dev_prop_read_u64_array_index(rt_device_t dev, const char *propname, + int index, int nr, rt_uint64_t *out_values); +int rt_dm_dev_prop_read_string_array_index(rt_device_t dev, const char *propname, + int index, int nr, const char **out_strings); + +int rt_dm_dev_prop_count_of_size(rt_device_t dev, const char *propname, int size); +int rt_dm_dev_prop_index_of_string(rt_device_t dev, const char *propname, const char *string); + +rt_bool_t rt_dm_dev_prop_read_bool(rt_device_t dev, const char *propname); + +rt_inline rt_err_t rt_dm_dev_prop_read_u8_index(rt_device_t dev, const char *propname, + int index, rt_uint8_t *out_value) +{ + int nr = rt_dm_dev_prop_read_u8_array_index(dev, propname, index, 1, out_value); + + return nr > 0 ? RT_EOK : (rt_err_t)nr; +} + +rt_inline rt_err_t rt_dm_dev_prop_read_u16_index(rt_device_t dev, const char *propname, + int index, rt_uint16_t *out_value) +{ + int nr = rt_dm_dev_prop_read_u16_array_index(dev, propname, index, 1, out_value); + + return nr > 0 ? RT_EOK : (rt_err_t)nr; +} + +rt_inline rt_err_t rt_dm_dev_prop_read_u32_index(rt_device_t dev, const char *propname, + int index, rt_uint32_t *out_value) +{ + int nr = rt_dm_dev_prop_read_u32_array_index(dev, propname, index, 1, out_value); + + return nr > 0 ? RT_EOK : (rt_err_t)nr; +} + +rt_inline rt_err_t rt_dm_dev_prop_read_u64_index(rt_device_t dev, const char *propname, + int index, rt_uint64_t *out_value) +{ + int nr = rt_dm_dev_prop_read_u64_array_index(dev, propname, index, 1, out_value); + + return nr > 0 ? RT_EOK : (rt_err_t)nr; +} + +rt_inline rt_err_t rt_dm_dev_prop_read_string_index(rt_device_t dev, const char *propname, + int index, const char **out_string) +{ + int nr = rt_dm_dev_prop_read_string_array_index(dev, propname, index, 1, out_string); + + return nr > 0 ? RT_EOK : (rt_err_t)nr; +} + +rt_inline rt_err_t rt_dm_dev_prop_read_u8(rt_device_t dev, const char *propname, + rt_uint8_t *out_value) +{ + return rt_dm_dev_prop_read_u8_index(dev, propname, 0, out_value); +} + +rt_inline rt_err_t rt_dm_dev_prop_read_u16(rt_device_t dev, const char *propname, + rt_uint16_t *out_value) +{ + return rt_dm_dev_prop_read_u16_index(dev, propname, 0, out_value); +} + +rt_inline rt_err_t rt_dm_dev_prop_read_u32(rt_device_t dev, const char *propname, + rt_uint32_t *out_value) +{ + return rt_dm_dev_prop_read_u32_index(dev, propname, 0, out_value); +} + +rt_inline rt_err_t rt_dm_dev_prop_read_s32(rt_device_t dev, const char *propname, + rt_int32_t *out_value) +{ + return rt_dm_dev_prop_read_u32_index(dev, propname, 0, (rt_uint32_t *)out_value); +} + +rt_inline rt_err_t rt_dm_dev_prop_read_u64(rt_device_t dev, const char *propname, + rt_uint64_t *out_value) +{ + return rt_dm_dev_prop_read_u64_index(dev, propname, 0, out_value); +} + +rt_inline rt_err_t rt_dm_dev_prop_read_string(rt_device_t dev, const char *propname, + const char **out_string) +{ + return rt_dm_dev_prop_read_string_index(dev, propname, 0, out_string); +} + +rt_inline int rt_dm_dev_prop_count_of_u8(rt_device_t dev, const char *propname) +{ + return rt_dm_dev_prop_count_of_size(dev, propname, sizeof(rt_uint8_t)); +} + +rt_inline int rt_dm_dev_prop_count_of_u16(rt_device_t dev, const char *propname) +{ + return rt_dm_dev_prop_count_of_size(dev, propname, sizeof(rt_uint16_t)); +} + +rt_inline int rt_dm_dev_prop_count_of_u32(rt_device_t dev, const char *propname) +{ + return rt_dm_dev_prop_count_of_size(dev, propname, sizeof(rt_uint32_t)); +} + +rt_inline int rt_dm_dev_prop_count_of_u64(rt_device_t dev, const char *propname) +{ + return rt_dm_dev_prop_count_of_size(dev, propname, sizeof(rt_uint64_t)); +} #endif /* __RT_DM_H__ */ diff --git a/components/drivers/include/drivers/core/driver.h b/components/drivers/include/drivers/core/driver.h index 75608e2732..f576c812af 100644 --- a/components/drivers/include/drivers/core/driver.h +++ b/components/drivers/include/drivers/core/driver.h @@ -13,13 +13,14 @@ #include <rtdef.h> -struct rt_bus; - struct rt_driver { + struct rt_object parent; struct rt_bus *bus; rt_list_t node; + rt_uint32_t ref_count; + #ifdef RT_USING_DEVICE_OPS const struct rt_device_ops *dev_ops; #else @@ -34,16 +35,10 @@ struct rt_driver const struct filesystem_ops *fops; - const char *name; - int (*probe)(struct rt_device *dev); int (*remove)(struct rt_device *dev); - - void *priv; + int (*shutdown)(struct rt_device *dev); }; -typedef struct rt_driver* rt_driver_t; - -int rt_driver_probe_device(struct rt_driver *drv, struct rt_device *dev); rt_err_t rt_driver_register(rt_driver_t drv); rt_err_t rt_driver_unregister(rt_driver_t drv); diff --git a/components/drivers/include/drivers/ofw.h b/components/drivers/include/drivers/ofw.h index c760cf7e83..4ee2049e8f 100644 --- a/components/drivers/include/drivers/ofw.h +++ b/components/drivers/include/drivers/ofw.h @@ -205,11 +205,15 @@ struct rt_ofw_node *rt_ofw_get_alias_node(const char *tag, int id); int rt_ofw_get_alias_id(struct rt_ofw_node *np, const char *tag); int rt_ofw_get_alias_last_id(const char *tag); +struct rt_ofw_node *rt_ofw_append_child(struct rt_ofw_node *parent, const char *full_name); +rt_err_t rt_ofw_append_prop(struct rt_ofw_node *np, const char *name, int length, void *value); + struct rt_ofw_node *rt_ofw_parse_phandle(const struct rt_ofw_node *np, const char *phandle_name, int index); rt_err_t rt_ofw_parse_phandle_cells(const struct rt_ofw_node *np, const char *list_name, const char *cells_name, int index, struct rt_ofw_cell_args *out_args); int rt_ofw_count_phandle_cells(const struct rt_ofw_node *np, const char *list_name, const char *cells_name); +const char *rt_ofw_get_prop_fuzzy_name(const struct rt_ofw_node *np, const char *name); struct rt_ofw_prop *rt_ofw_get_prop(const struct rt_ofw_node *np, const char *name, rt_ssize_t *out_length); rt_inline const void *rt_ofw_prop_read_raw(const struct rt_ofw_node *np, const char *name, rt_ssize_t *out_length) diff --git a/components/drivers/include/drivers/ofw_fdt.h b/components/drivers/include/drivers/ofw_fdt.h index a9c951ca40..4db4ecef6b 100755 --- a/components/drivers/include/drivers/ofw_fdt.h +++ b/components/drivers/include/drivers/ofw_fdt.h @@ -20,6 +20,7 @@ struct rt_fdt_earlycon union { rt_ubase_t size, width; }; void *fdt; + char options[32]; long nodeoffset; void *data; @@ -41,8 +42,6 @@ struct rt_fdt_earlycon_id rt_err_t (*setup)(struct rt_fdt_earlycon *earlycon, const char *options); }; -#define RT_FDT_EARLYCON_OPTION_SIGNATURE '\n' - #define RT_FDT_EARLYCON_EXPORT(_name, _type, _compatible, _setup) \ static const struct rt_fdt_earlycon_id __rt_fdt_##_name##_earlycon \ rt_used RT_OFW_SYMBOL(earlycon, _) = \ diff --git a/components/drivers/include/drivers/ofw_io.h b/components/drivers/include/drivers/ofw_io.h index 5fdfe8f5e6..4ebfbe2c82 100755 --- a/components/drivers/include/drivers/ofw_io.h +++ b/components/drivers/include/drivers/ofw_io.h @@ -11,6 +11,7 @@ #ifndef __OFW_IO_H__ #define __OFW_IO_H__ +#include <ioremap.h> #include <drivers/ofw.h> int rt_ofw_bus_addr_cells(struct rt_ofw_node *np); diff --git a/components/drivers/include/drivers/platform.h b/components/drivers/include/drivers/platform.h index 9ea1c9803a..d63980fc65 100644 --- a/components/drivers/include/drivers/platform.h +++ b/components/drivers/include/drivers/platform.h @@ -22,6 +22,8 @@ struct rt_platform_device { struct rt_device parent; + int dev_id; + const char *name; #ifdef RT_USING_OFW @@ -42,6 +44,8 @@ struct rt_platform_driver #endif rt_err_t (*probe)(struct rt_platform_device *pdev); + rt_err_t (*remove)(struct rt_platform_device *pdev); + rt_err_t (*shutdown)(struct rt_platform_device *pdev); }; struct rt_platform_device *rt_platform_device_alloc(const char *name); @@ -49,6 +53,8 @@ struct rt_platform_device *rt_platform_device_alloc(const char *name); rt_err_t rt_platform_driver_register(struct rt_platform_driver *pdrv); rt_err_t rt_platform_device_register(struct rt_platform_device *pdev); +rt_err_t rt_platform_ofw_device_probe_child(struct rt_ofw_node *np); + #define RT_PLATFORM_DRIVER_EXPORT(driver) RT_DRIVER_EXPORT(driver, platform, BUILIN) #endif /* __PLATFORM_H__ */ |
