The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
device.h File Reference

generic device model: a named/typed handle plus a registry. More...

#include "common/stdint.h"
#include "arch/arch.h"
#include "common/error.h"

Go to the source code of this file.

Data Structures

struct  device_ops_t
 optional per-device operations. More...
struct  device
 a registered device. More...

Macros

#define DEVICE_NAME_MAX   16
#define DEVICE_NUMBER(major, minor)
 a device number from its major and minor numbers, packed as Linux and the libc's makedev (sys/sysmacros.h) pack them.

Typedefs

typedef struct device device_t

Enumerations

enum  device_type_t {
  DEVICE_TYPE_UNKNOWN = 0 , DEVICE_TYPE_BLOCK , DEVICE_TYPE_CHAR , DEVICE_TYPE_INPUT ,
  DEVICE_TYPE_TIMER
}

Functions

void device_registry_init (void)
 reset the device registry.
bool device_register (device_t *dev)
 register a device.
uint32_t device_count (void)
 number of currently registered devices.
device_t * device_get (uint32_t index)
 get a registered device by index (0 .
device_t * device_find (const char *name)
 find a registered device by name.

Detailed Description

generic device model: a named/typed handle plus a registry.

drivers wrap their concrete device in a device_t and register it here during init, so the rest of the kernel has one place to enumerate what hardware is present. this is the groundwork for a future devfs that surfaces registered devices as /dev/hda, /dev/tty0, and so on.

the model intentionally stays thin: it does not replace the driver-specific init flow (which has its own ordering), it just records the result.

Macro Definition Documentation

◆ DEVICE_NAME_MAX

#define DEVICE_NAME_MAX   16

◆ DEVICE_NUMBER

#define DEVICE_NUMBER ( major,
minor )
Value:
((((major) & 0xfffu) << 8) | ((minor) & 0xffu) | (((minor) & 0xfff00u) << 12))
#define minor(dev)
Definition sysmacros.h:10
#define major(dev)
Definition sysmacros.h:9

a device number from its major and minor numbers, packed as Linux and the libc's makedev (sys/sysmacros.h) pack them.

ginnOS uses Linux's numbers for the terminals: tty0 4:0, ptmx 5:2, pts/N 136:N.

Typedef Documentation

◆ device_t

typedef struct device device_t

Enumeration Type Documentation

◆ device_type_t

Enumerator
DEVICE_TYPE_UNKNOWN 
DEVICE_TYPE_BLOCK 
DEVICE_TYPE_CHAR 
DEVICE_TYPE_INPUT 
DEVICE_TYPE_TIMER 

Function Documentation

◆ device_registry_init()

void device_registry_init ( void )

reset the device registry.

call once during early boot.

◆ device_register()

bool device_register ( device_t * dev)

register a device.

the device_t is owned by the caller and must outlive its registration (drivers use static or long-lived storage).

Parameters
devthe device to add.
Returns
true on success, false if the registry is full or dev is invalid.

◆ device_count()

uint32_t device_count ( void )

number of currently registered devices.

◆ device_get()

device_t * device_get ( uint32_t index)

get a registered device by index (0 .

. device_count()-1).

Returns
the device, or NULL if the index is out of range.

◆ device_find()

device_t * device_find ( const char * name)

find a registered device by name.

Returns
the device, or NULL if no device has that name.