git: 9edb8d0aedef - main - new-bus: Introduce a simpler bus API for managing resources
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 13 Mar 2024 22:13:35 UTC
The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=9edb8d0aedef2f1e13ed1f8134deb3f8291d2fe9 commit 9edb8d0aedef2f1e13ed1f8134deb3f8291d2fe9 Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2024-03-13 22:05:53 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2024-03-13 22:05:53 +0000 new-bus: Introduce a simpler bus API for managing resources Remove the 'type' and 'rid' arguments from the wrapper bus API functions (e.g. bus_release_resource) that accept a struct resource. The "new" versions extract the 'type' and/or 'rid' from the passed in resource object via rman_get_type and rman_get_rid. This commit adds the new API as functions with a _new suffix. Wrapper macros choose between the old and new functions based on the number of arguments provided to the macro. This commit does not change the ABI but can be safely MFCd to older branches so long as older kernels use rman_set_type when allocating resources. Future commits will push the removal of these extraneous arguments through the bus implementation. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D44124 --- sys/kern/subr_bus.c | 42 ++++++++++++++++++++++++++++++++++++++++++ sys/sys/bus.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index ecd5ad44959d..25cb5fba2108 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -4545,6 +4545,13 @@ bus_adjust_resource(device_t dev, int type, struct resource *r, rman_res_t start return (BUS_ADJUST_RESOURCE(dev->parent, dev, type, r, start, end)); } +int +bus_adjust_resource_new(device_t dev, struct resource *r, rman_res_t start, + rman_res_t end) +{ + return (bus_adjust_resource(dev, rman_get_type(r), r, start, end)); +} + /** * @brief Wrapper function for BUS_TRANSLATE_RESOURCE(). * @@ -4574,6 +4581,13 @@ bus_activate_resource(device_t dev, int type, int rid, struct resource *r) return (BUS_ACTIVATE_RESOURCE(dev->parent, dev, type, rid, r)); } +int +bus_activate_resource_new(device_t dev, struct resource *r) +{ + return (bus_activate_resource(dev, rman_get_type(r), rman_get_rid(r), + r)); +} + /** * @brief Wrapper function for BUS_DEACTIVATE_RESOURCE(). * @@ -4588,6 +4602,13 @@ bus_deactivate_resource(device_t dev, int type, int rid, struct resource *r) return (BUS_DEACTIVATE_RESOURCE(dev->parent, dev, type, rid, r)); } +int +bus_deactivate_resource_new(device_t dev, struct resource *r) +{ + return (bus_deactivate_resource(dev, rman_get_type(r), rman_get_rid(r), + r)); +} + /** * @brief Wrapper function for BUS_MAP_RESOURCE(). * @@ -4603,6 +4624,13 @@ bus_map_resource(device_t dev, int type, struct resource *r, return (BUS_MAP_RESOURCE(dev->parent, dev, type, r, args, map)); } +int +bus_map_resource_new(device_t dev, struct resource *r, + struct resource_map_request *args, struct resource_map *map) +{ + return (bus_map_resource(dev, rman_get_type(r), r, args, map)); +} + /** * @brief Wrapper function for BUS_UNMAP_RESOURCE(). * @@ -4618,6 +4646,13 @@ bus_unmap_resource(device_t dev, int type, struct resource *r, return (BUS_UNMAP_RESOURCE(dev->parent, dev, type, r, map)); } +int +bus_unmap_resource_new(device_t dev, struct resource *r, + struct resource_map *map) +{ + return (bus_unmap_resource(dev, rman_get_type(r), r, map)); +} + /** * @brief Wrapper function for BUS_RELEASE_RESOURCE(). * @@ -4635,6 +4670,13 @@ bus_release_resource(device_t dev, int type, int rid, struct resource *r) return (rv); } +int +bus_release_resource_new(device_t dev, struct resource *r) +{ + return (bus_release_resource(dev, rman_get_type(r), rman_get_rid(r), + r)); +} + /** * @brief Wrapper function for BUS_SETUP_INTR(). * diff --git a/sys/sys/bus.h b/sys/sys/bus.h index 581e81352be4..6fcd414dc7be 100644 --- a/sys/sys/bus.h +++ b/sys/sys/bus.h @@ -613,6 +613,43 @@ bus_alloc_resource_anywhere(device_t dev, int type, int *rid, return (bus_alloc_resource(dev, type, rid, 0, ~0, count, flags)); } +/* Compat shims for simpler bus resource API. */ +int bus_adjust_resource_new(device_t child, struct resource *r, + rman_res_t start, rman_res_t end); +int bus_activate_resource_new(device_t dev, struct resource *r); +int bus_deactivate_resource_new(device_t dev, struct resource *r); +int bus_map_resource_new(device_t dev, struct resource *r, + struct resource_map_request *args, struct resource_map *map); +int bus_unmap_resource_new(device_t dev, struct resource *r, + struct resource_map *map); +int bus_release_resource_new(device_t dev, struct resource *r); + +#define _BUS_API_MACRO(_1, _2, _3, _4, _5, NAME, ...) NAME + +#define bus_adjust_resource(...) \ + _BUS_API_MACRO(__VA_ARGS__, bus_adjust_resource, \ + bus_adjust_resource_new)(__VA_ARGS__) + +#define bus_activate_resource(...) \ + _BUS_API_MACRO(__VA_ARGS__, INVALID, bus_activate_resource, \ + INVALID, bus_activate_resource_new)(__VA_ARGS__) + +#define bus_deactivate_resource(...) \ + _BUS_API_MACRO(__VA_ARGS__, INVALID, bus_deactivate_resource, \ + INVALID, bus_deactivate_resource_new)(__VA_ARGS__) + +#define bus_map_resource(...) \ + _BUS_API_MACRO(__VA_ARGS__, bus_map_resource, \ + bus_map_resource_new)(__VA_ARGS__) + +#define bus_unmap_resource(...) \ + _BUS_API_MACRO(__VA_ARGS__, INVALID, bus_unmap_resource, \ + bus_unmap_resource_new)(__VA_ARGS__) + +#define bus_release_resource(...) \ + _BUS_API_MACRO(__VA_ARGS__, INVALID, bus_release_resource, \ + INVALID, bus_release_resource_new)(__VA_ARGS__) + /* * Access functions for device. */