Martin Roth | 9df9e939 | 2016-01-12 15:55:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 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. |
| 12 | */ |
| 13 | |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 14 | #include <arch/io.h> |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 15 | #include <device/pci.h> |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 16 | #include <device/pci_ops.h> |
| 17 | /* |
| 18 | * Functions for accessing PCI configuration space with type 1 accesses |
| 19 | */ |
| 20 | |
Martin Roth | d3bb09d | 2017-06-25 11:50:58 -0600 | [diff] [blame] | 21 | #if !IS_ENABLED(CONFIG_PCI_IO_CFG_EXT) |
Kyösti Mälkki | ad7758c | 2019-03-04 08:25:27 +0200 | [diff] [blame] | 22 | #define CONF_CMD(dev, where) (0x80000000 | ((dev)->bus->secondary << 16) | \ |
| 23 | ((dev)->path.pci.devfn << 8) | (where & ~3)) |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 24 | #else |
Kyösti Mälkki | ad7758c | 2019-03-04 08:25:27 +0200 | [diff] [blame] | 25 | #define CONF_CMD(dev, where) (0x80000000 | ((dev)->bus->secondary << 16) | \ |
| 26 | ((dev)->path.pci.devfn << 8) | ((where & 0xff) & ~3) |\ |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 27 | ((where & 0xf00)<<16)) |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 28 | #endif |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 29 | |
Kyösti Mälkki | ad7758c | 2019-03-04 08:25:27 +0200 | [diff] [blame] | 30 | static uint8_t pci_conf1_read_config8(struct device *dev, int where) |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 31 | { |
Kyösti Mälkki | ad7758c | 2019-03-04 08:25:27 +0200 | [diff] [blame] | 32 | outl(CONF_CMD(dev, where), 0xCF8); |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 33 | return inb(0xCFC + (where & 3)); |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Kyösti Mälkki | ad7758c | 2019-03-04 08:25:27 +0200 | [diff] [blame] | 36 | static uint16_t pci_conf1_read_config16(struct device *dev, int where) |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 37 | { |
Kyösti Mälkki | ad7758c | 2019-03-04 08:25:27 +0200 | [diff] [blame] | 38 | outl(CONF_CMD(dev, where), 0xCF8); |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 39 | return inw(0xCFC + (where & 2)); |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Kyösti Mälkki | ad7758c | 2019-03-04 08:25:27 +0200 | [diff] [blame] | 42 | static uint32_t pci_conf1_read_config32(struct device *dev, int where) |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 43 | { |
Kyösti Mälkki | ad7758c | 2019-03-04 08:25:27 +0200 | [diff] [blame] | 44 | outl(CONF_CMD(dev, where), 0xCF8); |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 45 | return inl(0xCFC); |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Kyösti Mälkki | ad7758c | 2019-03-04 08:25:27 +0200 | [diff] [blame] | 48 | static void pci_conf1_write_config8(struct device *dev, int where, |
Kyösti Mälkki | 00ad8df | 2019-01-23 15:56:30 +0200 | [diff] [blame] | 49 | uint8_t value) |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 50 | { |
Kyösti Mälkki | ad7758c | 2019-03-04 08:25:27 +0200 | [diff] [blame] | 51 | outl(CONF_CMD(dev, where), 0xCF8); |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 52 | outb(value, 0xCFC + (where & 3)); |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Kyösti Mälkki | ad7758c | 2019-03-04 08:25:27 +0200 | [diff] [blame] | 55 | static void pci_conf1_write_config16(struct device *dev, int where, |
Kyösti Mälkki | 00ad8df | 2019-01-23 15:56:30 +0200 | [diff] [blame] | 56 | uint16_t value) |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 57 | { |
Kyösti Mälkki | ad7758c | 2019-03-04 08:25:27 +0200 | [diff] [blame] | 58 | outl(CONF_CMD(dev, where), 0xCF8); |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 59 | outw(value, 0xCFC + (where & 2)); |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Kyösti Mälkki | ad7758c | 2019-03-04 08:25:27 +0200 | [diff] [blame] | 62 | static void pci_conf1_write_config32(struct device *dev, int where, |
Kyösti Mälkki | 00ad8df | 2019-01-23 15:56:30 +0200 | [diff] [blame] | 63 | uint32_t value) |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 64 | { |
Kyösti Mälkki | ad7758c | 2019-03-04 08:25:27 +0200 | [diff] [blame] | 65 | outl(CONF_CMD(dev, where), 0xCF8); |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 66 | outl(value, 0xCFC); |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Elyes HAOUAS | 251514d | 2019-01-23 11:36:44 +0100 | [diff] [blame] | 69 | #undef CONF_CMD |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 70 | |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 71 | const struct pci_bus_operations pci_cf8_conf1 = { |
| 72 | .read8 = pci_conf1_read_config8, |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 73 | .read16 = pci_conf1_read_config16, |
| 74 | .read32 = pci_conf1_read_config32, |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 75 | .write8 = pci_conf1_write_config8, |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 76 | .write16 = pci_conf1_write_config16, |
| 77 | .write32 = pci_conf1_write_config32, |
| 78 | }; |