cycv_platform.c revision 1.1 1 1.1 aymeric /* $NetBSD: cycv_platform.c,v 1.1 2018/09/19 17:31:38 aymeric Exp $ */
2 1.1 aymeric
3 1.1 aymeric /* This file is in the public domain. */
4 1.1 aymeric
5 1.1 aymeric #include "arml2cc.h"
6 1.1 aymeric #include "opt_multiprocessor.h"
7 1.1 aymeric
8 1.1 aymeric #include <sys/cdefs.h>
9 1.1 aymeric __KERNEL_RCSID(0, "$NetBSD: cycv_platform.c,v 1.1 2018/09/19 17:31:38 aymeric Exp $");
10 1.1 aymeric
11 1.1 aymeric #define _ARM32_BUS_DMA_PRIVATE
12 1.1 aymeric #include <sys/param.h>
13 1.1 aymeric #include <sys/bus.h>
14 1.1 aymeric #include <sys/cpu.h>
15 1.1 aymeric #include <sys/device.h>
16 1.1 aymeric
17 1.1 aymeric #include <uvm/uvm_extern.h>
18 1.1 aymeric
19 1.1 aymeric #include <arm/altera/cycv_reg.h>
20 1.1 aymeric #include <arm/altera/cycv_var.h>
21 1.1 aymeric #include <arm/cortex/a9tmr_var.h>
22 1.1 aymeric #include <arm/cortex/pl310_var.h>
23 1.1 aymeric #include <arm/cortex/scu_reg.h>
24 1.1 aymeric
25 1.1 aymeric #include <arm/bootconfig.h>
26 1.1 aymeric #include <arm/cpufunc.h>
27 1.1 aymeric
28 1.1 aymeric #include <arm/fdt/arm_fdtvar.h>
29 1.1 aymeric #include <dev/fdt/fdtvar.h>
30 1.1 aymeric
31 1.1 aymeric static void cycv_platform_early_putchar(char);
32 1.1 aymeric
33 1.1 aymeric static const struct pmap_devmap *
34 1.1 aymeric cycv_platform_devmap(void) {
35 1.1 aymeric static const struct pmap_devmap devmap[] = {
36 1.1 aymeric DEVMAP_ENTRY(CYCV_PERIPHERAL_VBASE,
37 1.1 aymeric CYCV_PERIPHERAL_BASE,
38 1.1 aymeric CYCV_PERIPHERAL_SIZE),
39 1.1 aymeric DEVMAP_ENTRY_END
40 1.1 aymeric };
41 1.1 aymeric
42 1.1 aymeric return devmap;
43 1.1 aymeric }
44 1.1 aymeric
45 1.1 aymeric extern void cortex_mpstart(void);
46 1.1 aymeric
47 1.1 aymeric static void
48 1.1 aymeric cycv_platform_bootstrap(void) {
49 1.1 aymeric uint32_t startfunc = (uint32_t) cortex_mpstart;
50 1.1 aymeric bus_space_tag_t bst = &armv7_generic_bs_tag;
51 1.1 aymeric bus_space_handle_t bsh_l2c;
52 1.1 aymeric bus_space_handle_t bsh_rst;
53 1.1 aymeric bus_space_handle_t bsh_scu;
54 1.1 aymeric
55 1.1 aymeric bus_space_map(bst, CYCV_L2CACHE_BASE, CYCV_L2CACHE_SIZE, 0, &bsh_l2c);
56 1.1 aymeric bus_space_map(bst, CYCV_RSTMGR_BASE, CYCV_RSTMGR_SIZE, 0, &bsh_rst);
57 1.1 aymeric bus_space_map(bst, CYCV_SCU_BASE, CYCV_SCU_SIZE, 0, &bsh_scu);
58 1.1 aymeric
59 1.1 aymeric /* Enable Snoop Control Unit */
60 1.1 aymeric bus_space_write_4(bst, bsh_rst, SCU_CTL,
61 1.1 aymeric bus_space_read_4(bst, bsh_rst, SCU_CTL) | SCU_CTL_SCU_ENA);
62 1.1 aymeric
63 1.1 aymeric #if NARML2CC > 0
64 1.1 aymeric arml2cc_init(bst, bsh_l2c, 0);
65 1.1 aymeric #endif
66 1.1 aymeric
67 1.1 aymeric /*
68 1.1 aymeric * We place a "B cortex_mpstart" at address 0 in order to bootstrap
69 1.1 aymeric * CPU 1. We can't use the similar feature of the Boot ROM because
70 1.1 aymeric * it was unmapped by u-boot in favor of the SDRAM. Plus the dtb is
71 1.1 aymeric * stored very low in RAM so we can't re-map the Boot ROM easily.
72 1.1 aymeric */
73 1.1 aymeric
74 1.1 aymeric *(volatile uint32_t *) 0x0 = 0xea000000 | ((startfunc - 8 - 0x0) >> 2);
75 1.1 aymeric
76 1.1 aymeric arm_cpu_max = 2;
77 1.1 aymeric
78 1.1 aymeric arm_dsb();
79 1.1 aymeric
80 1.1 aymeric armv7_dcache_wbinv_all();
81 1.1 aymeric
82 1.1 aymeric bus_space_write_4(bst, bsh_rst, CYCV_RSTMGR_MPUMODRST,
83 1.1 aymeric bus_space_read_4(bst, bsh_rst, CYCV_RSTMGR_MPUMODRST) &
84 1.1 aymeric ~CYCV_RSTMGR_MPUMODRST_CPU1);
85 1.1 aymeric }
86 1.1 aymeric
87 1.1 aymeric static void
88 1.1 aymeric cycv_platform_init_attach_args(struct fdt_attach_args *faa) {
89 1.1 aymeric faa->faa_bst = &armv7_generic_bs_tag;
90 1.1 aymeric faa->faa_a4x_bst = &armv7_generic_a4x_bs_tag;
91 1.1 aymeric faa->faa_dmat = &arm_generic_dma_tag;
92 1.1 aymeric }
93 1.1 aymeric
94 1.1 aymeric static void
95 1.1 aymeric cycv_platform_early_putchar(char c) {
96 1.1 aymeric #ifdef CONSADDR
97 1.1 aymeric #define CONSADDR_VA (CONSADDR - CYCV_PERIPHERAL_BASE + CYCV_PERIPHERAL_VBASE)
98 1.1 aymeric volatile uint32_t *uartaddr = (volatile uint32_t *) CONSADDR_VA;
99 1.1 aymeric
100 1.1 aymeric while ((uartaddr[com_lsr] & LSR_TXRDY) == 0)
101 1.1 aymeric ;
102 1.1 aymeric
103 1.1 aymeric uartaddr[com_data] = c;
104 1.1 aymeric #endif
105 1.1 aymeric }
106 1.1 aymeric
107 1.1 aymeric static void
108 1.1 aymeric cycv_platform_device_register(device_t dev, void *aux) {
109 1.1 aymeric prop_dictionary_t dict = device_properties(dev);
110 1.1 aymeric
111 1.1 aymeric if (device_is_a(dev, "arma9tmr")) {
112 1.1 aymeric prop_dictionary_set_uint32(dict, "frequency",
113 1.1 aymeric cycv_clkmgr_early_get_mpu_clk() / 4);
114 1.1 aymeric }
115 1.1 aymeric }
116 1.1 aymeric
117 1.1 aymeric static void
118 1.1 aymeric cycv_platform_reset(void) {
119 1.1 aymeric bus_space_tag_t bst = &armv7_generic_bs_tag;
120 1.1 aymeric bus_space_handle_t bsh;
121 1.1 aymeric uint32_t val;
122 1.1 aymeric
123 1.1 aymeric bus_space_map(bst, CYCV_RSTMGR_BASE, CYCV_RSTMGR_SIZE, 0, &bsh);
124 1.1 aymeric val = bus_space_read_4(bst, bsh, CYCV_RSTMGR_CTRL);
125 1.1 aymeric bus_space_write_4(bst, bsh, CYCV_RSTMGR_CTRL,
126 1.1 aymeric val | CYCV_RSTMGR_CTRL_SWCOLDRSTREQ);
127 1.1 aymeric }
128 1.1 aymeric
129 1.1 aymeric static u_int
130 1.1 aymeric cycv_platform_uart_freq(void) {
131 1.1 aymeric return cycv_clkmgr_early_get_l4_sp_clk();
132 1.1 aymeric }
133 1.1 aymeric
134 1.1 aymeric static const struct arm_platform cycv_platform = {
135 1.1 aymeric .ap_devmap = cycv_platform_devmap,
136 1.1 aymeric .ap_bootstrap = cycv_platform_bootstrap,
137 1.1 aymeric .ap_init_attach_args = cycv_platform_init_attach_args,
138 1.1 aymeric .ap_early_putchar = cycv_platform_early_putchar,
139 1.1 aymeric .ap_device_register = cycv_platform_device_register,
140 1.1 aymeric .ap_reset = cycv_platform_reset,
141 1.1 aymeric .ap_delay = a9tmr_delay,
142 1.1 aymeric .ap_uart_freq = cycv_platform_uart_freq,
143 1.1 aymeric };
144 1.1 aymeric
145 1.1 aymeric ARM_PLATFORM(cycv, "altr,socfpga-cyclone5", &cycv_platform);
146