util/: Replace GPLv2 boiler plate with SPDX header
Used commands:
perl -i -p0e 's|\/\*[\s*]*.*is free software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and\/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-2.0-only */|' $(cat filelist)
perl -i -p0e 's|This[\s*]*program[\s*]*is[\s*]*free[\s*]*software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*either[\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License,[\s*]*or[\s*]*.at[\s*]*your[\s*]*option.*[\s*]*any[\s*]*later[\s*]*version.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-2.0-or-later */|' $(cat filelist)
perl -i -p0e 's|\/\*[\s*]*.*This[\s*#]*program[\s*#]*is[\s*#]*free[\s*#]*software[;:,][\s*#]*you[\s*#]*can[\s*#]*redistribute[\s*#]*it[\s*#]*and/or[\s*#]*modify[\s*#]*it[\s*#]*under[\s*#]*the[\s*#]*terms[\s*#]*of[\s*#]*the[\s*#]*GNU[\s*#]*General[\s*#]*Public[\s*#]*License[\s*#]*as[\s*#]*published[\s*#]*by[\s*#]*the[\s*#]*Free[\s*#]*Software[\s*#]*Foundation[;:,][\s*#]*either[\s*#]*version[\s*#]*3[\s*#]*of[\s*#]*the[\s*#]*License[;:,][\s*#]*or[\s*#]*.at[\s*#]*your[\s*#]*option.*[\s*#]*any[\s*#]*later[\s*#]*version.[\s*#]*This[\s*#]*program[\s*#]*is[\s*#]*distributed[\s*#]*in[\s*#]*the[\s*#]*hope[\s*#]*that[\s*#]*it[\s*#]*will[\s*#]*be[\s*#]*useful[;:,][\s*#]*but[\s*#]*WITHOUT[\s*#]*ANY[\s*#]*WARRANTY[;:,][\s*#]*without[\s*#]*even[\s*#]*the[\s*#]*implied[\s*#]*warranty[\s*#]*of[\s*#]*MERCHANTABILITY[\s*#]*or[\s*#]*FITNESS[\s*#]*FOR[\s*#]*A[\s*#]*PARTICULAR[\s*#]*PURPOSE.[\s*#]*See[\s*#]*the[\s*#]*GNU[\s*#]*General[\s*#]*Public[\s*#]*License[\s*#]*for[\s*#]*more[\s*#]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-3.0-or-later */|' $(cat filelist)
perl -i -p0e 's|(\#\#*)[\w]*.*is free software[:;][\#\s]*you[\#\s]*can[\#\s]*redistribute[\#\s]*it[\#\s]*and\/or[\#\s]*modify[\#\s]*it[\s\#]*under[\s \#]*the[\s\#]*terms[\s\#]*of[\s\#]*the[\s\#]*GNU[\s\#]*General[\s\#]*Public[\s\#]*License[\s\#]*as[\s\#]*published[\s\#]*by[\s\#]*the[\s\#]*Free[\s\#]*Software[\s\#]*Foundation[;,][\s\#]*version[\s\#]*2[\s\#]*of[\s\#]*the[\s\#]*License.*[\s\#]*This[\s\#]*program[\s\#]*is[\s\#]*distributed[\s\#]*in[\s\#]*the[\s\#]*hope[\s\#]*that[\s\#]*it[\s\#]*will[\#\s]*be[\#\s]*useful,[\#\s]*but[\#\s]*WITHOUT[\#\s]*ANY[\#\s]*WARRANTY;[\#\s]*without[\#\s]*even[\#\s]*the[\#\s]*implied[\#\s]*warranty[\#\s]*of[\#\s]*MERCHANTABILITY[\#\s]*or[\#\s]*FITNESS[\#\s]*FOR[\#\s]*A[\#\s]*PARTICULAR[\#\s]*PURPOSE.[\#\s]*See[\#\s]*the[\#\s]*GNU[\#\s]*General[\#\s]*Public[\#\s]*License[\#\s]*for[\#\s]*more[\#\s]*details.\s(#* *\n)*|\1 SPDX-License-Identifier: GPL-2.0-only\n\n|' $(cat filelist)
perl -i -p0e 's|(\#\#*)[\w*]*.*is free software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and\/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.\s(#* *\n)*|\1 SPDX-License-Identifier: GPL-2.0-only\n\n|' $(cat filelist)
Change-Id: I1008a63b804f355a916221ac994701d7584f60ff
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/41177
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2020-05-08 20:48:04 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2015-10-21 22:00:41 +02:00
|
|
|
|
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
|
|
|
|
}
|