2019-01-23 15:15:48 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Linux Networx
|
|
|
|
* (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx)
|
|
|
|
* Copyright (C) 2009 coresystems GmbH
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2003-04-24 08:25:08 +02:00
|
|
|
#ifndef PCI_OPS_H
|
|
|
|
#define PCI_OPS_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2003-06-12 21:23:51 +02:00
|
|
|
#include <device/device.h>
|
2019-03-02 15:26:10 +01:00
|
|
|
#include <device/pci_type.h>
|
2004-11-04 12:04:33 +01:00
|
|
|
#include <arch/pci_ops.h>
|
2003-06-12 21:23:51 +02:00
|
|
|
|
2019-01-23 15:15:48 +01:00
|
|
|
void __noreturn pcidev_die(void);
|
|
|
|
|
2019-03-11 19:34:26 +01:00
|
|
|
static __always_inline pci_devfn_t pcidev_bdf(const struct device *dev)
|
|
|
|
{
|
|
|
|
return (dev->path.pci.devfn << 12) | (dev->bus->secondary << 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __always_inline pci_devfn_t pcidev_assert(const struct device *dev)
|
2019-01-23 15:15:48 +01:00
|
|
|
{
|
|
|
|
if (!dev)
|
|
|
|
pcidev_die();
|
2019-03-11 19:34:26 +01:00
|
|
|
return pcidev_bdf(dev);
|
2019-01-23 15:15:48 +01:00
|
|
|
}
|
2019-07-29 15:38:14 +02:00
|
|
|
|
2019-09-27 11:01:15 +02:00
|
|
|
#if defined(__SIMPLE_DEVICE__)
|
|
|
|
#define ENV_PCI_SIMPLE_DEVICE 1
|
|
|
|
#else
|
|
|
|
#define ENV_PCI_SIMPLE_DEVICE 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENV_PCI_SIMPLE_DEVICE
|
2019-07-29 15:38:14 +02:00
|
|
|
|
|
|
|
/* Avoid name collisions as different stages have different signature
|
|
|
|
* for these functions. The _s_ stands for simple, fundamental IO or
|
|
|
|
* MMIO variant.
|
|
|
|
*/
|
|
|
|
#define pci_read_config8 pci_s_read_config8
|
|
|
|
#define pci_read_config16 pci_s_read_config16
|
|
|
|
#define pci_read_config32 pci_s_read_config32
|
|
|
|
#define pci_write_config8 pci_s_write_config8
|
|
|
|
#define pci_write_config16 pci_s_write_config16
|
|
|
|
#define pci_write_config32 pci_s_write_config32
|
|
|
|
#else
|
2019-01-23 15:15:48 +01:00
|
|
|
|
|
|
|
static __always_inline
|
2019-03-11 19:33:01 +01:00
|
|
|
u8 pci_read_config8(const struct device *dev, u16 reg)
|
2019-01-23 15:15:48 +01:00
|
|
|
{
|
2019-03-07 13:18:28 +01:00
|
|
|
return pci_s_read_config8(PCI_BDF(dev), reg);
|
2019-01-23 15:15:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static __always_inline
|
2019-03-11 19:33:01 +01:00
|
|
|
u16 pci_read_config16(const struct device *dev, u16 reg)
|
2019-01-23 15:15:48 +01:00
|
|
|
{
|
2019-03-07 13:18:28 +01:00
|
|
|
return pci_s_read_config16(PCI_BDF(dev), reg);
|
2019-01-23 15:15:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static __always_inline
|
2019-03-11 19:33:01 +01:00
|
|
|
u32 pci_read_config32(const struct device *dev, u16 reg)
|
2019-01-23 15:15:48 +01:00
|
|
|
{
|
2019-03-07 13:18:28 +01:00
|
|
|
return pci_s_read_config32(PCI_BDF(dev), reg);
|
2019-01-23 15:15:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static __always_inline
|
2019-03-11 19:33:01 +01:00
|
|
|
void pci_write_config8(const struct device *dev, u16 reg, u8 val)
|
2019-01-23 15:15:48 +01:00
|
|
|
{
|
2019-03-07 13:18:28 +01:00
|
|
|
pci_s_write_config8(PCI_BDF(dev), reg, val);
|
2019-01-23 15:15:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static __always_inline
|
2019-03-11 19:33:01 +01:00
|
|
|
void pci_write_config16(const struct device *dev, u16 reg, u16 val)
|
2019-01-23 15:15:48 +01:00
|
|
|
{
|
2019-03-07 13:18:28 +01:00
|
|
|
pci_s_write_config16(PCI_BDF(dev), reg, val);
|
2019-01-23 15:15:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static __always_inline
|
2019-03-11 19:33:01 +01:00
|
|
|
void pci_write_config32(const struct device *dev, u16 reg, u32 val)
|
2019-01-23 15:15:48 +01:00
|
|
|
{
|
2019-03-07 13:18:28 +01:00
|
|
|
pci_s_write_config32(PCI_BDF(dev), reg, val);
|
2019-01-23 15:15:48 +01:00
|
|
|
}
|
|
|
|
|
2013-03-21 19:51:41 +01:00
|
|
|
#endif
|
2009-03-06 20:11:52 +01:00
|
|
|
|
2019-09-27 11:01:15 +02:00
|
|
|
#if ENV_PCI_SIMPLE_DEVICE
|
2018-09-13 10:10:45 +02:00
|
|
|
static __always_inline
|
2019-03-11 19:33:01 +01:00
|
|
|
void pci_or_config8(pci_devfn_t dev, u16 reg, u8 ormask)
|
2018-12-05 11:03:36 +01:00
|
|
|
#else
|
|
|
|
static __always_inline
|
2019-03-11 19:33:01 +01:00
|
|
|
void pci_or_config8(const struct device *dev, u16 reg, u8 ormask)
|
2018-12-05 11:03:36 +01:00
|
|
|
#endif
|
2018-04-18 10:11:59 +02:00
|
|
|
{
|
2019-03-11 19:33:01 +01:00
|
|
|
u8 value = pci_read_config8(dev, reg);
|
|
|
|
pci_write_config8(dev, reg, value | ormask);
|
2018-04-18 10:11:59 +02:00
|
|
|
}
|
|
|
|
|
2019-09-27 11:01:15 +02:00
|
|
|
#if ENV_PCI_SIMPLE_DEVICE
|
2018-12-05 11:03:36 +01:00
|
|
|
static __always_inline
|
2019-03-11 19:33:01 +01:00
|
|
|
void pci_or_config16(pci_devfn_t dev, u16 reg, u16 ormask)
|
2018-12-05 11:03:36 +01:00
|
|
|
#else
|
2018-09-13 10:10:45 +02:00
|
|
|
static __always_inline
|
2019-03-11 19:33:01 +01:00
|
|
|
void pci_or_config16(const struct device *dev, u16 reg, u16 ormask)
|
2018-12-05 11:03:36 +01:00
|
|
|
#endif
|
2018-04-18 10:11:59 +02:00
|
|
|
{
|
2019-03-11 19:33:01 +01:00
|
|
|
u16 value = pci_read_config16(dev, reg);
|
|
|
|
pci_write_config16(dev, reg, value | ormask);
|
2018-04-18 10:11:59 +02:00
|
|
|
}
|
|
|
|
|
2019-09-27 11:01:15 +02:00
|
|
|
#if ENV_PCI_SIMPLE_DEVICE
|
2018-12-05 11:03:36 +01:00
|
|
|
static __always_inline
|
2019-03-11 19:33:01 +01:00
|
|
|
void pci_or_config32(pci_devfn_t dev, u16 reg, u32 ormask)
|
2018-12-05 11:03:36 +01:00
|
|
|
#else
|
2018-09-13 10:10:45 +02:00
|
|
|
static __always_inline
|
2019-03-11 19:33:01 +01:00
|
|
|
void pci_or_config32(const struct device *dev, u16 reg, u32 ormask)
|
2018-12-05 11:03:36 +01:00
|
|
|
#endif
|
2018-04-18 10:11:59 +02:00
|
|
|
{
|
2019-03-11 19:33:01 +01:00
|
|
|
u32 value = pci_read_config32(dev, reg);
|
|
|
|
pci_write_config32(dev, reg, value | ormask);
|
2018-04-18 10:11:59 +02:00
|
|
|
}
|
|
|
|
|
2019-09-27 11:01:15 +02:00
|
|
|
#if ENV_PCI_SIMPLE_DEVICE
|
2018-09-13 10:10:45 +02:00
|
|
|
static __always_inline
|
2019-03-07 10:13:29 +01:00
|
|
|
void pci_update_config8(pci_devfn_t dev, u16 reg, u8 mask, u8 or)
|
2018-12-05 11:03:36 +01:00
|
|
|
#else
|
|
|
|
static __always_inline
|
2019-03-07 10:13:29 +01:00
|
|
|
void pci_update_config8(const struct device *dev, u16 reg, u8 mask, u8 or)
|
2018-12-05 11:03:36 +01:00
|
|
|
#endif
|
2018-04-18 10:11:59 +02:00
|
|
|
{
|
|
|
|
u8 reg8;
|
|
|
|
|
|
|
|
reg8 = pci_read_config8(dev, reg);
|
|
|
|
reg8 &= mask;
|
|
|
|
reg8 |= or;
|
|
|
|
pci_write_config8(dev, reg, reg8);
|
|
|
|
}
|
|
|
|
|
2019-09-27 11:01:15 +02:00
|
|
|
#if ENV_PCI_SIMPLE_DEVICE
|
2018-12-05 11:03:36 +01:00
|
|
|
static __always_inline
|
2019-03-07 10:13:29 +01:00
|
|
|
void pci_update_config16(pci_devfn_t dev, u16 reg, u16 mask, u16 or)
|
2018-12-05 11:03:36 +01:00
|
|
|
#else
|
2018-09-13 10:10:45 +02:00
|
|
|
static __always_inline
|
2019-03-07 10:13:29 +01:00
|
|
|
void pci_update_config16(const struct device *dev, u16 reg, u16 mask, u16 or)
|
2018-12-05 11:03:36 +01:00
|
|
|
#endif
|
2018-04-18 10:11:59 +02:00
|
|
|
{
|
|
|
|
u16 reg16;
|
|
|
|
|
|
|
|
reg16 = pci_read_config16(dev, reg);
|
|
|
|
reg16 &= mask;
|
|
|
|
reg16 |= or;
|
|
|
|
pci_write_config16(dev, reg, reg16);
|
|
|
|
}
|
|
|
|
|
2019-09-27 11:01:15 +02:00
|
|
|
#if ENV_PCI_SIMPLE_DEVICE
|
2018-12-05 11:03:36 +01:00
|
|
|
static __always_inline
|
2019-03-07 10:13:29 +01:00
|
|
|
void pci_update_config32(pci_devfn_t dev, u16 reg, u32 mask, u32 or)
|
2018-12-05 11:03:36 +01:00
|
|
|
#else
|
2018-09-13 10:10:45 +02:00
|
|
|
static __always_inline
|
2019-03-07 10:13:29 +01:00
|
|
|
void pci_update_config32(const struct device *dev, u16 reg, u32 mask, u32 or)
|
2018-12-05 11:03:36 +01:00
|
|
|
#endif
|
2018-04-18 10:11:59 +02:00
|
|
|
{
|
|
|
|
u32 reg32;
|
|
|
|
|
|
|
|
reg32 = pci_read_config32(dev, reg);
|
|
|
|
reg32 &= mask;
|
|
|
|
reg32 |= or;
|
|
|
|
pci_write_config32(dev, reg, reg32);
|
|
|
|
}
|
|
|
|
|
2019-01-23 15:46:35 +01:00
|
|
|
u16 pci_s_find_next_capability(pci_devfn_t dev, u16 cap, u16 last);
|
|
|
|
u16 pci_s_find_capability(pci_devfn_t dev, u16 cap);
|
|
|
|
|
|
|
|
static __always_inline
|
|
|
|
u16 pci_find_next_capability(const struct device *dev, u16 cap, u16 last)
|
|
|
|
{
|
|
|
|
return pci_s_find_next_capability(PCI_BDF(dev), cap, last);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __always_inline
|
|
|
|
u16 pci_find_capability(const struct device *dev, u16 cap)
|
|
|
|
{
|
|
|
|
return pci_s_find_capability(PCI_BDF(dev), cap);
|
|
|
|
}
|
|
|
|
|
2003-04-24 08:25:08 +02:00
|
|
|
#endif /* PCI_OPS_H */
|