diff --git a/arch/arm64/core/xen/CMakeLists.txt b/arch/arm64/core/xen/CMakeLists.txt index b0b573b7b9b2..e056ab29725b 100644 --- a/arch/arm64/core/xen/CMakeLists.txt +++ b/arch/arm64/core/xen/CMakeLists.txt @@ -8,4 +8,4 @@ zephyr_compile_options($<$:-D__ASSEMBLY__>) zephyr_compile_options(-D__XEN_INTERFACE_VERSION__=0x00040e00) zephyr_library_sources(hypercall.S) -zephyr_library_sources(enlighten.c) +zephyr_library_sources_ifdef(CONFIG_XEN_EVENTS enlighten.c) diff --git a/boards/arm64/rpi_5/Kconfig.board b/boards/arm64/rpi_5/Kconfig.board new file mode 100644 index 000000000000..2a60534b4c8d --- /dev/null +++ b/boards/arm64/rpi_5/Kconfig.board @@ -0,0 +1,6 @@ +# Copyright 2024 Junho Lee +# SPDX-License-Identifier: Apache-2.0 + +config BOARD_RPI_5 + bool "Broadcom BCM2712" + depends on SOC_BCM2712 diff --git a/boards/arm64/rpi_5/Kconfig.defconfig b/boards/arm64/rpi_5/Kconfig.defconfig new file mode 100644 index 000000000000..a555a718911a --- /dev/null +++ b/boards/arm64/rpi_5/Kconfig.defconfig @@ -0,0 +1,6 @@ +# Copyright 2023 honglin leng +# SPDX-License-Identifier: Apache-2.0 + +config BOARD + default "Raspberry Pi 5" + depends on BOARD_RPI_5 diff --git a/boards/arm64/rpi_5/board.cmake b/boards/arm64/rpi_5/board.cmake new file mode 100644 index 000000000000..9881313609aa --- /dev/null +++ b/boards/arm64/rpi_5/board.cmake @@ -0,0 +1 @@ +# SPDX-License-Identifier: Apache-2.0 diff --git a/boards/arm64/rpi_5/board.yml b/boards/arm64/rpi_5/board.yml new file mode 100644 index 000000000000..d604b7f4e513 --- /dev/null +++ b/boards/arm64/rpi_5/board.yml @@ -0,0 +1,5 @@ +board: + name: rpi_5 + vendor: raspberrypi + socs: + - name: bcm2712 diff --git a/boards/arm64/rpi_5/doc/index.rst b/boards/arm64/rpi_5/doc/index.rst new file mode 100644 index 000000000000..99bf51879d6f --- /dev/null +++ b/boards/arm64/rpi_5/doc/index.rst @@ -0,0 +1,193 @@ +.. rpi_5: + +Raspberry Pi 5 (Cortex-A76) +########################### + +Overview +******** + +`Raspberry Pi 5 product-brief`_ + +Hardware +******** + +- Broadcom BCM2712 2.4GHz quad-core 64-bit Arm Cortex-A76 CPU, with cryptography extensions, 512KB per-core L2 caches and a 2MB shared L3 cache +- VideoCore VII GPU, supporting OpenGL ES 3.1, Vulkan 1.2 +- Dual 4Kp60 HDMI® display output with HDR support +- 4Kp60 HEVC decoder +- LPDDR4X-4267 SDRAM (4GB and 8GB SKUs available at launch) +- Dual-band 802.11ac Wi-Fi® +- Bluetooth 5.0 / Bluetooth Low Energy (BLE) +- microSD card slot, with support for high-speed SDR104 mode +- 2 x USB 3.0 ports, supporting simultaneous 5Gbps operation +- 2 x USB 2.0 ports +- Gigabit Ethernet, with PoE+ support (requires separate PoE+ HAT) +- 2 x 4-lane MIPI camera/display transceivers +- PCIe 2.0 x1 interface for fast peripherals (requires separate M.2 HAT or other adapter) +- 5V/5A DC power via USB-C, with Power Delivery support +- Raspberry Pi standard 40-pin header +- Real-time clock (RTC), powered from external battery +- Power button + +Supported Features +================== + +The Raspberry Pi 5 board configuration supports the following hardware features: + +.. list-table:: + :header-rows: 1 + + * - Peripheral + - Kconfig option + - Devicetree compatible + * - GIC-400 + - N/A + - :dtcompatible:`arm,gic-v2` + * - GPIO + - :kconfig:option:`CONFIG_GPIO` + - :dtcompatible:`brcm,brcmstb-gpio` + * - UART + - :kconfig:option:`CONFIG_SERIAL` + - :dtcompatible:`arm,pl011` + +Not all hardware features are supported yet. See `Raspberry Pi hardware`_ for the complete list of hardware features. + +The default configuration can be found in +:zephyr_file:`boards/raspberrypi/rpi_5/rpi_5_defconfig`. + +Programming and Debugging +************************* + +Blinky +====== + +In brief, + 1. Format your Micro SD card with MBR and FAT32. + 2. Save three files below in the root directory. + * config.txt + * zephyr.bin + * `bcm2712-rpi-5.dtb`_ + 3. Insert the Micro SD card and power on the Raspberry Pi 5. + +then, You will see the Raspberry Pi 5 running the `zephyr.bin`. + +config.txt +---------- + +.. code-block:: text + + kernel=zephyr.bin + arm_64bit=1 + + +zephyr.bin +---------- + +Build an app `samples/basic/blinky` + +.. zephyr-app-commands:: + :zephyr-app: samples/basic/blinky + :board: rpi_5 + :goals: build + +Copy `zephyr.bin` from `build/zephyr` directory to the root directory of the Micro SD card. + +Insert the Micro SD card and power on the Raspberry Pi 5. And then, the STAT LED will start to blink. + + +Serial Communication +==================== + +wiring +------ + +You will need the following items: + * `Raspberry Pi Debug Probe`_ + * JST cable: 3-pin JST connector to 3-pin JST connector cable + * USB cable: USB A male - Micro USB B male + +Use the JST cable to connect the Raspberry Pi Debug Probe UART port to the Raspberry Pi 5 UART port between the HDMI ports. + +Then connect the Raspberry Pi Debug Probe to your computer with a USB cable. + + +config.txt +---------- + +.. code-block:: text + + kernel=zephyr.bin + arm_64bit=1 + enable_uart=1 + uart_2ndstage=1 + + +zephyr.bin +---------- + +Build an app `samples/hello_world` + +.. zephyr-app-commands:: + :zephyr-app: samples/hello_world + :board: rpi_5 + :goals: build + +Copy `zephyr.bin` from `build/zephyr` directory to the root directory of the Micro SD card. + +Insert the Micro SD card into your Raspberry Pi 5. + + +serial terminal emulator +------------------------ + +When you power on the Raspberry Pi 5, you will see the following output in the serial console: + +.. code-block:: text + + *** Booting Zephyr OS build XXXXXXXXXXXX *** + Hello World! rpi_5/bcm2712 + + +.. _Raspberry Pi 5 product-brief: + https://datasheets.raspberrypi.com/rpi5/raspberry-pi-5-product-brief.pdf + +.. _Raspberry Pi hardware: + https://www.raspberrypi.com/documentation/computers/raspberry-pi.html + +.. _bcm2712-rpi-5.dtb: + https://github.com/raspberrypi/firmware/raw/master/boot/bcm2712-rpi-5-b.dtb + +.. _Raspberry Pi Debug Probe: + https://www.raspberrypi.com/products/debug-probe/ + +XEN Dom0 +======== + +The Raspberry Pi 5 platform can be used to run as Xen Zephyr Dom0. For such purposes the `xen_dom0` +snippet can be used. + +Run below command as an example of RPI 5 Zephyr build as Dom0: + +.. code-block:: bash + + west build -b rpi_5 -p always -S xen_dom0 samples/hello_world + +It is expected to be used with special application performing Xen Domain-0/Dom0 functions. + +.. note:: + + The "hypervisor@x" and "memory@x" DT nodes may need to be updated depending on the Xen boot, + because normaly Xan will update DT for the target Kernel, but this is not possible in case + of Zephyr. See comments in `rpi_5_xen_dom0.dts`. + +XEN DomD with HW passthrough +============================ + +The Raspberry Pi 5 platform can be used to run as Xen Zephyr DomD with RPI 5 HW support. +For such purposes the `rpi_5_xen_domd` snippet can be used. + +Run the command below as an example of RPI 5 Zephyr build as DomD: + +.. code-block:: bash + + west build -b xenvm -S rpi_5_xen_domd samples/basic/blinky diff --git a/boards/arm64/rpi_5/rpi_5.dts b/boards/arm64/rpi_5/rpi_5.dts new file mode 100644 index 000000000000..6fca0efd3d0c --- /dev/null +++ b/boards/arm64/rpi_5/rpi_5.dts @@ -0,0 +1,45 @@ +/* + * Copyright 2024 Junho Lee + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; + +#include +#include + +/ { + compatible = "raspberrypi,5-model-b", "brcm,bcm2712"; + model = "Raspberry Pi 5"; + #address-cells = <2>; + #size-cells = <1>; + + aliases { + led0 = &led_act; + }; + + chosen { + zephyr,sram = &sram0; + zephyr,console = &uart10; + zephyr,shell-uart = &uart10; + }; + + leds { + compatible = "gpio-leds"; + + led_act: led-act { + gpios = <&gio_aon 9 GPIO_ACTIVE_LOW>; + label = "ACT"; + }; + }; +}; + +&gio_aon { + status = "okay"; +}; + +&uart10 { + status = "okay"; + current-speed = <115200>; +}; diff --git a/boards/arm64/rpi_5/rpi_5.yaml b/boards/arm64/rpi_5/rpi_5.yaml new file mode 100644 index 000000000000..e293d78e9cd1 --- /dev/null +++ b/boards/arm64/rpi_5/rpi_5.yaml @@ -0,0 +1,7 @@ +identifier: rpi_5 +name: Raspberry Pi 5 +type: mcu +arch: arm64 +toolchain: + - zephyr + - cross-compile diff --git a/boards/arm64/rpi_5/rpi_5_defconfig b/boards/arm64/rpi_5/rpi_5_defconfig new file mode 100644 index 000000000000..d3b777c339e5 --- /dev/null +++ b/boards/arm64/rpi_5/rpi_5_defconfig @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SOC_BCM2712=y +CONFIG_BOARD_RPI_5=y +CONFIG_ARM64_VA_BITS_40=y +CONFIG_ARM64_PA_BITS_40=y +CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME=y + +# Enable serial console. +CONFIG_SERIAL=y +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y diff --git a/boards/arm64/xenvm/xenvm.dts b/boards/arm64/xenvm/xenvm.dts index bbba268d9a35..9857f7885064 100644 --- a/boards/arm64/xenvm/xenvm.dts +++ b/boards/arm64/xenvm/xenvm.dts @@ -69,7 +69,7 @@ hypervisor: hypervisor@38000000 { compatible = "xen,xen"; - reg = <0x00 0x38000000 0x00 0x1000000>; + reg = <0x00 0x38000000 0x00 0x10000>; interrupts = ; interrupt-parent = <&gic>; }; diff --git a/boards/arm64/xenvm/xenvm_defconfig b/boards/arm64/xenvm/xenvm_defconfig index 39e8a20767cb..52f16c0df2cb 100644 --- a/boards/arm64/xenvm/xenvm_defconfig +++ b/boards/arm64/xenvm/xenvm_defconfig @@ -18,3 +18,4 @@ CONFIG_LOG_MODE_MINIMAL=n CONFIG_USERSPACE=n CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME=y +CONFIG_XEN_REGIONS=n diff --git a/drivers/gpio/CMakeLists.txt b/drivers/gpio/CMakeLists.txt index 3e4ae12dc4ad..d4fd0730e64f 100644 --- a/drivers/gpio/CMakeLists.txt +++ b/drivers/gpio/CMakeLists.txt @@ -91,6 +91,7 @@ zephyr_library_sources_ifdef(CONFIG_GPIO_BCM2711 gpio_bcm2711.c) zephyr_library_sources_ifdef(CONFIG_GPIO_RENESAS_RA gpio_renesas_ra.c) zephyr_library_sources_ifdef(CONFIG_GPIO_RZT2M gpio_rzt2m.c) zephyr_library_sources_ifdef(CONFIG_GPIO_AMBIQ gpio_ambiq.c) +zephyr_library_sources_ifdef(CONFIG_GPIO_BRCMSTB gpio_brcmstb.c) if (CONFIG_GPIO_EMUL_SDL) zephyr_library_sources(gpio_emul_sdl.c) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index ff9d02704d84..dfe46a315816 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -240,4 +240,6 @@ source "drivers/gpio/Kconfig.rzt2m" source "drivers/gpio/Kconfig.ambiq" +source "drivers/gpio/Kconfig.brcmstb" + endif # GPIO diff --git a/drivers/gpio/Kconfig.brcmstb b/drivers/gpio/Kconfig.brcmstb new file mode 100644 index 000000000000..0974f05239e6 --- /dev/null +++ b/drivers/gpio/Kconfig.brcmstb @@ -0,0 +1,9 @@ +# Copyright (c) 2024 Junho Lee +# SPDX-License-Identifier: Apache-2.0 + +config GPIO_BRCMSTB + bool "Broadcom Set-top box SoC GPIO Driver" + default y + depends on DT_HAS_BRCM_BRCMSTB_GPIO_ENABLED + help + Enable Driver for Broadcom Set-top box SoC GPIO Banks. diff --git a/drivers/gpio/gpio_brcmstb.c b/drivers/gpio/gpio_brcmstb.c new file mode 100644 index 000000000000..cfec6868f290 --- /dev/null +++ b/drivers/gpio/gpio_brcmstb.c @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2024 Junho Lee + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT brcm_brcmstb_gpio + +#include +#include +#include +#include +#include + +#define GIO_DATA 0x04 +#define GIO_IODIR 0x08 + +#define DEV_CFG(dev) ((const struct gpio_brcmstb_config *)(dev)->config) +#define DEV_DATA(dev) ((struct gpio_brcmstb_data *)(dev)->data) + +struct gpio_brcmstb_config { + struct gpio_driver_config common; + + DEVICE_MMIO_NAMED_ROM(reg_base); + mem_addr_t offset; +}; + +struct gpio_brcmstb_data { + struct gpio_driver_data common; + + DEVICE_MMIO_NAMED_RAM(reg_base); + mem_addr_t base; +}; + +static int gpio_brcmstb_pin_configure(const struct device *port, gpio_pin_t pin, gpio_flags_t flags) +{ + struct gpio_brcmstb_data *data = port->data; + + if (flags & (GPIO_SINGLE_ENDED | GPIO_PULL_UP | GPIO_PULL_DOWN)) { + return -ENOTSUP; + } + + if (flags & GPIO_INPUT) { + sys_set_bit(data->base + GIO_IODIR, pin); + } else if (flags & GPIO_OUTPUT) { + sys_clear_bit(data->base + GIO_IODIR, pin); + + if (flags & GPIO_OUTPUT_INIT_HIGH) { + sys_set_bit(data->base + GIO_DATA, pin); + } else if (flags & GPIO_OUTPUT_INIT_LOW) { + sys_clear_bit(data->base + GIO_DATA, pin); + } + } + + return 0; +} + +static int gpio_brcmstb_port_get_raw(const struct device *port, gpio_port_value_t *value) +{ + struct gpio_brcmstb_data *data = port->data; + + *value = sys_read32(data->base + GIO_DATA); + + return 0; +} + +static int gpio_brcmstb_port_set_masked_raw(const struct device *port, gpio_port_pins_t mask, + gpio_port_value_t value) +{ + struct gpio_brcmstb_data *data = port->data; + + sys_clear_bits(data->base + GIO_DATA, mask); + sys_set_bits(data->base + GIO_DATA, (value & mask)); + + return 0; +} + +static int gpio_brcmstb_port_set_bits_raw(const struct device *port, gpio_port_pins_t pins) +{ + struct gpio_brcmstb_data *data = port->data; + + sys_set_bits(data->base + GIO_DATA, pins); + + return 0; +} + +static int gpio_brcmstb_port_clear_bits_raw(const struct device *port, gpio_port_pins_t pins) +{ + struct gpio_brcmstb_data *data = port->data; + + sys_clear_bits(data->base + GIO_DATA, pins); + + return 0; +} + +static int gpio_brcmstb_port_toggle_bits(const struct device *port, gpio_port_pins_t pins) +{ + struct gpio_brcmstb_data *data = port->data; + uint32_t reg_data; + + reg_data = sys_read32(data->base + GIO_DATA); + reg_data ^= pins; + sys_write32(reg_data, data->base + GIO_DATA); + + return 0; +} + +static const struct gpio_driver_api gpio_brcmstb_api = { + .pin_configure = gpio_brcmstb_pin_configure, + .port_get_raw = gpio_brcmstb_port_get_raw, + .port_set_masked_raw = gpio_brcmstb_port_set_masked_raw, + .port_set_bits_raw = gpio_brcmstb_port_set_bits_raw, + .port_clear_bits_raw = gpio_brcmstb_port_clear_bits_raw, + .port_toggle_bits = gpio_brcmstb_port_toggle_bits, +}; + +int gpio_brcmstb_init(const struct device *port) +{ + const struct gpio_brcmstb_config *config = port->config; + struct gpio_brcmstb_data *data = port->data; + + DEVICE_MMIO_NAMED_MAP(port, reg_base, K_MEM_CACHE_NONE); + data->base = DEVICE_MMIO_NAMED_GET(port, reg_base) + config->offset; + + return 0; +} + +#define GPIO_BRCMSTB_INIT(n) \ + static struct gpio_brcmstb_data gpio_brcmstb_data_##n; \ + \ + static const struct gpio_brcmstb_config gpio_brcmstb_cfg_##n = { \ + .common = {.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(0)}, \ + DEVICE_MMIO_NAMED_ROM_INIT(reg_base, DT_INST_PARENT(n)), \ + .offset = DT_INST_REG_ADDR(n), \ + }; \ + \ + DEVICE_DT_INST_DEFINE(n, gpio_brcmstb_init, NULL, &gpio_brcmstb_data_##n, \ + &gpio_brcmstb_cfg_##n, PRE_KERNEL_1, CONFIG_GPIO_INIT_PRIORITY, \ + &gpio_brcmstb_api); + +DT_INST_FOREACH_STATUS_OKAY(GPIO_BRCMSTB_INIT) diff --git a/drivers/serial/Kconfig.xen b/drivers/serial/Kconfig.xen index 02492e7483fc..7a8f30590adc 100644 --- a/drivers/serial/Kconfig.xen +++ b/drivers/serial/Kconfig.xen @@ -11,6 +11,7 @@ config UART_XEN_HVC select SERIAL_HAS_DRIVER select SERIAL_SUPPORT_INTERRUPT depends on XEN && !XEN_DOM0 && !XEN_DOM0LESS + select XEN_EVENTS if UART_INTERRUPT_DRIVEN help Enable Xen ring buffer based hypervisor console driver. Used for Zephyr as unprivileged domain. diff --git a/drivers/xen/CMakeLists.txt b/drivers/xen/CMakeLists.txt index 76b02dfaa623..2c87f3766ec3 100644 --- a/drivers/xen/CMakeLists.txt +++ b/drivers/xen/CMakeLists.txt @@ -2,7 +2,7 @@ # Copyright (c) 2021-2023 EPAM Systems zephyr_sources(hvm.c) -zephyr_sources(events.c) +zephyr_sources_ifdef(CONFIG_XEN_EVENTS events.c) zephyr_sources_ifdef(CONFIG_XEN_GRANT_TABLE gnttab.c) zephyr_sources(memory.c) zephyr_include_directories_ifdef(CONFIG_XEN_REGIONS ${ZEPHYR_BASE}/kernel/include) diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig index 39baec1a8e1f..952029185585 100644 --- a/drivers/xen/Kconfig +++ b/drivers/xen/Kconfig @@ -29,6 +29,12 @@ config XEN_GRANT_TABLE_INIT_PRIORITY depends on XEN_GRANT_TABLE default 50 +config XEN_EVENTS + bool "Xen events driver" + default y + help + Xen event channels driver. + endmenu endif # XEN diff --git a/dts/arm64/broadcom/bcm2712.dtsi b/dts/arm64/broadcom/bcm2712.dtsi new file mode 100644 index 000000000000..a31e8b21d14b --- /dev/null +++ b/dts/arm64/broadcom/bcm2712.dtsi @@ -0,0 +1,89 @@ +/* + * Copyright 2024 Myeonghyeon Park + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/ { + cpus { + #address-cells = <1>; + #size-cells = <0>; + + cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a76"; + reg = <0>; + }; + }; + + interrupt-parent = <&gic>; + + timer { + compatible = "arm,armv8-timer"; + interrupts = , + , + , + ; + }; + + soc { + #address-cells = <2>; + #size-cells = <1>; + + sram0: memory@200000 { + device_type = "memory"; + compatible = "mmio-sram"; + reg = <0x0 0x200000 0x80000>; + }; + + gic: interrupt-controller@107fff9000 { + compatible = "arm,gic-v2", "arm,gic"; + reg = <0x10 0x7fff9000 0x1000>, + <0x10 0x7fffa000 0x2000>; + interrupt-controller; + #interrupt-cells = <4>; + status = "okay"; + }; + + gpio2@107d517c00 { + compatible = "simple-bus"; + reg = <0x10 0x7d517c00 0x40>; + + #address-cells = <1>; + #size-cells = <0>; + gio_aon: gpio@0 { + compatible = "brcm,brcmstb-gpio"; + reg = <0>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <17>; + status = "disabled"; + }; + }; + + uart10: serial@107d001000 { + compatible = "arm,pl011"; + reg = <0x10 0x7d001000 0x200>; + interrupts = ; + clocks = <&clk_uart>; + status = "disabled"; + }; + + }; + + clocks { + clk_uart: clk_uart { + compatible = "fixed-clock"; + clock-frequency = <44236800>; + #clock-cells = <0>; + }; + }; +}; diff --git a/dts/bindings/gpio/brcm,brcmstb-gpio.yaml b/dts/bindings/gpio/brcm,brcmstb-gpio.yaml new file mode 100644 index 000000000000..55f58a9f3fdd --- /dev/null +++ b/dts/bindings/gpio/brcm,brcmstb-gpio.yaml @@ -0,0 +1,19 @@ +# Copyright (c) 2024 Junho Lee +# SPDX-License-Identifier: Apache-2.0 + +description: BRCMSTB GPIO + +compatible: "brcm,brcmstb-gpio" + +include: [gpio-controller.yaml, base.yaml] + +properties: + reg: + required: true + + "#gpio-cells": + const: 2 + +gpio-cells: + - pin + - flags diff --git a/include/zephyr/xen/public/domctl.h b/include/zephyr/xen/public/domctl.h index dbb9f04dc2e7..cb0a3adbf6e9 100644 --- a/include/zephyr/xen/public/domctl.h +++ b/include/zephyr/xen/public/domctl.h @@ -20,7 +20,7 @@ #include "grant_table.h" #include "memory.h" -#define XEN_DOMCTL_INTERFACE_VERSION 0x00000015 +#define XEN_DOMCTL_INTERFACE_VERSION 0x00000016 /* * NB. xen_domctl.domain is an IN/OUT parameter for this operation. diff --git a/snippets/rpi_5_xen_domd/README.rst b/snippets/rpi_5_xen_domd/README.rst new file mode 100644 index 000000000000..37a7c271e909 --- /dev/null +++ b/snippets/rpi_5_xen_domd/README.rst @@ -0,0 +1,17 @@ +.. _rpi_5_xen_domd: + +RPI 5 Xen DomD: snippet for XEN HW domain +######################################### + +Overview +******** + +This snippet allows user to build Zephyr `xenvm` with RPI 5 hardware support as +a Xen hardware domain (DomD) to demonstrate how RPI 5 hardware can be passed to Xen domain. +Only GPIO LED is supported for now. + +For example: + +.. code-block:: console + + west build -b xenvm -S rpi_5_xen_domd samples/basic/blinky diff --git a/snippets/rpi_5_xen_domd/rpi_5_xen_domd.conf b/snippets/rpi_5_xen_domd/rpi_5_xen_domd.conf new file mode 100644 index 000000000000..cd989de2f625 --- /dev/null +++ b/snippets/rpi_5_xen_domd/rpi_5_xen_domd.conf @@ -0,0 +1,3 @@ +CONFIG_ARM64_VA_BITS_40=y +CONFIG_ARM64_PA_BITS_40=y +CONFIG_UART_INTERRUPT_DRIVEN=n diff --git a/snippets/rpi_5_xen_domd/rpi_5_xen_domd.overlay b/snippets/rpi_5_xen_domd/rpi_5_xen_domd.overlay new file mode 100644 index 000000000000..0074cdae2464 --- /dev/null +++ b/snippets/rpi_5_xen_domd/rpi_5_xen_domd.overlay @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2024 EPAM Systems. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/ { + compatible = "raspberrypi,5-model-b-domd", "raspberrypi,5-model-b", "brcm,bcm2712"; + model = "Raspberry Pi 5 Xen DomD"; + + chosen { + zephyr,shell-uart = &xen_hvc; + }; + + aliases { + led0 = &led_act; + }; + + leds { + compatible = "gpio-leds"; + + led_act: led-act { + gpios = <&gio_aon 9 GPIO_ACTIVE_LOW>; + label = "ACT"; + }; + }; + + gpio2@107d517c00 { + compatible = "simple-bus"; + reg = <0x10 0x7d517c00 0x0 0x40>; + + #address-cells = <1>; + #size-cells = <0>; + gio_aon: gpio@0 { + compatible = "brcm,brcmstb-gpio"; + reg = <0>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <17>; + }; + }; +}; diff --git a/snippets/rpi_5_xen_domd/snippet.yml b/snippets/rpi_5_xen_domd/snippet.yml new file mode 100644 index 000000000000..ef650dc0c232 --- /dev/null +++ b/snippets/rpi_5_xen_domd/snippet.yml @@ -0,0 +1,4 @@ +name: rpi_5_xen_domd +append: + EXTRA_DTC_OVERLAY_FILE: rpi_5_xen_domd.overlay + EXTRA_CONF_FILE: rpi_5_xen_domd.conf diff --git a/snippets/xen_dom0/boards/rpi_5.overlay b/snippets/xen_dom0/boards/rpi_5.overlay new file mode 100644 index 000000000000..cbe9d3812733 --- /dev/null +++ b/snippets/xen_dom0/boards/rpi_5.overlay @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2024 EPAM Systems. + * + * SPDX-License-Identifier: Apache-2.0 + */ + + /delete-node/ &sram0; + +#include + +/ { + #address-cells = <2>; + #size-cells = <1>; + /* + * This node may differs on different setups, please check + * following line in Xen boot log to set it right: + * (XEN) Grant table range: 0x00000002800000-0x00000002840000 + * Also, add extended region 1: + * (XEN) d0: extended region 1: 0x40000000->0x5fe00000 + * + * Xen passes actual values for setup in domain device tree, but Zephyr + * is not capable to parse and handle it in runtime. + */ + hypervisor: hypervisor@2800000 { + compatible = "xen,xen"; + reg = <0x00 0x2800000 0x40000>, <0x00 0x2a00000 0x5400000>; + interrupts = ; + interrupt-parent = <&gic>; + status = "okay"; + }; + + /* + * This node may differs on different setups, because Xen picks + * region for Domain-0 for every specific configuration. You can + * start Xen for your platform and check following log: + * (XEN) Allocating 1:1 mappings totalling 512MB for dom0: + * (XEN) BANK[0] 0x00000060000000-0x00000080000000 (512MB) + * (XEN) Loading zImage from 0000000000080000 to 0000000060000000-0000000060038004 + * + * Xen passes actual values for setup in domain device tree, but Zephyr + * is not capable to parse and handle it in runtime. + */ + sram0: memory@8000000 { + compatible = "mmio-sram"; + reg = <0x00 0x8000000 DT_SIZE_M(128)>; + }; +}; + +&uart10 { + status = "disabled"; +}; diff --git a/snippets/xen_dom0/snippet.yml b/snippets/xen_dom0/snippet.yml index ff47714267c0..9bbf3839ed06 100644 --- a/snippets/xen_dom0/snippet.yml +++ b/snippets/xen_dom0/snippet.yml @@ -16,3 +16,6 @@ boards: rcar_spider_ca55: append: EXTRA_DTC_OVERLAY_FILE: boards/rcar_spider_ca55.overlay + rpi_5: + append: + EXTRA_DTC_OVERLAY_FILE: boards/rpi_5.overlay diff --git a/soc/arm64/bcm2712/CMakeLists.txt b/soc/arm64/bcm2712/CMakeLists.txt new file mode 100644 index 000000000000..733abbebd911 --- /dev/null +++ b/soc/arm64/bcm2712/CMakeLists.txt @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: Apache-2.0 +zephyr_sources_ifdef(CONFIG_ARM_MMU mmu_regions.c) + +set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm64/scripts/linker.ld CACHE INTERNAL "") diff --git a/soc/arm64/bcm2712/Kconfig.defconfig b/soc/arm64/bcm2712/Kconfig.defconfig new file mode 100644 index 000000000000..0f57c8dffe82 --- /dev/null +++ b/soc/arm64/bcm2712/Kconfig.defconfig @@ -0,0 +1,17 @@ +# Copyright 2024 Junho Lee +# SPDX-License-Identifier: Apache-2.0 + +if SOC_BCM2712 + +config SOC + default "bcm2712" + +config NUM_IRQS + int + default 280 + +config SYS_CLOCK_HW_CYCLES_PER_SEC + int + default 54000000 + +endif diff --git a/soc/arm64/bcm2712/Kconfig.soc b/soc/arm64/bcm2712/Kconfig.soc new file mode 100644 index 000000000000..e1d05aaa92bc --- /dev/null +++ b/soc/arm64/bcm2712/Kconfig.soc @@ -0,0 +1,8 @@ +# Copyright 2024 Junho Lee +# SPDX-License-Identifier: Apache-2.0 + +config SOC_BCM2712 + bool "bcm2712" + select ARM64 + select CPU_CORTEX_A76 + select ARM_ARCH_TIMER if SYS_CLOCK_EXISTS diff --git a/soc/arm64/bcm2712/mmu_regions.c b/soc/arm64/bcm2712/mmu_regions.c new file mode 100644 index 000000000000..ea3314ffc2ed --- /dev/null +++ b/soc/arm64/bcm2712/mmu_regions.c @@ -0,0 +1,26 @@ +/* + * Copyright 2024 Junho Lee + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +static const struct arm_mmu_region mmu_regions[] = { + MMU_REGION_FLAT_ENTRY("GIC", + DT_REG_ADDR_BY_IDX(DT_INST(0, arm_gic), 0), + DT_REG_SIZE_BY_IDX(DT_INST(0, arm_gic), 0), + MT_DEVICE_nGnRnE | MT_P_RW_U_NA | MT_DEFAULT_SECURE_STATE), + + MMU_REGION_FLAT_ENTRY("GIC", + DT_REG_ADDR_BY_IDX(DT_INST(0, arm_gic), 1), + DT_REG_SIZE_BY_IDX(DT_INST(0, arm_gic), 1), + MT_DEVICE_nGnRnE | MT_P_RW_U_NA | MT_DEFAULT_SECURE_STATE), +}; + +const struct arm_mmu_config mmu_config = { + .num_regions = ARRAY_SIZE(mmu_regions), + .mmu_regions = mmu_regions, +}; diff --git a/soc/arm64/bcm2712/soc.yml b/soc/arm64/bcm2712/soc.yml new file mode 100644 index 000000000000..ce95e07ac683 --- /dev/null +++ b/soc/arm64/bcm2712/soc.yml @@ -0,0 +1,4 @@ +series: +- name: bcm2712 + socs: + - name: bcm2712