[b6b02c0] | 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 |
|
---|
[e1cad18] | 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 |
|
---|
[f6f22cdb] | 58 | static void ambapp_scan_area(uintptr_t, unsigned int);
|
---|
[b6b02c0] | 59 |
|
---|
[193d280c] | 60 | void ambapp_scan(void)
|
---|
[b6b02c0] | 61 | {
|
---|
[a73ebf0] | 62 | amba_fake = false;
|
---|
[f6f22cdb] | 63 |
|
---|
[b6b02c0] | 64 | /* Scan for AHB masters & slaves */
|
---|
| 65 | ambapp_scan_area(AMBAPP_AHBMASTER_AREA, 64);
|
---|
| 66 | ambapp_scan_area(AMBAPP_AHBSLAVE_AREA, 63);
|
---|
[f6f22cdb] | 67 |
|
---|
[b6b02c0] | 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);
|
---|
[f6f22cdb] | 72 |
|
---|
[b6b02c0] | 73 | /* If we found nothing, fake device entries */
|
---|
[a73ebf0] | 74 | if (amba_devices_found == 0)
|
---|
| 75 | ambapp_qemu_fake_scan();
|
---|
[b6b02c0] | 76 | }
|
---|
| 77 |
|
---|
[f6f22cdb] | 78 | static void ambapp_scan_area(uintptr_t master_bar, unsigned int max_entries)
|
---|
[b6b02c0] | 79 | {
|
---|
| 80 | ambapp_entry_t *entry = (ambapp_entry_t *) (master_bar | AMBAPP_CONF_AREA);
|
---|
[f6f22cdb] | 81 |
|
---|
| 82 | for (unsigned int i = 0; i < max_entries; i++) {
|
---|
[b6b02c0] | 83 | if (amba_devices_found == AMBAPP_MAX_DEVICES)
|
---|
| 84 | return;
|
---|
[f6f22cdb] | 85 |
|
---|
[b6b02c0] | 86 | if (entry->vendor_id == 0xff)
|
---|
| 87 | continue;
|
---|
[f6f22cdb] | 88 |
|
---|
[b6b02c0] | 89 | amba_device_t *device = &amba_devices[amba_devices_found];
|
---|
[f6f22cdb] | 90 | device->vendor_id = (amba_vendor_id_t) entry->vendor_id;
|
---|
| 91 | device->device_id = (amba_device_id_t) entry->device_id;
|
---|
[b6b02c0] | 92 | device->version = entry->version;
|
---|
| 93 | device->irq = entry->irq;
|
---|
[f6f22cdb] | 94 |
|
---|
| 95 | for (unsigned int bar = 0; bar < 4; bar++) {
|
---|
[b6b02c0] | 96 | device->bars[bar].start = entry->bar[bar].addr << 20;
|
---|
| 97 | device->bars[bar].size = entry->bar[bar].mask;
|
---|
[f6f22cdb] | 98 | device->bars[bar].prefetchable = (bool) entry->bar[bar].prefetchable;
|
---|
| 99 | device->bars[bar].cacheable = (bool) entry->bar[bar].cacheable;
|
---|
[b6b02c0] | 100 | }
|
---|
[f6f22cdb] | 101 |
|
---|
[b6b02c0] | 102 | amba_devices_found++;
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[193d280c] | 106 | void ambapp_qemu_fake_scan(void)
|
---|
[b6b02c0] | 107 | {
|
---|
| 108 | /* UART */
|
---|
| 109 | amba_devices[0].vendor_id = GAISLER;
|
---|
| 110 | amba_devices[0].device_id = GAISLER_APBUART;
|
---|
| 111 | amba_devices[0].version = 1;
|
---|
[208b5f5] | 112 | amba_devices[0].irq = 3;
|
---|
[b6b02c0] | 113 | amba_devices[0].bars[0].start = 0x80000100;
|
---|
| 114 | amba_devices[0].bars[0].size = 0x100;
|
---|
[f6f22cdb] | 115 |
|
---|
[b6b02c0] | 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;
|
---|
[f6f22cdb] | 123 |
|
---|
[b6b02c0] | 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;
|
---|
[f6f22cdb] | 131 |
|
---|
[a73ebf0] | 132 | amba_fake = true;
|
---|
[b6b02c0] | 133 | amba_devices_found = 3;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
[193d280c] | 136 | bool ambapp_fake(void)
|
---|
[a73ebf0] | 137 | {
|
---|
| 138 | return amba_fake;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
[193d280c] | 141 | void ambapp_print_devices(void)
|
---|
[b6b02c0] | 142 | {
|
---|
| 143 | printf("ABMA devices:\n");
|
---|
[f6f22cdb] | 144 |
|
---|
| 145 | for (unsigned int i = 0; i < amba_devices_found; i++) {
|
---|
[b6b02c0] | 146 | amba_device_t *dev = &amba_devices[i];
|
---|
[f6f22cdb] | 147 |
|
---|
| 148 | printf("<%1x:%03x> at 0x%08x ", dev->vendor_id, dev->device_id,
|
---|
| 149 | dev->bars[0].start);
|
---|
| 150 |
|
---|
[a73ebf0] | 151 | if (dev->irq == -1)
|
---|
| 152 | printf("\n");
|
---|
| 153 | else
|
---|
| 154 | printf("irq %d\n", dev->irq);
|
---|
[b6b02c0] | 155 | }
|
---|
| 156 | }
|
---|
| 157 |
|
---|
[f6f22cdb] | 158 | amba_device_t *ambapp_lookup_first(amba_vendor_id_t vendor,
|
---|
| 159 | amba_device_id_t device)
|
---|
[b6b02c0] | 160 | {
|
---|
[f6f22cdb] | 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))
|
---|
[b6b02c0] | 164 | return &amba_devices[i];
|
---|
| 165 | }
|
---|
[f6f22cdb] | 166 |
|
---|
[b6b02c0] | 167 | return NULL;
|
---|
| 168 | }
|
---|