1/* 2 * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) 3 * 4 * SPDX-License-Identifier: GPL-2.0-only 5 */ 6 7#pragma once 8 9#include <types.h> 10 11typedef uintptr_t paddr_t; 12typedef uintptr_t vaddr_t; 13 14#define PAGE_BITS 12 15 16#define BIT(x) (1 << (x)) 17#define MASK(n) (BIT(n) - 1) 18#define MIN(a, b) (((a) < (b)) ? (a) : (b)) 19#define IS_ALIGNED(n, b) (!((n) & MASK(b))) 20#define ROUND_UP(n, b) (((((n) - 1) >> (b)) + 1) << (b)) 21#define ROUND_DOWN(n, b) (((n) >> (b)) << (b)) 22#define ALIGN(n) __attribute__((__aligned__(n))) 23#if __has_attribute(externally_visible) 24#define VISIBLE __attribute__((externally_visible)) 25#else 26#define VISIBLE 27#endif 28#define UNUSED __attribute__((unused)) 29#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) 30#define NULL ((void *)0) 31 32/* 33 * Information about an image we are loading. 34 */ 35struct image_info { 36 /* Start/end byte of the image in physical memory. */ 37 paddr_t phys_region_start; 38 paddr_t phys_region_end; 39 40 /* Start/end byte in virtual memory the image requires to be located. */ 41 vaddr_t virt_region_start; 42 vaddr_t virt_region_end; 43 44 /* Virtual address of the user image's entry point. */ 45 vaddr_t virt_entry; 46 47 /* 48 * Offset between the physical/virtual addresses of the image. 49 * 50 * In particular: 51 * 52 * virtual_address + phys_virt_offset = physical_address 53 */ 54 uintptr_t phys_virt_offset; 55}; 56 57extern struct image_info kernel_info; 58extern struct image_info user_info; 59extern void *dtb; 60 61/* Symbols defined in linker scripts. */ 62extern char _text[]; 63extern char _end[]; 64extern char _archive_start[]; 65extern char _archive_start_end[]; 66 67/* Clear BSS. */ 68void clear_bss(void); 69 70/* Load images. */ 71void load_images(struct image_info *kernel_info, struct image_info *user_info, 72 int max_user_images, int *num_images, void *bootloader_dtb, void **chosen_dtb, 73 uint32_t *chosen_dtb_size); 74 75/* Platform functions */ 76void platform_init(void); 77void init_cpus(void); 78int plat_console_putchar(unsigned int c); 79