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