[dev] move the device/driver class api to __start __stop style symbols

This commit is contained in:
Travis Geiselbrecht
2020-05-15 00:11:14 -07:00
parent d3d22d68a5
commit 7544ff39b5
5 changed files with 6 additions and 30 deletions

View File

@@ -1,8 +0,0 @@
SECTIONS {
.devices : {
__devices = .;
KEEP (*(.devices))
__devices_end = .;
}
}
INSERT AFTER .data;

View File

@@ -12,14 +12,13 @@
#include <lk/trace.h>
/* static list of devices constructed with DEVICE_INSTANCE macros */
extern struct device __devices[];
extern struct device __devices_end[];
extern struct device __start_devices __WEAK;
extern struct device __stop_devices __WEAK;
status_t device_init_all(void) {
status_t res = NO_ERROR;
struct device *dev = __devices;
while (dev != __devices_end) {
for (struct device *dev = &__start_devices; dev != &__stop_devices; dev++) {
if (dev->flags & DEVICE_FLAG_AUTOINIT) {
status_t code = device_init(dev);
@@ -30,8 +29,6 @@ status_t device_init_all(void) {
res = code;
}
}
dev++;
}
return res;
@@ -40,8 +37,7 @@ status_t device_init_all(void) {
status_t device_fini_all(void) {
status_t res = NO_ERROR;
struct device *dev = __devices;
while (dev != __devices_end) {
for (struct device *dev = &__start_devices; dev != &__stop_devices; dev++) {
status_t code = device_fini(dev);
if (code < 0) {
@@ -50,8 +46,6 @@ status_t device_fini_all(void) {
res = code;
}
dev++;
}
return res;

View File

@@ -1,8 +0,0 @@
SECTIONS {
.drivers : {
__drivers = .;
KEEP (*(.drivers))
__drivers_end = .;
}
}
INSERT AFTER .rodata;

View File

@@ -70,7 +70,7 @@ struct driver {
#define DRIVER_EXPORT(type_, ops_) \
const struct driver concat(__driver_, type_) \
__ALIGNED(sizeof(void *)) __SECTION(".drivers") = { \
__ALIGNED(sizeof(void *)) __SECTION("drivers") = { \
.type = #type_, \
.ops = ops_, \
}
@@ -78,7 +78,7 @@ struct driver {
#define DEVICE_INSTANCE(type_, name_, config_, flags_) \
extern struct driver concat(__driver_, type_); \
struct device concat(__device_, concat(type_, concat(_, name_))) \
__ALIGNED(sizeof(void *)) __SECTION(".devices") = { \
__ALIGNED(sizeof(void *)) __SECTION("devices") = { \
.name = #name_, \
.driver = &concat(__driver_, type_), \
.flags = flags_, \

View File

@@ -12,6 +12,4 @@ MODULE_SRCS += \
$(LOCAL_DIR)/class/fb_api.c \
$(LOCAL_DIR)/class/netif_api.c \
EXTRA_LINKER_SCRIPTS += $(LOCAL_DIR)/devices.ld $(LOCAL_DIR)/drivers.ld
include make/module.mk