blob: a8febff02aad29ae0ebaaf39282e609ab7faf13b [file] [log] [blame]
stroese256e4be2004-12-16 17:33:38 +00001/*
2 * (C) Copyright 2003 Stefan Roese, stefan.roese@esd-electronics.com
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23#include <common.h>
24#include <command.h>
25#include <malloc.h>
26#include <asm/io.h>
27#include <pci.h>
28
29#include <universe.h>
30
stroese256e4be2004-12-16 17:33:38 +000031#if (CONFIG_COMMANDS & CFG_CMD_UNIVERSE)
32
stroese256e4be2004-12-16 17:33:38 +000033#define PCI_VENDOR PCI_VENDOR_ID_TUNDRA
34#define PCI_DEVICE PCI_DEVICE_ID_TUNDRA_CA91C042
35
36
37typedef struct _UNI_DEV UNI_DEV;
38
39struct _UNI_DEV {
40 int bus;
41 pci_dev_t busdevfn;
42 UNIVERSE *uregs;
43 unsigned int pci_bs;
44};
45
46static UNI_DEV *dev;
47
48
49int universe_init(void)
50{
51 int j, result, lastError = 0;
52 pci_dev_t busdevfn;
53 unsigned int val;
54
55 busdevfn = pci_find_device(PCI_VENDOR, PCI_DEVICE, 0);
56 if (busdevfn == -1) {
57 puts("No Tundra Universe found!\n");
58 return -1;
59 }
60
61 /* Lets turn Latency off */
62 pci_write_config_dword(busdevfn, 0x0c, 0);
63
64 dev = malloc(sizeof(*dev));
65 if (NULL == dev) {
66 puts("UNIVERSE: No memory!\n");
67 result = -1;
68 goto break_20;
69 }
70
71 memset(dev, 0, sizeof(*dev));
72 dev->busdevfn = busdevfn;
73
74 pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_1, &val);
75 val &= ~0xf;
76 dev->uregs = (UNIVERSE *)val;
77
wdenke2ffd592004-12-31 09:32:47 +000078 debug ("UNIVERSE-Base : %p\n", dev->uregs);
stroese256e4be2004-12-16 17:33:38 +000079
80 /* check mapping */
wdenke2ffd592004-12-31 09:32:47 +000081 debug (" Read via mapping, PCI_ID = %08X\n", readl(&dev->uregs->pci_id));
stroese256e4be2004-12-16 17:33:38 +000082 if (((PCI_DEVICE <<16) | PCI_VENDOR) != readl(&dev->uregs->pci_id)) {
wdenke2ffd592004-12-31 09:32:47 +000083 printf ("UNIVERSE: Cannot read PCI-ID via Mapping: %08x\n",
84 readl(&dev->uregs->pci_id));
stroese256e4be2004-12-16 17:33:38 +000085 result = -1;
86 goto break_30;
87 }
88
wdenke2ffd592004-12-31 09:32:47 +000089 debug ("PCI_BS = %08X\n", readl(&dev->uregs->pci_bs));
stroese256e4be2004-12-16 17:33:38 +000090
91 dev->pci_bs = readl(&dev->uregs->pci_bs);
92
93 /* turn off windows */
94 for (j=0; j <4; j ++) {
95 writel(0x00800000, &dev->uregs->lsi[j].ctl);
96 writel(0x00800000, &dev->uregs->vsi[j].ctl);
97 }
98
99 /*
100 * Write to Misc Register
101 * Set VME Bus Time-out
102 * Arbitration Mode
103 * DTACK Enable
104 */
105 writel(0x15060000, &dev->uregs->misc_ctl);
106
107 /*
108 * Lets turn off interrupts
109 */
110 writel(0x00000000,&dev->uregs->lint_en); /* Disable interrupts in the Universe first */
111 writel(0x0000FFFF,&dev->uregs->lint_stat); /* Clear Any Pending Interrupts */
112 eieio();
113 writel(0x0000, &dev->uregs->lint_map0); /* Map all ints to 0 */
114 writel(0x0000, &dev->uregs->lint_map1); /* Map all ints to 0 */
115 eieio();
116
117 break_30:
118 free(dev);
119 break_20:
120 lastError = result;
121
122 return 0;
123}
124
125
126/*
127 * Create pci slave window (access: pci -> vme)
128 */
129int universe_pci_slave_window(unsigned int pciAddr, unsigned int vmeAddr, int size, int vam, int pms, int vdw)
130{
131 int result, i;
132 unsigned int ctl = 0;
133
134 if (NULL == dev) {
135 result = -1;
136 goto exit_10;
137 }
138
139 for (i = 0; i < 4; i++) {
140 if (0x00800000 == readl(&dev->uregs->lsi[i].ctl))
141 break;
142 }
143
144 if (i == 4) {
wdenke2ffd592004-12-31 09:32:47 +0000145 printf ("universe: No Image available\n");
stroese256e4be2004-12-16 17:33:38 +0000146 result = -1;
147 goto exit_10;
148 }
149
wdenke2ffd592004-12-31 09:32:47 +0000150 debug ("universe: Using image %d\n", i);
stroese256e4be2004-12-16 17:33:38 +0000151
152 writel(pciAddr , &dev->uregs->lsi[i].bs);
153 writel((pciAddr + size), &dev->uregs->lsi[i].bd);
154 writel((vmeAddr - pciAddr), &dev->uregs->lsi[i].to);
155
156 switch (vam & VME_AM_Axx) {
157 case VME_AM_A16:
158 ctl = 0x00000000;
159 break;
160 case VME_AM_A24:
161 ctl = 0x00010000;
162 break;
163 case VME_AM_A32:
164 ctl = 0x00020000;
165 break;
166 }
167
168 switch (vam & VME_AM_Mxx) {
169 case VME_AM_DATA:
170 ctl |= 0x00000000;
171 break;
172 case VME_AM_PROG:
173 ctl |= 0x00008000;
174 break;
175 }
176
177 if (vam & VME_AM_SUP) {
178 ctl |= 0x00001000;
179
180 }
181
182 switch (vdw & VME_FLAG_Dxx) {
183 case VME_FLAG_D8:
184 ctl |= 0x00000000;
185 break;
186 case VME_FLAG_D16:
187 ctl |= 0x00400000;
188 break;
189 case VME_FLAG_D32:
190 ctl |= 0x00800000;
191 break;
192 }
193
194 switch (pms & PCI_MS_Mxx) {
195 case PCI_MS_MEM:
196 ctl = 0x00000000;
197 break;
198 case PCI_MS_IO:
199 ctl = 0x00000001;
200 break;
201 case PCI_MS_CONFIG:
202 ctl = 0x00000002;
203 break;
204 }
205
206 ctl |= 0x80000000; /* enable */
207
208 writel(ctl, &dev->uregs->lsi[i].ctl);
209
wdenke2ffd592004-12-31 09:32:47 +0000210 debug ("universe: window-addr=%p\n", &dev->uregs->lsi[i].ctl);
211 debug ("universe: pci slave window[%d] ctl=%08x\n", i, readl(&dev->uregs->lsi[i].ctl));
212 debug ("universe: pci slave window[%d] bs=%08x\n", i, readl(&dev->uregs->lsi[i].bs));
213 debug ("universe: pci slave window[%d] bd=%08x\n", i, readl(&dev->uregs->lsi[i].bd));
214 debug ("universe: pci slave window[%d] to=%08x\n", i, readl(&dev->uregs->lsi[i].to));
stroese256e4be2004-12-16 17:33:38 +0000215
216 return 0;
217
218 exit_10:
219 return -result;
220}
221
222
223/*
224 * Create vme slave window (access: vme -> pci)
225 */
226int universe_vme_slave_window(unsigned int vmeAddr, unsigned int pciAddr, int size, int vam, int pms)
227{
228 int result, i;
229 unsigned int ctl = 0;
230
231 if (NULL == dev) {
232 result = -1;
233 goto exit_10;
234 }
235
236 for (i = 0; i < 4; i++) {
237 if (0x00800000 == readl(&dev->uregs->vsi[i].ctl))
238 break;
239 }
240
241 if (i == 4) {
wdenke2ffd592004-12-31 09:32:47 +0000242 printf ("universe: No Image available\n");
stroese256e4be2004-12-16 17:33:38 +0000243 result = -1;
244 goto exit_10;
245 }
246
wdenke2ffd592004-12-31 09:32:47 +0000247 debug ("universe: Using image %d\n", i);
stroese256e4be2004-12-16 17:33:38 +0000248
249 writel(vmeAddr , &dev->uregs->vsi[i].bs);
250 writel((vmeAddr + size), &dev->uregs->vsi[i].bd);
251 writel((pciAddr - vmeAddr), &dev->uregs->vsi[i].to);
252
253 switch (vam & VME_AM_Axx) {
254 case VME_AM_A16:
255 ctl = 0x00000000;
256 break;
257 case VME_AM_A24:
258 ctl = 0x00010000;
259 break;
260 case VME_AM_A32:
261 ctl = 0x00020000;
262 break;
263 }
264
265 switch (vam & VME_AM_Mxx) {
266 case VME_AM_DATA:
267 ctl |= 0x00000000;
268 break;
269 case VME_AM_PROG:
270 ctl |= 0x00800000;
271 break;
272 }
273
274 if (vam & VME_AM_SUP) {
275 ctl |= 0x00100000;
276
277 }
278
279 switch (pms & PCI_MS_Mxx) {
280 case PCI_MS_MEM:
281 ctl = 0x00000000;
282 break;
283 case PCI_MS_IO:
284 ctl = 0x00000001;
285 break;
286 case PCI_MS_CONFIG:
287 ctl = 0x00000002;
288 break;
289 }
290
291 ctl |= 0x80f00000; /* enable */
292
293 writel(ctl, &dev->uregs->vsi[i].ctl);
294
wdenke2ffd592004-12-31 09:32:47 +0000295 debug ("universe: window-addr=%p\n", &dev->uregs->vsi[i].ctl);
296 debug ("universe: vme slave window[%d] ctl=%08x\n", i, readl(&dev->uregs->vsi[i].ctl));
297 debug ("universe: vme slave window[%d] bs=%08x\n", i, readl(&dev->uregs->vsi[i].bs));
298 debug ("universe: vme slave window[%d] bd=%08x\n", i, readl(&dev->uregs->vsi[i].bd));
299 debug ("universe: vme slave window[%d] to=%08x\n", i, readl(&dev->uregs->vsi[i].to));
stroese256e4be2004-12-16 17:33:38 +0000300
301 return 0;
302
303 exit_10:
304 return -result;
305}
306
307
308/*
309 * Tundra Universe configuration
310 */
311int do_universe(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
312{
313 ulong addr1 = 0, addr2 = 0, size = 0, vam = 0, pms = 0, vdw = 0;
314 char cmd = 'x';
315
316 /* get parameter */
317 if (argc > 1)
318 cmd = argv[1][0];
319 if (argc > 2)
320 addr1 = simple_strtoul(argv[2], NULL, 16);
321 if (argc > 3)
322 addr2 = simple_strtoul(argv[3], NULL, 16);
323 if (argc > 4)
324 size = simple_strtoul(argv[4], NULL, 16);
325 if (argc > 5)
326 vam = simple_strtoul(argv[5], NULL, 16);
327 if (argc > 6)
328 pms = simple_strtoul(argv[6], NULL, 16);
329 if (argc > 7)
330 vdw = simple_strtoul(argv[7], NULL, 16);
331
332 switch (cmd) {
333 case 'i': /* init */
334 universe_init();
335 break;
336 case 'v': /* vme */
337 printf("Configuring Universe VME Slave Window (VME->PCI):\n");
338 printf(" vme=%08lx pci=%08lx size=%08lx vam=%02lx pms=%02lx\n",
339 addr1, addr2, size, vam, pms);
340 universe_vme_slave_window(addr1, addr2, size, vam, pms);
341 break;
342 case 'p': /* pci */
343 printf("Configuring Universe PCI Slave Window (PCI->VME):\n");
344 printf(" pci=%08lx vme=%08lx size=%08lx vam=%02lx pms=%02lx vdw=%02lx\n",
345 addr1, addr2, size, vam, pms, vdw);
346 universe_pci_slave_window(addr1, addr2, size, vam, pms, vdw);
347 break;
348 default:
349 printf("Universe command %s not supported!\n", argv[1]);
350 }
351
352 return 0;
353}
354
355
356U_BOOT_CMD(
357 universe, 8, 1, do_universe,
358 "universe- initialize and configure Turndra Universe\n",
359 "init\n"
360 " - initialize universe\n"
361 "universe vme [vme_addr] [pci_addr] [size] [vam] [pms]\n"
362 " - create vme slave window (access: vme->pci)\n"
363 "universe pci [pci_addr] [vme_addr] [size] [vam] [pms] [vdw]\n"
364 " - create pci slave window (access: pci->vme)\n"
365 " [vam] = VMEbus Address-Modifier: 01 -> A16 Address Space\n"
366 " 02 -> A24 Address Space\n"
367 " 03 -> A32 Address Space\n"
368 " 04 -> Supervisor AM Code\n"
369 " 10 -> Data AM Code\n"
370 " 20 -> Program AM Code\n"
371 " [pms] = PCI Memory Space: 01 -> Memory Space\n"
372 " 02 -> I/O Space\n"
373 " 03 -> Configuration Space\n"
374 " [vdw] = VMEbus Maximum Datawidth: 01 -> D8 Data Width\n"
375 " 02 -> D16 Data Width\n"
376 " 03 -> D32 Data Width\n"
377);
378
379#endif /* (CONFIG_COMMANDS & CFG_CMD_UNIVERSE) */