Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 3 | * |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 2 of the License. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 12 | */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 13 | |
| 14 | #include <console/console.h> |
| 15 | #include <device/device.h> |
| 16 | #include <device/pci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 17 | #include <device/pci_ops.h> |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 18 | #include <device/pcix.h> |
| 19 | |
Elyes HAOUAS | b9e82f0 | 2018-05-02 21:29:55 +0200 | [diff] [blame] | 20 | static void pcix_tune_dev(struct device *dev) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 21 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 22 | u32 status; |
| 23 | u16 orig_cmd, cmd; |
| 24 | unsigned int cap, max_read, max_tran; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 25 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 26 | if (dev->hdr_type != PCI_HEADER_TYPE_NORMAL) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 27 | return; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 28 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 29 | cap = pci_find_capability(dev, PCI_CAP_ID_PCIX); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 30 | if (!cap) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 31 | return; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 32 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 33 | printk(BIOS_DEBUG, "%s PCI-X tuning\n", dev_path(dev)); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 34 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 35 | status = pci_read_config32(dev, cap + PCI_X_STATUS); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 36 | orig_cmd = cmd = pci_read_config16(dev, cap + PCI_X_CMD); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 37 | |
| 38 | max_read = (status & PCI_X_STATUS_MAX_READ) >> 21; |
| 39 | max_tran = (status & PCI_X_STATUS_MAX_SPLIT) >> 23; |
| 40 | if (max_read != ((cmd & PCI_X_CMD_MAX_READ) >> 2)) { |
| 41 | cmd &= ~PCI_X_CMD_MAX_READ; |
| 42 | cmd |= max_read << 2; |
| 43 | } |
| 44 | if (max_tran != ((cmd & PCI_X_CMD_MAX_SPLIT) >> 4)) { |
| 45 | cmd &= ~PCI_X_CMD_MAX_SPLIT; |
| 46 | cmd |= max_tran << 4; |
| 47 | } |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 48 | |
| 49 | /* Don't attempt to handle PCI-X errors. */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 50 | cmd &= ~PCI_X_CMD_DPERR_E; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 51 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 52 | /* Enable relaxed ordering. */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 53 | cmd |= PCI_X_CMD_ERO; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 54 | |
| 55 | if (orig_cmd != cmd) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 56 | pci_write_config16(dev, cap + PCI_X_CMD, cmd); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 59 | static void pcix_tune_bus(struct bus *bus) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 60 | { |
Elyes HAOUAS | b9e82f0 | 2018-05-02 21:29:55 +0200 | [diff] [blame] | 61 | struct device *child; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 62 | |
| 63 | for (child = bus->children; child; child = child->sibling) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 64 | pcix_tune_dev(child); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 67 | const char *pcix_speed(u16 sstatus) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 68 | { |
| 69 | static const char conventional[] = "Conventional PCI"; |
| 70 | static const char pcix_66mhz[] = "66MHz PCI-X"; |
| 71 | static const char pcix_100mhz[] = "100MHz PCI-X"; |
| 72 | static const char pcix_133mhz[] = "133MHz PCI-X"; |
| 73 | static const char pcix_266mhz[] = "266MHz PCI-X"; |
| 74 | static const char pcix_533mhz[] = "533MHZ PCI-X"; |
| 75 | static const char unknown[] = "Unknown"; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 76 | const char *result; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 77 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 78 | result = unknown; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 79 | |
| 80 | switch (PCI_X_SSTATUS_MFREQ(sstatus)) { |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 81 | case PCI_X_SSTATUS_CONVENTIONAL_PCI: |
| 82 | result = conventional; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 83 | break; |
| 84 | case PCI_X_SSTATUS_MODE1_66MHZ: |
| 85 | result = pcix_66mhz; |
| 86 | break; |
| 87 | case PCI_X_SSTATUS_MODE1_100MHZ: |
| 88 | result = pcix_100mhz; |
| 89 | break; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 90 | case PCI_X_SSTATUS_MODE1_133MHZ: |
| 91 | result = pcix_133mhz; |
| 92 | break; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 93 | case PCI_X_SSTATUS_MODE2_266MHZ_REF_66MHZ: |
| 94 | case PCI_X_SSTATUS_MODE2_266MHZ_REF_100MHZ: |
| 95 | case PCI_X_SSTATUS_MODE2_266MHZ_REF_133MHZ: |
| 96 | result = pcix_266mhz; |
| 97 | break; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 98 | case PCI_X_SSTATUS_MODE2_533MHZ_REF_66MHZ: |
| 99 | case PCI_X_SSTATUS_MODE2_533MHZ_REF_100MHZ: |
| 100 | case PCI_X_SSTATUS_MODE2_533MHZ_REF_133MHZ: |
| 101 | result = pcix_533mhz; |
| 102 | break; |
| 103 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 104 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 105 | return result; |
| 106 | } |
| 107 | |
Elyes HAOUAS | b9e82f0 | 2018-05-02 21:29:55 +0200 | [diff] [blame] | 108 | void pcix_scan_bridge(struct device *dev) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 109 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 110 | unsigned int pos; |
| 111 | u16 sstatus; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 112 | |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 113 | do_pci_scan_bridge(dev, pci_scan_bus); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 114 | |
| 115 | /* Find the PCI-X capability. */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 116 | pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); |
| 117 | sstatus = pci_read_config16(dev, pos + PCI_X_SEC_STATUS); |
| 118 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 119 | if (PCI_X_SSTATUS_MFREQ(sstatus) != PCI_X_SSTATUS_CONVENTIONAL_PCI) |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 120 | pcix_tune_bus(dev->link_list); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 121 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 122 | /* Print the PCI-X bus speed. */ |
| 123 | printk(BIOS_DEBUG, "PCI: %02x: %s\n", dev->link_list->secondary, |
| 124 | pcix_speed(sstatus)); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 127 | /** Default device operations for PCI-X bridges */ |
| 128 | static struct pci_operations pcix_bus_ops_pci = { |
| 129 | .set_subsystem = 0, |
| 130 | }; |
| 131 | |
| 132 | struct device_operations default_pcix_ops_bus = { |
| 133 | .read_resources = pci_bus_read_resources, |
| 134 | .set_resources = pci_dev_set_resources, |
| 135 | .enable_resources = pci_bus_enable_resources, |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 136 | .init = 0, |
| 137 | .scan_bus = pcix_scan_bridge, |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 138 | .enable = 0, |
| 139 | .reset_bus = pci_bus_reset, |
| 140 | .ops_pci = &pcix_bus_ops_pci, |
| 141 | }; |