The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
device_ops_t Struct Reference

optional per-device operations. More...

#include </home/runner/work/ginnOS-docs/ginnOS-docs/ginnOS/src/kernel/device/device.h>

Data Fields

void(*) shutdown (device_t *dev)
int32_t(*) ioctl (device_t *dev, uint32_t request, void *arg)
 device-specific control operation, the transport for ioctl(2)-style requests (e.g.
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, i.e.
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).
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).
uint64_t(*) size (device_t *dev)
 total byte size of the device's addressable memory (optional; NULL means unknown/zero).
kerr_t(*) open (device_t *dev, uint32_t flags, struct file **out)
 open the device as a stream of its own (optional).

Detailed Description

optional per-device operations.

all fields may be NULL; the model does not require any of them. concrete device families extend behaviour through their own interfaces (block_device_t, tty_t, ...) and use this only for lifecycle.

Field Documentation

◆ shutdown

void(*) device_ops_t::shutdown(device_t *dev)

◆ ioctl

int32_t(*) device_ops_t::ioctl(device_t *dev, uint32_t request, void *arg)

device-specific control operation, the transport for ioctl(2)-style requests (e.g.

the framebuffer's FBIOGET_VSCREENINFO). optional: a NULL hook means the device supports no ioctls.

Parameters
devthe device.
requestdriver-defined request code.
argrequest-specific argument (often a user pointer, already bounds-checked by the syscall layer before it reaches here).
Returns
0 on success, or a negative errno on failure (-ENOTTY for an unrecognized request).

◆ mmap

int32_t(*) device_ops_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, i.e.

-ENODEV). the device maps its own frames at virt in as; the caller (SYS_mmap) has already reserved the virtual range and validated it. eager mapping, no demand paging. the frames are device memory (outside PMM), so process teardown leaves them alone.

Parameters
devthe device.
asthe target process's address space.
virtpage-aligned destination virtual address.
lengthnumber of bytes to map (page-multiple).
protPROT_* protection bits.
offsetbyte offset into the device memory (page-aligned).
Returns
0 on success, or a negative errno on failure.

◆ read

uint32_t(*) device_ops_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).

the caller (devfs) owns the cursor and passes it in.

Returns
number of bytes read (may be short at end of device).

◆ write

uint32_t(*) device_ops_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).

Returns
number of bytes written.

◆ size

uint64_t(*) device_ops_t::size(device_t *dev)

total byte size of the device's addressable memory (optional; NULL means unknown/zero).

used for read clamping and lseek(SEEK_END).

◆ open

kerr_t(*) device_ops_t::open(device_t *dev, uint32_t flags, struct file **out)

open the device as a stream of its own (optional).

when set, open(2) of the /dev node gives the file this hook makes, with the device's own file operations (blocking, O_NONBLOCK, poll, a release when the last descriptor closes), and read, write and ioctl above are not used for it.

Parameters
devthe device.
flagsthe O_ access mode and status flags of the open.
outreceives the new open-file description.
Returns
KERR_OK, or an error (KERR_BUSY if the device is in use).

The documentation for this struct was generated from the following file: