AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
fbdev.c
Go to the documentation of this file.
1
11
12#include <core/system.h>
13#include <sys/uaccess.h>
14#include <core/module.h>
15
16#include <dev/fbdev.h>
17#include <dev/ramdev.h>
18
19#include <fs/vfs.h>
20#include <fs/devfs.h>
21#include <fs/posix.h>
22
23#define MAX_FBDEV 2
24
26static size_t fbdev_cnt = 0;
27
37int fbdev_register(int type, void *data)
38{
39 if (fbdev_cnt == MAX_FBDEV)
40 return -ENOSPC;
41
44
45 return 0;
46}
47
49static struct fbdev *fbdev_get(struct devid *dd)
50{
51 if (dd->minor >= fbdev_cnt)
52 return NULL;
53
54 return &registered_fbs[dd->minor];
55}
56
63struct fbdev *fbdev_primary(void)
64{
66 return NULL;
67
68 return &registered_fbs[0];
69}
70
72static ssize_t fbdev_write(struct devid *dd, off_t offset, struct iobuf *io)
73{
74 struct fbdev *fb = fbdev_get(dd);
75
76 if (!fb || !fb->write)
77 return -ENXIO;
78
79 return fb->write(fb, offset, io);
80}
81
84static int fbdev_ioctl(struct devid *dd, int request, void *argp)
85{
86 struct fbdev *fb = fbdev_get(dd);
87
88 if (!fb)
89 return -ENXIO;
90
91 switch (request) {
92 case FBIOGET_FSCREENINFO:
93 if (!fb->fix_screeninfo)
94 return -ENXIO;
95 return copyout(argp, fb->fix_screeninfo, sizeof(struct fb_fix_screeninfo));
96 case FBIOGET_VSCREENINFO:
97 if (!fb->var_screeninfo)
98 return -ENXIO;
99 return copyout(argp, fb->var_screeninfo, sizeof(struct fb_var_screeninfo));
100 case FBIOPUT_VSCREENINFO: {
101 /* the mode can't be changed: only a request for the mode it is
102 * already succeeds, and the caller gets the mode back */
103 struct fb_var_screeninfo *var = fb->var_screeninfo, _new, *new = &_new;
104
105 if (!var)
106 return -ENXIO;
107 if (copyin(new, argp, sizeof(*new)))
108 return -EFAULT;
109
110 if (new->xres != var->xres || new->yres != var->yres ||
111 new->xres_virtual > var->xres_virtual ||
112 new->yres_virtual > var->yres_virtual ||
113 (new->bits_per_pixel && new->bits_per_pixel != var->bits_per_pixel) ||
114 new->xoffset || new->yoffset)
115 return -EINVAL;
116
117 return copyout(argp, var, sizeof(struct fb_var_screeninfo));
118 }
119 case FBIOPAN_DISPLAY: {
120 /* no panning: the virtual screen is the visible one */
121 struct fb_var_screeninfo new;
122
123 if (copyin(&new, argp, sizeof(new)))
124 return -EFAULT;
125
126 return new.xoffset || new.yoffset ? -EINVAL : 0;
127 }
128 }
129
130 return -ENOTTY;
131}
132
135static int fbdev_map(struct devid *dd, struct vm_space *vm_space, struct vm_entry *vm_entry)
136{
137 struct fbdev *fb = fbdev_get(dd);
138
139 if (!fb || !fb->map)
140 return -ENXIO;
141
142 return fb->map(fb, vm_space, vm_entry);
143}
144
152{
153 for (size_t i = 0; i < fbdev_cnt; ++i) {
154 struct fbdev *fb = &registered_fbs[i];
155
156 switch (fb->type) {
157 case FBDEV_TYPE_VESA:
158 fbdev_vesa.probe(i, fb);
159 break;
160 }
161 }
162
164 return 0;
165}
166
167struct dev fbdev = {
168 .name = "fbdev",
169
170 .probe = fbdev_probe,
171 .write = fbdev_write,
172 .ioctl = fbdev_ioctl,
173 .map = fbdev_map,
174
175 /* no driver can read the screen back (vesa's only writes), so there
176 * is no read() */
177 .fops = {
178 .open = posix_file_open,
179 .write = posix_file_write,
180 .ioctl = posix_file_ioctl,
181 .lseek = posix_file_lseek,
182
183 .can_write = __vfs_can_always,
184 .can_read = __vfs_can_never,
185 .eof = __vfs_eof_never,
186 },
187};
188
static uint8_t * fb
Definition fb.c:24
static ssize_t fbdev_write(struct devid *dd, off_t offset, struct iobuf *io)
Writes to a framebuffer, through its driver.
Definition fbdev.c:72
static int fbdev_map(struct devid *dd, struct vm_space *vm_space, struct vm_entry *vm_entry)
Maps a framebuffer into a process's address space, through its driver.
Definition fbdev.c:135
int fbdev_probe()
Sets up the registered framebuffers with their drivers, and registers the framebuffer devices.
Definition fbdev.c:151
static struct fbdev * fbdev_get(struct devid *dd)
Returns the framebuffer of a device number, or NULL if there's none.
Definition fbdev.c:49
#define MAX_FBDEV
Definition fbdev.c:23
static size_t fbdev_cnt
Definition fbdev.c:26
static int fbdev_ioctl(struct devid *dd, int request, void *argp)
Handles Linux's framebuffer ioctl()s: the screen information, which can be read but not changed,...
Definition fbdev.c:84
struct fbdev * fbdev_primary(void)
Returns the first framebuffer, once it is set up, for the virtual terminals.
Definition fbdev.c:63
static struct fbdev registered_fbs[MAX_FBDEV]
Definition fbdev.c:25
int fbdev_register(int type, void *data)
Registers a framebuffer, which fbdev_probe() sets up with its driver.
Definition fbdev.c:37
#define FBDEV_TYPE_VESA
Definition fbdev.h:11
void kdev_chrdev_register(devid_t major, struct dev *dev)
Registers a driver as the character device of a major number.
Definition kdev.c:575
off_t posix_file_lseek(struct file *file, off_t offset, int whence)
Moves an open file's offset: to offset (SEEK_SET), by offset from where it is (SEEK_CUR),...
Definition lseek.c:22
#define MODULE_INIT(name, i, f)
Definition module.h:10
int posix_file_open(struct file *file)
Finishes opening a file: with O_TRUNC, a regular file is truncated to 0 bytes.
Definition open.c:17
int posix_file_ioctl(struct file *file, int request, void *argp)
Passes an ioctl() request on to the file's vnode (a device's, or its filesystem's).
Definition ioctl.c:19
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
#define NULL
Definition stddef.h:27
A device driver: its operations, any of which may be NULL.
Definition dev.h:28
Which device: its kind (S_IFCHR or S_IFBLK) and numbers.
Definition dev.h:21
devid_t minor
Definition dev.h:24
The boot loader's VBE framebuffer: what VBE said about the card and the mode (dev/fb/vesa/).
Definition vesa.h:8
A framebuffer: its driver, its screen's information, its operations.
Definition fbdev.h:23
ssize_t(*) write(struct fbdev *fb, off_t offset, struct iobuf *io)
Definition fbdev.h:31
struct fb_var_screeninfo * var_screeninfo
Definition fbdev.h:27
int type
Definition fbdev.h:24
struct fb_fix_screeninfo * fix_screeninfo
Definition fbdev.h:26
int(*) map(struct fbdev *fb, struct vm_space *vm_space, struct vm_entry *vm_entry)
Definition fbdev.h:33
void * data
Definition fbdev.h:25
An iobuf.
Definition iobuf.h:35
A mapping (map entry): a range of an address space, its permissions, and where its pages come from.
Definition vm.h:66
An address space: its mappings, and its page tables.
Definition vm.h:25
long int ssize_t
Definition types.h:12
long int off_t
Definition types.h:10