vexpress_platform.c revision 1.1
11.1Sjmcneill/* $NetBSD: vexpress_platform.c,v 1.1 2017/06/02 15:22:47 jmcneill Exp $ */ 21.1Sjmcneill 31.1Sjmcneill/*- 41.1Sjmcneill * Copyright (c) 2017 Jared McNeill <jmcneill@invisible.ca> 51.1Sjmcneill * All rights reserved. 61.1Sjmcneill * 71.1Sjmcneill * Redistribution and use in source and binary forms, with or without 81.1Sjmcneill * modification, are permitted provided that the following conditions 91.1Sjmcneill * are met: 101.1Sjmcneill * 1. Redistributions of source code must retain the above copyright 111.1Sjmcneill * notice, this list of conditions and the following disclaimer. 121.1Sjmcneill * 2. Redistributions in binary form must reproduce the above copyright 131.1Sjmcneill * notice, this list of conditions and the following disclaimer in the 141.1Sjmcneill * documentation and/or other materials provided with the distribution. 151.1Sjmcneill * 161.1Sjmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 171.1Sjmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 181.1Sjmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 191.1Sjmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 201.1Sjmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 211.1Sjmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 221.1Sjmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 231.1Sjmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 241.1Sjmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 251.1Sjmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 261.1Sjmcneill * SUCH DAMAGE. 271.1Sjmcneill */ 281.1Sjmcneill 291.1Sjmcneill#include "opt_multiprocessor.h" 301.1Sjmcneill#include "opt_fdt_arm.h" 311.1Sjmcneill 321.1Sjmcneill#include <sys/cdefs.h> 331.1Sjmcneill__KERNEL_RCSID(0, "$NetBSD: vexpress_platform.c,v 1.1 2017/06/02 15:22:47 jmcneill Exp $"); 341.1Sjmcneill 351.1Sjmcneill#include <sys/param.h> 361.1Sjmcneill#include <sys/bus.h> 371.1Sjmcneill#include <sys/cpu.h> 381.1Sjmcneill#include <sys/device.h> 391.1Sjmcneill#include <sys/termios.h> 401.1Sjmcneill 411.1Sjmcneill#include <dev/fdt/fdtvar.h> 421.1Sjmcneill 431.1Sjmcneill#include <uvm/uvm_extern.h> 441.1Sjmcneill 451.1Sjmcneill#include <machine/bootconfig.h> 461.1Sjmcneill#include <arm/cpufunc.h> 471.1Sjmcneill 481.1Sjmcneill#include <arm/fdt/arm_fdtvar.h> 491.1Sjmcneill 501.1Sjmcneill#include <arm/cortex/gtmr_var.h> 511.1Sjmcneill 521.1Sjmcneill#include <evbarm/dev/plcomvar.h> 531.1Sjmcneill 541.1Sjmcneill#define VEXPRESS_REF_FREQ 24000000 551.1Sjmcneill 561.1Sjmcneill#define VEXPRESS_CORE_VBASE 0xf0000000 571.1Sjmcneill#define VEXPRESS_CORE_PBASE 0x10000000 581.1Sjmcneill#define VEXPRESS_CORE_SIZE 0x10000000 591.1Sjmcneill 601.1Sjmcneill#define DEVMAP_ALIGN(a) ((a) & ~L1_S_OFFSET) 611.1Sjmcneill#define DEVMAP_SIZE(s) roundup2((s), L1_S_SIZE) 621.1Sjmcneill#define DEVMAP_ENTRY(va, pa, sz) \ 631.1Sjmcneill { \ 641.1Sjmcneill .pd_va = DEVMAP_ALIGN(va), \ 651.1Sjmcneill .pd_pa = DEVMAP_ALIGN(pa), \ 661.1Sjmcneill .pd_size = DEVMAP_SIZE(sz), \ 671.1Sjmcneill .pd_prot = VM_PROT_READ|VM_PROT_WRITE, \ 681.1Sjmcneill .pd_cache = PTE_NOCACHE \ 691.1Sjmcneill } 701.1Sjmcneill#define DEVMAP_ENTRY_END { 0 } 711.1Sjmcneill 721.1Sjmcneillextern struct bus_space armv7_generic_bs_tag; 731.1Sjmcneillextern struct bus_space armv7_generic_a4x_bs_tag; 741.1Sjmcneillextern struct arm32_bus_dma_tag armv7_generic_dma_tag; 751.1Sjmcneill 761.1Sjmcneill#define SYSREG_BASE 0x1c010000 771.1Sjmcneill#define SYSREG_SIZE 0x1000 781.1Sjmcneill 791.1Sjmcneill#define SYS_FLAGS 0x0030 801.1Sjmcneill#define SYS_FLAGSCLR 0x0034 811.1Sjmcneill#define SYS_CFGDATA 0x00a0 821.1Sjmcneill#define SYS_CFGCTRL 0x00a4 831.1Sjmcneill#define SYS_CFGCTRL_START __BIT(31) 841.1Sjmcneill#define SYS_CFGCTRL_WRITE __BIT(30) 851.1Sjmcneill#define SYS_CFGCTRL_DCC __BITS(29,26) 861.1Sjmcneill#define SYS_CFGCTRL_FUNCTION __BITS(25,20) 871.1Sjmcneill#define SYS_CFGCTRL_FUNCTION_SHUTDOWN 8 881.1Sjmcneill#define SYS_CFGCTRL_FUNCTION_REBOOT 9 891.1Sjmcneill#define SYS_CFGCTRL_SITE __BITS(17,16) 901.1Sjmcneill#define SYS_CFGCTRL_POSITION __BITS(15,12) 911.1Sjmcneill#define SYS_CFGCTRL_DEVICE __BITS(11,0) 921.1Sjmcneill#define SYS_CFGSTAT 0x00a8 931.1Sjmcneill#define SYS_CFGSTAT_ERROR __BIT(1) 941.1Sjmcneill#define SYS_CFGSTAT_COMPLETE __BIT(0) 951.1Sjmcneill 961.1Sjmcneillstatic bus_space_tag_t sysreg_bst = &armv7_generic_bs_tag; 971.1Sjmcneillstatic bus_space_handle_t sysreg_bsh; 981.1Sjmcneill 991.1Sjmcneill#define SYSREG_WRITE(o, v) \ 1001.1Sjmcneill bus_space_write_4(sysreg_bst, sysreg_bsh, (o), (v)) 1011.1Sjmcneill 1021.1Sjmcneill 1031.1Sjmcneillstatic const struct pmap_devmap * 1041.1Sjmcneillvexpress_platform_devmap(void) 1051.1Sjmcneill{ 1061.1Sjmcneill static const struct pmap_devmap devmap[] = { 1071.1Sjmcneill DEVMAP_ENTRY(VEXPRESS_CORE_VBASE, 1081.1Sjmcneill VEXPRESS_CORE_PBASE, 1091.1Sjmcneill VEXPRESS_CORE_SIZE), 1101.1Sjmcneill DEVMAP_ENTRY_END 1111.1Sjmcneill }; 1121.1Sjmcneill 1131.1Sjmcneill return devmap; 1141.1Sjmcneill} 1151.1Sjmcneill 1161.1Sjmcneillstatic void 1171.1Sjmcneillvexpress_platform_bootstrap(void) 1181.1Sjmcneill{ 1191.1Sjmcneill bus_space_map(sysreg_bst, SYSREG_BASE, SYSREG_SIZE, 0, 1201.1Sjmcneill &sysreg_bsh); 1211.1Sjmcneill} 1221.1Sjmcneill 1231.1Sjmcneillstatic void 1241.1Sjmcneillvexpress_platform_init_attach_args(struct fdt_attach_args *faa) 1251.1Sjmcneill{ 1261.1Sjmcneill faa->faa_bst = &armv7_generic_bs_tag; 1271.1Sjmcneill faa->faa_a4x_bst = &armv7_generic_a4x_bs_tag; 1281.1Sjmcneill faa->faa_dmat = &armv7_generic_dma_tag; 1291.1Sjmcneill} 1301.1Sjmcneill 1311.1Sjmcneillstatic void 1321.1Sjmcneillvexpress_platform_early_putchar(char c) 1331.1Sjmcneill{ 1341.1Sjmcneill} 1351.1Sjmcneill 1361.1Sjmcneillstatic void 1371.1Sjmcneillvexpress_platform_device_register(device_t self, void *aux) 1381.1Sjmcneill{ 1391.1Sjmcneill} 1401.1Sjmcneill 1411.1Sjmcneillstatic void 1421.1Sjmcneillvexpress_platform_reset(void) 1431.1Sjmcneill{ 1441.1Sjmcneill SYSREG_WRITE(SYS_CFGSTAT, 0); 1451.1Sjmcneill SYSREG_WRITE(SYS_CFGDATA, 0); 1461.1Sjmcneill SYSREG_WRITE(SYS_CFGCTRL, 1471.1Sjmcneill SYS_CFGCTRL_START | 1481.1Sjmcneill SYS_CFGCTRL_WRITE | 1491.1Sjmcneill __SHIFTIN(SYS_CFGCTRL_FUNCTION_REBOOT, 1501.1Sjmcneill SYS_CFGCTRL_FUNCTION)); 1511.1Sjmcneill} 1521.1Sjmcneill 1531.1Sjmcneillstatic u_int 1541.1Sjmcneillvexpress_platform_uart_freq(void) 1551.1Sjmcneill{ 1561.1Sjmcneill return VEXPRESS_REF_FREQ; 1571.1Sjmcneill} 1581.1Sjmcneill 1591.1Sjmcneillstatic const struct arm_platform vexpress_platform = { 1601.1Sjmcneill .devmap = vexpress_platform_devmap, 1611.1Sjmcneill .bootstrap = vexpress_platform_bootstrap, 1621.1Sjmcneill .init_attach_args = vexpress_platform_init_attach_args, 1631.1Sjmcneill .early_putchar = vexpress_platform_early_putchar, 1641.1Sjmcneill .device_register = vexpress_platform_device_register, 1651.1Sjmcneill .reset = vexpress_platform_reset, 1661.1Sjmcneill .delay = gtmr_delay, 1671.1Sjmcneill .uart_freq = vexpress_platform_uart_freq, 1681.1Sjmcneill}; 1691.1Sjmcneill 1701.1SjmcneillARM_PLATFORM(vexpress, "arm,vexpress", &vexpress_platform); 171