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