License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 21:07:57 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2007-03-09 12:55:49 +07:00
|
|
|
/* pci_common.c: PCI controller common support.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2007-03-09 12:55:49 +07:00
|
|
|
* Copyright (C) 1999, 2007 David S. Miller (davem@davemloft.net)
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/slab.h>
|
2006-12-21 00:22:28 +07:00
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/device.h>
|
2008-08-08 05:33:36 +07:00
|
|
|
#include <linux/of_device.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-06-23 06:18:54 +07:00
|
|
|
#include <asm/prom.h>
|
2007-05-08 14:43:56 +07:00
|
|
|
#include <asm/oplib.h>
|
2006-06-23 06:18:54 +07:00
|
|
|
|
|
|
|
#include "pci_impl.h"
|
2007-05-09 16:35:27 +07:00
|
|
|
#include "pci_sun4v.h"
|
|
|
|
|
|
|
|
static int config_out_of_range(struct pci_pbm_info *pbm,
|
|
|
|
unsigned long bus,
|
|
|
|
unsigned long devfn,
|
|
|
|
unsigned long reg)
|
|
|
|
{
|
|
|
|
if (bus < pbm->pci_first_busno ||
|
|
|
|
bus > pbm->pci_last_busno)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *sun4u_config_mkaddr(struct pci_pbm_info *pbm,
|
|
|
|
unsigned long bus,
|
|
|
|
unsigned long devfn,
|
|
|
|
unsigned long reg)
|
|
|
|
{
|
|
|
|
unsigned long rbits = pbm->config_space_reg_bits;
|
|
|
|
|
|
|
|
if (config_out_of_range(pbm, bus, devfn, reg))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
reg = (reg & ((1 << rbits) - 1));
|
|
|
|
devfn <<= rbits;
|
|
|
|
bus <<= rbits + 8;
|
|
|
|
|
|
|
|
return (void *) (pbm->config_space | bus | devfn | reg);
|
|
|
|
}
|
|
|
|
|
2007-07-26 13:30:16 +07:00
|
|
|
/* At least on Sabre, it is necessary to access all PCI host controller
|
|
|
|
* registers at their natural size, otherwise zeros are returned.
|
|
|
|
* Strange but true, and I see no language in the UltraSPARC-IIi
|
|
|
|
* programmer's manual that mentions this even indirectly.
|
|
|
|
*/
|
|
|
|
static int sun4u_read_pci_cfg_host(struct pci_pbm_info *pbm,
|
|
|
|
unsigned char bus, unsigned int devfn,
|
|
|
|
int where, int size, u32 *value)
|
|
|
|
{
|
|
|
|
u32 tmp32, *addr;
|
|
|
|
u16 tmp16;
|
|
|
|
u8 tmp8;
|
|
|
|
|
|
|
|
addr = sun4u_config_mkaddr(pbm, bus, devfn, where);
|
|
|
|
if (!addr)
|
|
|
|
return PCIBIOS_SUCCESSFUL;
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
if (where < 8) {
|
|
|
|
unsigned long align = (unsigned long) addr;
|
|
|
|
|
|
|
|
align &= ~1;
|
|
|
|
pci_config_read16((u16 *)align, &tmp16);
|
|
|
|
if (where & 1)
|
|
|
|
*value = tmp16 >> 8;
|
|
|
|
else
|
|
|
|
*value = tmp16 & 0xff;
|
|
|
|
} else {
|
|
|
|
pci_config_read8((u8 *)addr, &tmp8);
|
|
|
|
*value = (u32) tmp8;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
if (where < 8) {
|
|
|
|
pci_config_read16((u16 *)addr, &tmp16);
|
|
|
|
*value = (u32) tmp16;
|
|
|
|
} else {
|
|
|
|
pci_config_read8((u8 *)addr, &tmp8);
|
|
|
|
*value = (u32) tmp8;
|
|
|
|
pci_config_read8(((u8 *)addr) + 1, &tmp8);
|
|
|
|
*value |= ((u32) tmp8) << 8;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
tmp32 = 0xffffffff;
|
|
|
|
sun4u_read_pci_cfg_host(pbm, bus, devfn,
|
|
|
|
where, 2, &tmp32);
|
|
|
|
*value = tmp32;
|
|
|
|
|
|
|
|
tmp32 = 0xffffffff;
|
|
|
|
sun4u_read_pci_cfg_host(pbm, bus, devfn,
|
|
|
|
where + 2, 2, &tmp32);
|
|
|
|
*value |= tmp32 << 16;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return PCIBIOS_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
2007-05-09 16:35:27 +07:00
|
|
|
static int sun4u_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
|
|
|
|
int where, int size, u32 *value)
|
|
|
|
{
|
|
|
|
struct pci_pbm_info *pbm = bus_dev->sysdata;
|
|
|
|
unsigned char bus = bus_dev->number;
|
|
|
|
u32 *addr;
|
|
|
|
u16 tmp16;
|
|
|
|
u8 tmp8;
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
*value = 0xff;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
*value = 0xffff;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
*value = 0xffffffff;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-07-26 13:30:16 +07:00
|
|
|
if (!bus_dev->number && !PCI_SLOT(devfn))
|
|
|
|
return sun4u_read_pci_cfg_host(pbm, bus, devfn, where,
|
|
|
|
size, value);
|
|
|
|
|
2007-05-09 16:35:27 +07:00
|
|
|
addr = sun4u_config_mkaddr(pbm, bus, devfn, where);
|
|
|
|
if (!addr)
|
|
|
|
return PCIBIOS_SUCCESSFUL;
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
pci_config_read8((u8 *)addr, &tmp8);
|
|
|
|
*value = (u32) tmp8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
if (where & 0x01) {
|
|
|
|
printk("pci_read_config_word: misaligned reg [%x]\n",
|
|
|
|
where);
|
|
|
|
return PCIBIOS_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
pci_config_read16((u16 *)addr, &tmp16);
|
|
|
|
*value = (u32) tmp16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
if (where & 0x03) {
|
|
|
|
printk("pci_read_config_dword: misaligned reg [%x]\n",
|
|
|
|
where);
|
|
|
|
return PCIBIOS_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
pci_config_read32(addr, value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return PCIBIOS_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
2007-07-26 13:30:16 +07:00
|
|
|
static int sun4u_write_pci_cfg_host(struct pci_pbm_info *pbm,
|
|
|
|
unsigned char bus, unsigned int devfn,
|
|
|
|
int where, int size, u32 value)
|
|
|
|
{
|
|
|
|
u32 *addr;
|
|
|
|
|
|
|
|
addr = sun4u_config_mkaddr(pbm, bus, devfn, where);
|
|
|
|
if (!addr)
|
|
|
|
return PCIBIOS_SUCCESSFUL;
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
if (where < 8) {
|
|
|
|
unsigned long align = (unsigned long) addr;
|
|
|
|
u16 tmp16;
|
|
|
|
|
|
|
|
align &= ~1;
|
|
|
|
pci_config_read16((u16 *)align, &tmp16);
|
|
|
|
if (where & 1) {
|
|
|
|
tmp16 &= 0x00ff;
|
|
|
|
tmp16 |= value << 8;
|
|
|
|
} else {
|
|
|
|
tmp16 &= 0xff00;
|
|
|
|
tmp16 |= value;
|
|
|
|
}
|
|
|
|
pci_config_write16((u16 *)align, tmp16);
|
|
|
|
} else
|
|
|
|
pci_config_write8((u8 *)addr, value);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (where < 8) {
|
|
|
|
pci_config_write16((u16 *)addr, value);
|
|
|
|
} else {
|
|
|
|
pci_config_write8((u8 *)addr, value & 0xff);
|
|
|
|
pci_config_write8(((u8 *)addr) + 1, value >> 8);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
sun4u_write_pci_cfg_host(pbm, bus, devfn,
|
|
|
|
where, 2, value & 0xffff);
|
|
|
|
sun4u_write_pci_cfg_host(pbm, bus, devfn,
|
|
|
|
where + 2, 2, value >> 16);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return PCIBIOS_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
2007-05-09 16:35:27 +07:00
|
|
|
static int sun4u_write_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
|
|
|
|
int where, int size, u32 value)
|
|
|
|
{
|
|
|
|
struct pci_pbm_info *pbm = bus_dev->sysdata;
|
|
|
|
unsigned char bus = bus_dev->number;
|
|
|
|
u32 *addr;
|
|
|
|
|
2007-07-26 13:30:16 +07:00
|
|
|
if (!bus_dev->number && !PCI_SLOT(devfn))
|
|
|
|
return sun4u_write_pci_cfg_host(pbm, bus, devfn, where,
|
|
|
|
size, value);
|
|
|
|
|
2007-05-09 16:35:27 +07:00
|
|
|
addr = sun4u_config_mkaddr(pbm, bus, devfn, where);
|
|
|
|
if (!addr)
|
|
|
|
return PCIBIOS_SUCCESSFUL;
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
pci_config_write8((u8 *)addr, value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
if (where & 0x01) {
|
|
|
|
printk("pci_write_config_word: misaligned reg [%x]\n",
|
|
|
|
where);
|
|
|
|
return PCIBIOS_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
pci_config_write16((u16 *)addr, value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
if (where & 0x03) {
|
|
|
|
printk("pci_write_config_dword: misaligned reg [%x]\n",
|
|
|
|
where);
|
|
|
|
return PCIBIOS_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
pci_config_write32(addr, value);
|
|
|
|
}
|
|
|
|
return PCIBIOS_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct pci_ops sun4u_pci_ops = {
|
|
|
|
.read = sun4u_read_pci_cfg,
|
|
|
|
.write = sun4u_write_pci_cfg,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int sun4v_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
|
|
|
|
int where, int size, u32 *value)
|
|
|
|
{
|
|
|
|
struct pci_pbm_info *pbm = bus_dev->sysdata;
|
|
|
|
u32 devhandle = pbm->devhandle;
|
|
|
|
unsigned int bus = bus_dev->number;
|
|
|
|
unsigned int device = PCI_SLOT(devfn);
|
|
|
|
unsigned int func = PCI_FUNC(devfn);
|
|
|
|
unsigned long ret;
|
|
|
|
|
|
|
|
if (config_out_of_range(pbm, bus, devfn, where)) {
|
|
|
|
ret = ~0UL;
|
|
|
|
} else {
|
|
|
|
ret = pci_sun4v_config_get(devhandle,
|
|
|
|
HV_PCI_DEVICE_BUILD(bus, device, func),
|
|
|
|
where, size);
|
|
|
|
}
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
*value = ret & 0xff;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
*value = ret & 0xffff;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
*value = ret & 0xffffffff;
|
|
|
|
break;
|
2011-06-03 21:45:23 +07:00
|
|
|
}
|
2007-05-09 16:35:27 +07:00
|
|
|
|
|
|
|
|
|
|
|
return PCIBIOS_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sun4v_write_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
|
|
|
|
int where, int size, u32 value)
|
|
|
|
{
|
|
|
|
struct pci_pbm_info *pbm = bus_dev->sysdata;
|
|
|
|
u32 devhandle = pbm->devhandle;
|
|
|
|
unsigned int bus = bus_dev->number;
|
|
|
|
unsigned int device = PCI_SLOT(devfn);
|
|
|
|
unsigned int func = PCI_FUNC(devfn);
|
|
|
|
|
|
|
|
if (config_out_of_range(pbm, bus, devfn, where)) {
|
|
|
|
/* Do nothing. */
|
|
|
|
} else {
|
2011-02-27 14:40:02 +07:00
|
|
|
/* We don't check for hypervisor errors here, but perhaps
|
|
|
|
* we should and influence our return value depending upon
|
|
|
|
* what kind of error is thrown.
|
|
|
|
*/
|
|
|
|
pci_sun4v_config_put(devhandle,
|
|
|
|
HV_PCI_DEVICE_BUILD(bus, device, func),
|
|
|
|
where, size, value);
|
2007-05-09 16:35:27 +07:00
|
|
|
}
|
|
|
|
return PCIBIOS_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct pci_ops sun4v_pci_ops = {
|
|
|
|
.read = sun4v_read_pci_cfg,
|
|
|
|
.write = sun4v_write_pci_cfg,
|
|
|
|
};
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-05-08 11:51:41 +07:00
|
|
|
void pci_get_pbm_props(struct pci_pbm_info *pbm)
|
|
|
|
{
|
2010-04-14 06:12:29 +07:00
|
|
|
const u32 *val = of_get_property(pbm->op->dev.of_node, "bus-range", NULL);
|
2007-05-08 11:51:41 +07:00
|
|
|
|
|
|
|
pbm->pci_first_busno = val[0];
|
|
|
|
pbm->pci_last_busno = val[1];
|
|
|
|
|
2010-04-14 06:12:29 +07:00
|
|
|
val = of_get_property(pbm->op->dev.of_node, "ino-bitmap", NULL);
|
2007-05-08 11:51:41 +07:00
|
|
|
if (val) {
|
|
|
|
pbm->ino_bitmap = (((u64)val[1] << 32UL) |
|
|
|
|
((u64)val[0] << 0UL));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-09 12:55:49 +07:00
|
|
|
static void pci_register_legacy_regions(struct resource *io_res,
|
|
|
|
struct resource *mem_res)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct resource *p;
|
|
|
|
|
|
|
|
/* VGA Video RAM. */
|
2006-03-07 04:48:40 +07:00
|
|
|
p = kzalloc(sizeof(*p), GFP_KERNEL);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!p)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p->name = "Video RAM area";
|
|
|
|
p->start = mem_res->start + 0xa0000UL;
|
|
|
|
p->end = p->start + 0x1ffffUL;
|
|
|
|
p->flags = IORESOURCE_BUSY;
|
|
|
|
request_resource(mem_res, p);
|
|
|
|
}
|
|
|
|
|
2007-03-09 12:55:49 +07:00
|
|
|
static void pci_register_iommu_region(struct pci_pbm_info *pbm)
|
|
|
|
{
|
2010-04-14 06:12:29 +07:00
|
|
|
const u32 *vdma = of_get_property(pbm->op->dev.of_node, "virtual-dma",
|
|
|
|
NULL);
|
2007-03-09 12:55:49 +07:00
|
|
|
|
|
|
|
if (vdma) {
|
2009-03-19 13:53:16 +07:00
|
|
|
struct resource *rp = kzalloc(sizeof(*rp), GFP_KERNEL);
|
2007-03-09 12:55:49 +07:00
|
|
|
|
|
|
|
if (!rp) {
|
2010-04-11 10:26:55 +07:00
|
|
|
pr_info("%s: Cannot allocate IOMMU resource.\n",
|
|
|
|
pbm->name);
|
|
|
|
return;
|
2007-03-09 12:55:49 +07:00
|
|
|
}
|
|
|
|
rp->name = "IOMMU";
|
|
|
|
rp->start = pbm->mem_space.start + (unsigned long) vdma[0];
|
|
|
|
rp->end = rp->start + (unsigned long) vdma[1] - 1UL;
|
|
|
|
rp->flags = IORESOURCE_BUSY;
|
2010-04-11 10:26:55 +07:00
|
|
|
if (request_resource(&pbm->mem_space, rp)) {
|
|
|
|
pr_info("%s: Unable to request IOMMU resource.\n",
|
|
|
|
pbm->name);
|
|
|
|
kfree(rp);
|
|
|
|
}
|
2007-03-09 12:55:49 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pci_determine_mem_io_space(struct pci_pbm_info *pbm)
|
|
|
|
{
|
2007-03-29 15:50:16 +07:00
|
|
|
const struct linux_prom_pci_ranges *pbm_ranges;
|
2007-03-09 12:55:49 +07:00
|
|
|
int i, saw_mem, saw_io;
|
2007-03-09 13:28:17 +07:00
|
|
|
int num_pbm_ranges;
|
2007-03-09 12:55:49 +07:00
|
|
|
|
2017-04-21 12:04:48 +07:00
|
|
|
/* Corresponding generic code in of_pci_get_host_bridge_resources() */
|
|
|
|
|
2007-03-09 12:55:49 +07:00
|
|
|
saw_mem = saw_io = 0;
|
2010-04-14 06:12:29 +07:00
|
|
|
pbm_ranges = of_get_property(pbm->op->dev.of_node, "ranges", &i);
|
2007-10-16 10:45:32 +07:00
|
|
|
if (!pbm_ranges) {
|
|
|
|
prom_printf("PCI: Fatal error, missing PBM ranges property "
|
|
|
|
" for %s\n",
|
|
|
|
pbm->name);
|
|
|
|
prom_halt();
|
|
|
|
}
|
|
|
|
|
2007-03-09 13:28:17 +07:00
|
|
|
num_pbm_ranges = i / sizeof(*pbm_ranges);
|
2015-10-20 23:36:53 +07:00
|
|
|
memset(&pbm->mem64_space, 0, sizeof(struct resource));
|
2007-03-09 13:28:17 +07:00
|
|
|
|
|
|
|
for (i = 0; i < num_pbm_ranges; i++) {
|
2007-03-29 15:50:16 +07:00
|
|
|
const struct linux_prom_pci_ranges *pr = &pbm_ranges[i];
|
2017-04-21 12:04:48 +07:00
|
|
|
unsigned long a, size, region_a;
|
2007-03-09 13:28:17 +07:00
|
|
|
u32 parent_phys_hi, parent_phys_lo;
|
2017-04-21 12:04:48 +07:00
|
|
|
u32 child_phys_mid, child_phys_lo;
|
2007-06-13 06:54:08 +07:00
|
|
|
u32 size_hi, size_lo;
|
2007-03-09 12:55:49 +07:00
|
|
|
int type;
|
|
|
|
|
2007-03-09 13:28:17 +07:00
|
|
|
parent_phys_hi = pr->parent_phys_hi;
|
|
|
|
parent_phys_lo = pr->parent_phys_lo;
|
2017-04-21 12:04:48 +07:00
|
|
|
child_phys_mid = pr->child_phys_mid;
|
|
|
|
child_phys_lo = pr->child_phys_lo;
|
2007-03-09 13:28:17 +07:00
|
|
|
if (tlb_type == hypervisor)
|
|
|
|
parent_phys_hi &= 0x0fffffff;
|
|
|
|
|
2007-06-13 06:54:08 +07:00
|
|
|
size_hi = pr->size_hi;
|
|
|
|
size_lo = pr->size_lo;
|
|
|
|
|
2007-03-09 12:55:49 +07:00
|
|
|
type = (pr->child_phys_hi >> 24) & 0x3;
|
2007-03-09 13:28:17 +07:00
|
|
|
a = (((unsigned long)parent_phys_hi << 32UL) |
|
|
|
|
((unsigned long)parent_phys_lo << 0UL));
|
2017-04-21 12:04:48 +07:00
|
|
|
region_a = (((unsigned long)child_phys_mid << 32UL) |
|
|
|
|
((unsigned long)child_phys_lo << 0UL));
|
2007-06-13 06:54:08 +07:00
|
|
|
size = (((unsigned long)size_hi << 32UL) |
|
|
|
|
((unsigned long)size_lo << 0UL));
|
2007-03-09 12:55:49 +07:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case 0:
|
|
|
|
/* PCI config space, 16MB */
|
|
|
|
pbm->config_space = a;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
/* 16-bit IO space, 16MB */
|
|
|
|
pbm->io_space.start = a;
|
2007-06-13 06:54:08 +07:00
|
|
|
pbm->io_space.end = a + size - 1UL;
|
2007-03-09 12:55:49 +07:00
|
|
|
pbm->io_space.flags = IORESOURCE_IO;
|
2017-04-21 12:04:48 +07:00
|
|
|
pbm->io_offset = a - region_a;
|
2007-03-09 12:55:49 +07:00
|
|
|
saw_io = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
/* 32-bit MEM space, 2GB */
|
|
|
|
pbm->mem_space.start = a;
|
2007-06-13 06:54:08 +07:00
|
|
|
pbm->mem_space.end = a + size - 1UL;
|
2007-03-09 12:55:49 +07:00
|
|
|
pbm->mem_space.flags = IORESOURCE_MEM;
|
2017-04-21 12:04:48 +07:00
|
|
|
pbm->mem_offset = a - region_a;
|
2007-03-09 12:55:49 +07:00
|
|
|
saw_mem = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2015-10-20 23:36:53 +07:00
|
|
|
/* 64-bit MEM handling */
|
|
|
|
pbm->mem64_space.start = a;
|
|
|
|
pbm->mem64_space.end = a + size - 1UL;
|
|
|
|
pbm->mem64_space.flags = IORESOURCE_MEM;
|
2017-04-21 12:04:48 +07:00
|
|
|
pbm->mem64_offset = a - region_a;
|
2015-10-20 23:36:53 +07:00
|
|
|
saw_mem = 1;
|
|
|
|
break;
|
2007-03-09 12:55:49 +07:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2011-06-03 21:45:23 +07:00
|
|
|
}
|
2007-03-09 12:55:49 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!saw_io || !saw_mem) {
|
|
|
|
prom_printf("%s: Fatal error, missing %s PBM range.\n",
|
|
|
|
pbm->name,
|
|
|
|
(!saw_io ? "IO" : "MEM"));
|
|
|
|
prom_halt();
|
|
|
|
}
|
|
|
|
|
2017-04-21 12:04:48 +07:00
|
|
|
if (pbm->io_space.flags)
|
|
|
|
printk("%s: PCI IO %pR offset %llx\n",
|
|
|
|
pbm->name, &pbm->io_space, pbm->io_offset);
|
|
|
|
if (pbm->mem_space.flags)
|
|
|
|
printk("%s: PCI MEM %pR offset %llx\n",
|
|
|
|
pbm->name, &pbm->mem_space, pbm->mem_offset);
|
|
|
|
if (pbm->mem64_space.flags && pbm->mem_space.flags) {
|
|
|
|
if (pbm->mem64_space.start <= pbm->mem_space.end)
|
|
|
|
pbm->mem64_space.start = pbm->mem_space.end + 1;
|
|
|
|
if (pbm->mem64_space.start > pbm->mem64_space.end)
|
|
|
|
pbm->mem64_space.flags = 0;
|
|
|
|
}
|
|
|
|
|
2015-10-20 23:36:53 +07:00
|
|
|
if (pbm->mem64_space.flags)
|
2017-04-21 12:04:48 +07:00
|
|
|
printk("%s: PCI MEM64 %pR offset %llx\n",
|
|
|
|
pbm->name, &pbm->mem64_space, pbm->mem64_offset);
|
2007-03-09 12:55:49 +07:00
|
|
|
|
|
|
|
pbm->io_space.name = pbm->mem_space.name = pbm->name;
|
2015-10-20 23:36:53 +07:00
|
|
|
pbm->mem64_space.name = pbm->name;
|
2007-03-09 12:55:49 +07:00
|
|
|
|
|
|
|
request_resource(&ioport_resource, &pbm->io_space);
|
|
|
|
request_resource(&iomem_resource, &pbm->mem_space);
|
2015-10-20 23:36:53 +07:00
|
|
|
if (pbm->mem64_space.flags)
|
|
|
|
request_resource(&iomem_resource, &pbm->mem64_space);
|
2007-03-09 12:55:49 +07:00
|
|
|
|
|
|
|
pci_register_legacy_regions(&pbm->io_space,
|
|
|
|
&pbm->mem_space);
|
|
|
|
pci_register_iommu_region(pbm);
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Generic helper routines for PCI error reporting. */
|
2007-05-08 13:49:01 +07:00
|
|
|
void pci_scan_for_target_abort(struct pci_pbm_info *pbm,
|
2005-04-17 05:20:36 +07:00
|
|
|
struct pci_bus *pbus)
|
|
|
|
{
|
|
|
|
struct pci_dev *pdev;
|
|
|
|
struct pci_bus *bus;
|
|
|
|
|
|
|
|
list_for_each_entry(pdev, &pbus->devices, bus_list) {
|
|
|
|
u16 status, error_bits;
|
|
|
|
|
|
|
|
pci_read_config_word(pdev, PCI_STATUS, &status);
|
|
|
|
error_bits =
|
|
|
|
(status & (PCI_STATUS_SIG_TARGET_ABORT |
|
|
|
|
PCI_STATUS_REC_TARGET_ABORT));
|
|
|
|
if (error_bits) {
|
|
|
|
pci_write_config_word(pdev, PCI_STATUS, error_bits);
|
2007-05-08 13:49:01 +07:00
|
|
|
printk("%s: Device %s saw Target Abort [%016x]\n",
|
|
|
|
pbm->name, pci_name(pdev), status);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry(bus, &pbus->children, node)
|
2007-05-08 13:49:01 +07:00
|
|
|
pci_scan_for_target_abort(pbm, bus);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2007-05-08 13:49:01 +07:00
|
|
|
void pci_scan_for_master_abort(struct pci_pbm_info *pbm,
|
2005-04-17 05:20:36 +07:00
|
|
|
struct pci_bus *pbus)
|
|
|
|
{
|
|
|
|
struct pci_dev *pdev;
|
|
|
|
struct pci_bus *bus;
|
|
|
|
|
|
|
|
list_for_each_entry(pdev, &pbus->devices, bus_list) {
|
|
|
|
u16 status, error_bits;
|
|
|
|
|
|
|
|
pci_read_config_word(pdev, PCI_STATUS, &status);
|
|
|
|
error_bits =
|
|
|
|
(status & (PCI_STATUS_REC_MASTER_ABORT));
|
|
|
|
if (error_bits) {
|
|
|
|
pci_write_config_word(pdev, PCI_STATUS, error_bits);
|
2007-05-08 13:49:01 +07:00
|
|
|
printk("%s: Device %s received Master Abort [%016x]\n",
|
|
|
|
pbm->name, pci_name(pdev), status);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry(bus, &pbus->children, node)
|
2007-05-08 13:49:01 +07:00
|
|
|
pci_scan_for_master_abort(pbm, bus);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2007-05-08 13:49:01 +07:00
|
|
|
void pci_scan_for_parity_error(struct pci_pbm_info *pbm,
|
2005-04-17 05:20:36 +07:00
|
|
|
struct pci_bus *pbus)
|
|
|
|
{
|
|
|
|
struct pci_dev *pdev;
|
|
|
|
struct pci_bus *bus;
|
|
|
|
|
|
|
|
list_for_each_entry(pdev, &pbus->devices, bus_list) {
|
|
|
|
u16 status, error_bits;
|
|
|
|
|
|
|
|
pci_read_config_word(pdev, PCI_STATUS, &status);
|
|
|
|
error_bits =
|
|
|
|
(status & (PCI_STATUS_PARITY |
|
|
|
|
PCI_STATUS_DETECTED_PARITY));
|
|
|
|
if (error_bits) {
|
|
|
|
pci_write_config_word(pdev, PCI_STATUS, error_bits);
|
2007-05-08 13:49:01 +07:00
|
|
|
printk("%s: Device %s saw Parity Error [%016x]\n",
|
|
|
|
pbm->name, pci_name(pdev), status);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry(bus, &pbus->children, node)
|
2007-05-08 13:49:01 +07:00
|
|
|
pci_scan_for_parity_error(pbm, bus);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|