zephyr/drivers/pcie/host/pcie.c
Abhishek Shah 08ed93fed9 drivers: pcie: refactor pcie directory to make RC and EP independent
With this refactoring of pcie directory, RC drivers are placed under
host/ directory, EP drivers are placed under endpoint/ directory and
they are completely independent of each other.

Signed-off-by: Abhishek Shah <abhishek.shah@broadcom.com>
2020-07-14 19:35:31 -04:00

87 lines
1.5 KiB
C

/*
* Copyright (c) 2019 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <kernel.h>
#include <stdbool.h>
#include <drivers/pcie/pcie.h>
#if CONFIG_PCIE_MSI
#include <drivers/pcie/msi.h>
#endif
/* functions documented in drivers/pcie/pcie.h */
bool pcie_probe(pcie_bdf_t bdf, pcie_id_t id)
{
uint32_t data;
data = pcie_conf_read(bdf, PCIE_CONF_ID);
if (data == PCIE_ID_NONE) {
return false;
}
if (id == PCIE_ID_NONE) {
return true;
}
return (id == data);
}
void pcie_set_cmd(pcie_bdf_t bdf, uint32_t bits, bool on)
{
uint32_t cmdstat;
cmdstat = pcie_conf_read(bdf, PCIE_CONF_CMDSTAT);
if (on) {
cmdstat |= bits;
} else {
cmdstat &= ~bits;
}
pcie_conf_write(bdf, PCIE_CONF_CMDSTAT, cmdstat);
}
uintptr_t pcie_get_mbar(pcie_bdf_t bdf, unsigned int index)
{
uint32_t reg, bar;
uintptr_t addr = PCIE_CONF_BAR_NONE;
reg = PCIE_CONF_BAR0;
for (bar = 0; bar < index && reg <= PCIE_CONF_BAR5; bar++) {
if (PCIE_CONF_BAR_64(pcie_conf_read(bdf, reg++))) {
reg++;
}
}
if (bar == index) {
addr = pcie_conf_read(bdf, reg++);
if (IS_ENABLED(CONFIG_64BIT) && PCIE_CONF_BAR_64(addr)) {
addr |= ((uint64_t)pcie_conf_read(bdf, reg)) << 32;
}
}
return PCIE_CONF_BAR_ADDR(addr);
}
unsigned int pcie_wired_irq(pcie_bdf_t bdf)
{
uint32_t data = pcie_conf_read(bdf, PCIE_CONF_INTR);
return PCIE_CONF_INTR_IRQ(data);
}
void pcie_irq_enable(pcie_bdf_t bdf, unsigned int irq)
{
#if CONFIG_PCIE_MSI
if (pcie_set_msi(bdf, irq)) {
return;
}
#endif
irq_enable(irq);
}