Karg  v0.2.0
The kernel of CargOS
dev.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <driver.h>
4 #include <utils/compiler.h>
5 
6 typedef struct {
7  const driver_t *driver;
9 } dev_t;
10 
11 #define make_dev(driver, num) ((dev_t){&(driver), num})
12 
13 isize dev_read(dev_t dev, u8 *buf, usize size);
14 isize dev_write(dev_t dev, const u8 *buf, usize size);
15 
16 typedef struct {
17  const char *name;
21 } dev_node_t;
22 
23 extern const dev_node_t DEV_TABLE[];
24 
25 typedef struct {
26  const char *name;
27  const char *compat;
28  i32 (*init)(const dev_node_t *node);
29 } dev_init_t;
30 
31 #define dev_init(compat, func) \
32  section(.init.dev) \
33  used static const dev_init_t _DEV_INIT = {_MODULE_NAME, compat, func}
isize dev_write(dev_t dev, const u8 *buf, usize size)
Definition: dev.c:19
isize dev_read(dev_t dev, u8 *buf, usize size)
Definition: dev.c:13
const dev_node_t DEV_TABLE[]
Definition: virt.c:3
Definition: dev.h:25
const char * compat
Definition: dev.h:27
const char * name
Definition: dev.h:26
Definition: dev.h:16
const char * name
Definition: dev.h:17
u32 irq
Definition: dev.h:19
u8 reg_size
Definition: dev.h:20
usize addr
Definition: dev.h:18
Definition: dev.h:6
u32 num
Definition: dev.h:8
const driver_t * driver
Definition: dev.h:7
Definition: driver.h:5
__INTPTR_TYPE__ isize
Definition: types.h:29
__INT32_TYPE__ i32
Definition: types.h:15
__UINTPTR_TYPE__ usize
Definition: types.h:28
__UINT8_TYPE__ u8
Definition: types.h:3
__UINT32_TYPE__ u32
Definition: types.h:5