Kernelite 0.1.0
Kernelite is a minimalist, educational operating system kernel built from scratch. The project aims to recreate core components of the Linux architecture to explore the fundamentals of operating system design and hardware-software interaction.
Loading...
Searching...
No Matches
fdt.h
Go to the documentation of this file.
1
12#ifndef FDT_FDT_H
13#define FDT_FDT_H
14
16#include "utils/kprintf.h"
17
18#include <stdbool.h>
19#include <stddef.h>
20#include <stdint.h>
21
23#define MAX_MEM_REGIONS 16
24
35
46
51typedef enum irq_type_t {
54
58
69
84
95static inline int32_t interrupt_to_intid(const interrupt_t *const interrupt)
96{
97 if (interrupt->type == IRQ_TYPE_PPI) {
98 return (int32_t)(16U + interrupt->id);
99 }
100 if (interrupt->type == IRQ_TYPE_SPI) {
101 return (int32_t)(32U + interrupt->id);
102 }
103
104 kprintf("FDT Error: unrecognized interrupt type %d\n", interrupt->type);
105 return -1;
106}
107
113bool check_fdt(const void *ptr);
114
126int get_mem(const void *fdt, memory_map_t *mmap);
127
134int get_intc_node_offset(const void *fdt);
135
141bool fdt_is_error(int offset);
142
150char *get_compatible_string(const void *fdt, int node_offset);
151
162bool get_reg_property(const void *fdt, int node_offset, memory_map_t *reg_map);
163
175int get_intr_property(const void *fdt, int node_offset,
176 interrupt_t *out_intr_array, size_t out_intr_array_len);
177
189int get_nodes_by_compatible(const void *fdt, const char *compatible,
190 int *out_node_offsets, size_t out_node_offsets_len);
191
192#endif // FDT_FDT_H
irq_trigger_t
Signal shape used to trigger an interrupt.
Definition fdt.h:62
@ IRQ_TRIGGER_EDGE
Interrupt is asserted on a signal edge.
Definition fdt.h:64
@ IRQ_TRIGGER_LEVEL_HIGH
Interrupt is asserted while the signal level is high.
Definition fdt.h:67
static int32_t interrupt_to_intid(const interrupt_t *const interrupt)
Converts a parsed FDT interrupt specifier to its GIC INTID.
Definition fdt.h:95
bool get_reg_property(const void *fdt, int node_offset, memory_map_t *reg_map)
Retrieves the register property for a given node.
Definition fdt.c:163
#define MAX_MEM_REGIONS
Maximum number of distinct memory regions the kernel will track.
Definition fdt.h:23
bool check_fdt(const void *ptr)
Check the validity of the Device Tree Blob (FDT).
Definition fdt.c:22
int get_mem(const void *fdt, memory_map_t *mmap)
Scans the FDT for memory nodes and populates the provided map.
Definition fdt.c:51
irq_type_t
Interrupt category, as encoded in the first cell of an FDT "interrupts" property.
Definition fdt.h:51
@ IRQ_TYPE_PPI
Private Peripheral Interrupt (local to a single core).
Definition fdt.h:56
@ IRQ_TYPE_SPI
Shared Peripheral Interrupt (routable to any core).
Definition fdt.h:53
bool fdt_is_error(int offset)
Checks if the given FDT offset represents an error.
Definition fdt.c:144
char * get_compatible_string(const void *fdt, int node_offset)
Retrieves the compatible string for a given node.
Definition fdt.c:149
int get_nodes_by_compatible(const void *fdt, const char *compatible, int *out_node_offsets, size_t out_node_offsets_len)
Finds all nodes in the FDT matching a given "compatible" string.
Definition fdt.c:297
int get_intr_property(const void *fdt, int node_offset, interrupt_t *out_intr_array, size_t out_intr_array_len)
Retrieves the interrupt property for a given node.
Definition fdt.c:207
int get_intc_node_offset(const void *fdt)
Retrieves a pointer to the interrupt controller node in the FDT.
Definition fdt.c:135
Utility functions for formatted output and serial console management.
int kprintf(const char *format,...)
Standard formatted print to the serial console.
Definition kprintf.c:181
Memory layout definitions.
uint64_t phy_addr
Type for representing physical addresses.
Definition mem_layout.h:17
Describes a single interrupt as parsed from an FDT "interrupts" specifier.
Definition fdt.h:74
irq_type_t type
Interrupt category (SPI or PPI).
Definition fdt.h:76
irq_trigger_t trigger
Trigger type for this interrupt.
Definition fdt.h:82
uint32_t id
Interrupt number within its category.
Definition fdt.h:79
Container for the system physical memory layout.
Definition fdt.h:39
memory_region_t regions[MAX_MEM_REGIONS]
Array of discovered regions.
Definition fdt.h:41
int count
Actual number of regions populated.
Definition fdt.h:44
Represents a single physical memory span.
Definition fdt.h:28
phy_addr base
Start physical address of the region.
Definition fdt.h:30
uint64_t size
Size of the region in bytes.
Definition fdt.h:33