13 #include <linux/kernel.h>
14 #include <linux/types.h>
17 #include <linux/slab.h>
23 #include <linux/ctype.h>
24 #include <linux/pci.h>
25 #include <linux/time.h>
26 #include <linux/timex.h>
28 #include <linux/export.h>
31 #include <asm/oplib.h>
34 #include <asm/timex.h>
35 #include <asm/timer.h>
36 #include <asm/uaccess.h>
37 #include <asm/irq_regs.h>
90 { 0, 0x00, 2, 12, 0 },
97 { 0, 0x00, 0, 13, 0 },
100 { 0, 0x10, 6, 8, 0 },
101 { 0, 0x18, 7, 12, 0 },
102 { 0, 0x38, 4, 9, 0 },
103 { 0, 0x80, 5, 11, 0 },
105 { 0, 0xA0, 4, 9, 0 },
119 { 0, 0x08, 0, 2, 0 },
120 { 0, 0x01, 1, 6, 0 },
121 { 0, 0x00, 3, 13, 0 },
137 { 0, 0x00, 0, 13, 0 },
138 { 0, 0x01, 1, 6, 0 },
145 #define SN2L_INIT(name, map) \
146 { name, map, ARRAY_SIZE(map) }
149 SN2L_INIT(
"SUNW,JavaEngine1", pcic_i_je1a),
151 SN2L_INIT(
"SUNW,SPARCengine-6", pcic_i_se6),
170 unsigned int real_irq);
172 #define CONFIG_CMD(bus, device_fn, where) (0x80000000 | (((unsigned int)bus) << 16) | (((unsigned int)device_fn) << 8) | (where & ~3))
174 static int pcic_read_config_dword(
unsigned int busno,
unsigned int devfn,
219 pcic_read_config_dword(bus->
number, devfn, where&~3, &v);
220 *val = 0xff & (v >> (8*(where & 3)));
223 if (where&1)
return -
EINVAL;
224 pcic_read_config_dword(bus->
number, devfn, where&~3, &v);
225 *val = 0xffff & (v >> (8*(where & 3)));
228 if (where&3)
return -
EINVAL;
229 pcic_read_config_dword(bus->
number, devfn, where&~3, val);
235 static int pcic_write_config_dword(
unsigned int busno,
unsigned int devfn,
250 static int pcic_write_config(
struct pci_bus *bus,
unsigned int devfn,
251 int where,
int size,
u32 val)
258 pcic_read_config_dword(bus->
number, devfn, where&~3, &v);
259 v = (v & ~(0xff << (8*(where&3)))) |
260 ((0xff&
val) << (8*(where&3)));
261 return pcic_write_config_dword(bus->
number, devfn, where&~3, v);
263 if (where&1)
return -
EINVAL;
264 pcic_read_config_dword(bus->
number, devfn, where&~3, &v);
265 v = (v & ~(0xffff << (8*(where&3)))) |
266 ((0xffff&
val) << (8*(where&3)));
267 return pcic_write_config_dword(bus->
number, devfn, where&~3, v);
269 if (where&3)
return -
EINVAL;
270 return pcic_write_config_dword(bus->
number, devfn, where, val);
275 static struct pci_ops pcic_ops = {
276 .read = pcic_read_config,
277 .write = pcic_write_config,
308 if (err == 0 || err == -1) {
309 prom_printf(
"PCIC: Error, cannot get PCIC registers "
319 prom_printf(
"PCIC: Error, cannot map PCIC registers.\n");
324 if ((pcic->
pcic_io = (
unsigned long)
325 ioremap(regs[1].phys_addr, 0x10000)) == 0) {
326 prom_printf(
"PCIC: Error, cannot map PCIC IO Base.\n");
332 ioremap(regs[2].phys_addr, regs[2].reg_size * 2)) == 0) {
334 "PCI Configuration Space Address.\n");
344 ioremap(regs[3].phys_addr, regs[3].reg_size * 2)) == 0) {
346 "PCI Configuration Space Data.\n");
356 extern volatile int t_nmi[4];
357 extern int pcic_nmi_trap_patch[4];
359 t_nmi[0] = pcic_nmi_trap_patch[0];
360 t_nmi[1] = pcic_nmi_trap_patch[1];
361 t_nmi[2] = pcic_nmi_trap_patch[2];
362 t_nmi[3] = pcic_nmi_trap_patch[3];
363 swift_flush_dcache();
371 for (p = pcic_known_sysnames; p->
sysname !=
NULL; p++) {
382 printk(
"PCIC: System %s is unknown, cannot route interrupts\n",
396 pci_record_assignments(pbm, pbm->
pci_bus);
397 pci_assign_unassigned(pbm, pbm->
pci_bus);
398 pci_fixup_irq(pbm, pbm->
pci_bus);
405 static int __init pcic_init(
void)
432 pcic_pbm_scan_bus(pcic);
452 if(err != 0 && err != -1) {
453 unsigned long devfn = (
regs[0].which_io >> 8) & 0xff;
454 if(devfn == pdev->
devfn)
462 static inline struct pcidev_cookie *pci_devcookie_alloc(
void)
467 static void pcic_map_pci_device(
struct linux_pcic *pcic,
475 if (node == 0 || node == -1) {
481 for (j = 0; j < 6; j++) {
483 if (address == 0)
break;
486 if (address < 0x10000) {
517 printk(
"PCIC: Skipping I/O space at 0x%lx, "
518 "this will Oops if a driver attaches "
519 "device '%s' at %02x:%02x)\n", address,
520 namebuf, dev->
bus->number, dev->
devfn);
530 unsigned int real_irq;
534 if (node == 0 || node == -1) {
550 printk(
"PCIC: device %s devfn %02x:%02x not found in %d\n",
557 if (i >= 0 && i < 4) {
559 real_irq = ivec >> (i << 2) & 0xF;
560 }
else if (i >= 4 && i < 8) {
562 real_irq = ivec >> ((i-4) << 2) & 0xF;
564 printk(
"PCIC: BAD PIN %d\n", i);
for (;;) {}
571 if (real_irq == 0 || p->
force) {
572 if (p->
irq == 0 || p->
irq >= 15) {
573 printk(
"PCIC: BAD IRQ %d\n", p->
irq);
for (;;) {}
575 printk(
"PCIC: setting irq %d at pin %d for device %02x:%02x\n",
582 ivec &= ~(0xF << ((i - 4) << 2));
583 ivec |= p->
irq << ((i - 4) << 2);
587 ivec &= ~(0xF << (i << 2));
588 ivec |= p->
irq << (i << 2);
601 int i, has_io, has_mem;
609 printk(
"pcibios_fixup_bus: no PCIC\n");
618 printk(
"pcibios_fixup_bus: nonzero bus 0x%x\n", bus->
number);
632 has_io = has_mem = 0;
642 printk(
"PCIC: Enabling I/O for device %02x:%02x\n",
645 pcic_write_config(dev->
bus, dev->
devfn,
649 printk(
"PCIC: Enabling memory for device %02x:%02x\n",
652 pcic_write_config(dev->
bus, dev->
devfn,
656 node = pdev_to_pnode(&pcic->
pbm, dev);
661 pcp = pci_devcookie_alloc();
668 pcic_map_pci_device(pcic, dev, node);
670 pcic_fill_irq(pcic, dev, node);
686 irq = ivec >> (pin << 2) & 0xF;
687 }
else if (pin < 8) {
689 irq = ivec >> ((pin-4) << 2) & 0xF;
691 printk(
"PCIC: BAD PIN %d FOR %s\n", pin, name);
699 static volatile int pcic_timer_dummy;
701 static void pcic_clear_clock_irq(
void)
707 #define USECS_PER_JIFFY (1000000 / HZ)
708 #define TICK_TIMER_LIMIT ((100 * 1000000 / 4) / HZ)
710 static unsigned int pcic_cycles_offset(
void)
757 prom_printf(
"time_init: unable to attach IRQ%d\n", timer_irq);
765 static void watchdog_reset() {
787 pend = flip_dword(pend);
794 printk(
"Aiee, NMI pend 0x%x pc 0x%x spec %d, hanging\n",
800 regs->
pc = regs->
npc;
804 static inline unsigned long get_irqmask(
int irq_nr)
819 static void pcic_unmask_irq(
struct irq_data *data)
829 static unsigned int pcic_startup_irq(
struct irq_data *data)
832 pcic_unmask_irq(data);
838 .irq_startup = pcic_startup_irq,
839 .irq_mask = pcic_mask_irq,
840 .irq_unmask = pcic_unmask_irq,
844 unsigned int real_irq)
850 mask = get_irqmask(real_irq);
867 static void pcic_load_profile_irq(
int cpu,
unsigned int limit)
869 printk(
"PCIC: unimplemented code: FILE=%s LINE=%d", __FILE__, __LINE__);
892 outb(*(
const char *)src, addr);
903 outw(*(
const short *)src, addr);
914 outl(*(
const long *)src, addr);
925 *(
unsigned char *)dst =
inb(addr);
936 *(
unsigned short *)dst =
inw(addr);
950 *(
unsigned long *)dst =
inl(addr);