Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 4 | * Copyright (C) 2008-2009 coresystems GmbH |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 5 | * |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <device/device.h> |
| 19 | #include <device/pci.h> |
| 20 | #include <device/pci_ids.h> |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 21 | #include "i82801gx.h" |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 22 | |
| 23 | static void pci_init(struct device *dev) |
| 24 | { |
| 25 | u16 reg16; |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 26 | u8 reg8; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 27 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 28 | /* Enable Bus Master */ |
| 29 | reg16 = pci_read_config16(dev, PCI_COMMAND); |
| 30 | reg16 |= PCI_COMMAND_MASTER; |
| 31 | pci_write_config16(dev, PCI_COMMAND, reg16); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 32 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 33 | /* This device has no interrupt */ |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 34 | pci_write_config8(dev, INTR, 0xff); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 35 | |
| 36 | /* disable parity error response and SERR */ |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 37 | reg16 = pci_read_config16(dev, BCTRL); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 38 | reg16 &= ~(1 << 0); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 39 | reg16 &= ~(1 << 1); |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 40 | pci_write_config16(dev, BCTRL, reg16); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 41 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 42 | /* Master Latency Count must be set to 0x04! */ |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 43 | reg8 = pci_read_config8(dev, SMLT); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 44 | reg8 &= 0x07; |
| 45 | reg8 |= (0x04 << 3); |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 46 | pci_write_config8(dev, SMLT, reg8); |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 47 | |
| 48 | /* Will this improve throughput of bus masters? */ |
| 49 | pci_write_config8(dev, PCI_MIN_GNT, 0x06); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 50 | |
| 51 | /* Clear errors in status registers */ |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 52 | reg16 = pci_read_config16(dev, PSTS); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 53 | //reg16 |= 0xf900; |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 54 | pci_write_config16(dev, PSTS, reg16); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 55 | |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 56 | reg16 = pci_read_config16(dev, SECSTS); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 57 | // reg16 |= 0xf900; |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 58 | pci_write_config16(dev, SECSTS, reg16); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 61 | #undef PCI_BRIDGE_UPDATE_COMMAND |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 62 | static void ich_pci_dev_enable_resources(struct device *dev) |
| 63 | { |
| 64 | const struct pci_operations *ops; |
| 65 | uint16_t command; |
| 66 | |
| 67 | /* Set the subsystem vendor and device id for mainboard devices */ |
| 68 | ops = ops_pci(dev); |
| 69 | if (dev->on_mainboard && ops && ops->set_subsystem) { |
Sven Schnelle | 9132102 | 2011-03-01 19:58:47 +0000 | [diff] [blame] | 70 | printk(BIOS_DEBUG, "%s subsystem <- %04x/%04x\n", |
| 71 | dev_path(dev), dev->subsystem_vendor, |
| 72 | dev->subsystem_device); |
| 73 | ops->set_subsystem(dev, dev->subsystem_vendor, |
| 74 | dev->subsystem_device); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 77 | command = pci_read_config16(dev, PCI_COMMAND); |
| 78 | command |= dev->command; |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 79 | #ifdef PCI_BRIDGE_UPDATE_COMMAND |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 80 | /* If we write to PCI_COMMAND, on some systems |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 81 | * this will cause the ROM and APICs not being visible |
| 82 | * anymore. |
| 83 | */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 84 | printk(BIOS_DEBUG, "%s cmd <- %02x\n", dev_path(dev), command); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 85 | pci_write_config16(dev, PCI_COMMAND, command); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 86 | #else |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 87 | printk(BIOS_DEBUG, "%s cmd <- %02x (NOT WRITTEN!)\n", dev_path(dev), command); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 88 | #endif |
| 89 | } |
| 90 | |
| 91 | static void ich_pci_bus_enable_resources(struct device *dev) |
| 92 | { |
| 93 | uint16_t ctrl; |
| 94 | /* enable IO in command register if there is VGA card |
| 95 | * connected with (even it does not claim IO resource) |
| 96 | */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 97 | if (dev->link_list->bridge_ctrl & PCI_BRIDGE_CTL_VGA) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 98 | dev->command |= PCI_COMMAND_IO; |
| 99 | ctrl = pci_read_config16(dev, PCI_BRIDGE_CONTROL); |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 100 | ctrl |= dev->link_list->bridge_ctrl; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 101 | ctrl |= (PCI_BRIDGE_CTL_PARITY + PCI_BRIDGE_CTL_SERR); /* error check */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 102 | printk(BIOS_DEBUG, "%s bridge ctrl <- %04x\n", dev_path(dev), ctrl); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 103 | pci_write_config16(dev, PCI_BRIDGE_CONTROL, ctrl); |
| 104 | |
| 105 | /* This is the reason we need our own pci_bus_enable_resources */ |
| 106 | ich_pci_dev_enable_resources(dev); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | static void set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 110 | { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 111 | /* NOTE: This is not the default position! */ |
| 112 | if (!vendor || !device) { |
| 113 | pci_write_config32(dev, 0x54, |
| 114 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 115 | } else { |
| 116 | pci_write_config32(dev, 0x54, |
| 117 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 118 | } |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | static struct pci_operations pci_ops = { |
| 122 | .set_subsystem = set_subsystem, |
| 123 | }; |
| 124 | |
| 125 | static struct device_operations device_ops = { |
| 126 | .read_resources = pci_bus_read_resources, |
| 127 | .set_resources = pci_dev_set_resources, |
| 128 | .enable_resources = ich_pci_bus_enable_resources, |
| 129 | .init = pci_init, |
| 130 | .scan_bus = pci_scan_bridge, |
| 131 | .ops_pci = &pci_ops, |
| 132 | }; |
| 133 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 134 | /* Desktop */ |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 135 | /* 82801BA/CA/DB/EB/ER/FB/FR/FW/FRW/GB/GR/GDH/HB/IB/6300ESB/i3100 */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 136 | static const struct pci_driver i82801g_pci __pci_driver = { |
| 137 | .ops = &device_ops, |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 138 | .vendor = PCI_VENDOR_ID_INTEL, |
Uwe Hermann | 5d7a1c8 | 2008-10-31 18:41:09 +0000 | [diff] [blame] | 139 | .device = 0x244e, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | /* Mobile / Ultra Mobile */ |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 143 | /* 82801BAM/CAM/DBL/DBM/FBM/GBM/GHM/GU/HBM/HEM */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 144 | static const struct pci_driver i82801gmu_pci __pci_driver = { |
| 145 | .ops = &device_ops, |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 146 | .vendor = PCI_VENDOR_ID_INTEL, |
Uwe Hermann | 5d7a1c8 | 2008-10-31 18:41:09 +0000 | [diff] [blame] | 147 | .device = 0x2448, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 148 | }; |