gen_kobject_list.py: device driver support

Device drivers need to be treated like other kernel objects, with
thread-level permissions and validation of struct device pointers passed
in from userspace when making API calls.

However it's not sufficient to identify an object as a driver, we need
to know what subsystem it belongs to (if any) so that userspace cannot,
for example, make Ethernet driver API calls using a UART driver object.

Upon encountering a variable representing a device struct, we look at
the value of its driver_api member. If that corresponds to an instance
of a driver API struct belonging to a known subsystem, the proper
K_OBJ_DRIVER_* enumeration type will be associated with this device in
the generated gperf table.

If there is no API struct or it doesn't correspond to a known subsystem,
the device is omitted from the table; it's presumably used internally
by the kernel or is a singleton with specific APIs for it that do not
take a struct device parameter.

The list of kobjects and subsystems in the script is simplified since
the enumeration type name is strongly derived from the name of the data
structure.

A device object is marked as initialized after its init function has
been run at boot.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2017-09-27 12:59:28 -07:00 committed by Andrew Boie
commit 5bd891d3b6
4 changed files with 215 additions and 30 deletions

View file

@ -124,7 +124,12 @@ struct k_timer;
struct k_poll_event;
struct k_poll_signal;
/* This enumeration needs to be kept in sync with the lists of kernel objects
* and subsystems in scripts/gen_kobject_list.py, as well as the otype_to_str()
* function in kernel/userspace.c
*/
enum k_objects {
/* Core kernel objects */
K_OBJ_ALERT,
K_OBJ_DELAYED_WORK,
K_OBJ_MEM_SLAB,
@ -138,6 +143,29 @@ enum k_objects {
K_OBJ_WORK,
K_OBJ_WORK_Q,
/* Driver subsystems */
K_OBJ_DRIVER_ADC,
K_OBJ_DRIVER_AIO_CMP,
K_OBJ_DRIVER_CLOCK_CONTROL,
K_OBJ_DRIVER_COUNTER,
K_OBJ_DRIVER_CRYPTO,
K_OBJ_DRIVER_DMA,
K_OBJ_DRIVER_ETH,
K_OBJ_DRIVER_FLASH,
K_OBJ_DRIVER_GPIO,
K_OBJ_DRIVER_I2C,
K_OBJ_DRIVER_I2S,
K_OBJ_DRIVER_IPM,
K_OBJ_DRIVER_PINMUX,
K_OBJ_DRIVER_PWM,
K_OBJ_DRIVER_RANDOM,
K_OBJ_DRIVER_RTC,
K_OBJ_DRIVER_SENSOR,
K_OBJ_DRIVER_SHARED_IRQ,
K_OBJ_DRIVER_SPI,
K_OBJ_DRIVER_UART,
K_OBJ_DRIVER_WDT,
K_OBJ_LAST
};