AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
misc.h
Go to the documentation of this file.
1#ifndef _PLATFORM_MISC_H
2#define _PLATFORM_MISC_H
3
4#include <cpu/cpu.h>
5#include <cpu/io.h>
6#include <dev/irq.h>
7
8/* x86: the PC's interrupt controllers, timers and firmware tables
9 * (platform/misc/). */
10
11/* irq.c: IRQ n is vector 32 + n; the local APIC's timer is an IRQ apart */
12#define X86_IRQ_NR 49
13#define X86_IRQ_TIMER 48
14#define X86_TIMER_VECTOR 0xF0
15#define X86_TLB_VECTOR 0xF1 /* an IPI: flush the TLB (mm/tlb.c) */
16#define X86_WAKE_VECTOR 0xF2 /* an IPI: enter the kernel (arch_cpu_kick) */
17#define X86_SPURIOUS_VECTOR 0xFF
18
21 const char *name;
22 void (*mask)(unsigned irq);
23 void (*unmask)(unsigned irq);
24 void (*eoi)(unsigned irq);
25 const char *(*describe)(unsigned irq); /* for /proc/interrupts */
26 const char *timer; /* the tick's timer, if it has its own */
27};
28
30const char *x86_irq_chip_name(void);
31void x86_irq_gates_setup(void);
32void x86_irq_tick_switch(void);
33void x86_irq_alloc_from(unsigned first);
35
36/* pic.c: the 8259s */
37int x86_pic_setup(struct ioaddr *master, struct ioaddr *slave);
38void x86_pic_disable(void);
39extern struct x86_irq_chip x86_pic_chip;
40
41/* apic.c: the local and I/O APICs; x86_apic_setup() returns 0 if the
42 * APIC brings the interrupts */
43int x86_apic_setup(void) __attribute__((weak));
44uint32_t x86_lapic_timer_setup(uint32_t period_ns, irq_handler_t handler) __attribute__((weak));
45void x86_lapic_cpu_setup(void);
46int x86_apic_cpus(uint32_t *ids, int max);
47void x86_lapic_ipi(uint32_t id, uint32_t icr);
48void x86_lapic_eoi(void);
50
51/* cpu/smp.c: starts the other CPUs (with the APIC) */
52void x86_smp_init(void);
53
54/* sys/clock.c: whether the clock counts finer than the ticks (the TSC or
55 * the HPET) */
56int x86_clock_precise(void);
57
58/* acpi.c (if it's built) */
59void x86_acpi_poweroff(void) __attribute__((weak));
60void *x86_acpi_table(const char *signature) __attribute__((weak));
61
62/* hpet.c (if it's built) */
63int x86_hpet_init(void) __attribute__((weak));
64uint64_t x86_hpet_read(void) __attribute__((weak));
65uint32_t x86_hpet_read32(void) __attribute__((weak));
66uint64_t x86_hpet_period_fs(void) __attribute__((weak));
67
68/* pit.c: the 8254 timer */
69int x86_pit_setup(struct ioaddr *io);
71void x86_pit_delay(uint32_t us);
72
73/* cmos.c: the real time clock */
74int x86_cmos_setup(struct ioaddr *ioaddr);
75
76#endif /* ! _PLATFORM_MISC_H */
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 struct x86_irq_chip * chip
Definition irq.c:51
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
void x86_pic_disable(void)
Masks every IRQ of the 8259s, when the APIC brings the interrupts.
Definition pic.c:152
int x86_clock_precise(void)
Says whether the clock counts finer than the ticks.
Definition clock.c:193
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
void x86_irq_tick_switch(void)
Asks for a thread switch once the current interrupt is done: the tick calls it.
Definition irq.c:169
struct x86_irq_chip x86_pic_chip
Definition pic.c:126
int x86_irq_alloc(struct x86_irq_chip *chip)
Gives a free IRQ with a controller of its own, for an MSI.
Definition irq.c:99
uint32_t x86_pit_period_set(uint32_t period_ns)
Makes channel 0 interrupt periodically, for the scheduler's tick.
Definition pit.c:82
int x86_hpet_init(void)
Finds the HPET and starts its counter.
Definition hpet.c:90
void x86_lapic_eoi(void)
Tells the running CPU's local APIC that its interrupt (an IPI) is handled.
Definition apic.c:216
uint64_t x86_hpet_read(void)
Reads the HPET's 64-bit counter.
Definition hpet.c:51
void * x86_acpi_table(const char *signature)
Finds one of ACPI's tables, by its signature.
Definition acpi.c:183
void x86_irq_chip_set(struct x86_irq_chip *chip)
Sets the system's interrupt controller.
Definition irq.c:67
uint32_t x86_hpet_read32(void)
Reads the low half of the HPET's counter only: a single read, which matters because each read is slow...
Definition hpet.c:69
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
uint64_t x86_hpet_period_fs(void)
Returns the HPET counter's period.
Definition hpet.c:79
void x86_pit_delay(uint32_t us)
Waits us microseconds, at most 54 ms, busy.
Definition pit.c:123
int x86_apic_cpus(uint32_t *ids, int max)
Lists the CPUs' local APIC IDs, the boot CPU's among them.
Definition apic.c:322
void x86_lapic_ipi(uint32_t id, uint32_t icr)
Sends an IPI to a CPU, and waits until it is delivered.
Definition apic.c:342
void x86_irq_alloc_from(unsigned first)
Sets the first IRQ that x86_irq_alloc() may give: past the I/O APICs' last pin.
Definition irq.c:88
void x86_acpi_poweroff(void)
Powers the machine off, by entering ACPI's S5 sleep state.
Definition acpi.c:265
int x86_cmos_setup(struct ioaddr *ioaddr)
Sets where the CMOS's ports are.
Definition cmos.c:139
void x86_lapic_timer_cpu_start(void)
Starts the running CPU's local APIC timer, with the boot CPU's calibration, once it has been done.
Definition apic.c:529
void x86_lapic_cpu_setup(void)
Sets up the running CPU's local APIC: enabled, with the spurious vector 0xFF, its timer off,...
Definition apic.c:303
unsigned int uint32_t
Definition stddef.h:22
unsigned long long int uint64_t
Definition stddef.h:23
An installed handler, on its interrupt's list.
Definition irq.c:19
Where a device's registers are.
Definition io.h:95
An interrupt controller: the 8259s, or the APIC.
Definition misc.h:20
void(*) unmask(unsigned irq)
Definition misc.h:23
const char * timer
Definition misc.h:26
const char * name
Definition misc.h:21
void(*) eoi(unsigned irq)
Definition misc.h:24
void(*) mask(unsigned irq)
Definition misc.h:22