AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
dev.h File Reference
#include <core/system.h>
#include <mm/vm.h>
#include <fs/vfs.h>
#include <sys/proc.h>
#include <fs/iobuf.h>

Go to the source code of this file.

Data Structures

struct  devid
 Which device: its kind (S_IFCHR or S_IFBLK) and numbers. More...
struct  dev
 A device driver: its operations, any of which may be NULL. More...

Macros

#define DEV(major, minor)
#define DEV_MAJOR(dev)
#define DEV_MINOR(dev)
#define VNODE_DEV(vnode)

Functions

void kdev_init (void)
 Starts the device layer, at boot.
void kdev_chrdev_register (devid_t major, struct dev *dev)
 Registers a driver as the character device of a major number.
void kdev_blkdev_register (devid_t major, struct dev *dev)
 Registers a driver as the block device of a major number.
int kdev_sync (void)
 Writes what the block cache holds that was written, and what the block devices hold in their write caches, to the media.
ssize_t kdev_read (struct devid *dd, off_t offset, struct iobuf *io)
 Reads from a device: a character device through its driver, a block device in blocks.
ssize_t kdev_write (struct devid *dd, off_t offset, struct iobuf *io)
 Writes to a device: a character device through its driver, a block device in blocks.
int kdev_ioctl (struct devid *dd, int request, void *argp)
 Passes an ioctl() to a device's driver.
int kdev_map (struct devid *dd, struct vm_space *vm_space, struct vm_entry *vm_entry)
 Maps a device into an address space (mmap() of a framebuffer).
struct fops * kdev_fops (struct devid *dd)
 Returns the file operations of a device.
int kdev_file_open (struct devid *dd, struct file *file)
 Opens a device, through its driver's file operations.
ssize_t kdev_file_read (struct devid *dd, struct file *file, struct iobuf *io)
 Reads an open device file, through its driver's file operations.
ssize_t kdev_file_write (struct devid *dd, struct file *file, struct iobuf *io)
 Writes to an open device file, through its driver's file operations.
off_t kdev_file_lseek (struct devid *dd, struct file *file, off_t offset, int whence)
 Moves an open device file's offset, through its driver's file operations.
ssize_t kdev_file_close (struct devid *dd, struct file *file)
 Closes an open device file, through its driver's file operations.
int kdev_file_ioctl (struct devid *dd, struct file *file, int request, void *argp)
 Passes an ioctl() on an open device file to its driver's file operations.
int kdev_file_can_read (struct devid *dd, struct file *file, size_t size)
 Asks a device's driver whether a read wouldn't have to wait.
int kdev_file_can_write (struct devid *dd, struct file *file, size_t size)
 Asks a device's driver whether a write wouldn't have to wait.
int kdev_file_eof (struct devid *dd, struct file *file)
 Asks a device's driver whether a read that found no data is at the end of the file.

Variables

struct dev ttydev
struct dev pcidev
struct dev atadev
struct dev fbdev
struct dev rddev

Macro Definition Documentation

◆ DEV

#define DEV ( major,
minor )
Value:
((dev_t)(((major) & 0xFF) << 8) | ((minor) & 0xFF))
uint16_t dev_t
Definition types.h:18

Definition at line 76 of file dev.h.

Referenced by ext2_inode_build(), ext2_vmknod(), kmain(), load_ramdisk(), minix_vmknod(), ptm_new(), pts_new(), root_dev(), and tty_open().

◆ DEV_MAJOR

#define DEV_MAJOR ( dev)
Value:
((devid_t)(((dev) >> 8) & 0xFF))
A device driver: its operations, any of which may be NULL.
Definition dev.h:28
uint8_t devid_t
Definition types.h:17

Definition at line 77 of file dev.h.

Referenced by ext2_vmknod(), minix_vmknod(), vt_file_close(), and vt_file_open().

◆ DEV_MINOR

#define DEV_MINOR ( dev)
Value:
((devid_t)(((dev) >> 0) & 0xFF))

Definition at line 78 of file dev.h.

Referenced by ext2_vmknod(), minix_vmknod(), uart_can_read(), uart_file_eof(), uart_file_open(), uart_read_timeout(), vt_file_close(), and vt_file_open().

◆ VNODE_DEV

#define VNODE_DEV ( vnode)
Value:
((struct devid){.type = (vnode)->mode & S_IFMT, .major = DEV_MAJOR((vnode)->rdev), .minor = DEV_MINOR((vnode)->rdev)})
#define DEV_MAJOR(dev)
Definition dev.h:77
#define DEV_MINOR(dev)
Definition dev.h:78
Which device: its kind (S_IFCHR or S_IFBLK) and numbers.
Definition dev.h:21
A file in memory (a vnode): what its inode says, and the kernel's own state.
Definition vfs.h:113

Definition at line 79 of file dev.h.

Referenced by ctty_open(), posix_file_read(), ptm_can_read(), pts_can_read(), pts_eof(), pts_open(), pts_read_timeout(), vfs_file_can_read(), vfs_file_can_write(), vfs_file_close(), vfs_file_eof(), vfs_file_ioctl(), vfs_file_lseek(), vfs_file_open(), vfs_file_read(), vfs_file_write(), vfs_ioctl(), vfs_map(), vfs_read_io(), vfs_write_io(), and vt_file().

Function Documentation

◆ kdev_blkdev_register()

void kdev_blkdev_register ( devid_t major,
struct dev * dev )

Registers a driver as the block device of a major number.

A driver registered before for that major is replaced.

Parameters
majorthe major number
devthe driver

Definition at line 605 of file kdev.c.

References blkdev, kdev_blkdev_register(), dev::name, and printk().

Referenced by ata_probe(), kdev_blkdev_register(), and rd_probe().

◆ kdev_chrdev_register()

void kdev_chrdev_register ( devid_t major,
struct dev * dev )

Registers a driver as the character device of a major number.

A driver registered before for that major is replaced.

Parameters
majorthe major number
devthe driver

Definition at line 575 of file kdev.c.

References chrdev, kdev_chrdev_register(), dev::name, and printk().

Referenced by fbdev_probe(), kdev_chrdev_register(), memdev_probe(), ps2mouse_probe(), pty_init(), ttydev_probe(), and vt_probe().

◆ kdev_file_can_read()

int kdev_file_can_read ( struct devid * dd,
struct file * file,
size_t size )

Asks a device's driver whether a read wouldn't have to wait.

Parameters
ddthe device's number
filethe open file
sizehow much would be read
Returns
whether it can be read, or a negative errno

Definition at line 513 of file kdev.c.

References fops::can_read, dev::fops, kdev_file_can_read(), kdev_get(), and NULL.

Referenced by kdev_file_can_read(), and vfs_file_can_read().

◆ kdev_file_can_write()

int kdev_file_can_write ( struct devid * dd,
struct file * file,
size_t size )

Asks a device's driver whether a write wouldn't have to wait.

Parameters
ddthe device's number
filethe open file
sizehow much would be written
Returns
whether it can be written, or a negative errno

Definition at line 534 of file kdev.c.

References fops::can_write, dev::fops, kdev_file_can_write(), kdev_get(), and NULL.

Referenced by kdev_file_can_write(), and vfs_file_can_write().

◆ kdev_file_close()

ssize_t kdev_file_close ( struct devid * dd,
struct file * file )

Closes an open device file, through its driver's file operations.

Parameters
ddthe device's number
filethe open file
Returns
0, or a negative errno

Definition at line 468 of file kdev.c.

References fops::close, dev::fops, kdev_file_close(), kdev_get(), NULL, and posix_file_close().

Referenced by kdev_file_close(), and vfs_file_close().

◆ kdev_file_eof()

int kdev_file_eof ( struct devid * dd,
struct file * file )

Asks a device's driver whether a read that found no data is at the end of the file.

Parameters
ddthe device's number
filethe open file
Returns
whether it is, or a negative errno

Definition at line 555 of file kdev.c.

References fops::eof, dev::fops, kdev_file_eof(), kdev_get(), and NULL.

Referenced by kdev_file_eof(), and vfs_file_eof().

◆ kdev_file_ioctl()

int kdev_file_ioctl ( struct devid * dd,
struct file * file,
int request,
void * argp )

Passes an ioctl() on an open device file to its driver's file operations.

Parameters
ddthe device's number
filethe open file
requestthe request
argpits argument
Returns
what the driver returns, or a negative errno

Definition at line 492 of file kdev.c.

References dev::fops, fops::ioctl, kdev_file_ioctl(), kdev_get(), and NULL.

Referenced by kdev_file_ioctl(), and vfs_file_ioctl().

◆ kdev_file_lseek()

off_t kdev_file_lseek ( struct devid * dd,
struct file * file,
off_t offset,
int whence )

Moves an open device file's offset, through its driver's file operations.

Parameters
ddthe device's number
filethe open file
offsetthe offset
whencewhat it is from (SEEK_SET, SEEK_CUR, SEEK_END)
Returns
the new offset, or a negative errno (-ESPIPE for a device that can't seek)

Definition at line 447 of file kdev.c.

References dev::fops, kdev_file_lseek(), kdev_get(), fops::lseek, and NULL.

Referenced by kdev_file_lseek(), and vfs_file_lseek().

◆ kdev_file_open()

int kdev_file_open ( struct devid * dd,
struct file * file )

Opens a device, through its driver's file operations.

Parameters
ddthe device's number
filethe open file
Returns
0, or a negative errno (-ENXIO if there is no such device)

Definition at line 381 of file kdev.c.

References dev::fops, kdev_file_open(), kdev_get(), NULL, and fops::open.

Referenced by ctty_open(), kdev_file_open(), and vfs_file_open().

◆ kdev_file_read()

ssize_t kdev_file_read ( struct devid * dd,
struct file * file,
struct iobuf * io )

Reads an open device file, through its driver's file operations.

Parameters
ddthe device's number
filethe open file
iowhere to put what is read
Returns
how many bytes were read, or a negative errno

Definition at line 402 of file kdev.c.

References dev::fops, kdev_file_read(), kdev_get(), NULL, and fops::read.

Referenced by kdev_file_read(), and vfs_file_read().

◆ kdev_file_write()

ssize_t kdev_file_write ( struct devid * dd,
struct file * file,
struct iobuf * io )

Writes to an open device file, through its driver's file operations.

Parameters
ddthe device's number
filethe open file
iowhat to write
Returns
how many bytes were written, or a negative errno

Definition at line 423 of file kdev.c.

References dev::fops, kdev_file_write(), kdev_get(), NULL, and fops::write.

Referenced by kdev_file_write(), and vfs_file_write().

◆ kdev_fops()

struct fops * kdev_fops ( struct devid * dd)

Returns the file operations of a device.

Parameters
ddthe device's number
Returns
its file operations, or NULL if there is no such device

Definition at line 52 of file kdev.c.

References dev::fops, kdev_fops(), kdev_get(), and NULL.

Referenced by kdev_fops(), and posix_file_read().

◆ kdev_init()

void kdev_init ( void )

Starts the device layer, at boot.

It has nothing to set up: the drivers register themselves.

Definition at line 615 of file kdev.c.

References kdev_init(), and printk().

Referenced by kdev_init(), and kmain().

◆ kdev_ioctl()

int kdev_ioctl ( struct devid * dd,
int request,
void * argp )

Passes an ioctl() to a device's driver.

Parameters
ddthe device's number
requestthe request
argpits argument
Returns
what the driver returns, or -ENXIO if it takes no ioctl()

Definition at line 340 of file kdev.c.

References dev::ioctl, kdev_get(), kdev_ioctl(), and NULL.

Referenced by kdev_ioctl(), and vfs_ioctl().

◆ kdev_map()

int kdev_map ( struct devid * dd,
struct vm_space * vm_space,
struct vm_entry * vm_entry )

Maps a device into an address space (mmap() of a framebuffer).

Parameters
ddthe device's number
vm_spacethe address space
vm_entrythe mapping
Returns
0, or a negative errno (-ENXIO if the device can't be mapped)

Definition at line 361 of file kdev.c.

References kdev_get(), kdev_map(), dev::map, and NULL.

Referenced by kdev_map(), and vfs_map().

◆ kdev_read()

ssize_t kdev_read ( struct devid * dd,
off_t offset,
struct iobuf * io )

Reads from a device: a character device through its driver, a block device in blocks.

Parameters
ddthe device's number
offsetwhere to read from, in bytes
iowhere to put what is read
Returns
how many bytes were read, or a negative errno

Definition at line 297 of file kdev.c.

References dev::bread, kdev_blk_io(), kdev_get(), kdev_read(), NULL, dev::read, and devid::type.

Referenced by kdev_read(), and vfs_read_io().

◆ kdev_sync()

int kdev_sync ( void )

Writes what the block cache holds that was written, and what the block devices hold in their write caches, to the media.

Returns
0, or a negative errno if a write failed

Definition at line 587 of file kdev.c.

References blkcache_flush(), blkdev, kdev_sync(), and dev::sync.

Referenced by kdev_sync(), kernel_reboot(), and sys_sync().

◆ kdev_write()

ssize_t kdev_write ( struct devid * dd,
off_t offset,
struct iobuf * io )

Writes to a device: a character device through its driver, a block device in blocks.

Parameters
ddthe device's number
offsetwhere to write, in bytes
iowhat to write
Returns
how many bytes were written, or a negative errno

Definition at line 319 of file kdev.c.

References dev::bwrite, kdev_blk_io(), kdev_get(), kdev_write(), NULL, devid::type, and dev::write.

Referenced by kdev_write(), and vfs_write_io().

Variable Documentation

◆ atadev

struct dev atadev
extern

Definition at line 592 of file ata.c.

Referenced by ata_probe().

◆ fbdev

struct dev fbdev
extern

Definition at line 167 of file fbdev.c.

◆ pcidev

struct dev pcidev
extern

Definition at line 225 of file pci.c.

◆ rddev

struct dev rddev
extern

Definition at line 93 of file ramdisk.c.

◆ ttydev

struct dev ttydev
extern

Definition at line 121 of file tty.c.