2020-05-05 20:48:50 +02:00
|
|
|
/* This file is part of the coreboot project. */
|
2015-10-21 22:00:41 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Google Inc
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2004-07-08 19:18:27 +02:00
|
|
|
#include <stdio.h>
|
2015-10-21 22:00:41 +02:00
|
|
|
#include <pci/pci.h>
|
2015-09-28 22:12:04 +02:00
|
|
|
#include "pci-userspace.h"
|
2004-07-08 19:18:27 +02:00
|
|
|
|
|
|
|
#define DEBUG_PCI 1
|
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
static struct pci_access *pacc;
|
2004-07-08 19:18:27 +02:00
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
int pci_initialize(void)
|
2004-07-08 19:18:27 +02:00
|
|
|
{
|
2015-10-21 22:00:41 +02:00
|
|
|
struct pci_dev *dev;
|
|
|
|
|
2004-07-08 19:18:27 +02:00
|
|
|
pacc = pci_alloc();
|
|
|
|
|
|
|
|
pci_init(pacc);
|
|
|
|
pci_scan_bus(pacc);
|
|
|
|
for (dev = pacc->devices; dev; dev = dev->next) {
|
|
|
|
pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
int pci_exit(void)
|
2004-07-08 19:18:27 +02:00
|
|
|
{
|
|
|
|
pci_cleanup(pacc);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
u8 pci_read_config8(struct device *dev, unsigned int where)
|
2004-07-08 19:18:27 +02:00
|
|
|
{
|
|
|
|
struct pci_dev *d;
|
2015-10-21 22:00:41 +02:00
|
|
|
if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
|
|
|
|
return pci_read_byte(d, where);
|
2004-07-08 19:18:27 +02:00
|
|
|
#ifdef DEBUG_PCI
|
|
|
|
printf("PCI: device not found while read byte (%x:%x.%x)\n",
|
2015-10-21 22:00:41 +02:00
|
|
|
dev->busno, dev->slot, dev->func);
|
2004-07-08 19:18:27 +02:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
u16 pci_read_config16(struct device *dev, unsigned int where)
|
2004-07-08 19:18:27 +02:00
|
|
|
{
|
|
|
|
struct pci_dev *d;
|
2015-10-21 22:00:41 +02:00
|
|
|
if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
|
|
|
|
return pci_read_word(d, where);
|
2004-07-08 19:18:27 +02:00
|
|
|
#ifdef DEBUG_PCI
|
|
|
|
printf("PCI: device not found while read word (%x:%x.%x)\n",
|
2015-10-21 22:00:41 +02:00
|
|
|
dev->busno, dev->slot, dev->func);
|
2004-07-08 19:18:27 +02:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
u32 pci_read_config32(struct device *dev, unsigned int where)
|
2004-07-08 19:18:27 +02:00
|
|
|
{
|
|
|
|
struct pci_dev *d;
|
2015-10-21 22:00:41 +02:00
|
|
|
if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
|
|
|
|
return pci_read_long(d, where);
|
2004-07-08 19:18:27 +02:00
|
|
|
#ifdef DEBUG_PCI
|
2015-10-21 22:00:41 +02:00
|
|
|
printf("PCI: device not found while read dword (%x:%x.%x)\n",
|
|
|
|
dev->busno, dev->slot, dev->func);
|
2004-07-08 19:18:27 +02:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
void pci_write_config8(struct device *dev, unsigned int where, u8 val)
|
2004-07-08 19:18:27 +02:00
|
|
|
{
|
|
|
|
struct pci_dev *d;
|
2015-10-21 22:00:41 +02:00
|
|
|
if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
|
|
|
|
pci_write_byte(d, where, val);
|
2004-07-08 19:18:27 +02:00
|
|
|
#ifdef DEBUG_PCI
|
|
|
|
else
|
2015-10-21 22:00:41 +02:00
|
|
|
printf("PCI: device not found while write byte (%x:%x.%x)\n",
|
|
|
|
dev->busno, dev->slot, dev->func);
|
2004-07-08 19:18:27 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
void pci_write_config16(struct device *dev, unsigned int where, u16 val)
|
2004-07-08 19:18:27 +02:00
|
|
|
{
|
|
|
|
struct pci_dev *d;
|
2015-10-21 22:00:41 +02:00
|
|
|
if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
|
|
|
|
pci_write_word(d, where, val);
|
2004-07-08 19:18:27 +02:00
|
|
|
#ifdef DEBUG_PCI
|
|
|
|
else
|
|
|
|
printf("PCI: device not found while write word (%x:%x.%x)\n",
|
2015-10-21 22:00:41 +02:00
|
|
|
dev->busno, dev->slot, dev->func);
|
2004-07-08 19:18:27 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-10-21 22:00:41 +02:00
|
|
|
void pci_write_config32(struct device *dev, unsigned int where, u32 val)
|
2004-07-08 19:18:27 +02:00
|
|
|
{
|
|
|
|
struct pci_dev *d;
|
2015-10-21 22:00:41 +02:00
|
|
|
if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
|
|
|
|
pci_write_long(d, where, val);
|
2004-07-08 19:18:27 +02:00
|
|
|
#ifdef DEBUG_PCI
|
|
|
|
else
|
2015-10-21 22:00:41 +02:00
|
|
|
printf("PCI: device not found while write dword (%x:%x.%x)\n",
|
|
|
|
dev->busno, dev->slot, dev->func);
|
2004-07-08 19:18:27 +02:00
|
|
|
#endif
|
|
|
|
}
|