Skip to content

Instantly share code, notes, and snippets.

@nilhoel1
Created August 22, 2019 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilhoel1/02ee0733d64c3155659ad9c39e201efa to your computer and use it in GitHub Desktop.
Save nilhoel1/02ee0733d64c3155659ad9c39e201efa to your computer and use it in GitHub Desktop.
Documentation on RTEMS-libbsd Bus init process.

Bus Initialisation

Bus Initialization

This section describes the initialisation of buses using a flattened device tree. All the device information is provided in the device tree, so the drivers no longer need hard coded headers and are more versatile. The fdt is scanned during the init process and all drivers, that find their device in the fdt will attach themselves.

Registering Modules

Driver modules can be registered during different passes and in a different order. This is done by using one of these four macros:

DRIVER_MODULE(name, busname, driver_t driver, devclass_t devclass,
    modeventhand_t evh, void *arg);

DRIVER_MODULE_ORDERED(name, busname, driver_t driver,
    devclass_t devclass, modeventhand_t evh, void *arg, int order);

EARLY_DRIVER_MODULE(name, busname,  driver_t driver, devclass_t devclass,
    modeventhand_t  evh, void *arg, enum sysinit_elem_order order,
    int pass);

EARLY_DRIVER_MODULE_ORDERED(name, busname, driver_t driver,
    devclass_t devclass, modeventhand_t evh, void *arg,
    enum sysinit_elem_order order, int pass);

All driver module macros default to the EARLY_DRIVER_MODULE_ORDERED macro. The two DRIVER_MODULE macros will use BUS_PASS_DEFAULT as pass level. The macros not using the _ORDERED suffix will default to SI_ORDER_MIDDLE.

For more information see the FreeBSD manual.

Initialisation in rtems-libbsd

The first step during initialisation sorts all registered devices by their subsystem. And in their subsystem they are sorted by their order. If it is intended to load a driver before others, a lower order level has to be chosen when registering the driver.

Focusing on the bus subsystem the super bus saves the fdt's head as the root_bus and iterates over it for every pass level with an existing driver. The first bus driver that attache is the nexus bus in rtems. When the nexus bus attaches all its device children get attached too. This also holds for the simplebus and ofwbus to name a few. The bus drivers are stored in the link list and the pass levels are stored in the passlink list. However the passlink list only hold one driver per pass level and is used to determine which and how many pass levels exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment