AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
virt.h
Go to the documentation of this file.
1#ifndef _PLATFORM_VIRT_H
2#define _PLATFORM_VIRT_H
3
4#include <core/system.h>
5#include <mm/mm.h>
6
7/*
8 * QEMU's virt machine (hw/arm/virt.c): where its devices are, as its
9 * devicetree also says. They are in the first GiB of physical memory,
10 * which is device memory, mapped in the direct map from boot
11 * (boot/head.S).
12 */
13#define VIRT_GICD 0x08000000 /* GICv2 distributor */
14#define VIRT_GICC 0x08010000 /* GICv2 CPU interface */
15#define VIRT_UART 0x09000000 /* PL011 */
16#define VIRT_RTC 0x09010000 /* PL031 */
17#define VIRT_PCIE_MMIO 0x10000000 /* PCIe: memory for BARs (the same bus addresses) */
18#define VIRT_PCIE_MMIO_SIZE 0x2EFF0000
19#define VIRT_PCIE_PIO 0x3EFF0000 /* PCIe: its I/O ports, 64 KiB */
20#define VIRT_PCIE_ECAM 0x4010000000ULL /* PCIe: configuration space */
21
22/* Interrupt IDs: the SPIs (shared) start at 32, and the PPIs (a CPU's
23 * own) are 16 to 31. */
24#define VIRT_UART_IRQ (32 + 1)
25#define VIRT_PCIE_IRQ (32 + 3) /* INTA# to INTD#: the 4 from here, level-triggered */
26#define VIRT_TIMER_IRQ 27 /* the virtual timer (EL1) */
27
28/* A device's registers, in the direct map: the boot tables map the
29 * devices there (arch_mmio_map() maps them elsewhere). */
30#define VIRT_REG(base) ((uintptr_t) (ARCH_DMAP_BASE + (base)))
31
32/* Sets up the platform: the interrupt controller, PCI (init.c). */
33int platform_init(void);
34
35/* The GICv2 interrupt controller (gic.c). */
36void gic_setup(void);
37void gic_enable(unsigned irq);
38void gic_disable(unsigned irq);
39unsigned gic_ack(void); /* the interrupt that came, or 1023 for none */
40void gic_eoi(unsigned irq);
41
42/* The interrupts' handlers (irq.c; irq_install() is in dev/irq.h). */
43#define IRQ_NR 128
44void irq_handle(void); /* runs the handlers of the interrupt that came */
45
46/* Starts the generic timer's tick, every `period_ns` (timer.c). */
47uint64_t timer_setup(uint64_t period_ns, void (*handler)(void));
48
49#endif /* ! _PLATFORM_VIRT_H */
void gic_setup(void)
Sets up the GIC at boot: every interrupt masked, of the same priority, and sent to CPU 0.
Definition gic.c:38
void gic_eoi(unsigned irq)
Tells the GIC that an interrupt has been handled (end of interrupt).
Definition gic.c:95
unsigned gic_ack(void)
Acknowledges the interrupt that came.
Definition gic.c:85
void gic_disable(unsigned irq)
Disables (masks) an interrupt.
Definition gic.c:75
void gic_enable(unsigned irq)
Enables (unmasks) an interrupt.
Definition gic.c:65
unsigned long long int uint64_t
Definition stddef.h:23
An installed handler, on its interrupt's list.
Definition irq.c:19
int platform_init(void)
Definition init.c:31
void irq_handle(void)
Runs the handlers of the interrupt that came, then tells the GIC it's done, before any thread switch,...
Definition irq.c:84
uint64_t timer_setup(uint64_t period_ns, void(*handler)(void))
Starts the tick.
Definition timer.c:37