AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
init.c
Go to the documentation of this file.
1
5
6#include <core/kargs.h>
7#include <core/system.h>
8#include <cpu/io.h>
9#include <dev/pci.h>
10#include <platform/misc.h>
11
12/* the 8254 PIT's ports */
13#define I8254_ADDR 0x40
14#define I8254_TYPE IOADDR_PORT
15
16/* the 8259s' ports */
17#define PIC_MASTER 0x20
18#define PIC_SLAVE 0xA0
19
21static int x86_pc_pic_init(void)
22{
23 struct ioaddr pic_master;
24 struct ioaddr pic_slave;
25
26 pic_master.addr = PIC_MASTER;
27 pic_master.type = IOADDR_PORT;
28 pic_slave.addr = PIC_SLAVE;
29 pic_slave.type = IOADDR_PORT;
30
31 return x86_pic_setup(&pic_master, &pic_slave);
32}
33
34/* The PCI bus, through configuration mechanism #1's ports. The firmware
35 * set up its devices' registers and interrupt lines. */
36static struct pci_host x86_pc_pci = {
37 .name = "configuration mechanism #1",
38 .config = {.type = IOADDR_PORT, .addr = 0xCF8},
39 .read = pci_conf1_read,
40 .write = pci_conf1_write,
41};
42
44static void x86_pc_pci_init(void)
45{
46#ifdef CONFIG_DEV_PCI
48#endif
49}
50
52static int x86_pc_pit_init(void)
53{
54 struct ioaddr pit;
55
56 pit.addr = I8254_ADDR;
57 pit.type = I8254_TYPE;
58
59 return x86_pit_setup(&pit);
60}
61
63static int x86_pc_cmos_init(void)
64{
65 struct ioaddr cmos;
66 cmos.addr = 0x70;
67 cmos.type = IOADDR_PORT;
68
69 return x86_cmos_setup(&cmos);
70}
71
72#define PIT_IRQ 0
73
74static int apic;
75
85{
86 if (apic)
87 return x86_lapic_timer_setup(period_ns, handler);
88
89 uint32_t period = x86_pit_period_set(period_ns);
91 return period;
92}
93
96static void x86_pc_irq_init(void)
97{
99
100 int pic = x86_pc_pic_init();
101
103
104 if (!apic) {
105 if (pic)
106 printk("x86: no interrupt controller\n");
107 else
109 }
110
111 printk("x86: interrupts through the %s\n", x86_irq_chip_name());
112}
113
114/*
115 * Sets up the PC platform at boot: PCI, the interrupt controllers, the
116 * timers, the real time clock, then the other CPUs.
117 */
119{
124
125 /* start the other CPUs (the PIT times their start) */
126 if (apic)
127 x86_smp_init();
128
129 return 0;
130}
int irq_install(unsigned irq, irq_handler_t fn, void *arg)
Installs a handler for an IRQ.
Definition irq.c:32
uint32_t platform_timer_setup(size_t period_ns, irq_handler_t handler)
Starts the scheduler's tick: the local APIC's timer if the APIC brings the interrupts,...
Definition init.c:84
#define IOADDR_PORT
Definition io.h:89
void pci_conf1_write(struct pci_host *host, struct pci_dev *dev, uint16_t reg, uint32_t val)
Writes a 32-bit register of a function's configuration space.
Definition conf1.c:73
uint32_t pci_conf1_read(struct pci_host *host, struct pci_dev *dev, uint16_t reg)
Reads a 32-bit register of a function's configuration space.
Definition conf1.c:55
void x86_smp_init(void)
Starts the other CPUs, at boot, unless the kernel's command line says smp=off.
Definition smp.c:182
static int x86_pc_pit_init(void)
Sets up the PIT at the PC's ports.
Definition init.c:52
#define PIC_MASTER
Definition init.c:17
static int x86_pc_cmos_init(void)
Sets up the real time clock at the PC's ports.
Definition init.c:63
#define PIT_IRQ
Definition init.c:72
#define I8254_ADDR
Definition init.c:13
static int x86_pc_pic_init(void)
Sets up the 8259s at the PC's ports.
Definition init.c:21
static struct pci_host x86_pc_pci
Definition init.c:36
#define I8254_TYPE
Definition init.c:14
static void x86_pc_irq_init(void)
Sets up the interrupts: through the APIC if there's one (and not apic=off), else through the 8259s.
Definition init.c:96
#define PIC_SLAVE
Definition init.c:18
static int apic
Definition init.c:74
static void x86_pc_pci_init(void)
Gives PCI its host bridge.
Definition init.c:44
void(*) irq_handler_t(void *arg)
Definition irq.h:21
void x86_irq_gates_setup(void)
Sets the IDT's gates for the interrupts: vectors 32 to 79, the local APIC's timer,...
Definition irq.c:266
int x86_pic_setup(struct ioaddr *master, struct ioaddr *slave)
Sets up the 8259s, with every IRQ masked.
Definition pic.c:165
uint32_t x86_lapic_timer_setup(uint32_t period_ns, irq_handler_t handler)
Starts the scheduler's tick with the local APIC's timer, calibrated first.
Definition apic.c:512
struct x86_irq_chip x86_pic_chip
Definition pic.c:126
uint32_t x86_pit_period_set(uint32_t period_ns)
Makes channel 0 interrupt periodically, for the scheduler's tick.
Definition pit.c:82
void x86_irq_chip_set(struct x86_irq_chip *chip)
Sets the system's interrupt controller.
Definition irq.c:67
const char * x86_irq_chip_name(void)
Returns the name of the system's interrupt controller.
Definition irq.c:77
int x86_apic_setup(void)
Sets up the APIC to bring the interrupts, if the CPU has one, the MADT describes it,...
Definition apic.c:359
int x86_pit_setup(struct ioaddr *io)
Sets where the PIT's ports are.
Definition pit.c:52
int x86_cmos_setup(struct ioaddr *ioaddr)
Sets where the CMOS's ports are.
Definition cmos.c:139
int pci_host_set(struct pci_host *h)
Sets the platform's host bridge, from platform_init().
Definition pci.c:443
int printk(const char *fmt,...)
Writes a kernel message, to the message buffer and the consoles.
Definition printk.c:249
#define NULL
Definition stddef.h:27
unsigned int uint32_t
Definition stddef.h:22
An installed handler, on its interrupt's list.
Definition irq.c:19
Where a device's registers are.
Definition io.h:95
uintptr_t addr
Definition io.h:97
char type
Definition io.h:96
The host bridge, which the platform describes (platform_init() sets it): how its configuration space ...
Definition pci.h:32
int platform_init(void)
Definition init.c:31