source: trunk/libs/newlib/src/libgloss/sparc_leon/amba_scan.c @ 612

Last change on this file since 612 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 3.0 KB
Line 
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
31unsigned int
32leon3_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
50unsigned int
51leon3_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
61unsigned int
62leon3_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
87unsigned int
88leon3_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}
Note: See TracBrowser for help on using the repository browser.