[444] | 1 | /* |
---|
| 2 | * Copyright (c) 2011 Aeroflex Gaisler |
---|
| 3 | * |
---|
| 4 | * BSD license: |
---|
| 5 | * |
---|
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 7 | * of this software and associated documentation files (the "Software"), to deal |
---|
| 8 | * in the Software without restriction, including without limitation the rights |
---|
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 10 | * copies of the Software, and to permit persons to whom the Software is |
---|
| 11 | * furnished to do so, subject to the following conditions: |
---|
| 12 | * |
---|
| 13 | * The above copyright notice and this permission notice shall be included in |
---|
| 14 | * all copies or substantial portions of the Software. |
---|
| 15 | * |
---|
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
---|
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 22 | * THE SOFTWARE. |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | #include <asm-leon/leon.h> |
---|
| 27 | #include <stdio.h> |
---|
| 28 | #include <stdlib.h> |
---|
| 29 | #include <string.h> |
---|
| 30 | |
---|
| 31 | unsigned int |
---|
| 32 | leon3_ahbslv_scan (register unsigned int vendor, register unsigned int driver) |
---|
| 33 | { |
---|
| 34 | register unsigned int conf, i, *confp; |
---|
| 35 | register unsigned int cfg_area = |
---|
| 36 | (unsigned int) (LEON3_IO_AREA | LEON3_CONF_AREA | |
---|
| 37 | LEON3_AHB_SLAVE_CONF_AREA); |
---|
| 38 | for (i = 0; i < LEON3_AHB_SLAVES; i++) |
---|
| 39 | { |
---|
| 40 | confp = (unsigned int *) (cfg_area + (i * LEON3_AHB_CONF_WORDS * 4)); |
---|
| 41 | conf = *confp; |
---|
| 42 | if ((amba_vendor (conf) == vendor) && (amba_device (conf) == driver)) |
---|
| 43 | { |
---|
| 44 | return (unsigned int) confp; |
---|
| 45 | } |
---|
| 46 | } |
---|
| 47 | return 0; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | unsigned int |
---|
| 51 | leon3_getbase (register unsigned int *mbar, register unsigned int iobase, |
---|
| 52 | int *irq) |
---|
| 53 | { |
---|
| 54 | register unsigned int conf = mbar[1]; |
---|
| 55 | return (unsigned int) (((iobase & 0xfff00000) | |
---|
| 56 | ((conf & 0xfff00000) >> 12)) & (((conf & 0x0000fff0) |
---|
| 57 | << 4) | |
---|
| 58 | 0xfff00000)); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | unsigned int |
---|
| 62 | leon3_apbslv_scan (register unsigned int base, |
---|
| 63 | register unsigned int vendor, |
---|
| 64 | register unsigned int driver, |
---|
| 65 | amba_apb_device * apbdevs, int c) |
---|
| 66 | { |
---|
| 67 | register unsigned int conf, i, *confp; |
---|
| 68 | int j = 0; |
---|
| 69 | for (i = 0; i < LEON3_APB_SLAVES; i++) |
---|
| 70 | { |
---|
| 71 | confp = (unsigned int *) (base + (i * LEON3_APB_CONF_WORDS * 4)); |
---|
| 72 | conf = *confp; |
---|
| 73 | if ((amba_vendor (conf) == vendor) && (amba_device (conf) == driver)) |
---|
| 74 | { |
---|
| 75 | if (j < c) |
---|
| 76 | { |
---|
| 77 | apbdevs[j].start = leon3_getbase (confp, base, 0); |
---|
| 78 | apbdevs[j].irq = amba_irq (conf); |
---|
| 79 | j++; |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | return j; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | unsigned int |
---|
| 88 | leon3_getapbbase (register unsigned int vendor, |
---|
| 89 | register unsigned int driver, |
---|
| 90 | amba_apb_device * apbdevs, int c) |
---|
| 91 | { |
---|
| 92 | unsigned int apb = leon3_ahbslv_scan (VENDOR_GAISLER, GAISLER_APBMST); |
---|
| 93 | apb = (*(unsigned int *) (apb + 16)) & LEON3_IO_AREA; |
---|
| 94 | apb |= LEON3_CONF_AREA; |
---|
| 95 | return leon3_apbslv_scan (apb, vendor, driver, apbdevs, c); |
---|
| 96 | } |
---|