Home | History | Annotate | Line # | Download | only in fdt
arm_platform.c revision 1.3.2.1
      1  1.3.2.1   thorpej /* $NetBSD: arm_platform.c,v 1.3.2.1 2021/04/03 22:28:16 thorpej Exp $ */
      2      1.1  jmcneill 
      3      1.1  jmcneill /*-
      4      1.1  jmcneill  * Copyright (c) 2020 Jared McNeill <jmcneill (at) invisible.ca>
      5      1.1  jmcneill  * All rights reserved.
      6      1.1  jmcneill  *
      7      1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
      8      1.1  jmcneill  * modification, are permitted provided that the following conditions
      9      1.1  jmcneill  * are met:
     10      1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     11      1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     12      1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     14      1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     15      1.1  jmcneill  *
     16      1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17      1.1  jmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18      1.1  jmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19      1.1  jmcneill  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20      1.1  jmcneill  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21      1.1  jmcneill  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22      1.1  jmcneill  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23      1.1  jmcneill  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24      1.1  jmcneill  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25      1.1  jmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26      1.1  jmcneill  * SUCH DAMAGE.
     27      1.1  jmcneill  */
     28      1.1  jmcneill 
     29      1.1  jmcneill /*
     30      1.1  jmcneill  * This is the default Arm FDT platform implementation. It assumes the
     31      1.1  jmcneill  * following:
     32      1.1  jmcneill  *
     33      1.1  jmcneill  *  - Generic timer
     34      1.1  jmcneill  *  - PSCI support
     35      1.1  jmcneill  *  - Console UART is pre-configured by firmware
     36      1.1  jmcneill  */
     37      1.1  jmcneill 
     38      1.1  jmcneill #include <sys/cdefs.h>
     39  1.3.2.1   thorpej __KERNEL_RCSID(0, "$NetBSD: arm_platform.c,v 1.3.2.1 2021/04/03 22:28:16 thorpej Exp $");
     40      1.1  jmcneill 
     41      1.1  jmcneill #include <sys/param.h>
     42      1.1  jmcneill #include <sys/bus.h>
     43      1.1  jmcneill #include <sys/cpu.h>
     44      1.1  jmcneill #include <sys/device.h>
     45      1.1  jmcneill #include <sys/termios.h>
     46      1.1  jmcneill 
     47      1.1  jmcneill #include <dev/fdt/fdtvar.h>
     48      1.1  jmcneill #include <arm/fdt/arm_fdtvar.h>
     49      1.1  jmcneill 
     50      1.1  jmcneill #include <uvm/uvm_extern.h>
     51      1.1  jmcneill 
     52      1.1  jmcneill #include <machine/bootconfig.h>
     53      1.2     skrll 
     54      1.1  jmcneill #include <arm/cpufunc.h>
     55      1.1  jmcneill 
     56      1.1  jmcneill #include <arm/cortex/gtmr_var.h>
     57      1.1  jmcneill 
     58      1.1  jmcneill #include <arm/arm/psci.h>
     59      1.1  jmcneill #include <arm/fdt/psci_fdtvar.h>
     60      1.1  jmcneill 
     61      1.1  jmcneill #include <libfdt.h>
     62      1.1  jmcneill 
     63      1.1  jmcneill #include <arch/evbarm/fdt/platform.h>
     64      1.1  jmcneill 
     65      1.1  jmcneill extern struct arm32_bus_dma_tag arm_generic_dma_tag;
     66      1.1  jmcneill extern struct bus_space arm_generic_bs_tag;
     67      1.1  jmcneill 
     68      1.1  jmcneill static void
     69      1.1  jmcneill arm_platform_init_attach_args(struct fdt_attach_args *faa)
     70      1.1  jmcneill {
     71      1.1  jmcneill 	faa->faa_bst = &arm_generic_bs_tag;
     72      1.1  jmcneill 	faa->faa_dmat = &arm_generic_dma_tag;
     73      1.1  jmcneill }
     74      1.1  jmcneill 
     75      1.1  jmcneill static void
     76      1.1  jmcneill arm_platform_device_register(device_t self, void *aux)
     77      1.1  jmcneill {
     78  1.3.2.1   thorpej 	fdtbus_device_register(self, aux);
     79      1.1  jmcneill }
     80      1.1  jmcneill 
     81      1.1  jmcneill static const struct pmap_devmap *
     82      1.1  jmcneill arm_platform_devmap(void)
     83      1.1  jmcneill {
     84      1.1  jmcneill 	static const struct pmap_devmap devmap_empty[] = {
     85      1.1  jmcneill 		DEVMAP_ENTRY_END
     86      1.1  jmcneill 	};
     87      1.1  jmcneill 	static struct pmap_devmap devmap_uart[] = {
     88      1.2     skrll 		DEVMAP_ENTRY(KERNEL_IO_VBASE, 0, PAGE_SIZE),
     89      1.1  jmcneill 		DEVMAP_ENTRY_END
     90      1.1  jmcneill 	};
     91      1.1  jmcneill 	bus_addr_t uart_base;
     92      1.1  jmcneill 
     93      1.1  jmcneill 	const int phandle = fdtbus_get_stdout_phandle();
     94      1.1  jmcneill 	if (phandle <= 0)
     95      1.1  jmcneill 		return devmap_empty;
     96      1.1  jmcneill 
     97      1.1  jmcneill 	if (fdtbus_get_reg(phandle, 0, &uart_base, NULL) != 0)
     98      1.1  jmcneill 		return devmap_empty;
     99      1.1  jmcneill 
    100      1.2     skrll 	devmap_uart[0].pd_pa = DEVMAP_ALIGN(uart_base);
    101      1.1  jmcneill 
    102      1.1  jmcneill 	return devmap_uart;
    103      1.1  jmcneill }
    104      1.1  jmcneill 
    105      1.1  jmcneill static u_int
    106      1.1  jmcneill arm_platform_uart_freq(void)
    107      1.1  jmcneill {
    108      1.1  jmcneill 	return 0;
    109      1.1  jmcneill }
    110      1.1  jmcneill 
    111      1.1  jmcneill static const struct arm_platform arm_platform = {
    112      1.1  jmcneill 	.ap_devmap = arm_platform_devmap,
    113      1.1  jmcneill 	.ap_bootstrap = arm_fdt_cpu_bootstrap,
    114      1.1  jmcneill 	.ap_init_attach_args = arm_platform_init_attach_args,
    115      1.1  jmcneill 	.ap_device_register = arm_platform_device_register,
    116      1.1  jmcneill 	.ap_reset = psci_fdt_reset,
    117      1.1  jmcneill 	.ap_delay = gtmr_delay,
    118      1.1  jmcneill 	.ap_uart_freq = arm_platform_uart_freq,
    119      1.1  jmcneill 	.ap_mpstart = arm_fdt_cpu_mpstart,
    120      1.1  jmcneill };
    121      1.1  jmcneill 
    122      1.1  jmcneill ARM_PLATFORM(arm, ARM_PLATFORM_DEFAULT, &arm_platform);
    123