blob: b1dadc3e23a66cbe8df85490fc8201c222b4a26c [file] [log] [blame]
Martin Roth9df9e9392016-01-12 15:55:28 -07001/*
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 Biederman018d8dd2004-11-04 11:04:33 +000014#include <arch/io.h>
Eric Biederman018d8dd2004-11-04 11:04:33 +000015#include <device/pci.h>
Eric Biederman018d8dd2004-11-04 11:04:33 +000016#include <device/pci_ops.h>
17/*
18 * Functions for accessing PCI configuration space with type 1 accesses
19 */
20
Martin Rothd3bb09d2017-06-25 11:50:58 -060021#if !IS_ENABLED(CONFIG_PCI_IO_CFG_EXT)
Kyösti Mälkkiad7758c2019-03-04 08:25:27 +020022#define CONF_CMD(dev, where) (0x80000000 | ((dev)->bus->secondary << 16) | \
23 ((dev)->path.pci.devfn << 8) | (where & ~3))
Yinghai Lu5f9624d2006-10-04 22:56:21 +000024#else
Kyösti Mälkkiad7758c2019-03-04 08:25:27 +020025#define CONF_CMD(dev, where) (0x80000000 | ((dev)->bus->secondary << 16) | \
26 ((dev)->path.pci.devfn << 8) | ((where & 0xff) & ~3) |\
Lee Leahy6f80ccc2017-03-16 15:18:22 -070027 ((where & 0xf00)<<16))
Yinghai Lu5f9624d2006-10-04 22:56:21 +000028#endif
Eric Biederman018d8dd2004-11-04 11:04:33 +000029
Kyösti Mälkkiad7758c2019-03-04 08:25:27 +020030static uint8_t pci_conf1_read_config8(struct device *dev, int where)
Eric Biederman018d8dd2004-11-04 11:04:33 +000031{
Kyösti Mälkkiad7758c2019-03-04 08:25:27 +020032 outl(CONF_CMD(dev, where), 0xCF8);
Vikram Narayanan31b680b2012-01-24 19:17:47 +053033 return inb(0xCFC + (where & 3));
Eric Biederman018d8dd2004-11-04 11:04:33 +000034}
35
Kyösti Mälkkiad7758c2019-03-04 08:25:27 +020036static uint16_t pci_conf1_read_config16(struct device *dev, int where)
Eric Biederman018d8dd2004-11-04 11:04:33 +000037{
Kyösti Mälkkiad7758c2019-03-04 08:25:27 +020038 outl(CONF_CMD(dev, where), 0xCF8);
Vikram Narayanan31b680b2012-01-24 19:17:47 +053039 return inw(0xCFC + (where & 2));
Eric Biederman018d8dd2004-11-04 11:04:33 +000040}
41
Kyösti Mälkkiad7758c2019-03-04 08:25:27 +020042static uint32_t pci_conf1_read_config32(struct device *dev, int where)
Eric Biederman018d8dd2004-11-04 11:04:33 +000043{
Kyösti Mälkkiad7758c2019-03-04 08:25:27 +020044 outl(CONF_CMD(dev, where), 0xCF8);
Vikram Narayanan31b680b2012-01-24 19:17:47 +053045 return inl(0xCFC);
Eric Biederman018d8dd2004-11-04 11:04:33 +000046}
47
Kyösti Mälkkiad7758c2019-03-04 08:25:27 +020048static void pci_conf1_write_config8(struct device *dev, int where,
Kyösti Mälkki00ad8df2019-01-23 15:56:30 +020049 uint8_t value)
Eric Biederman018d8dd2004-11-04 11:04:33 +000050{
Kyösti Mälkkiad7758c2019-03-04 08:25:27 +020051 outl(CONF_CMD(dev, where), 0xCF8);
Vikram Narayanan31b680b2012-01-24 19:17:47 +053052 outb(value, 0xCFC + (where & 3));
Eric Biederman018d8dd2004-11-04 11:04:33 +000053}
54
Kyösti Mälkkiad7758c2019-03-04 08:25:27 +020055static void pci_conf1_write_config16(struct device *dev, int where,
Kyösti Mälkki00ad8df2019-01-23 15:56:30 +020056 uint16_t value)
Eric Biederman018d8dd2004-11-04 11:04:33 +000057{
Kyösti Mälkkiad7758c2019-03-04 08:25:27 +020058 outl(CONF_CMD(dev, where), 0xCF8);
Vikram Narayanan31b680b2012-01-24 19:17:47 +053059 outw(value, 0xCFC + (where & 2));
Eric Biederman018d8dd2004-11-04 11:04:33 +000060}
61
Kyösti Mälkkiad7758c2019-03-04 08:25:27 +020062static void pci_conf1_write_config32(struct device *dev, int where,
Kyösti Mälkki00ad8df2019-01-23 15:56:30 +020063 uint32_t value)
Eric Biederman018d8dd2004-11-04 11:04:33 +000064{
Kyösti Mälkkiad7758c2019-03-04 08:25:27 +020065 outl(CONF_CMD(dev, where), 0xCF8);
Vikram Narayanan31b680b2012-01-24 19:17:47 +053066 outl(value, 0xCFC);
Eric Biederman018d8dd2004-11-04 11:04:33 +000067}
68
Elyes HAOUAS251514d2019-01-23 11:36:44 +010069#undef CONF_CMD
Eric Biederman018d8dd2004-11-04 11:04:33 +000070
Vikram Narayanan31b680b2012-01-24 19:17:47 +053071const struct pci_bus_operations pci_cf8_conf1 = {
72 .read8 = pci_conf1_read_config8,
Eric Biederman018d8dd2004-11-04 11:04:33 +000073 .read16 = pci_conf1_read_config16,
74 .read32 = pci_conf1_read_config32,
Vikram Narayanan31b680b2012-01-24 19:17:47 +053075 .write8 = pci_conf1_write_config8,
Eric Biederman018d8dd2004-11-04 11:04:33 +000076 .write16 = pci_conf1_write_config16,
77 .write32 = pci_conf1_write_config32,
78};