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 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/arch/alpha/kernel/pci.c
|
|
|
|
*
|
|
|
|
* Extruded from code written by
|
|
|
|
* Dave Rusling (david.rusling@reo.mts.dec.com)
|
|
|
|
* David Mosberger (davidm@cs.arizona.edu)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* 2.3.x PCI/resources, 1999 Andrea Arcangeli <andrea@suse.de> */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Nov 2000, Ivan Kokshaysky <ink@jurassic.park.msu.ru>
|
|
|
|
* PCI-PCI bridges cleanup
|
|
|
|
*/
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/kernel.h>
|
2018-10-31 06:09:49 +08:00
|
|
|
#include <linux/memblock.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/cache.h>
|
|
|
|
#include <linux/slab.h>
|
2018-03-19 00:58:18 +08:00
|
|
|
#include <linux/syscalls.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/machvec.h>
|
|
|
|
|
|
|
|
#include "proto.h"
|
|
|
|
#include "pci_impl.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some string constants used by the various core logics.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const char *const pci_io_names[] = {
|
|
|
|
"PCI IO bus 0", "PCI IO bus 1", "PCI IO bus 2", "PCI IO bus 3",
|
|
|
|
"PCI IO bus 4", "PCI IO bus 5", "PCI IO bus 6", "PCI IO bus 7"
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *const pci_mem_names[] = {
|
|
|
|
"PCI mem bus 0", "PCI mem bus 1", "PCI mem bus 2", "PCI mem bus 3",
|
|
|
|
"PCI mem bus 4", "PCI mem bus 5", "PCI mem bus 6", "PCI mem bus 7"
|
|
|
|
};
|
|
|
|
|
|
|
|
const char pci_hae0_name[] = "HAE0";
|
|
|
|
|
|
|
|
/*
|
2012-02-24 11:18:56 +08:00
|
|
|
* If PCI_PROBE_ONLY in pci_flags is set, we don't change any PCI resource
|
|
|
|
* assignments.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The PCI controller list.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct pci_controller *hose_head, **hose_tail = &hose_head;
|
|
|
|
struct pci_controller *pci_isa_hose;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Quirks.
|
|
|
|
*/
|
|
|
|
|
2012-12-22 06:05:55 +08:00
|
|
|
static void quirk_isa_bridge(struct pci_dev *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
dev->class = PCI_CLASS_BRIDGE_ISA << 8;
|
|
|
|
}
|
|
|
|
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82378, quirk_isa_bridge);
|
|
|
|
|
2012-12-22 06:05:55 +08:00
|
|
|
static void quirk_cypress(struct pci_dev *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-21 07:28:54 +08:00
|
|
|
/* The Notorious Cy82C693 chip. */
|
|
|
|
|
|
|
|
/* The generic legacy mode IDE fixup in drivers/pci/probe.c
|
|
|
|
doesn't work correctly with the Cypress IDE controller as
|
|
|
|
it has non-standard register layout. Fix that. */
|
|
|
|
if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE) {
|
|
|
|
dev->resource[2].start = dev->resource[3].start = 0;
|
|
|
|
dev->resource[2].end = dev->resource[3].end = 0;
|
|
|
|
dev->resource[2].flags = dev->resource[3].flags = 0;
|
|
|
|
if (PCI_FUNC(dev->devfn) == 2) {
|
|
|
|
dev->resource[0].start = 0x170;
|
|
|
|
dev->resource[0].end = 0x177;
|
|
|
|
dev->resource[1].start = 0x376;
|
|
|
|
dev->resource[1].end = 0x376;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* The Cypress bridge responds on the PCI bus in the address range
|
|
|
|
0xffff0000-0xffffffff (conventional x86 BIOS ROM). There is no
|
|
|
|
way to turn this off. The bridge also supports several extended
|
|
|
|
BIOS ranges (disabled after power-up), and some consoles do turn
|
|
|
|
them on. So if we use a large direct-map window, or a large SG
|
|
|
|
window, we must avoid the entire 0xfff00000-0xffffffff region. */
|
2008-04-24 20:51:55 +08:00
|
|
|
if (dev->class >> 8 == PCI_CLASS_BRIDGE_ISA) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (__direct_map_base + __direct_map_size >= 0xfff00000UL)
|
|
|
|
__direct_map_size = 0xfff00000UL - __direct_map_base;
|
|
|
|
else {
|
|
|
|
struct pci_controller *hose = dev->sysdata;
|
|
|
|
struct pci_iommu_arena *pci = hose->sg_pci;
|
|
|
|
if (pci && pci->dma_base + pci->size >= 0xfff00000UL)
|
|
|
|
pci->size = 0xfff00000UL - pci->dma_base;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_CONTAQ, PCI_DEVICE_ID_CONTAQ_82C693, quirk_cypress);
|
|
|
|
|
|
|
|
/* Called for each device after PCI setup is done. */
|
2012-12-22 06:05:55 +08:00
|
|
|
static void pcibios_fixup_final(struct pci_dev *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned int class = dev->class >> 8;
|
|
|
|
|
|
|
|
if (class == PCI_CLASS_BRIDGE_ISA || class == PCI_CLASS_BRIDGE_EISA) {
|
|
|
|
dev->dma_mask = MAX_ISA_DMA_ADDRESS - 1;
|
|
|
|
isa_bridge = dev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, pcibios_fixup_final);
|
|
|
|
|
|
|
|
/* Just declaring that the power-of-ten prefixes are actually the
|
|
|
|
power-of-two ones doesn't make it true :) */
|
|
|
|
#define KB 1024
|
|
|
|
#define MB (1024*KB)
|
|
|
|
#define GB (1024*MB)
|
|
|
|
|
2010-01-02 00:40:49 +08:00
|
|
|
resource_size_t
|
2010-01-02 00:40:50 +08:00
|
|
|
pcibios_align_resource(void *data, const struct resource *res,
|
2006-06-13 08:06:02 +08:00
|
|
|
resource_size_t size, resource_size_t align)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct pci_dev *dev = data;
|
|
|
|
struct pci_controller *hose = dev->sysdata;
|
|
|
|
unsigned long alignto;
|
2006-06-13 08:06:02 +08:00
|
|
|
resource_size_t start = res->start;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (res->flags & IORESOURCE_IO) {
|
|
|
|
/* Make sure we start at our min on all hoses */
|
|
|
|
if (start - hose->io_space->start < PCIBIOS_MIN_IO)
|
|
|
|
start = PCIBIOS_MIN_IO + hose->io_space->start;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Put everything into 0x00-0xff region modulo 0x400
|
|
|
|
*/
|
|
|
|
if (start & 0x300)
|
|
|
|
start = (start + 0x3ff) & ~0x3ff;
|
|
|
|
}
|
|
|
|
else if (res->flags & IORESOURCE_MEM) {
|
|
|
|
/* Make sure we start at our min on all hoses */
|
|
|
|
if (start - hose->mem_space->start < PCIBIOS_MIN_MEM)
|
|
|
|
start = PCIBIOS_MIN_MEM + hose->mem_space->start;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following holds at least for the Low Cost
|
|
|
|
* Alpha implementation of the PCI interface:
|
|
|
|
*
|
|
|
|
* In sparse memory address space, the first
|
|
|
|
* octant (16MB) of every 128MB segment is
|
|
|
|
* aliased to the very first 16 MB of the
|
|
|
|
* address space (i.e., it aliases the ISA
|
|
|
|
* memory address space). Thus, we try to
|
|
|
|
* avoid allocating PCI devices in that range.
|
|
|
|
* Can be allocated in 2nd-7th octant only.
|
|
|
|
* Devices that need more than 112MB of
|
|
|
|
* address space must be accessed through
|
|
|
|
* dense memory space only!
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Align to multiple of size of minimum base. */
|
2009-04-01 06:23:36 +08:00
|
|
|
alignto = max_t(resource_size_t, 0x1000, align);
|
2005-04-17 06:20:36 +08:00
|
|
|
start = ALIGN(start, alignto);
|
|
|
|
if (hose->sparse_mem_base && size <= 7 * 16*MB) {
|
|
|
|
if (((start / (16*MB)) & 0x7) == 0) {
|
|
|
|
start &= ~(128*MB - 1);
|
|
|
|
start += 16*MB;
|
|
|
|
start = ALIGN(start, alignto);
|
|
|
|
}
|
|
|
|
if (start/(128*MB) != (start + size - 1)/(128*MB)) {
|
|
|
|
start &= ~(128*MB - 1);
|
|
|
|
start += (128 + 16)*MB;
|
|
|
|
start = ALIGN(start, alignto);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-02 00:40:49 +08:00
|
|
|
return start;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
#undef KB
|
|
|
|
#undef MB
|
|
|
|
#undef GB
|
|
|
|
|
|
|
|
static int __init
|
|
|
|
pcibios_init(void)
|
|
|
|
{
|
|
|
|
if (alpha_mv.init_pci)
|
|
|
|
alpha_mv.init_pci();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
subsys_initcall(pcibios_init);
|
|
|
|
|
|
|
|
#ifdef ALPHA_RESTORE_SRM_SETUP
|
2017-09-29 05:52:51 +08:00
|
|
|
/* Store PCI device configuration left by SRM here. */
|
|
|
|
struct pdev_srm_saved_conf
|
|
|
|
{
|
|
|
|
struct pdev_srm_saved_conf *next;
|
|
|
|
struct pci_dev *dev;
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct pdev_srm_saved_conf *srm_saved_configs;
|
|
|
|
|
2017-09-29 05:52:51 +08:00
|
|
|
static void pdev_save_srm_config(struct pci_dev *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct pdev_srm_saved_conf *tmp;
|
|
|
|
static int printed = 0;
|
|
|
|
|
2012-02-24 11:18:56 +08:00
|
|
|
if (!alpha_using_srm || pci_has_flag(PCI_PROBE_ONLY))
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!printed) {
|
|
|
|
printk(KERN_INFO "pci: enabling save/restore of SRM state\n");
|
|
|
|
printed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
|
|
|
|
if (!tmp) {
|
2008-04-28 17:13:46 +08:00
|
|
|
printk(KERN_ERR "%s: kmalloc() failed!\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
tmp->next = srm_saved_configs;
|
|
|
|
tmp->dev = dev;
|
|
|
|
|
|
|
|
pci_save_state(dev);
|
|
|
|
|
|
|
|
srm_saved_configs = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pci_restore_srm_config(void)
|
|
|
|
{
|
|
|
|
struct pdev_srm_saved_conf *tmp;
|
|
|
|
|
|
|
|
/* No need to restore if probed only. */
|
2012-02-24 11:18:56 +08:00
|
|
|
if (pci_has_flag(PCI_PROBE_ONLY))
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Restore SRM config. */
|
|
|
|
for (tmp = srm_saved_configs; tmp; tmp = tmp->next) {
|
|
|
|
pci_restore_state(tmp->dev);
|
|
|
|
}
|
|
|
|
}
|
2017-09-29 05:52:51 +08:00
|
|
|
#else
|
|
|
|
#define pdev_save_srm_config(dev) do {} while (0)
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
2012-12-22 06:05:55 +08:00
|
|
|
void pcibios_fixup_bus(struct pci_bus *bus)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
PCI: Revert "PCI: Call pci_read_bridge_bases() from core instead of arch code"
Revert dff22d2054b5 ("PCI: Call pci_read_bridge_bases() from core instead
of arch code").
Reading PCI bridge windows is not arch-specific in itself, but there is PCI
core code that doesn't work correctly if we read them too early. For
example, Hannes found this case on an ARM Freescale i.mx6 board:
pci_bus 0000:00: root bus resource [mem 0x01000000-0x01efffff]
pci 0000:00:00.0: PCI bridge to [bus 01-ff]
pci 0000:00:00.0: BAR 8: no space for [mem size 0x01000000] (mem window)
pci 0000:01:00.0: BAR 2: failed to assign [mem size 0x00200000]
pci 0000:01:00.0: BAR 1: failed to assign [mem size 0x00004000]
pci 0000:01:00.0: BAR 0: failed to assign [mem size 0x00000100]
The 00:00.0 mem window needs to be at least 3MB: the 01:00.0 device needs
0x204100 of space, and mem windows are megabyte-aligned.
Bus sizing can increase a bridge window size, but never *decrease* it (see
d65245c3297a ("PCI: don't shrink bridge resources")). Prior to
dff22d2054b5, ARM didn't read bridge windows at all, so the "original size"
was zero, and we assigned a 3MB window.
After dff22d2054b5, we read the bridge windows before sizing the bus. The
firmware programmed a 16MB window (size 0x01000000) in 00:00.0, and since
we never decrease the size, we kept 16MB even though we only needed 3MB.
But 16MB doesn't fit in the host bridge aperture, so we failed to assign
space for the window and the downstream devices.
I think this is a defect in the PCI core: we shouldn't rely on the firmware
to assign sensible windows.
Ray reported a similar problem, also on ARM, with Broadcom iProc.
Issues like this are too hard to fix right now, so revert dff22d2054b5.
Reported-by: Hannes <oe5hpm@gmail.com>
Reported-by: Ray Jui <rjui@broadcom.com>
Link: http://lkml.kernel.org/r/CAAa04yFQEUJm7Jj1qMT57-LG7ZGtnhNDBe=PpSRa70Mj+XhW-A@mail.gmail.com
Link: http://lkml.kernel.org/r/55F75BB8.4070405@broadcom.com
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
2015-09-16 02:18:04 +08:00
|
|
|
struct pci_dev *dev = bus->self;
|
|
|
|
|
|
|
|
if (pci_has_flag(PCI_PROBE_ONLY) && dev &&
|
|
|
|
(dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
|
|
|
|
pci_read_bridge_bases(bus);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
list_for_each_entry(dev, &bus->devices, bus_list) {
|
|
|
|
pdev_save_srm_config(dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we set up a device for bus mastering, we need to check the latency
|
|
|
|
* timer as certain firmware forgets to set it properly, as seen
|
|
|
|
* on SX164 and LX164 with SRM.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pcibios_set_master(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
u8 lat;
|
|
|
|
pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
|
|
|
|
if (lat >= 16) return;
|
|
|
|
printk("PCI: Setting latency timer of device %s to 64\n",
|
|
|
|
pci_name(dev));
|
|
|
|
pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64);
|
|
|
|
}
|
|
|
|
|
2008-04-24 20:51:55 +08:00
|
|
|
void __init
|
2005-04-17 06:20:36 +08:00
|
|
|
pcibios_claim_one_bus(struct pci_bus *b)
|
|
|
|
{
|
|
|
|
struct pci_dev *dev;
|
|
|
|
struct pci_bus *child_bus;
|
|
|
|
|
|
|
|
list_for_each_entry(dev, &b->devices, bus_list) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < PCI_NUM_RESOURCES; i++) {
|
|
|
|
struct resource *r = &dev->resource[i];
|
|
|
|
|
|
|
|
if (r->parent || !r->start || !r->flags)
|
|
|
|
continue;
|
2012-02-24 11:18:56 +08:00
|
|
|
if (pci_has_flag(PCI_PROBE_ONLY) ||
|
2015-01-16 06:21:49 +08:00
|
|
|
(r->flags & IORESOURCE_PCI_FIXED)) {
|
|
|
|
if (pci_claim_resource(dev, i) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pci_claim_bridge_resource(dev, i);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry(child_bus, &b->children, node)
|
|
|
|
pcibios_claim_one_bus(child_bus);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init
|
|
|
|
pcibios_claim_console_setup(void)
|
|
|
|
{
|
|
|
|
struct pci_bus *b;
|
|
|
|
|
|
|
|
list_for_each_entry(b, &pci_root_buses, node)
|
|
|
|
pcibios_claim_one_bus(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init
|
|
|
|
common_init_pci(void)
|
|
|
|
{
|
|
|
|
struct pci_controller *hose;
|
2011-10-29 06:26:11 +08:00
|
|
|
struct list_head resources;
|
2017-08-01 00:37:51 +08:00
|
|
|
struct pci_host_bridge *bridge;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct pci_bus *bus;
|
2017-08-01 00:37:51 +08:00
|
|
|
int ret, next_busno;
|
2005-04-17 06:20:36 +08:00
|
|
|
int need_domain_info = 0;
|
2011-10-29 06:26:11 +08:00
|
|
|
u32 pci_mem_end;
|
|
|
|
u32 sg_base;
|
|
|
|
unsigned long end;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Scan all of the recorded PCI controllers. */
|
|
|
|
for (next_busno = 0, hose = hose_head; hose; hose = hose->next) {
|
2011-10-29 06:26:11 +08:00
|
|
|
sg_base = hose->sg_pci ? hose->sg_pci->dma_base : ~0;
|
|
|
|
|
|
|
|
/* Adjust hose mem_space limit to prevent PCI allocations
|
|
|
|
in the iommu windows. */
|
|
|
|
pci_mem_end = min((u32)__direct_map_base, sg_base) - 1;
|
|
|
|
end = hose->mem_space->start + pci_mem_end;
|
|
|
|
if (hose->mem_space->end > end)
|
|
|
|
hose->mem_space->end = end;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&resources);
|
2012-02-24 11:19:01 +08:00
|
|
|
pci_add_resource_offset(&resources, hose->io_space,
|
|
|
|
hose->io_space->start);
|
|
|
|
pci_add_resource_offset(&resources, hose->mem_space,
|
|
|
|
hose->mem_space->start);
|
2011-10-29 06:26:11 +08:00
|
|
|
|
2017-08-01 00:37:51 +08:00
|
|
|
bridge = pci_alloc_host_bridge(0);
|
|
|
|
if (!bridge)
|
PCI: Assign resources before drivers claim devices (pci_scan_root_bus())
Previously, pci_scan_root_bus() created a root PCI bus, enumerated the
devices on it, and called pci_bus_add_devices(), which made the devices
available for drivers to claim them.
Most callers assigned resources to devices after pci_scan_root_bus()
returns, which may be after drivers have claimed the devices. This is
incorrect; the PCI core should not change device resources while a driver
is managing the device.
Remove pci_bus_add_devices() from pci_scan_root_bus() and do it after any
resource assignment in the callers.
Note that ARM's pci_common_init_dev() already called pci_bus_add_devices()
after pci_scan_root_bus(), so we only need to remove the first call:
pci_common_init_dev
pcibios_init_hw
pci_scan_root_bus
pci_bus_add_devices # first call
pci_bus_assign_resources
pci_bus_add_devices # second call
[bhelgaas: changelog, drop "root_bus" var in alpha common_init_pci(),
return failure earlier in mn10300, add "return" in x86 pcibios_scan_root(),
return early if xtensa platform_pcibios_fixup() fails]
Signed-off-by: Yijing Wang <wangyijing@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
CC: Richard Henderson <rth@twiddle.net>
CC: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
CC: Matt Turner <mattst88@gmail.com>
CC: David Howells <dhowells@redhat.com>
CC: Tony Luck <tony.luck@intel.com>
CC: Michal Simek <monstr@monstr.eu>
CC: Ralf Baechle <ralf@linux-mips.org>
CC: Koichi Yasutake <yasutake.koichi@jp.panasonic.com>
CC: Sebastian Ott <sebott@linux.vnet.ibm.com>
CC: "David S. Miller" <davem@davemloft.net>
CC: Chris Metcalf <cmetcalf@ezchip.com>
CC: Chris Zankel <chris@zankel.net>
CC: Max Filippov <jcmvbkbc@gmail.com>
CC: Thomas Gleixner <tglx@linutronix.de>
2015-03-16 11:18:56 +08:00
|
|
|
continue;
|
2017-08-01 00:37:51 +08:00
|
|
|
|
|
|
|
list_splice_init(&resources, &bridge->windows);
|
|
|
|
bridge->dev.parent = NULL;
|
|
|
|
bridge->sysdata = hose;
|
|
|
|
bridge->busnr = next_busno;
|
|
|
|
bridge->ops = alpha_mv.pci_ops;
|
|
|
|
bridge->swizzle_irq = alpha_mv.pci_swizzle;
|
|
|
|
bridge->map_irq = alpha_mv.pci_map_irq;
|
|
|
|
|
|
|
|
ret = pci_scan_root_bus_bridge(bridge);
|
|
|
|
if (ret) {
|
|
|
|
pci_free_host_bridge(bridge);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bus = hose->bus = bridge->bus;
|
2005-04-17 06:20:36 +08:00
|
|
|
hose->need_domain_info = need_domain_info;
|
2012-05-18 09:51:11 +08:00
|
|
|
next_busno = bus->busn_res.end + 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Don't allow 8-bit bus number overflow inside the hose -
|
|
|
|
reserve some space for bridges. */
|
|
|
|
if (next_busno > 224) {
|
|
|
|
next_busno = 0;
|
|
|
|
need_domain_info = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-24 20:51:55 +08:00
|
|
|
pcibios_claim_console_setup();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
pci_assign_unassigned_resources();
|
PCI: Assign resources before drivers claim devices (pci_scan_root_bus())
Previously, pci_scan_root_bus() created a root PCI bus, enumerated the
devices on it, and called pci_bus_add_devices(), which made the devices
available for drivers to claim them.
Most callers assigned resources to devices after pci_scan_root_bus()
returns, which may be after drivers have claimed the devices. This is
incorrect; the PCI core should not change device resources while a driver
is managing the device.
Remove pci_bus_add_devices() from pci_scan_root_bus() and do it after any
resource assignment in the callers.
Note that ARM's pci_common_init_dev() already called pci_bus_add_devices()
after pci_scan_root_bus(), so we only need to remove the first call:
pci_common_init_dev
pcibios_init_hw
pci_scan_root_bus
pci_bus_add_devices # first call
pci_bus_assign_resources
pci_bus_add_devices # second call
[bhelgaas: changelog, drop "root_bus" var in alpha common_init_pci(),
return failure earlier in mn10300, add "return" in x86 pcibios_scan_root(),
return early if xtensa platform_pcibios_fixup() fails]
Signed-off-by: Yijing Wang <wangyijing@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
CC: Richard Henderson <rth@twiddle.net>
CC: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
CC: Matt Turner <mattst88@gmail.com>
CC: David Howells <dhowells@redhat.com>
CC: Tony Luck <tony.luck@intel.com>
CC: Michal Simek <monstr@monstr.eu>
CC: Ralf Baechle <ralf@linux-mips.org>
CC: Koichi Yasutake <yasutake.koichi@jp.panasonic.com>
CC: Sebastian Ott <sebott@linux.vnet.ibm.com>
CC: "David S. Miller" <davem@davemloft.net>
CC: Chris Metcalf <cmetcalf@ezchip.com>
CC: Chris Zankel <chris@zankel.net>
CC: Max Filippov <jcmvbkbc@gmail.com>
CC: Thomas Gleixner <tglx@linutronix.de>
2015-03-16 11:18:56 +08:00
|
|
|
for (hose = hose_head; hose; hose = hose->next) {
|
|
|
|
bus = hose->bus;
|
|
|
|
if (bus)
|
|
|
|
pci_bus_add_devices(bus);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct pci_controller * __init
|
|
|
|
alloc_pci_controller(void)
|
|
|
|
{
|
|
|
|
struct pci_controller *hose;
|
|
|
|
|
memblock: stop using implicit alignment to SMP_CACHE_BYTES
When a memblock allocation APIs are called with align = 0, the alignment
is implicitly set to SMP_CACHE_BYTES.
Implicit alignment is done deep in the memblock allocator and it can
come as a surprise. Not that such an alignment would be wrong even
when used incorrectly but it is better to be explicit for the sake of
clarity and the prinicple of the least surprise.
Replace all such uses of memblock APIs with the 'align' parameter
explicitly set to SMP_CACHE_BYTES and stop implicit alignment assignment
in the memblock internal allocation functions.
For the case when memblock APIs are used via helper functions, e.g. like
iommu_arena_new_node() in Alpha, the helper functions were detected with
Coccinelle's help and then manually examined and updated where
appropriate.
The direct memblock APIs users were updated using the semantic patch below:
@@
expression size, min_addr, max_addr, nid;
@@
(
|
- memblock_alloc_try_nid_raw(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid_raw(size, SMP_CACHE_BYTES, min_addr, max_addr,
nid)
|
- memblock_alloc_try_nid_nopanic(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid_nopanic(size, SMP_CACHE_BYTES, min_addr, max_addr,
nid)
|
- memblock_alloc_try_nid(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, nid)
|
- memblock_alloc(size, 0)
+ memblock_alloc(size, SMP_CACHE_BYTES)
|
- memblock_alloc_raw(size, 0)
+ memblock_alloc_raw(size, SMP_CACHE_BYTES)
|
- memblock_alloc_from(size, 0, min_addr)
+ memblock_alloc_from(size, SMP_CACHE_BYTES, min_addr)
|
- memblock_alloc_nopanic(size, 0)
+ memblock_alloc_nopanic(size, SMP_CACHE_BYTES)
|
- memblock_alloc_low(size, 0)
+ memblock_alloc_low(size, SMP_CACHE_BYTES)
|
- memblock_alloc_low_nopanic(size, 0)
+ memblock_alloc_low_nopanic(size, SMP_CACHE_BYTES)
|
- memblock_alloc_from_nopanic(size, 0, min_addr)
+ memblock_alloc_from_nopanic(size, SMP_CACHE_BYTES, min_addr)
|
- memblock_alloc_node(size, 0, nid)
+ memblock_alloc_node(size, SMP_CACHE_BYTES, nid)
)
[mhocko@suse.com: changelog update]
[akpm@linux-foundation.org: coding-style fixes]
[rppt@linux.ibm.com: fix missed uses of implicit alignment]
Link: http://lkml.kernel.org/r/20181016133656.GA10925@rapoport-lnx
Link: http://lkml.kernel.org/r/1538687224-17535-1-git-send-email-rppt@linux.vnet.ibm.com
Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Suggested-by: Michal Hocko <mhocko@suse.com>
Acked-by: Paul Burton <paul.burton@mips.com> [MIPS]
Acked-by: Michael Ellerman <mpe@ellerman.id.au> [powerpc]
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Guan Xuetao <gxt@pku.edu.cn>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Richard Weinberger <richard@nod.at>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tony Luck <tony.luck@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-31 06:09:57 +08:00
|
|
|
hose = memblock_alloc(sizeof(*hose), SMP_CACHE_BYTES);
|
2019-03-12 14:30:31 +08:00
|
|
|
if (!hose)
|
|
|
|
panic("%s: Failed to allocate %zu bytes\n", __func__,
|
|
|
|
sizeof(*hose));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
*hose_tail = hose;
|
|
|
|
hose_tail = &hose->next;
|
|
|
|
|
|
|
|
return hose;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct resource * __init
|
|
|
|
alloc_resource(void)
|
|
|
|
{
|
2019-03-12 14:30:31 +08:00
|
|
|
void *ptr = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
|
|
|
|
|
|
|
|
if (!ptr)
|
|
|
|
panic("%s: Failed to allocate %zu bytes\n", __func__,
|
|
|
|
sizeof(struct resource));
|
|
|
|
|
|
|
|
return ptr;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Provide information on locations of various I/O regions in physical
|
|
|
|
memory. Do this on a per-card basis so that we choose the right hose. */
|
|
|
|
|
2018-03-19 00:58:18 +08:00
|
|
|
SYSCALL_DEFINE3(pciconfig_iobase, long, which, unsigned long, bus,
|
|
|
|
unsigned long, dfn)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct pci_controller *hose;
|
|
|
|
struct pci_dev *dev;
|
|
|
|
|
|
|
|
/* from hose or from bus.devfn */
|
|
|
|
if (which & IOBASE_FROM_HOSE) {
|
|
|
|
for(hose = hose_head; hose; hose = hose->next)
|
|
|
|
if (hose->index == bus) break;
|
|
|
|
if (!hose) return -ENODEV;
|
|
|
|
} else {
|
|
|
|
/* Special hook for ISA access. */
|
|
|
|
if (bus == 0 && dfn == 0) {
|
|
|
|
hose = pci_isa_hose;
|
|
|
|
} else {
|
2017-11-28 00:57:38 +08:00
|
|
|
dev = pci_get_domain_bus_and_slot(0, bus, dfn);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
hose = dev->sysdata;
|
2006-12-07 12:33:59 +08:00
|
|
|
pci_dev_put(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (which & ~IOBASE_FROM_HOSE) {
|
|
|
|
case IOBASE_HOSE:
|
|
|
|
return hose->index;
|
|
|
|
case IOBASE_SPARSE_MEM:
|
|
|
|
return hose->sparse_mem_base;
|
|
|
|
case IOBASE_DENSE_MEM:
|
|
|
|
return hose->dense_mem_base;
|
|
|
|
case IOBASE_SPARSE_IO:
|
|
|
|
return hose->sparse_io_base;
|
|
|
|
case IOBASE_DENSE_IO:
|
|
|
|
return hose->dense_io_base;
|
|
|
|
case IOBASE_ROOT_BUS:
|
|
|
|
return hose->bus->number;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2011-11-25 02:48:56 +08:00
|
|
|
/* Destroy an __iomem token. Not copied from lib/iomap.c. */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
void pci_iounmap(struct pci_dev *dev, void __iomem * addr)
|
|
|
|
{
|
|
|
|
if (__is_mmio(addr))
|
|
|
|
iounmap(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(pci_iounmap);
|
2007-01-07 04:48:41 +08:00
|
|
|
|
|
|
|
/* FIXME: Some boxes have multiple ISA bridges! */
|
|
|
|
struct pci_dev *isa_bridge;
|
|
|
|
EXPORT_SYMBOL(isa_bridge);
|