1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/kernel.h>
14#include <linux/types.h>
15#include <linux/init.h>
16#include <linux/mm.h>
17#include <linux/slab.h>
18#include <linux/jiffies.h>
19
20#include <asm/swift.h>
21#include <asm/io.h>
22
23#include <linux/ctype.h>
24#include <linux/pci.h>
25#include <linux/time.h>
26#include <linux/timex.h>
27#include <linux/interrupt.h>
28
29#include <asm/irq.h>
30#include <asm/oplib.h>
31#include <asm/prom.h>
32#include <asm/pcic.h>
33#include <asm/timer.h>
34#include <asm/uaccess.h>
35#include <asm/irq_regs.h>
36
37#include "irq.h"
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54struct pcic_ca2irq {
55 unsigned char busno;
56 unsigned char devfn;
57 unsigned char pin;
58 unsigned char irq;
59 unsigned int force;
60};
61
62struct pcic_sn2list {
63 char *sysname;
64 struct pcic_ca2irq *intmap;
65 int mapdim;
66};
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87static struct pcic_ca2irq pcic_i_je1a[] = {
88 { 0, 0x00, 2, 12, 0 },
89 { 0, 0x01, 1, 6, 1 },
90 { 0, 0x80, 0, 7, 0 },
91};
92
93
94static struct pcic_ca2irq pcic_i_jse[] = {
95 { 0, 0x00, 0, 13, 0 },
96 { 0, 0x01, 1, 6, 0 },
97 { 0, 0x08, 2, 9, 0 },
98 { 0, 0x10, 6, 8, 0 },
99 { 0, 0x18, 7, 12, 0 },
100 { 0, 0x38, 4, 9, 0 },
101 { 0, 0x80, 5, 11, 0 },
102
103 { 0, 0xA0, 4, 9, 0 },
104
105
106
107
108
109
110
111};
112
113
114
115
116static struct pcic_ca2irq pcic_i_se6[] = {
117 { 0, 0x08, 0, 2, 0 },
118 { 0, 0x01, 1, 6, 0 },
119 { 0, 0x00, 3, 13, 0 },
120};
121
122
123
124
125
126
127
128
129
130
131
132
133
134static struct pcic_ca2irq pcic_i_jk[] = {
135 { 0, 0x00, 0, 13, 0 },
136 { 0, 0x01, 1, 6, 0 },
137};
138
139
140
141
142
143#define SN2L_INIT(name, map) \
144 { name, map, ARRAY_SIZE(map) }
145
146static struct pcic_sn2list pcic_known_sysnames[] = {
147 SN2L_INIT("SUNW,JavaEngine1", pcic_i_je1a),
148 SN2L_INIT("SUNW,JS-E", pcic_i_jse),
149 SN2L_INIT("SUNW,SPARCengine-6", pcic_i_se6),
150 SN2L_INIT("SUNW,JS-NC", pcic_i_jk),
151 SN2L_INIT("SUNW,JSIIep", pcic_i_jk),
152 { NULL, NULL, 0 }
153};
154
155
156
157
158
159static int pcic0_up;
160static struct linux_pcic pcic0;
161
162void __iomem *pcic_regs;
163volatile int pcic_speculative;
164volatile int pcic_trapped;
165
166static void pci_do_gettimeofday(struct timeval *tv);
167static int pci_do_settimeofday(struct timespec *tv);
168
169#define CONFIG_CMD(bus, device_fn, where) (0x80000000 | (((unsigned int)bus) << 16) | (((unsigned int)device_fn) << 8) | (where & ~3))
170
171static int pcic_read_config_dword(unsigned int busno, unsigned int devfn,
172 int where, u32 *value)
173{
174 struct linux_pcic *pcic;
175 unsigned long flags;
176
177 pcic = &pcic0;
178
179 local_irq_save(flags);
180#if 0
181 pcic_speculative = 1;
182 pcic_trapped = 0;
183#endif
184 writel(CONFIG_CMD(busno, devfn, where), pcic->pcic_config_space_addr);
185#if 0
186 nop();
187 if (pcic_trapped) {
188 local_irq_restore(flags);
189 *value = ~0;
190 return 0;
191 }
192#endif
193 pcic_speculative = 2;
194 pcic_trapped = 0;
195 *value = readl(pcic->pcic_config_space_data + (where&4));
196 nop();
197 if (pcic_trapped) {
198 pcic_speculative = 0;
199 local_irq_restore(flags);
200 *value = ~0;
201 return 0;
202 }
203 pcic_speculative = 0;
204 local_irq_restore(flags);
205 return 0;
206}
207
208static int pcic_read_config(struct pci_bus *bus, unsigned int devfn,
209 int where, int size, u32 *val)
210{
211 unsigned int v;
212
213 if (bus->number != 0) return -EINVAL;
214 switch (size) {
215 case 1:
216 pcic_read_config_dword(bus->number, devfn, where&~3, &v);
217 *val = 0xff & (v >> (8*(where & 3)));
218 return 0;
219 case 2:
220 if (where&1) return -EINVAL;
221 pcic_read_config_dword(bus->number, devfn, where&~3, &v);
222 *val = 0xffff & (v >> (8*(where & 3)));
223 return 0;
224 case 4:
225 if (where&3) return -EINVAL;
226 pcic_read_config_dword(bus->number, devfn, where&~3, val);
227 return 0;
228 }
229 return -EINVAL;
230}
231
232static int pcic_write_config_dword(unsigned int busno, unsigned int devfn,
233 int where, u32 value)
234{
235 struct linux_pcic *pcic;
236 unsigned long flags;
237
238 pcic = &pcic0;
239
240 local_irq_save(flags);
241 writel(CONFIG_CMD(busno, devfn, where), pcic->pcic_config_space_addr);
242 writel(value, pcic->pcic_config_space_data + (where&4));
243 local_irq_restore(flags);
244 return 0;
245}
246
247static int pcic_write_config(struct pci_bus *bus, unsigned int devfn,
248 int where, int size, u32 val)
249{
250 unsigned int v;
251
252 if (bus->number != 0) return -EINVAL;
253 switch (size) {
254 case 1:
255 pcic_read_config_dword(bus->number, devfn, where&~3, &v);
256 v = (v & ~(0xff << (8*(where&3)))) |
257 ((0xff&val) << (8*(where&3)));
258 return pcic_write_config_dword(bus->number, devfn, where&~3, v);
259 case 2:
260 if (where&1) return -EINVAL;
261 pcic_read_config_dword(bus->number, devfn, where&~3, &v);
262 v = (v & ~(0xffff << (8*(where&3)))) |
263 ((0xffff&val) << (8*(where&3)));
264 return pcic_write_config_dword(bus->number, devfn, where&~3, v);
265 case 4:
266 if (where&3) return -EINVAL;
267 return pcic_write_config_dword(bus->number, devfn, where, val);
268 }
269 return -EINVAL;
270}
271
272static struct pci_ops pcic_ops = {
273 .read = pcic_read_config,
274 .write = pcic_write_config,
275};
276
277
278
279
280
281
282int __init pcic_probe(void)
283{
284 struct linux_pcic *pcic;
285 struct linux_prom_registers regs[PROMREG_MAX];
286 struct linux_pbm_info* pbm;
287 char namebuf[64];
288 int node;
289 int err;
290
291 if (pcic0_up) {
292 prom_printf("PCIC: called twice!\n");
293 prom_halt();
294 }
295 pcic = &pcic0;
296
297 node = prom_getchild (prom_root_node);
298 node = prom_searchsiblings (node, "pci");
299 if (node == 0)
300 return -ENODEV;
301
302
303
304 err = prom_getproperty(node, "reg", (char*)regs, sizeof(regs));
305 if (err == 0 || err == -1) {
306 prom_printf("PCIC: Error, cannot get PCIC registers "
307 "from PROM.\n");
308 prom_halt();
309 }
310
311 pcic0_up = 1;
312
313 pcic->pcic_res_regs.name = "pcic_registers";
314 pcic->pcic_regs = ioremap(regs[0].phys_addr, regs[0].reg_size);
315 if (!pcic->pcic_regs) {
316 prom_printf("PCIC: Error, cannot map PCIC registers.\n");
317 prom_halt();
318 }
319
320 pcic->pcic_res_io.name = "pcic_io";
321 if ((pcic->pcic_io = (unsigned long)
322 ioremap(regs[1].phys_addr, 0x10000)) == 0) {
323 prom_printf("PCIC: Error, cannot map PCIC IO Base.\n");
324 prom_halt();
325 }
326
327 pcic->pcic_res_cfg_addr.name = "pcic_cfg_addr";
328 if ((pcic->pcic_config_space_addr =
329 ioremap(regs[2].phys_addr, regs[2].reg_size * 2)) == 0) {
330 prom_printf("PCIC: Error, cannot map "
331 "PCI Configuration Space Address.\n");
332 prom_halt();
333 }
334
335
336
337
338
339 pcic->pcic_res_cfg_data.name = "pcic_cfg_data";
340 if ((pcic->pcic_config_space_data =
341 ioremap(regs[3].phys_addr, regs[3].reg_size * 2)) == 0) {
342 prom_printf("PCIC: Error, cannot map "
343 "PCI Configuration Space Data.\n");
344 prom_halt();
345 }
346
347 pbm = &pcic->pbm;
348 pbm->prom_node = node;
349 prom_getstring(node, "name", namebuf, 63); namebuf[63] = 0;
350 strcpy(pbm->prom_name, namebuf);
351
352 {
353 extern volatile int t_nmi[1];
354 extern int pcic_nmi_trap_patch[1];
355
356 t_nmi[0] = pcic_nmi_trap_patch[0];
357 t_nmi[1] = pcic_nmi_trap_patch[1];
358 t_nmi[2] = pcic_nmi_trap_patch[2];
359 t_nmi[3] = pcic_nmi_trap_patch[3];
360 swift_flush_dcache();
361 pcic_regs = pcic->pcic_regs;
362 }
363
364 prom_getstring(prom_root_node, "name", namebuf, 63); namebuf[63] = 0;
365 {
366 struct pcic_sn2list *p;
367
368 for (p = pcic_known_sysnames; p->sysname != NULL; p++) {
369 if (strcmp(namebuf, p->sysname) == 0)
370 break;
371 }
372 pcic->pcic_imap = p->intmap;
373 pcic->pcic_imdim = p->mapdim;
374 }
375 if (pcic->pcic_imap == NULL) {
376
377
378
379 printk("PCIC: System %s is unknown, cannot route interrupts\n",
380 namebuf);
381 }
382
383 return 0;
384}
385
386static void __init pcic_pbm_scan_bus(struct linux_pcic *pcic)
387{
388 struct linux_pbm_info *pbm = &pcic->pbm;
389
390 pbm->pci_bus = pci_scan_bus(pbm->pci_first_busno, &pcic_ops, pbm);
391#if 0
392 pci_fill_in_pbm_cookies(pbm->pci_bus, pbm, pbm->prom_node);
393 pci_record_assignments(pbm, pbm->pci_bus);
394 pci_assign_unassigned(pbm, pbm->pci_bus);
395 pci_fixup_irq(pbm, pbm->pci_bus);
396#endif
397}
398
399
400
401
402static int __init pcic_init(void)
403{
404 struct linux_pcic *pcic;
405
406
407
408
409
410 if(!pcic0_up)
411 return 0;
412 pcic = &pcic0;
413
414
415
416
417 writeb(PCI_DVMA_CONTROL_IOTLB_DISABLE,
418 pcic->pcic_regs+PCI_DVMA_CONTROL);
419
420
421
422
423
424
425 writel(0xF0000000UL, pcic->pcic_regs+PCI_SIZE_0);
426 writel(0+PCI_BASE_ADDRESS_SPACE_MEMORY,
427 pcic->pcic_regs+PCI_BASE_ADDRESS_0);
428
429 pcic_pbm_scan_bus(pcic);
430
431 return 0;
432}
433
434int pcic_present(void)
435{
436 return pcic0_up;
437}
438
439static int __devinit pdev_to_pnode(struct linux_pbm_info *pbm,
440 struct pci_dev *pdev)
441{
442 struct linux_prom_pci_registers regs[PROMREG_MAX];
443 int err;
444 int node = prom_getchild(pbm->prom_node);
445
446 while(node) {
447 err = prom_getproperty(node, "reg",
448 (char *)®s[0], sizeof(regs));
449 if(err != 0 && err != -1) {
450 unsigned long devfn = (regs[0].which_io >> 8) & 0xff;
451 if(devfn == pdev->devfn)
452 return node;
453 }
454 node = prom_getsibling(node);
455 }
456 return 0;
457}
458
459static inline struct pcidev_cookie *pci_devcookie_alloc(void)
460{
461 return kmalloc(sizeof(struct pcidev_cookie), GFP_ATOMIC);
462}
463
464static void pcic_map_pci_device(struct linux_pcic *pcic,
465 struct pci_dev *dev, int node)
466{
467 char namebuf[64];
468 unsigned long address;
469 unsigned long flags;
470 int j;
471
472 if (node == 0 || node == -1) {
473 strcpy(namebuf, "???");
474 } else {
475 prom_getstring(node, "name", namebuf, 63); namebuf[63] = 0;
476 }
477
478 for (j = 0; j < 6; j++) {
479 address = dev->resource[j].start;
480 if (address == 0) break;
481 flags = dev->resource[j].flags;
482 if ((flags & IORESOURCE_IO) != 0) {
483 if (address < 0x10000) {
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501 dev->resource[j].start =
502 pcic->pcic_io + address;
503 dev->resource[j].end = 1;
504 dev->resource[j].flags =
505 (flags & ~IORESOURCE_IO) | IORESOURCE_MEM;
506 } else {
507
508
509
510
511
512
513
514 printk("PCIC: Skipping I/O space at 0x%lx, "
515 "this will Oops if a driver attaches "
516 "device '%s' at %02x:%02x)\n", address,
517 namebuf, dev->bus->number, dev->devfn);
518 }
519 }
520 }
521}
522
523static void
524pcic_fill_irq(struct linux_pcic *pcic, struct pci_dev *dev, int node)
525{
526 struct pcic_ca2irq *p;
527 int i, ivec;
528 char namebuf[64];
529
530 if (node == 0 || node == -1) {
531 strcpy(namebuf, "???");
532 } else {
533 prom_getstring(node, "name", namebuf, sizeof(namebuf));
534 }
535
536 if ((p = pcic->pcic_imap) == 0) {
537 dev->irq = 0;
538 return;
539 }
540 for (i = 0; i < pcic->pcic_imdim; i++) {
541 if (p->busno == dev->bus->number && p->devfn == dev->devfn)
542 break;
543 p++;
544 }
545 if (i >= pcic->pcic_imdim) {
546 printk("PCIC: device %s devfn %02x:%02x not found in %d\n",
547 namebuf, dev->bus->number, dev->devfn, pcic->pcic_imdim);
548 dev->irq = 0;
549 return;
550 }
551
552 i = p->pin;
553 if (i >= 0 && i < 4) {
554 ivec = readw(pcic->pcic_regs+PCI_INT_SELECT_LO);
555 dev->irq = ivec >> (i << 2) & 0xF;
556 } else if (i >= 4 && i < 8) {
557 ivec = readw(pcic->pcic_regs+PCI_INT_SELECT_HI);
558 dev->irq = ivec >> ((i-4) << 2) & 0xF;
559 } else {
560 printk("PCIC: BAD PIN %d\n", i); for (;;) {}
561 }
562
563
564
565
566
567
568 if (dev->irq == 0 || p->force) {
569 if (p->irq == 0 || p->irq >= 15) {
570 printk("PCIC: BAD IRQ %d\n", p->irq); for (;;) {}
571 }
572 printk("PCIC: setting irq %d at pin %d for device %02x:%02x\n",
573 p->irq, p->pin, dev->bus->number, dev->devfn);
574 dev->irq = p->irq;
575
576 i = p->pin;
577 if (i >= 4) {
578 ivec = readw(pcic->pcic_regs+PCI_INT_SELECT_HI);
579 ivec &= ~(0xF << ((i - 4) << 2));
580 ivec |= p->irq << ((i - 4) << 2);
581 writew(ivec, pcic->pcic_regs+PCI_INT_SELECT_HI);
582 } else {
583 ivec = readw(pcic->pcic_regs+PCI_INT_SELECT_LO);
584 ivec &= ~(0xF << (i << 2));
585 ivec |= p->irq << (i << 2);
586 writew(ivec, pcic->pcic_regs+PCI_INT_SELECT_LO);
587 }
588 }
589
590 return;
591}
592
593
594
595
596void __devinit pcibios_fixup_bus(struct pci_bus *bus)
597{
598 struct pci_dev *dev;
599 int i, has_io, has_mem;
600 unsigned int cmd;
601 struct linux_pcic *pcic;
602
603 int node;
604 struct pcidev_cookie *pcp;
605
606 if (!pcic0_up) {
607 printk("pcibios_fixup_bus: no PCIC\n");
608 return;
609 }
610 pcic = &pcic0;
611
612
613
614
615 if (bus->number != 0) {
616 printk("pcibios_fixup_bus: nonzero bus 0x%x\n", bus->number);
617 return;
618 }
619
620 list_for_each_entry(dev, &bus->devices, bus_list) {
621
622
623
624
625
626
627
628
629
630 has_io = has_mem = 0;
631 for(i=0; i<6; i++) {
632 unsigned long f = dev->resource[i].flags;
633 if (f & IORESOURCE_IO) {
634 has_io = 1;
635 } else if (f & IORESOURCE_MEM)
636 has_mem = 1;
637 }
638 pcic_read_config(dev->bus, dev->devfn, PCI_COMMAND, 2, &cmd);
639 if (has_io && !(cmd & PCI_COMMAND_IO)) {
640 printk("PCIC: Enabling I/O for device %02x:%02x\n",
641 dev->bus->number, dev->devfn);
642 cmd |= PCI_COMMAND_IO;
643 pcic_write_config(dev->bus, dev->devfn,
644 PCI_COMMAND, 2, cmd);
645 }
646 if (has_mem && !(cmd & PCI_COMMAND_MEMORY)) {
647 printk("PCIC: Enabling memory for device %02x:%02x\n",
648 dev->bus->number, dev->devfn);
649 cmd |= PCI_COMMAND_MEMORY;
650 pcic_write_config(dev->bus, dev->devfn,
651 PCI_COMMAND, 2, cmd);
652 }
653
654 node = pdev_to_pnode(&pcic->pbm, dev);
655 if(node == 0)
656 node = -1;
657
658
659 pcp = pci_devcookie_alloc();
660 pcp->pbm = &pcic->pbm;
661 pcp->prom_node = of_find_node_by_phandle(node);
662 dev->sysdata = pcp;
663
664
665 if ((dev->class>>16) != PCI_BASE_CLASS_BRIDGE)
666 pcic_map_pci_device(pcic, dev, node);
667
668 pcic_fill_irq(pcic, dev, node);
669 }
670}
671
672
673
674
675unsigned int
676pcic_pin_to_irq(unsigned int pin, const char *name)
677{
678 struct linux_pcic *pcic = &pcic0;
679 unsigned int irq;
680 unsigned int ivec;
681
682 if (pin < 4) {
683 ivec = readw(pcic->pcic_regs+PCI_INT_SELECT_LO);
684 irq = ivec >> (pin << 2) & 0xF;
685 } else if (pin < 8) {
686 ivec = readw(pcic->pcic_regs+PCI_INT_SELECT_HI);
687 irq = ivec >> ((pin-4) << 2) & 0xF;
688 } else {
689 printk("PCIC: BAD PIN %d FOR %s\n", pin, name);
690 for (;;) {}
691 }
692
693 return irq;
694}
695
696
697static volatile int pcic_timer_dummy;
698
699static void pcic_clear_clock_irq(void)
700{
701 pcic_timer_dummy = readl(pcic0.pcic_regs+PCI_SYS_LIMIT);
702}
703
704static irqreturn_t pcic_timer_handler (int irq, void *h)
705{
706 write_seqlock(&xtime_lock);
707 pcic_clear_clock_irq();
708 do_timer(1);
709 write_sequnlock(&xtime_lock);
710#ifndef CONFIG_SMP
711 update_process_times(user_mode(get_irq_regs()));
712#endif
713 return IRQ_HANDLED;
714}
715
716#define USECS_PER_JIFFY 10000
717#define TICK_TIMER_LIMIT ((100*1000000/4)/100)
718
719void __init pci_time_init(void)
720{
721 struct linux_pcic *pcic = &pcic0;
722 unsigned long v;
723 int timer_irq, irq;
724
725
726
727 ((unsigned int *)do_gettimeofday)[0] =
728 0x10800000 | ((((unsigned long)pci_do_gettimeofday -
729 (unsigned long)do_gettimeofday) >> 2) & 0x003fffff);
730 ((unsigned int *)do_gettimeofday)[1] = 0x01000000;
731 BTFIXUPSET_CALL(bus_do_settimeofday, pci_do_settimeofday, BTFIXUPCALL_NORM);
732 btfixup();
733
734 writel (TICK_TIMER_LIMIT, pcic->pcic_regs+PCI_SYS_LIMIT);
735
736 v = readb(pcic->pcic_regs+PCI_COUNTER_IRQ);
737 timer_irq = PCI_COUNTER_IRQ_SYS(v);
738 writel (PCI_COUNTER_IRQ_SET(timer_irq, 0),
739 pcic->pcic_regs+PCI_COUNTER_IRQ);
740 irq = request_irq(timer_irq, pcic_timer_handler,
741 (IRQF_DISABLED | SA_STATIC_ALLOC), "timer", NULL);
742 if (irq) {
743 prom_printf("time_init: unable to attach IRQ%d\n", timer_irq);
744 prom_halt();
745 }
746 local_irq_enable();
747}
748
749static inline unsigned long do_gettimeoffset(void)
750{
751
752
753
754
755 unsigned long count =
756 readl(pcic0.pcic_regs+PCI_SYS_COUNTER) & ~PCI_SYS_COUNTER_OVERFLOW;
757 count = ((count/100)*USECS_PER_JIFFY) / (TICK_TIMER_LIMIT/100);
758 return count;
759}
760
761static void pci_do_gettimeofday(struct timeval *tv)
762{
763 unsigned long flags;
764 unsigned long seq;
765 unsigned long usec, sec;
766 unsigned long max_ntp_tick = tick_usec - tickadj;
767
768 do {
769 seq = read_seqbegin_irqsave(&xtime_lock, flags);
770 usec = do_gettimeoffset();
771
772
773
774
775
776
777 if (unlikely(time_adjust < 0))
778 usec = min(usec, max_ntp_tick);
779
780 sec = xtime.tv_sec;
781 usec += (xtime.tv_nsec / 1000);
782 } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
783
784 while (usec >= 1000000) {
785 usec -= 1000000;
786 sec++;
787 }
788
789 tv->tv_sec = sec;
790 tv->tv_usec = usec;
791}
792
793static int pci_do_settimeofday(struct timespec *tv)
794{
795 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
796 return -EINVAL;
797
798
799
800
801
802
803
804 tv->tv_nsec -= 1000 * do_gettimeoffset();
805 while (tv->tv_nsec < 0) {
806 tv->tv_nsec += NSEC_PER_SEC;
807 tv->tv_sec--;
808 }
809
810 wall_to_monotonic.tv_sec += xtime.tv_sec - tv->tv_sec;
811 wall_to_monotonic.tv_nsec += xtime.tv_nsec - tv->tv_nsec;
812
813 if (wall_to_monotonic.tv_nsec > NSEC_PER_SEC) {
814 wall_to_monotonic.tv_nsec -= NSEC_PER_SEC;
815 wall_to_monotonic.tv_sec++;
816 }
817 if (wall_to_monotonic.tv_nsec < 0) {
818 wall_to_monotonic.tv_nsec += NSEC_PER_SEC;
819 wall_to_monotonic.tv_sec--;
820 }
821
822 xtime.tv_sec = tv->tv_sec;
823 xtime.tv_nsec = tv->tv_nsec;
824 ntp_clear();
825 return 0;
826}
827
828#if 0
829static void watchdog_reset() {
830 writeb(0, pcic->pcic_regs+PCI_SYS_STATUS);
831}
832#endif
833
834
835
836
837char * __devinit pcibios_setup(char *str)
838{
839 return str;
840}
841
842void pcibios_align_resource(void *data, struct resource *res,
843 resource_size_t size, resource_size_t align)
844{
845}
846
847int pcibios_enable_device(struct pci_dev *pdev, int mask)
848{
849 return 0;
850}
851
852
853
854
855void pcic_nmi(unsigned int pend, struct pt_regs *regs)
856{
857
858 pend = flip_dword(pend);
859
860 if (!pcic_speculative || (pend & PCI_SYS_INT_PENDING_PIO) == 0) {
861
862
863
864
865 printk("Aiee, NMI pend 0x%x pc 0x%x spec %d, hanging\n",
866 pend, (int)regs->pc, pcic_speculative);
867 for (;;) { }
868 }
869 pcic_speculative = 0;
870 pcic_trapped = 1;
871 regs->pc = regs->npc;
872 regs->npc += 4;
873}
874
875static inline unsigned long get_irqmask(int irq_nr)
876{
877 return 1 << irq_nr;
878}
879
880static void pcic_disable_irq(unsigned int irq_nr)
881{
882 unsigned long mask, flags;
883
884 mask = get_irqmask(irq_nr);
885 local_irq_save(flags);
886 writel(mask, pcic0.pcic_regs+PCI_SYS_INT_TARGET_MASK_SET);
887 local_irq_restore(flags);
888}
889
890static void pcic_enable_irq(unsigned int irq_nr)
891{
892 unsigned long mask, flags;
893
894 mask = get_irqmask(irq_nr);
895 local_irq_save(flags);
896 writel(mask, pcic0.pcic_regs+PCI_SYS_INT_TARGET_MASK_CLEAR);
897 local_irq_restore(flags);
898}
899
900static void pcic_load_profile_irq(int cpu, unsigned int limit)
901{
902 printk("PCIC: unimplemented code: FILE=%s LINE=%d", __FILE__, __LINE__);
903}
904
905
906
907
908static void pcic_disable_pil_irq(unsigned int pil)
909{
910 writel(get_irqmask(pil), pcic0.pcic_regs+PCI_SYS_INT_TARGET_MASK_SET);
911}
912
913static void pcic_enable_pil_irq(unsigned int pil)
914{
915 writel(get_irqmask(pil), pcic0.pcic_regs+PCI_SYS_INT_TARGET_MASK_CLEAR);
916}
917
918void __init sun4m_pci_init_IRQ(void)
919{
920 BTFIXUPSET_CALL(enable_irq, pcic_enable_irq, BTFIXUPCALL_NORM);
921 BTFIXUPSET_CALL(disable_irq, pcic_disable_irq, BTFIXUPCALL_NORM);
922 BTFIXUPSET_CALL(enable_pil_irq, pcic_enable_pil_irq, BTFIXUPCALL_NORM);
923 BTFIXUPSET_CALL(disable_pil_irq, pcic_disable_pil_irq, BTFIXUPCALL_NORM);
924 BTFIXUPSET_CALL(clear_clock_irq, pcic_clear_clock_irq, BTFIXUPCALL_NORM);
925 BTFIXUPSET_CALL(load_profile_irq, pcic_load_profile_irq, BTFIXUPCALL_NORM);
926}
927
928int pcibios_assign_resource(struct pci_dev *pdev, int resource)
929{
930 return -ENXIO;
931}
932
933struct device_node *pci_device_to_OF_node(struct pci_dev *pdev)
934{
935 struct pcidev_cookie *pc = pdev->sysdata;
936
937 return pc->prom_node;
938}
939EXPORT_SYMBOL(pci_device_to_OF_node);
940
941
942
943
944
945
946
947
948
949
950void outsb(unsigned long addr, const void *src, unsigned long count)
951{
952 while (count) {
953 count -= 1;
954 outb(*(const char *)src, addr);
955 src += 1;
956
957 }
958}
959EXPORT_SYMBOL(outsb);
960
961void outsw(unsigned long addr, const void *src, unsigned long count)
962{
963 while (count) {
964 count -= 2;
965 outw(*(const short *)src, addr);
966 src += 2;
967
968 }
969}
970EXPORT_SYMBOL(outsw);
971
972void outsl(unsigned long addr, const void *src, unsigned long count)
973{
974 while (count) {
975 count -= 4;
976 outl(*(const long *)src, addr);
977 src += 4;
978
979 }
980}
981EXPORT_SYMBOL(outsl);
982
983void insb(unsigned long addr, void *dst, unsigned long count)
984{
985 while (count) {
986 count -= 1;
987 *(unsigned char *)dst = inb(addr);
988 dst += 1;
989
990 }
991}
992EXPORT_SYMBOL(insb);
993
994void insw(unsigned long addr, void *dst, unsigned long count)
995{
996 while (count) {
997 count -= 2;
998 *(unsigned short *)dst = inw(addr);
999 dst += 2;
1000
1001 }
1002}
1003EXPORT_SYMBOL(insw);
1004
1005void insl(unsigned long addr, void *dst, unsigned long count)
1006{
1007 while (count) {
1008 count -= 4;
1009
1010
1011
1012 *(unsigned long *)dst = inl(addr);
1013 dst += 4;
1014
1015 }
1016}
1017EXPORT_SYMBOL(insl);
1018
1019subsys_initcall(pcic_init);
1020