AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
ps2mouse.c File Reference

The PS/2 mouse driver: /dev/mouse (character device 10, 1). More...

#include <core/system.h>
#include <core/module.h>
#include <core/arch.h>
#include <cpu/cpu.h>
#include <dev/i8042.h>
#include <sys/proc.h>
#include <sys/sched.h>
#include <dev/dev.h>
#include <fs/devfs.h>
#include <fs/posix.h>
#include <ds/ringbuf.h>
#include <ds/queue.h>
#include <aquila/errno.h>

Go to the source code of this file.

Macros

#define USE_DEFAULTS   0xF6
#define ENABLE_MOUSE   0xF4
#define RESET   0xFF
#define BUF_SIZE   1024

Functions

void ps2mouse_handler (int byte)
 Takes a byte from the mouse, which the i8042 driver received: it goes to the readers, unless it is a reply to the reset done at open.
void ps2mouse_register (void)
 Has the i8042 driver send the bytes of its second port, the mouse's, to this driver.
static ssize_t ps2mouse_read (struct devid *dd, off_t offset, struct iobuf *io)
 Reads the bytes received from the mouse.
static ssize_t ps2mouse_write (struct devid *dd, off_t offset, struct iobuf *io)
 Sends what is written to the mouse, a byte at a time: commands, which it replies to (an ACK to each byte, and more to some).
int ps2mouse_probe ()
 Sets the mouse up at boot (its default settings, and reporting on) and registers /dev/mouse.
static int ps2mouse_file_open (struct file *file)
 Opens /dev/mouse, which one process at a time may have open (EACCES otherwise), and resets the mouse.
static int ps2mouse_file_can_read (struct file *file, size_t size)
 Returns whether there are bytes to read.
static int ps2mouse_file_close (struct file *file)
 Closes /dev/mouse: another process may open it now.

Variables

struct dev ps2mousedev
static struct ringbuf * mouse_ring = RINGBUF_NEW(BUF_SIZE)
static struct proc * proc = NULL
static struct waitq * mouse_read_queue = &(struct waitq){0}
static int skip = 0

Detailed Description

The PS/2 mouse driver: /dev/mouse (character device 10, 1).

As Linux's /dev/psaux, reading it gives the mouse's bytes as they come: its movement packets (3 bytes, or 4 with a wheel), and its replies (an ACK, its ID) to the commands written to it, which go to the mouse. A reader finds where packets start by bit 3 of their first byte. Opening it resets the mouse to a plain PS/2 mouse, so the first byte read starts a packet. The mouse is on the second port of the i8042 controller (dev/input/i8042.c).

Definition in file ps2mouse.c.

Macro Definition Documentation

◆ BUF_SIZE

#define BUF_SIZE   1024

Definition at line 40 of file ps2mouse.c.

Referenced by e1000_transmit(), rx_init(), and tx_init().

◆ ENABLE_MOUSE

#define ENABLE_MOUSE   0xF4

Definition at line 37 of file ps2mouse.c.

Referenced by ps2mouse_file_open(), and ps2mouse_probe().

◆ RESET

#define RESET   0xFF

Definition at line 38 of file ps2mouse.c.

Referenced by ps2mouse_file_open().

◆ USE_DEFAULTS

#define USE_DEFAULTS   0xF6

Definition at line 36 of file ps2mouse.c.

Referenced by ps2mouse_probe().

Function Documentation

◆ ps2mouse_file_can_read()

int ps2mouse_file_can_read ( struct file * file,
size_t size )
static

Returns whether there are bytes to read.

Definition at line 149 of file ps2mouse.c.

References mouse_ring, and ps2mouse_file_can_read().

Referenced by ps2mouse_file_can_read().

◆ ps2mouse_file_close()

int ps2mouse_file_close ( struct file * file)
static

Closes /dev/mouse: another process may open it now.

Definition at line 156 of file ps2mouse.c.

References NULL, posix_file_close(), and ps2mouse_file_close().

Referenced by ps2mouse_file_close().

◆ ps2mouse_file_open()

int ps2mouse_file_open ( struct file * file)
static

Opens /dev/mouse, which one process at a time may have open (EACCES otherwise), and resets the mouse.

Definition at line 127 of file ps2mouse.c.

References curproc, ENABLE_MOUSE, i8042_aux_write(), mouse_read_queue, mouse_ring, posix_file_open(), ps2mouse_file_open(), RESET, and skip.

Referenced by ps2mouse_file_open().

◆ ps2mouse_handler()

void ps2mouse_handler ( int byte)

Takes a byte from the mouse, which the i8042 driver received: it goes to the readers, unless it is a reply to the reset done at open.

Parameters
bytethe byte

Definition at line 56 of file ps2mouse.c.

References mouse_read_queue, mouse_ring, ps2mouse_handler(), skip, and waitq_wakeup().

Referenced by ps2mouse_handler(), and ps2mouse_register().

◆ ps2mouse_probe()

int ps2mouse_probe ( )

Sets the mouse up at boot (its default settings, and reporting on) and registers /dev/mouse.

The i8042 driver turned the controller's second port on. The mouse's replies come before anyone reads, and opening the device sets the mouse up again anyway.

Returns
0

Definition at line 114 of file ps2mouse.c.

References ENABLE_MOUSE, i8042_aux_write(), kdev_chrdev_register(), ps2mouse_probe(), ps2mouse_register(), ps2mousedev, and USE_DEFAULTS.

Referenced by ps2mouse_probe().

◆ ps2mouse_read()

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

Reads the bytes received from the mouse.

Definition at line 81 of file ps2mouse.c.

References mouse_ring, ps2mouse_read(), and iobuf::resid.

Referenced by ps2mouse_read().

◆ ps2mouse_register()

void ps2mouse_register ( void )

Has the i8042 driver send the bytes of its second port, the mouse's, to this driver.

Definition at line 75 of file ps2mouse.c.

References i8042_handler_register(), ps2mouse_handler(), and ps2mouse_register().

Referenced by ps2mouse_probe(), and ps2mouse_register().

◆ ps2mouse_write()

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

Sends what is written to the mouse, a byte at a time: commands, which it replies to (an ACK to each byte, and more to some).

Definition at line 88 of file ps2mouse.c.

References i8042_aux_write(), iobuf_in(), ps2mouse_write(), and iobuf::resid.

Referenced by ps2mouse_write().

Variable Documentation

◆ mouse_read_queue

struct waitq* mouse_read_queue = &(struct waitq){0}
static

Definition at line 44 of file ps2mouse.c.

Referenced by ps2mouse_file_open(), and ps2mouse_handler().

◆ mouse_ring

struct ringbuf* mouse_ring = RINGBUF_NEW(BUF_SIZE)
static

◆ proc

struct proc* proc = NULL
static

Definition at line 43 of file ps2mouse.c.

◆ ps2mousedev

struct dev ps2mousedev
Initial value:
= {
.name = "mousedev",
.probe = ps2mouse_probe,
.read = ps2mouse_read,
.write = ps2mouse_write,
.fops = {
.read = posix_file_read,
.write = posix_file_write,
.can_write = __vfs_can_always,
.eof = __vfs_eof_never,
},
}
ssize_t posix_file_read(struct file *file, struct iobuf *io)
Reads from an open file at its offset, and moves the offset past what was read.
Definition read.c:29
ssize_t posix_file_write(struct file *file, struct iobuf *io)
Writes to an open file at its offset, and moves the offset past what was written.
Definition write.c:25
static ssize_t ps2mouse_read(struct devid *dd, off_t offset, struct iobuf *io)
Reads the bytes received from the mouse.
Definition ps2mouse.c:81
static int ps2mouse_file_can_read(struct file *file, size_t size)
Returns whether there are bytes to read.
Definition ps2mouse.c:149
static int ps2mouse_file_close(struct file *file)
Closes /dev/mouse: another process may open it now.
Definition ps2mouse.c:156
int ps2mouse_probe()
Sets the mouse up at boot (its default settings, and reporting on) and registers /dev/mouse.
Definition ps2mouse.c:114
static int ps2mouse_file_open(struct file *file)
Opens /dev/mouse, which one process at a time may have open (EACCES otherwise), and resets the mouse.
Definition ps2mouse.c:127
static ssize_t ps2mouse_write(struct devid *dd, off_t offset, struct iobuf *io)
Sends what is written to the mouse, a byte at a time: commands, which it replies to (an ACK to each b...
Definition ps2mouse.c:88

Definition at line 34 of file ps2mouse.c.

Referenced by ps2mouse_probe().

◆ skip

int skip = 0
static