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 | static void ambapp_scan_area(uintptr_t, int);
|
---|
53 |
|
---|
54 | void ambapp_scan()
|
---|
55 | {
|
---|
56 | /* Scan for AHB masters & slaves */
|
---|
57 | ambapp_scan_area(AMBAPP_AHBMASTER_AREA, 64);
|
---|
58 | ambapp_scan_area(AMBAPP_AHBSLAVE_AREA, 63);
|
---|
59 |
|
---|
60 | /* Scan for APB slaves on APBMST */
|
---|
61 | amba_device_t *apbmst = ambapp_lookup_first(GAISLER, GAISLER_APBMST);
|
---|
62 | if (apbmst != NULL)
|
---|
63 | ambapp_scan_area(apbmst->bars[0].start, 16);
|
---|
64 |
|
---|
65 | /* If we found nothing, fake device entries */
|
---|
66 | ambapp_qemu_fake_scan();
|
---|
67 | }
|
---|
68 |
|
---|
69 | static void ambapp_scan_area(uintptr_t master_bar, int max_entries)
|
---|
70 | {
|
---|
71 | ambapp_entry_t *entry = (ambapp_entry_t *) (master_bar | AMBAPP_CONF_AREA);
|
---|
72 |
|
---|
73 | for (int i = 0; i < max_entries; i++) {
|
---|
74 | if (amba_devices_found == AMBAPP_MAX_DEVICES)
|
---|
75 | return;
|
---|
76 |
|
---|
77 | if (entry->vendor_id == 0xff)
|
---|
78 | continue;
|
---|
79 |
|
---|
80 | amba_device_t *device = &amba_devices[amba_devices_found];
|
---|
81 | device->vendor_id = (amba_vendor_id_t)entry->vendor_id;
|
---|
82 | device->device_id = (amba_device_id_t)entry->device_id;
|
---|
83 | device->version = entry->version;
|
---|
84 | device->irq = entry->irq;
|
---|
85 |
|
---|
86 | for (int bar = 0; bar < 4; bar++) {
|
---|
87 | device->bars[bar].start = entry->bar[bar].addr << 20;
|
---|
88 | device->bars[bar].size = entry->bar[bar].mask;
|
---|
89 | device->bars[bar].prefetchable = (bool)entry->bar[bar].prefetchable;
|
---|
90 | device->bars[bar].cacheable = (bool)entry->bar[bar].cacheable;
|
---|
91 | }
|
---|
92 |
|
---|
93 | amba_devices_found++;
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | void ambapp_qemu_fake_scan()
|
---|
98 | {
|
---|
99 | /* UART */
|
---|
100 | amba_devices[0].vendor_id = GAISLER;
|
---|
101 | amba_devices[0].device_id = GAISLER_APBUART;
|
---|
102 | amba_devices[0].version = 1;
|
---|
103 | amba_devices[0].irq = 2;
|
---|
104 | amba_devices[0].bars[0].start = 0x80000100;
|
---|
105 | amba_devices[0].bars[0].size = 0x100;
|
---|
106 |
|
---|
107 | /* IRQMP */
|
---|
108 | amba_devices[1].vendor_id = GAISLER;
|
---|
109 | amba_devices[1].device_id = GAISLER_IRQMP;
|
---|
110 | amba_devices[1].version = 1;
|
---|
111 | amba_devices[1].irq = -1;
|
---|
112 | amba_devices[1].bars[0].start = 0x80000200;
|
---|
113 | amba_devices[1].bars[0].size = 0x100;
|
---|
114 |
|
---|
115 | /* GPTIMER */
|
---|
116 | amba_devices[2].vendor_id = GAISLER;
|
---|
117 | amba_devices[2].device_id = GAISLER_GPTIMER;
|
---|
118 | amba_devices[2].version = 1;
|
---|
119 | amba_devices[2].irq = 8;
|
---|
120 | amba_devices[2].bars[0].start = 0x80000300;
|
---|
121 | amba_devices[2].bars[0].size = 0x100;
|
---|
122 |
|
---|
123 | amba_devices_found = 3;
|
---|
124 | }
|
---|
125 |
|
---|
126 | void ambapp_print_devices()
|
---|
127 | {
|
---|
128 | printf("ABMA devices:\n");
|
---|
129 |
|
---|
130 | for (int i = 0; i < amba_devices_found; i++) {
|
---|
131 | amba_device_t *dev = &amba_devices[i];
|
---|
132 | printf("<%1x:%03x> at 0x%08x, irq %d\n", dev->vendor_id, dev->device_id, dev->bars[0].start, dev->irq);
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | amba_device_t *ambapp_lookup_first(amba_vendor_id_t vendor, amba_device_id_t device)
|
---|
137 | {
|
---|
138 | for (int i = 0; i < amba_devices_found; i++) {
|
---|
139 | if (amba_devices[i].vendor_id == vendor &&
|
---|
140 | amba_devices[i].device_id == device)
|
---|
141 | return &amba_devices[i];
|
---|
142 | }
|
---|
143 |
|
---|
144 | return NULL;
|
---|
145 | }
|
---|