source: rtems/c/src/lib/libbsp/powerpc/shared/pci/detect_raven_bridge.c @ d59cae9

4.104.114.84.95
Last change on this file since d59cae9 was d59cae9, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 04/09/07 at 14:30:49

adapted BSP "motorola_powerpc" to support MVME24xx

  • Property mode set to 100644
File size: 7.4 KB
Line 
1/*
2 *  $Id$
3 */
4
5#include <libcpu/io.h>
6#include <libcpu/spr.h>
7
8#include <bsp.h>
9#include <bsp/pci.h>
10#include <bsp/consoleIo.h>
11#include <bsp/residual.h>
12#include <bsp/openpic.h>
13
14#include <rtems/bspIo.h>
15#include <libcpu/cpuIdent.h>
16
17#define SHOW_RAVEN_SETTINGS
18
19#define RAVEN_MPIC_IOSPACE_ENABLE  0x0001
20#define RAVEN_MPIC_MEMSPACE_ENABLE 0x0002
21#define RAVEN_MASTER_ENABLE        0x0004
22#define RAVEN_PARITY_CHECK_ENABLE  0x0040
23#define RAVEN_SYSTEM_ERROR_ENABLE  0x0100
24#define RAVEN_CLEAR_EVENTS_MASK    0xf9000000
25
26#define RAVEN_MPIC_MEREN    ((volatile unsigned *)0xfeff0020)
27#define RAVEN_MPIC_MERST    ((volatile unsigned *)0xfeff0024)
28#define MEREN_VAL           0x2f00
29
30#define pci BSP_pci_configuration
31
32extern const pci_config_access_functions pci_direct_functions;
33extern const pci_config_access_functions pci_indirect_functions;
34
35
36#define PCI_ERR_BITS        0xf900
37#define PCI_STATUS_OK(x)    (!((x)&PCI_ERR_BITS))
38
39/* For now, just clear errors in the PCI status reg.
40 *
41 * Returns: (for diagnostic purposes)
42 *          original settings (i.e. before applying the clearing
43 *          sequence) or the error bits or 0 if there were no errors.
44 *
45 */
46
47unsigned long
48_BSP_clear_hostbridge_errors(int enableMCP, int quiet)
49{
50unsigned long   rval;
51unsigned short  pcistat;
52int             count;
53
54    if (enableMCP)
55        return -1; /* exceptions not supported / MCP not wired */
56
57    /* read error status for info return */
58    pci_read_config_word(0,0,0,PCI_STATUS,&pcistat);
59    rval = pcistat;
60
61    count=10;
62    do {
63        /* clear error reporting registers */
64
65        /* clear PCI status register */
66        pci_write_config_word(0,0,0,PCI_STATUS, PCI_ERR_BITS);
67
68        /* read  new status */
69        pci_read_config_word(0,0,0,PCI_STATUS, &pcistat);
70
71    } while ( ! PCI_STATUS_OK(pcistat) && count-- );
72
73    if ( !PCI_STATUS_OK(rval) && !quiet) {
74        printk("Cleared PCI errors: pci_stat was 0x%04x\n", rval);
75    }
76    if ( !PCI_STATUS_OK(pcistat) ) {
77        printk("Unable to clear PCI errors: still 0x%04x after 10 attempts\n", pcistat);
78    }
79    return rval & PCI_ERR_BITS;
80}
81
82#if (defined(mpc8240) || defined(mpc8245))
83/* FIXME - this should really be in a separate file - the 2100 doesn't
84 *         have a raven chip so there is no point having 2100 code here
85 */
86
87extern unsigned int EUMBBAR;
88
89void detect_host_bridge()
90{
91  /*
92   * If the processor is an 8240 or an 8245 then the PIC is built
93   * in instead of being on the PCI bus. The MVME2100 is using Processor
94   * Address Map B (CHRP) although the Programmer's Reference Guide says
95   * it defaults to Map A.
96   */
97  /* We have an EPIC Interrupt Controller  */
98  OpenPIC = (volatile struct OpenPIC *) (EUMBBAR + BSP_OPEN_PIC_BASE_OFFSET);
99  pci.pci_functions = &pci_indirect_functions;
100  pci.pci_config_addr = (volatile unsigned char *) 0xfec00000;
101  pci.pci_config_data = (volatile unsigned char *) 0xfee00000;
102}
103
104#else
105
106#if 0
107/* Unfortunately, PCI config space access to empty slots generates
108 * a 'signalled master abort' condition --> we can't really use
109 * the machine check interrupt for memory probing unless
110 * we use probing for PCI scanning also (which would make
111 * all that code either BSP dependent or requiring yet another
112 * API, sigh...).
113 * So for the moment, we just don't use MCP on all mvme2xxx
114 * boards (using the generic, hostbridge-independent 'clear'
115 * implementation above).
116 */
117/*
118 * enableMCP: whether to enable MCP checkstop / machine check interrupts
119 *            on the hostbridge and in HID0.
120 *
121 *            NOTE: HID0 and MEREN are left alone if this flag is 0
122 *
123 * quiet    : be silent
124 *
125 * RETURNS  : raven MERST register contents (lowermost 16 bits), 0 if
126 *            there were no errors
127 */
128unsigned long
129_BSP_clear_hostbridge_errors(int enableMCP, int quiet)
130{
131unsigned merst;
132
133    merst = in_be32(RAVEN_MPIC_MERST);
134    /* write back value to clear status */
135    out_be32(RAVEN_MPIC_MERST, merst);
136
137    if (enableMCP) {
138      if (!quiet)
139        printk("Enabling MCP generation on hostbridge errors\n");
140      out_be32(RAVEN_MPIC_MEREN, MEREN_VAL);
141    } else {
142      out_be32(RAVEN_MPIC_MEREN, 0);
143      if ( !quiet && enableMCP ) {
144        printk("leaving MCP interrupt disabled\n");
145      }
146    }
147    return (merst & 0xffff);
148}
149#endif
150
151void detect_host_bridge()
152{
153  PPC_DEVICE *hostbridge;
154  uint32_t id0;
155  uint32_t tmp;
156
157  /*
158   * This code assumes that the host bridge is located at
159   * bus 0, dev 0, func 0 AND that the old pre PCI 2.1
160   * standart devices detection mecahnism that was used on PC
161   * (still used in BSD source code) works.
162   */
163  hostbridge=residual_find_device(&residualCopy, PROCESSORDEVICE, NULL,
164                                  BridgeController,
165                                  PCIBridge, -1, 0);
166  if (hostbridge) {
167    if (hostbridge->DeviceId.Interface==PCIBridgeIndirect) {
168      pci.pci_functions=&pci_indirect_functions;
169      /* Should be extracted from residual data,
170       * indeed MPC106 in CHRP mode is different,
171       * but we should not use residual data in
172       * this case anyway.
173       */
174      pci.pci_config_addr = ((volatile unsigned char *)
175                              (ptr_mem_map->io_base+0xcf8));
176      pci.pci_config_data = ptr_mem_map->io_base+0xcfc;
177    } else if(hostbridge->DeviceId.Interface==PCIBridgeDirect) {
178      pci.pci_functions=&pci_direct_functions;
179      pci.pci_config_data=(unsigned char *) 0x80800000;
180    } else {
181    }
182  } else {
183    /* Let us try by experimentation at our own risk! */
184    pci.pci_functions = &pci_direct_functions;
185    /* On all direct bridges I know the host bridge itself
186     * appears as device 0 function 0.
187                 */
188    pci_read_config_dword(0, 0, 0, PCI_VENDOR_ID, &id0);
189    if (id0==~0U) {
190      pci.pci_functions = &pci_indirect_functions;
191      pci.pci_config_addr = ((volatile unsigned char*)
192                              (ptr_mem_map->io_base+0xcf8));
193      pci.pci_config_data = ((volatile unsigned char*)ptr_mem_map->io_base+0xcfc);
194    }
195    /* Here we should check that the host bridge is actually
196     * present, but if it not, we are in such a desperate
197     * situation, that we probably can't even tell it.
198     */
199  }
200  pci_read_config_dword(0, 0, 0, 0, &id0);
201#ifdef SHOW_RAVEN_SETTINGS
202  printk("idreg 0 = 0x%x\n",id0);
203#endif
204  if((id0 == PCI_VENDOR_ID_MOTOROLA +
205      (PCI_DEVICE_ID_MOTOROLA_RAVEN<<16)) ||
206     (id0 == PCI_VENDOR_ID_MOTOROLA +
207      (PCI_DEVICE_ID_MOTOROLA_HAWK<<16))) {
208    /*
209     * We have a Raven bridge. We will get information about its settings
210     */
211    pci_read_config_dword(0, 0, 0, PCI_COMMAND, &id0);
212#ifdef SHOW_RAVEN_SETTING
213    printk("RAVEN PCI command register = %x\n",id0);
214#endif
215    id0 |= RAVEN_CLEAR_EVENTS_MASK;
216    pci_write_config_dword(0, 0, 0, PCI_COMMAND, id0);
217    pci_read_config_dword(0, 0, 0, PCI_COMMAND, &id0);
218#ifdef SHOW_RAVEN_SETTING
219    printk("After error clearing RAVEN PCI command register = %x\n",id0);
220#endif
221
222    if (id0 & RAVEN_MPIC_IOSPACE_ENABLE) {
223      pci_read_config_dword(0, 0, 0,PCI_BASE_ADDRESS_0, &tmp);
224#ifdef SHOW_RAVEN_SETTING
225      printk("Raven MPIC is accessed via IO Space Access at address : %x\n",(tmp & ~0x1));
226#endif
227    }
228    if (id0 & RAVEN_MPIC_MEMSPACE_ENABLE) {
229      pci_read_config_dword(0, 0, 0,PCI_BASE_ADDRESS_1, &tmp);
230#ifdef SHOW_RAVEN_SETTING
231      printk("Raven MPIC is accessed via memory Space Access at address : %x\n", tmp);
232#endif
233      OpenPIC=(volatile struct OpenPIC *) (tmp + PREP_ISA_MEM_BASE);
234      printk("OpenPIC found at %x.\n", OpenPIC);
235    }
236  }
237  if (OpenPIC == (volatile struct OpenPIC *)0) {
238    BSP_panic("OpenPic Not found\n");
239  }
240
241}
242
243#endif
Note: See TracBrowser for help on using the repository browser.