summaryrefslogtreecommitdiffhomepage
path: root/include/pci-tree.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/pci-tree.h')
-rw-r--r--include/pci-tree.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/include/pci-tree.h b/include/pci-tree.h
new file mode 100644
index 0000000..574cd1d
--- /dev/null
+++ b/include/pci-tree.h
@@ -0,0 +1,68 @@
+// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org)
+// Distributed under the Apache Software License, Version 2.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.apache.org/licenses/LICENSE-2.0)
+// Official repository: https://github.com/nekernel-org/neboot
+
+#pragma once
+
+/// @file pci-tree.h
+/// @brief PCI Tree layout.
+/// @author Amlal El Mahrouss
+
+#include <include/boot.h>
+
+#define PCI_INVALID_DATA_U8 ((uint8_t) ~0)
+#define PCI_INVALID_DATA_U16 ((uint16_t) ~0)
+#define PCI_INVALID_DATA_U32 ((uint32_t) ~0)
+
+#define NB_BASE_ADDRESS (0x20008000) /* PCI base mapped in virtual memory. */
+#define NB_PCI_TREE_BASE (0x802000) /* The PCI tree base address. */
+
+/* version 1.0 */
+#define NB_PCI_VERSION (0x0100)
+
+#define NB_PCI_DEV_MAGIC (0xfeedd00d)
+#define NB_PCI_INT_SZ sizeof(cb_pci_num_t)
+
+#define NB_PCI_NAME_LEN (255U)
+
+#define PCI_CONFIG_SPACE (4096U)
+
+#define PCI_BUS_MAX (256U)
+#define PCI_DEV_MAX (32U)
+#define PCI_FN_MAX (8U
+
+typedef char cb_pci_char_t;
+typedef uintptr_t cb_pci_num_t;
+
+typedef uint8_t cb_pci_fn_t;
+typedef uint8_t cb_pci_bus_t;
+typedef uint8_t cb_pci_device_t;
+
+/// @brief hardware tree header
+/// used by guest to resolve hardware peripherals.
+struct hw_nb_pci_tree {
+ cb_pci_num_t d_magic;
+ cb_pci_num_t d_version;
+ cb_pci_num_t d_off_props;
+ cb_pci_num_t d_off_struct;
+ cb_pci_num_t d_sz_props;
+ cb_pci_num_t d_sz_struct;
+
+ cb_pci_num_t d_first_node;
+ cb_pci_num_t d_next_sibling;
+
+ cb_pci_char_t d_name[NB_PCI_NAME_LEN];
+};
+
+/// @brief Init PCI tree.
+/// @param void
+/// @return if it's successful or not.
+boolean cb_pci_init_tree(void);
+
+/// @brief Adds a new tree into the internal data structure.
+/// @param name device name
+/// @param struct_ptr device structure
+/// @param struct_sz the structure size of the device.
+/// @return if it was successful or not.
+boolean cb_pci_append_tree(const caddr_t name, cb_pci_num_t struct_ptr, cb_pci_num_t struct_sz);