1433d6423SLionel Sambuc 2433d6423SLionel Sambuc #ifndef _ARM_PROTO_H 3433d6423SLionel Sambuc #define _ARM_PROTO_H 4433d6423SLionel Sambuc 5433d6423SLionel Sambuc #include <machine/vm.h> 6433d6423SLionel Sambuc 7433d6423SLionel Sambuc #define K_STACK_SIZE ARM_PAGE_SIZE 8433d6423SLionel Sambuc 9433d6423SLionel Sambuc 10433d6423SLionel Sambuc #ifndef __ASSEMBLY__ 11433d6423SLionel Sambuc 12433d6423SLionel Sambuc #include "cpufunc.h" 13433d6423SLionel Sambuc 14433d6423SLionel Sambuc /* klib */ 15433d6423SLionel Sambuc __dead void reset(void); 16433d6423SLionel Sambuc phys_bytes vir2phys(void *); 17433d6423SLionel Sambuc vir_bytes phys_memset(phys_bytes ph, u32_t c, phys_bytes bytes); 18433d6423SLionel Sambuc 19433d6423SLionel Sambuc void __switch_address_space(struct proc *p, struct proc **__ptproc); 20433d6423SLionel Sambuc #define switch_address_space(proc) \ 21433d6423SLionel Sambuc __switch_address_space(proc, get_cpulocal_var_ptr(ptproc)) 22433d6423SLionel Sambuc 23433d6423SLionel Sambuc void __copy_msg_from_user_end(void); 24433d6423SLionel Sambuc void __copy_msg_to_user_end(void); 25433d6423SLionel Sambuc void __user_copy_msg_pointer_failure(void); 26433d6423SLionel Sambuc 27433d6423SLionel Sambuc /* multiboot.c */ 28433d6423SLionel Sambuc void multiboot_init(void); 29433d6423SLionel Sambuc 30433d6423SLionel Sambuc /* protect.c */ 31433d6423SLionel Sambuc struct tss_s { 32433d6423SLionel Sambuc reg_t sp0; /* stack pointer to use during interrupt */ 33433d6423SLionel Sambuc } __attribute__((packed)); 34433d6423SLionel Sambuc int tss_init(unsigned cpu, void * kernel_stack); 35433d6423SLionel Sambuc 36433d6423SLionel Sambuc void add_memmap(kinfo_t *cbi, u64_t addr, u64_t len); 37433d6423SLionel Sambuc phys_bytes alloc_lowest(kinfo_t *cbi, phys_bytes len); 38433d6423SLionel Sambuc void vm_enable_paging(void); 39433d6423SLionel Sambuc void cut_memmap(kinfo_t *cbi, phys_bytes start, phys_bytes end); 40433d6423SLionel Sambuc phys_bytes pg_roundup(phys_bytes b); 41433d6423SLionel Sambuc void pg_info(reg_t *, u32_t **); 42433d6423SLionel Sambuc void pg_clear(void); 43433d6423SLionel Sambuc void pg_identity(kinfo_t *); 44433d6423SLionel Sambuc phys_bytes pg_load(void); 45433d6423SLionel Sambuc void pg_map(phys_bytes phys, vir_bytes vaddr, vir_bytes vaddr_end, kinfo_t *cbi); 46433d6423SLionel Sambuc int pg_mapkernel(void); 47433d6423SLionel Sambuc void pg_mapproc(struct proc *p, struct boot_image *ip, kinfo_t *cbi); 48433d6423SLionel Sambuc 49433d6423SLionel Sambuc EXTERN void * k_stacks_start; 50433d6423SLionel Sambuc extern void * k_stacks; 51433d6423SLionel Sambuc 52433d6423SLionel Sambuc #define get_k_stack_top(cpu) ((void *)(((char*)(k_stacks)) \ 53433d6423SLionel Sambuc + 2 * ((cpu) + 1) * K_STACK_SIZE)) 54433d6423SLionel Sambuc 55433d6423SLionel Sambuc 56433d6423SLionel Sambuc /* 57433d6423SLionel Sambuc * Definition of a callback used when a memory map changed it's base address 58433d6423SLionel Sambuc */ 59433d6423SLionel Sambuc typedef int (*kern_phys_map_mapped)(vir_bytes id, vir_bytes new_addr ); 60433d6423SLionel Sambuc 61433d6423SLionel Sambuc /* 62433d6423SLionel Sambuc * struct used internally by memory.c to keep a list of 63433d6423SLionel Sambuc * items to map. These should be statically allocated 64433d6423SLionel Sambuc * in the individual files and passed as argument. 65433d6423SLionel Sambuc * The data doesn't need to be initialized. See omap_serial for 66433d6423SLionel Sambuc * and example usage. 67433d6423SLionel Sambuc */ 68433d6423SLionel Sambuc typedef struct kern_phys_map{ 69433d6423SLionel Sambuc phys_bytes addr; /* The physical address to map */ 70433d6423SLionel Sambuc vir_bytes size; /* The size of the mapping */ 71433d6423SLionel Sambuc vir_bytes id; /* an id passed to the callback */ 72433d6423SLionel Sambuc int vm_flags; /* flags to be passed to vm map */ 73433d6423SLionel Sambuc kern_phys_map_mapped cb; /* the callback itself */ 74433d6423SLionel Sambuc phys_bytes vir; /* The virtual address once remapped */ 75433d6423SLionel Sambuc int index; /* index */ 76433d6423SLionel Sambuc struct kern_phys_map *next; /* pointer to the next */ 77433d6423SLionel Sambuc } kern_phys_map ; 78433d6423SLionel Sambuc 79433d6423SLionel Sambuc 80433d6423SLionel Sambuc /* 81433d6423SLionel Sambuc * Request an in kernel physical mapping. 82433d6423SLionel Sambuc * 83433d6423SLionel Sambuc * On ARM many devices are memory mapped and some of these devices 84433d6423SLionel Sambuc * are used in the kernel. These device can be things like serial 85433d6423SLionel Sambuc * lines, interrupt controller and clocks. The kernel needs to be 86433d6423SLionel Sambuc * able to access these devices at the various stages of booting. 87433d6423SLionel Sambuc * During startup, until arch_enable_paging is called, it is the 88433d6423SLionel Sambuc * kernel whom is controlling the mappings and it often needs to 89433d6423SLionel Sambuc * access the memory using a 1:1 mapping between virtual and 90433d6423SLionel Sambuc * physical memory. 91433d6423SLionel Sambuc * 92433d6423SLionel Sambuc * Once processes start to run it is no longer desirable for the 93433d6423SLionel Sambuc * kernel to have devices mapped in the middle of the process 94433d6423SLionel Sambuc * address space. 95433d6423SLionel Sambuc * 96433d6423SLionel Sambuc * This method requests the memory manager to map base_address/size 97433d6423SLionel Sambuc * in the kernel address space and call back the kernel when this 98433d6423SLionel Sambuc * mapping takes effect (after enable_paging). 99433d6423SLionel Sambuc * 100433d6423SLionel Sambuc * Before the callback is called it is up to the kernel to use it's 101433d6423SLionel Sambuc * own addressing. The callback will happen *after* the kernel lost 102433d6423SLionel Sambuc * it's initial mapping. It it therefore not safe to use the initial 103433d6423SLionel Sambuc * mapping in the callback. It also is not possible to use printf for 104433d6423SLionel Sambuc * the same reason. 105433d6423SLionel Sambuc */ 106433d6423SLionel Sambuc int kern_req_phys_map( phys_bytes base_address, vir_bytes io_size, 107433d6423SLionel Sambuc int vm_flags, kern_phys_map * priv, 108433d6423SLionel Sambuc kern_phys_map_mapped cb, vir_bytes id); 109433d6423SLionel Sambuc 110433d6423SLionel Sambuc /* 111433d6423SLionel Sambuc * Request a physical mapping and put the result in the given prt 112433d6423SLionel Sambuc * Note that ptr will only be valid once the callback happened. 113433d6423SLionel Sambuc */ 114433d6423SLionel Sambuc int kern_phys_map_ptr( phys_bytes base_address, vir_bytes io_size, 115433d6423SLionel Sambuc int vm_flags, kern_phys_map * priv, 116433d6423SLionel Sambuc vir_bytes ptr); 117433d6423SLionel Sambuc 118*6077d1adSDr. Florian Grätz void arch_ser_init(void); 119433d6423SLionel Sambuc 120433d6423SLionel Sambuc /* functions defined in architecture-independent kernel source. */ 121433d6423SLionel Sambuc #include "kernel/proto.h" 122433d6423SLionel Sambuc 123433d6423SLionel Sambuc #endif /* __ASSEMBLY__ */ 124433d6423SLionel Sambuc 125433d6423SLionel Sambuc #endif 126