AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
vesa.c
Go to the documentation of this file.
1
12
13#include <core/system.h>
14#include <dev/fbdev.h>
15#include <fs/devfs.h>
16#include <video/vesa.h>
17#include <mm/vm.h>
18
19/* the framebuffer, in the kernel's address space */
20static char *vmem = (char *) ARCH_VESA_BASE;
21
22static struct vm_entry vesa_vm = {
23 .base = ARCH_VESA_BASE,
24};
25
26/* the framebuffer's size, in bytes */
27static size_t len = 0;
28
29static struct fb_fix_screeninfo vesa_fix_screeninfo = {
30 .id = "VESA FB",
31};
32
33static struct fb_var_screeninfo vesa_var_screeninfo;
34
37static ssize_t fbdev_vesa_write(struct fbdev *fb __unused, off_t offset, struct iobuf *io)
38{
39 if (offset < 0)
40 return -EINVAL;
41
42 if ((size_t) offset >= len)
43 return 0;
44
45 /* copy what fits into the framebuffer */
46 return iobuf_in(io, (char *) vmem + offset, MIN(io->resid, len - (size_t) offset));
47}
48
52static int fbdev_vesa_map(struct fbdev *fb, struct vm_space *vm_space, struct vm_entry *vm_entry)
53{
54
55 /* private mappings aren't supported */
56 if (!(vm_entry->flags & VM_SHARED))
57 return -ENOTSUP;
58
59 /* the mapping must lie within the framebuffer (rounded to pages) */
61
63 return -ENXIO;
64
66 return vm_map(vm_space, vm_entry);
67}
68
73static int fbdev_vesa_prope(int i __unused, struct fbdev *fb)
74{
75 struct fbdev_vesa *data = (struct fbdev_vesa *) fb->data;
76
77 struct mode_info_block *info = data->mode_info;
78 size_t size = info->y_resolution * info->lin_bytes_per_scanline;
79
81 vesa_vm.size = size;
82 /* cached, as the early console's mapping is (arch/i386/earlycon/fb.c) */
84
85 int err = vm_map(&kvm_space, &vesa_vm);
86
87 if (err) {
88 printk("vesa: can't map the framebuffer: error %d\n", -err);
89 return err;
90 }
91
92 len = size;
93
94
100
101 /* the screen information, which ioctl() gives */
102 vesa_fix_screeninfo.smem_start = (uintptr_t) vmem;
103 vesa_fix_screeninfo.smem_len = size;
104 vesa_fix_screeninfo.type = FB_TYPE_PACKED_PIXELS;
105 vesa_fix_screeninfo.visual = FB_VISUAL_TRUECOLOR;
106 vesa_fix_screeninfo.xpanstep = 0;
107 vesa_fix_screeninfo.ypanstep = 0;
108 vesa_fix_screeninfo.ywrapstep = 0;
110 vesa_fix_screeninfo.mmio_start = info->phys_base_ptr;
111 vesa_fix_screeninfo.mmio_len = size;
112
115 vesa_var_screeninfo.xres_virtual = info->x_resolution;
116 vesa_var_screeninfo.yres_virtual = info->y_resolution;
117 vesa_var_screeninfo.xoffset = 0;
118 vesa_var_screeninfo.yoffset = 0;
119
120 vesa_var_screeninfo.bits_per_pixel = info->bits_per_pixel;
121
122 /* where each colour's bits are; if the mode doesn't say, xRGB with 8
123 * bits each, or 5-6-5 for 16 bits per pixel */
124 if (info->red_mask_size && info->green_mask_size && info->blue_mask_size) {
125 vesa_var_screeninfo.red = (struct fb_bitfield) {info->red_field_position, info->red_mask_size, 0};
126 vesa_var_screeninfo.green = (struct fb_bitfield) {info->green_field_position, info->green_mask_size, 0};
127 vesa_var_screeninfo.blue = (struct fb_bitfield) {info->blue_field_position, info->blue_mask_size, 0};
128 } else if (info->bits_per_pixel == 16) {
129 vesa_var_screeninfo.red = (struct fb_bitfield) {11, 5, 0};
130 vesa_var_screeninfo.green = (struct fb_bitfield) {5, 6, 0};
131 vesa_var_screeninfo.blue = (struct fb_bitfield) {0, 5, 0};
132 } else {
133 vesa_var_screeninfo.red = (struct fb_bitfield) {16, 8, 0};
134 vesa_var_screeninfo.green = (struct fb_bitfield) {8, 8, 0};
135 vesa_var_screeninfo.blue = (struct fb_bitfield) {0, 8, 0};
136 }
137
138 return 0;
139}
140
142 .probe = fbdev_vesa_prope,
143 .write = fbdev_vesa_write,
144 .map = fbdev_vesa_map,
145};
static uint32_t fb_size
Definition fb.c:21
#define ARCH_VESA_BASE
Definition mm.h:44
static uint8_t * fb
Definition fb.c:24
#define MIN(a, b)
Definition system.h:11
#define PAGE_ROUND(ptr)
Definition mm.h:10
ssize_t iobuf_in(struct iobuf *io, void *dst, size_t n)
Copies bytes from the iobuf's buffer into the kernel, and moves past them.
Definition iobuf.c:135
int printk(const char *fmt,...)
Writes a kernel message, to the message buffer and the consoles.
Definition printk.c:249
__SIZE_TYPE__ uintptr_t
Definition stddef.h:12
The boot loader's VBE framebuffer: what VBE said about the card and the mode (dev/fb/vesa/).
Definition vesa.h:8
struct mode_info_block * mode_info
Definition vesa.h:10
A framebuffer: its driver, its screen's information, its operations.
Definition fbdev.h:23
int(*) probe(int id, struct fbdev *fb)
Definition fbdev.h:29
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
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
size_t resid
Definition iobuf.h:38
A VBE mode's information block.
Definition vbe.h:33
uint8_t bits_per_pixel
Definition vbe.h:50
uint8_t red_field_position
Definition vbe.h:58
uint8_t blue_mask_size
Definition vbe.h:61
uint8_t red_mask_size
Definition vbe.h:57
uint8_t blue_field_position
Definition vbe.h:62
uint8_t green_mask_size
Definition vbe.h:59
uint16_t x_resolution
Definition vbe.h:45
uint8_t green_field_position
Definition vbe.h:60
uint32_t phys_base_ptr
Definition vbe.h:67
uint16_t y_resolution
Definition vbe.h:46
uint16_t lin_bytes_per_scanline
Definition vbe.h:71
A mapping (map entry): a range of an address space, its permissions, and where its pages come from.
Definition vm.h:66
uint32_t flags
its permissions and flags (VM_*)
Definition vm.h:78
paddr_t paddr
physical memory to map all at once (vm_map()), or 0 for pages that come in on page faults
Definition vm.h:69
size_t off
where the mapping starts in its object
Definition vm.h:87
size_t size
its size
Definition vm.h:75
An address space: its mappings, and its page tables.
Definition vm.h:25
An arena: a range, and its segments.
Definition vmem.h:41
long int ssize_t
Definition types.h:12
long int off_t
Definition types.h:10
static int fbdev_vesa_prope(int i, struct fbdev *fb)
Sets up the framebuffer from the mode the boot loader chose: maps it into the kernel's address space,...
Definition vesa.c:73
static struct fb_fix_screeninfo vesa_fix_screeninfo
Definition vesa.c:29
static struct fb_var_screeninfo vesa_var_screeninfo
Definition vesa.c:33
static size_t len
Definition vesa.c:27
static ssize_t fbdev_vesa_write(struct fbdev *fb, off_t offset, struct iobuf *io)
Writes to the framebuffer at offset, as much as fits before its end.
Definition vesa.c:37
static int fbdev_vesa_map(struct fbdev *fb, struct vm_space *vm_space, struct vm_entry *vm_entry)
Maps the framebuffer, or part of it, into a process's address space.
Definition vesa.c:52
static struct vm_entry vesa_vm
Definition vesa.c:22
int vm_map(struct vm_space *vm_space, struct vm_entry *vm_entry)
Maps a map entry's whole range at once: its physical memory (paddr), or new pages of memory if it has...
Definition vmm.c:29
#define VM_SHARED
shared: a fork doesn't copy it
Definition vm.h:46
struct vm_space kvm_space
Definition vmm.c:17
#define VM_KRW
kernel read/write
Definition vm.h:49