31#define DEVICE_NAME_MAX 16
75 size_t length,
int prot,
uint64_t offset);
127#define DEVICE_NUMBER(major, minor) \
128 ((((major) & 0xfffu) << 8) | ((minor) & 0xffu) | (((minor) & 0xfff00u) << 12))
uintptr_t addr_space_t
an address space handle.
Definition arch.h:105
void device_registry_init(void)
reset the device registry.
Definition device.c:40
device_t * device_find(const char *name)
find a registered device by name.
Definition device.c:94
uint32_t device_count(void)
number of currently registered devices.
Definition device.c:72
bool device_register(device_t *dev)
register a device.
Definition device.c:50
device_t * device_get(uint32_t index)
get a registered device by index (0 .
Definition device.c:80
#define DEVICE_NAME_MAX
Definition device.h:31
struct device device_t
Definition device.h:34
device_type_t
Definition device.h:22
@ DEVICE_TYPE_UNKNOWN
Definition device.h:23
@ DEVICE_TYPE_CHAR
Definition device.h:25
@ DEVICE_TYPE_INPUT
Definition device.h:26
@ DEVICE_TYPE_TIMER
Definition device.h:27
@ DEVICE_TYPE_BLOCK
Definition device.h:24
kerr_t
unified kernel error codes.
Definition error.h:14
uint8_t flags
Definition idt.c:3
unsigned int uint32_t
Definition fb.h:17
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
int int32_t
Definition stdint.h:14
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:19
optional per-device operations.
Definition device.h:43
kerr_t(*) open(device_t *dev, uint32_t flags, struct file **out)
open the device as a stream of its own (optional).
Definition device.h:107
void(*) shutdown(device_t *dev)
Definition device.h:44
int32_t(*) ioctl(device_t *dev, uint32_t request, void *arg)
device-specific control operation, the transport for ioctl(2)-style requests (e.g.
Definition device.h:57
uint32_t(*) read(device_t *dev, uint64_t offset, void *buf, uint32_t len)
byte-oriented read at an explicit offset (optional; NULL means the device is not readable).
Definition device.h:82
uint64_t(*) size(device_t *dev)
total byte size of the device's addressable memory (optional; NULL means unknown/zero).
Definition device.h:95
uint32_t(*) write(device_t *dev, uint64_t offset, const void *buf, uint32_t len)
byte-oriented write at an explicit offset (optional; NULL means the device is not writable).
Definition device.h:89
int32_t(*) mmap(device_t *dev, addr_space_t as, uintptr_t virt, size_t length, int prot, uint64_t offset)
map the device's memory into a process address space (optional; NULL means the device is not mappable...
Definition device.h:74
a registered device.
Definition device.h:114
const device_ops_t * ops
Definition device.h:117
char name[DEVICE_NAME_MAX]
Definition device.h:115
uint32_t number
Definition device.h:119
device_type_t type
Definition device.h:116
void * driver_data
Definition device.h:118
an open-file description.
Definition file.h:64