blob: 9b9f70263041ee983d794e13a881099714b5f22c [file] [log] [blame]
Stefan Reinauer00636b02012-04-04 00:08:51 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2009 coresystems GmbH
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Stefan Reinauer00636b02012-04-04 00:08:51 +020014 */
15
Kyösti Mälkki54d6abd2013-06-19 23:05:00 +030016#ifndef _PCI_MMIO_CFG_H
17#define _PCI_MMIO_CFG_H
18
19#include <arch/io.h>
20
Kyösti Mälkki54d6abd2013-06-19 23:05:00 +030021#define DEFAULT_PCIEXBAR CONFIG_MMCONF_BASE_ADDRESS
Stefan Reinauer00636b02012-04-04 00:08:51 +020022
23static inline __attribute__ ((always_inline))
Kyösti Mälkkid8d43ba2013-10-27 14:59:00 +020024u8 pci_mmio_read_config8(pci_devfn_t dev, unsigned int where)
Stefan Reinauer00636b02012-04-04 00:08:51 +020025{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080026 void *addr;
Stefan Reinauerb0bb8a12015-06-17 16:12:17 -070027 addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | where);
Stefan Reinauer00636b02012-04-04 00:08:51 +020028 return read8(addr);
29}
30
31static inline __attribute__ ((always_inline))
Kyösti Mälkkid8d43ba2013-10-27 14:59:00 +020032u16 pci_mmio_read_config16(pci_devfn_t dev, unsigned int where)
Stefan Reinauer00636b02012-04-04 00:08:51 +020033{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080034 void *addr;
Stefan Reinauerb0bb8a12015-06-17 16:12:17 -070035 addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~1));
Stefan Reinauer00636b02012-04-04 00:08:51 +020036 return read16(addr);
37}
38
39static inline __attribute__ ((always_inline))
Kyösti Mälkkid8d43ba2013-10-27 14:59:00 +020040u32 pci_mmio_read_config32(pci_devfn_t dev, unsigned int where)
Stefan Reinauer00636b02012-04-04 00:08:51 +020041{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080042 void *addr;
Stefan Reinauerb0bb8a12015-06-17 16:12:17 -070043 addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~3));
Stefan Reinauer00636b02012-04-04 00:08:51 +020044 return read32(addr);
45}
46
47static inline __attribute__ ((always_inline))
Kyösti Mälkkid8d43ba2013-10-27 14:59:00 +020048void pci_mmio_write_config8(pci_devfn_t dev, unsigned int where, u8 value)
Stefan Reinauer00636b02012-04-04 00:08:51 +020049{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080050 void *addr;
Stefan Reinauerb0bb8a12015-06-17 16:12:17 -070051 addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | where);
Stefan Reinauer00636b02012-04-04 00:08:51 +020052 write8(addr, value);
53}
54
55static inline __attribute__ ((always_inline))
Kyösti Mälkkid8d43ba2013-10-27 14:59:00 +020056void pci_mmio_write_config16(pci_devfn_t dev, unsigned int where, u16 value)
Stefan Reinauer00636b02012-04-04 00:08:51 +020057{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080058 void *addr;
Stefan Reinauerb0bb8a12015-06-17 16:12:17 -070059 addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~1));
Stefan Reinauer00636b02012-04-04 00:08:51 +020060 write16(addr, value);
61}
62
63static inline __attribute__ ((always_inline))
Kyösti Mälkkid8d43ba2013-10-27 14:59:00 +020064void pci_mmio_write_config32(pci_devfn_t dev, unsigned int where, u32 value)
Stefan Reinauer00636b02012-04-04 00:08:51 +020065{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080066 void *addr;
Stefan Reinauerb0bb8a12015-06-17 16:12:17 -070067 addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~3));
Stefan Reinauer00636b02012-04-04 00:08:51 +020068 write32(addr, value);
69}
70
Kyösti Mälkki54d6abd2013-06-19 23:05:00 +030071#endif /* _PCI_MMIO_CFG_H */