1 | /*
|
---|
2 | * Copyright (c) 2013 Jakub Klama
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup sparc32boot
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | * @brief Bootstrap.
|
---|
34 | */
|
---|
35 |
|
---|
36 | #include <arch/asm.h>
|
---|
37 | #include <arch/common.h>
|
---|
38 | #include <arch/arch.h>
|
---|
39 | #include <arch/ambapp.h>
|
---|
40 | #include <arch/mm.h>
|
---|
41 | #include <arch/main.h>
|
---|
42 | #include <arch/_components.h>
|
---|
43 | #include <halt.h>
|
---|
44 | #include <printf.h>
|
---|
45 | #include <memstr.h>
|
---|
46 | #include <version.h>
|
---|
47 | #include <macros.h>
|
---|
48 | #include <align.h>
|
---|
49 | #include <str.h>
|
---|
50 | #include <errno.h>
|
---|
51 |
|
---|
52 | uintptr_t amba_uart_base;
|
---|
53 |
|
---|
54 | static amba_device_t amba_devices[AMBAPP_MAX_DEVICES];
|
---|
55 | static unsigned int amba_devices_found;
|
---|
56 | static bool amba_fake;
|
---|
57 |
|
---|
58 | static void ambapp_scan_area(uintptr_t, unsigned int);
|
---|
59 |
|
---|
60 | void ambapp_scan(void)
|
---|
61 | {
|
---|
62 | amba_fake = false;
|
---|
63 |
|
---|
64 | /* Scan for AHB masters & slaves */
|
---|
65 | ambapp_scan_area(AMBAPP_AHBMASTER_AREA, 64);
|
---|
66 | ambapp_scan_area(AMBAPP_AHBSLAVE_AREA, 63);
|
---|
67 |
|
---|
68 | /* Scan for APB slaves on APBMST */
|
---|
69 | amba_device_t *apbmst = ambapp_lookup_first(GAISLER, GAISLER_APBMST);
|
---|
70 | if (apbmst != NULL)
|
---|
71 | ambapp_scan_area(apbmst->bars[0].start, 16);
|
---|
72 |
|
---|
73 | /* If we found nothing, fake device entries */
|
---|
74 | if (amba_devices_found == 0)
|
---|
75 | ambapp_qemu_fake_scan();
|
---|
76 | }
|
---|
77 |
|
---|
78 | static void ambapp_scan_area(uintptr_t master_bar, unsigned int max_entries)
|
---|
79 | {
|
---|
80 | ambapp_entry_t *entry = (ambapp_entry_t *) (master_bar | AMBAPP_CONF_AREA);
|
---|
81 |
|
---|
82 | for (unsigned int i = 0; i < max_entries; i++) {
|
---|
83 | if (amba_devices_found == AMBAPP_MAX_DEVICES)
|
---|
84 | return;
|
---|
85 |
|
---|
86 | if (entry->vendor_id == 0xff)
|
---|
87 | continue;
|
---|
88 |
|
---|
89 | amba_device_t *device = &amba_devices[amba_devices_found];
|
---|
90 | device->vendor_id = (amba_vendor_id_t) entry->vendor_id;
|
---|
91 | device->device_id = (amba_device_id_t) entry->device_id;
|
---|
92 | device->version = entry->version;
|
---|
93 | device->irq = entry->irq;
|
---|
94 |
|
---|
95 | for (unsigned int bar = 0; bar < 4; bar++) {
|
---|
96 | device->bars[bar].start = entry->bar[bar].addr << 20;
|
---|
97 | device->bars[bar].size = entry->bar[bar].mask;
|
---|
98 | device->bars[bar].prefetchable = (bool) entry->bar[bar].prefetchable;
|
---|
99 | device->bars[bar].cacheable = (bool) entry->bar[bar].cacheable;
|
---|
100 | }
|
---|
101 |
|
---|
102 | amba_devices_found++;
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | void ambapp_qemu_fake_scan(void)
|
---|
107 | {
|
---|
108 | /* UART */
|
---|
109 | amba_devices[0].vendor_id = GAISLER;
|
---|
110 | amba_devices[0].device_id = GAISLER_APBUART;
|
---|
111 | amba_devices[0].version = 1;
|
---|
112 | amba_devices[0].irq = 3;
|
---|
113 | amba_devices[0].bars[0].start = 0x80000100;
|
---|
114 | amba_devices[0].bars[0].size = 0x100;
|
---|
115 |
|
---|
116 | /* IRQMP */
|
---|
117 | amba_devices[1].vendor_id = GAISLER;
|
---|
118 | amba_devices[1].device_id = GAISLER_IRQMP;
|
---|
119 | amba_devices[1].version = 1;
|
---|
120 | amba_devices[1].irq = -1;
|
---|
121 | amba_devices[1].bars[0].start = 0x80000200;
|
---|
122 | amba_devices[1].bars[0].size = 0x100;
|
---|
123 |
|
---|
124 | /* GPTIMER */
|
---|
125 | amba_devices[2].vendor_id = GAISLER;
|
---|
126 | amba_devices[2].device_id = GAISLER_GPTIMER;
|
---|
127 | amba_devices[2].version = 1;
|
---|
128 | amba_devices[2].irq = 8;
|
---|
129 | amba_devices[2].bars[0].start = 0x80000300;
|
---|
130 | amba_devices[2].bars[0].size = 0x100;
|
---|
131 |
|
---|
132 | amba_fake = true;
|
---|
133 | amba_devices_found = 3;
|
---|
134 | }
|
---|
135 |
|
---|
136 | bool ambapp_fake(void)
|
---|
137 | {
|
---|
138 | return amba_fake;
|
---|
139 | }
|
---|
140 |
|
---|
141 | void ambapp_print_devices(void)
|
---|
142 | {
|
---|
143 | printf("ABMA devices:\n");
|
---|
144 |
|
---|
145 | for (unsigned int i = 0; i < amba_devices_found; i++) {
|
---|
146 | amba_device_t *dev = &amba_devices[i];
|
---|
147 |
|
---|
148 | printf("<%1x:%03x> at 0x%08x ", dev->vendor_id, dev->device_id,
|
---|
149 | dev->bars[0].start);
|
---|
150 |
|
---|
151 | if (dev->irq == -1)
|
---|
152 | printf("\n");
|
---|
153 | else
|
---|
154 | printf("irq %d\n", dev->irq);
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | amba_device_t *ambapp_lookup_first(amba_vendor_id_t vendor,
|
---|
159 | amba_device_id_t device)
|
---|
160 | {
|
---|
161 | for (unsigned int i = 0; i < amba_devices_found; i++) {
|
---|
162 | if ((amba_devices[i].vendor_id == vendor) &&
|
---|
163 | (amba_devices[i].device_id == device))
|
---|
164 | return &amba_devices[i];
|
---|
165 | }
|
---|
166 |
|
---|
167 | return NULL;
|
---|
168 | }
|
---|