blob: d724a5119179916c13871cc5ab846c943c89165e [file] [log] [blame]
Morgan Tsai1602dd52007-10-29 21:00:14 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Morgan Tsai1602dd52007-10-29 21:00:14 +00003 *
4 * Copyright (C) 2007 AMD
5 * Written by Yinghai Lu <yinghailu@amd.com> for AMD.
6 * Copyright (C) 2007 Silicon Integrated Systems Corp. (SiS)
7 * Written by Morgan Tsai <my_tsai@sis.com> for SiS.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
Morgan Tsai1602dd52007-10-29 21:00:14 +000018 */
19
Morgan Tsai1602dd52007-10-29 21:00:14 +000020#include <console/console.h>
21#include <device/pci.h>
22#include <string.h>
23#include <stdint.h>
24#include <arch/pirq_routing.h>
Morgan Tsai218c2652007-11-02 16:09:58 +000025#include <device/pci_ids.h>
Morgan Tsai1602dd52007-10-29 21:00:14 +000026#include <cpu/amd/amdk8_sysconf.h>
27
28static void write_pirq_info(struct irq_info *pirq_info, uint8_t bus, uint8_t devfn, uint8_t link0, uint16_t bitmap0,
29 uint8_t link1, uint16_t bitmap1, uint8_t link2, uint16_t bitmap2,uint8_t link3, uint16_t bitmap3,
30 uint8_t slot, uint8_t rfu)
31{
32 pirq_info->bus = bus;
33 pirq_info->devfn = devfn;
34 pirq_info->irq[0].link = link0;
35 pirq_info->irq[0].bitmap = bitmap0;
36 pirq_info->irq[1].link = link1;
37 pirq_info->irq[1].bitmap = bitmap1;
38 pirq_info->irq[2].link = link2;
39 pirq_info->irq[2].bitmap = bitmap2;
40 pirq_info->irq[3].link = link3;
41 pirq_info->irq[3].bitmap = bitmap3;
42 pirq_info->slot = slot;
43 pirq_info->rfu = rfu;
44}
Morgan Tsai1602dd52007-10-29 21:00:14 +000045extern unsigned char bus_sis966[8]; //1
46
47unsigned long write_pirq_routing_table(unsigned long addr)
48{
49
50 struct irq_routing_table *pirq;
51 struct irq_info *pirq_info;
52 unsigned slot_num;
53 uint8_t *v;
54 unsigned sbdn;
55
56 uint8_t sum=0;
57 int i;
58
59 get_bus_conf(); // it will find out all bus num and apic that share with mptable.c and mptable.c and acpi_tables.c
60 sbdn = sysconf.sbdn;
61
62 /* Align the table to be 16 byte aligned. */
63 addr += 15;
64 addr &= ~15;
65
Kyösti Mälkki9533d832014-06-26 05:30:54 +030066 /* This table must be between 0xf0000 & 0x100000 */
Myles Watson08e0fb82010-03-22 16:33:25 +000067 printk(BIOS_INFO, "Writing IRQ routing tables to 0x%lx...", addr);
Morgan Tsai1602dd52007-10-29 21:00:14 +000068
69 pirq = (void *)(addr);
70 v = (uint8_t *)(addr);
71
72 pirq->signature = PIRQ_SIGNATURE;
73 pirq->version = PIRQ_VERSION;
74
Morgan Tsaic8cf4ad2007-11-20 14:11:24 +000075 pirq->rtr_bus = 0;
76 pirq->rtr_devfn = PCI_DEVFN(2, 0);
Morgan Tsai1602dd52007-10-29 21:00:14 +000077
78 pirq->exclusive_irqs = 0;
79
Morgan Tsai218c2652007-11-02 16:09:58 +000080 pirq->rtr_vendor = PCI_VENDOR_ID_SIS;
Morgan Tsai31e805d2007-11-14 01:34:02 +000081 pirq->rtr_device = PCI_DEVICE_ID_SIS_SIS966_LPC;
Morgan Tsai1602dd52007-10-29 21:00:14 +000082
83 pirq->miniport_data = 0;
84
85 memset(pirq->rfu, 0, sizeof(pirq->rfu));
86
87 pirq_info = (void *) ( &pirq->checksum + 1);
88 slot_num = 0;
89
Morgan Tsaic8cf4ad2007-11-20 14:11:24 +000090 write_pirq_info(pirq_info, 0, PCI_DEVFN(2, 0), 0x1, 0xdef8, 0x2, 0xdef8, 0x3, 0xdef8, 0x4, 0xdef8, 0, 0);
91 pirq_info++; slot_num++;
92
93 pirq->size = 32 + 16 * slot_num;
94
95 for (i = 0; i < pirq->size; i++)
96 sum += v[i];
97
98 sum = pirq->checksum - sum;
99
100 if (sum != pirq->checksum) {
101 pirq->checksum = sum;
102 }
103
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000104 printk(BIOS_INFO, "done.\n");
Morgan Tsaic8cf4ad2007-11-20 14:11:24 +0000105
Morgan Tsai1602dd52007-10-29 21:00:14 +0000106 {
107 device_t dev;
108 dev = dev_find_slot(0, PCI_DEVFN(2,0));
Morgan Tsaic8cf4ad2007-11-20 14:11:24 +0000109 if (dev) {
Morgan Tsai1602dd52007-10-29 21:00:14 +0000110 /* initialize PCI interupts - these assignments depend
111 on the PCB routing of PINTA-D
112
113 PINTA = IRQ10
114 PINTB = IRQ11
Morgan Tsaic8cf4ad2007-11-20 14:11:24 +0000115 PINTC = NA
116 PINTD = IRQ10
Morgan Tsai1602dd52007-10-29 21:00:14 +0000117 PINTE = IRQ11
118 PINTF = IRQ5
Morgan Tsaic8cf4ad2007-11-20 14:11:24 +0000119 PINTG = NA
120 PINTH = IRQ7
Morgan Tsai1602dd52007-10-29 21:00:14 +0000121
122 */
Morgan Tsai1602dd52007-10-29 21:00:14 +0000123 uint8_t reg[8]={0x41,0x42,0x43,0x44,0x60,0x61,0x62,0x63};
Morgan Tsaic8cf4ad2007-11-20 14:11:24 +0000124 uint8_t irq[8]={0x0A,0X0B,0X0,0X0a,0X0B,0X05,0X0,0X07};
Morgan Tsai1602dd52007-10-29 21:00:14 +0000125
126 for(i=0;i<8;i++)
127 pci_write_config8(dev, reg[i], irq[i]);
Morgan Tsaic8cf4ad2007-11-20 14:11:24 +0000128 } // endif
Morgan Tsai1602dd52007-10-29 21:00:14 +0000129
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000130 printk(BIOS_DEBUG, "Setting Onboard SiS Southbridge\n");
Morgan Tsai218c2652007-11-02 16:09:58 +0000131
Morgan Tsai218c2652007-11-02 16:09:58 +0000132 dev = dev_find_slot(0, PCI_DEVFN(2,5)); // 5513 (IDE)
133 pci_write_config8(dev, 0x3C, 0x0A);
Morgan Tsai218c2652007-11-02 16:09:58 +0000134 dev = dev_find_slot(0, PCI_DEVFN(3,0)); // USB 1.1
Morgan Tsai1602dd52007-10-29 21:00:14 +0000135 pci_write_config8(dev, 0x3C, 0x0B);
Morgan Tsai218c2652007-11-02 16:09:58 +0000136 dev = dev_find_slot(0, PCI_DEVFN(3,1)); // USB 1.1
Morgan Tsai1602dd52007-10-29 21:00:14 +0000137 pci_write_config8(dev, 0x3C, 0x05);
138 dev = dev_find_slot(0, PCI_DEVFN(3,3)); // USB 2.0
Morgan Tsaic8cf4ad2007-11-20 14:11:24 +0000139 pci_write_config8(dev, 0x3C, 0x07);
Morgan Tsai1602dd52007-10-29 21:00:14 +0000140 dev = dev_find_slot(0, PCI_DEVFN(4,0)); // 191 (LAN)
Morgan Tsaic8cf4ad2007-11-20 14:11:24 +0000141 pci_write_config8(dev, 0x3C, 0x0A);
Morgan Tsai31e805d2007-11-14 01:34:02 +0000142 dev = dev_find_slot(0, PCI_DEVFN(5,0)); // 1183 (SATA)
Morgan Tsai1602dd52007-10-29 21:00:14 +0000143 pci_write_config8(dev, 0x3C, 0x0B);
Morgan Tsai218c2652007-11-02 16:09:58 +0000144 dev = dev_find_slot(0, PCI_DEVFN(6,0)); // PCI-E
145 pci_write_config8(dev, 0x3C, 0x0A);
146 dev = dev_find_slot(0, PCI_DEVFN(7,0)); // PCI-E
147 pci_write_config8(dev, 0x3C, 0x0A);
Morgan Tsai1602dd52007-10-29 21:00:14 +0000148 dev = dev_find_slot(0, PCI_DEVFN(15,0)); // Azalia
149 pci_write_config8(dev, 0x3C, 0x05);
Morgan Tsai1602dd52007-10-29 21:00:14 +0000150 }
151
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000152 printk(BIOS_DEBUG, "pirq routing table, size=%d\n", pirq->size);
Morgan Tsaic8cf4ad2007-11-20 14:11:24 +0000153 for (i = 0; i < pirq->size; i+=4)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000154 printk(BIOS_DEBUG, "%.2x%.2x%.2x%.2x\n", v[i+3],v[i+2],v[i+1],v[i]);
Morgan Tsai1602dd52007-10-29 21:00:14 +0000155
156 return (unsigned long) pirq_info;
157
158}