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 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* BIOS32 and PCI BIOS handling.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/init.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2005-06-23 07:08:33 +00:00
|
|
|
#include <linux/module.h>
|
2006-12-07 01:14:08 +00:00
|
|
|
#include <linux/uaccess.h>
|
2017-01-27 10:59:46 +00:00
|
|
|
|
2008-12-27 13:02:28 +00:00
|
|
|
#include <asm/pci_x86.h>
|
2017-01-27 10:59:46 +00:00
|
|
|
#include <asm/e820/types.h>
|
2009-01-28 18:34:09 +00:00
|
|
|
#include <asm/pci-functions.h>
|
2017-05-08 22:58:11 +00:00
|
|
|
#include <asm/set_memory.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* BIOS32 signature: "_32_" */
|
|
|
|
#define BIOS32_SIGNATURE (('_' << 0) + ('3' << 8) + ('2' << 16) + ('_' << 24))
|
|
|
|
|
|
|
|
/* PCI signature: "PCI " */
|
|
|
|
#define PCI_SIGNATURE (('P' << 0) + ('C' << 8) + ('I' << 16) + (' ' << 24))
|
|
|
|
|
|
|
|
/* PCI service signature: "$PCI" */
|
|
|
|
#define PCI_SERVICE (('$' << 0) + ('P' << 8) + ('C' << 16) + ('I' << 24))
|
|
|
|
|
|
|
|
/* PCI BIOS hardware mechanism flags */
|
|
|
|
#define PCIBIOS_HW_TYPE1 0x01
|
|
|
|
#define PCIBIOS_HW_TYPE2 0x02
|
|
|
|
#define PCIBIOS_HW_TYPE1_SPEC 0x10
|
|
|
|
#define PCIBIOS_HW_TYPE2_SPEC 0x20
|
|
|
|
|
2010-11-16 21:31:26 +00:00
|
|
|
int pcibios_enabled;
|
|
|
|
|
|
|
|
/* According to the BIOS specification at:
|
|
|
|
* http://members.datafast.net.au/dft0802/specs/bios21.pdf, we could
|
|
|
|
* restrict the x zone to some pages and make it ro. But this may be
|
|
|
|
* broken on some bios, complex to handle with static_protections.
|
|
|
|
* We could make the 0xe0000-0x100000 range rox, but this can break
|
|
|
|
* some ISA mapping.
|
|
|
|
*
|
|
|
|
* So we let's an rw and x hole when pcibios is used. This shouldn't
|
|
|
|
* happen for modern system with mmconfig, and if you don't want it
|
|
|
|
* you could disable pcibios...
|
|
|
|
*/
|
|
|
|
static inline void set_bios_x(void)
|
|
|
|
{
|
|
|
|
pcibios_enabled = 1;
|
|
|
|
set_memory_x(PAGE_OFFSET + BIOS_BEGIN, (BIOS_END - BIOS_BEGIN) >> PAGE_SHIFT);
|
|
|
|
if (__supported_pte_mask & _PAGE_NX)
|
2017-05-21 09:04:41 +00:00
|
|
|
printk(KERN_INFO "PCI: PCI BIOS area is rw and x. Use pci=nobios if you want it NX.\n");
|
2010-11-16 21:31:26 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* This is the standard structure used to identify the entry point
|
|
|
|
* to the BIOS32 Service Directory, as documented in
|
|
|
|
* Standard BIOS 32-bit Service Directory Proposal
|
|
|
|
* Revision 0.4 May 24, 1993
|
|
|
|
* Phoenix Technologies Ltd.
|
|
|
|
* Norwood, MA
|
|
|
|
* and the PCI BIOS specification.
|
|
|
|
*/
|
|
|
|
|
|
|
|
union bios32 {
|
|
|
|
struct {
|
|
|
|
unsigned long signature; /* _32_ */
|
|
|
|
unsigned long entry; /* 32 bit physical address */
|
|
|
|
unsigned char revision; /* Revision level, 0 */
|
|
|
|
unsigned char length; /* Length in paragraphs should be 01 */
|
|
|
|
unsigned char checksum; /* All bytes must add up to zero */
|
|
|
|
unsigned char reserved[5]; /* Must be zero */
|
|
|
|
} fields;
|
|
|
|
char chars[16];
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Physical address of the service directory. I don't know if we're
|
|
|
|
* allowed to have more than one of these or not, so just in case
|
|
|
|
* we'll make pcibios_present() take a memory start parameter and store
|
|
|
|
* the array there.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
unsigned long address;
|
|
|
|
unsigned short segment;
|
2014-08-25 21:26:39 +00:00
|
|
|
} bios32_indirect __initdata = { 0, __KERNEL_CS };
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the entry point for the given service, NULL on error
|
|
|
|
*/
|
|
|
|
|
2014-08-25 21:26:39 +00:00
|
|
|
static unsigned long __init bios32_service(unsigned long service)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned char return_code; /* %al */
|
|
|
|
unsigned long address; /* %ebx */
|
|
|
|
unsigned long length; /* %ecx */
|
|
|
|
unsigned long entry; /* %edx */
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
__asm__("lcall *(%%edi); cld"
|
|
|
|
: "=a" (return_code),
|
|
|
|
"=b" (address),
|
|
|
|
"=c" (length),
|
|
|
|
"=d" (entry)
|
|
|
|
: "0" (service),
|
|
|
|
"1" (0),
|
|
|
|
"D" (&bios32_indirect));
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
switch (return_code) {
|
|
|
|
case 0:
|
|
|
|
return address + entry;
|
|
|
|
case 0x80: /* Not present */
|
|
|
|
printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
|
|
|
|
return 0;
|
|
|
|
default: /* Shouldn't happen */
|
|
|
|
printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
|
|
|
|
service, return_code);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
unsigned long address;
|
|
|
|
unsigned short segment;
|
2016-08-08 23:29:06 +00:00
|
|
|
} pci_indirect __ro_after_init = {
|
|
|
|
.address = 0,
|
|
|
|
.segment = __KERNEL_CS,
|
|
|
|
};
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-08-08 23:29:06 +00:00
|
|
|
static int pci_bios_present __ro_after_init;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-08-25 21:26:39 +00:00
|
|
|
static int __init check_pcibios(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
u32 signature, eax, ebx, ecx;
|
|
|
|
u8 status, major_ver, minor_ver, hw_mech;
|
|
|
|
unsigned long flags, pcibios_entry;
|
|
|
|
|
|
|
|
if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
|
|
|
|
pci_indirect.address = pcibios_entry + PAGE_OFFSET;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
__asm__(
|
|
|
|
"lcall *(%%edi); cld\n\t"
|
|
|
|
"jc 1f\n\t"
|
|
|
|
"xor %%ah, %%ah\n"
|
|
|
|
"1:"
|
|
|
|
: "=d" (signature),
|
|
|
|
"=a" (eax),
|
|
|
|
"=b" (ebx),
|
|
|
|
"=c" (ecx)
|
|
|
|
: "1" (PCIBIOS_PCI_BIOS_PRESENT),
|
|
|
|
"D" (&pci_indirect)
|
|
|
|
: "memory");
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
status = (eax >> 8) & 0xff;
|
|
|
|
hw_mech = eax & 0xff;
|
|
|
|
major_ver = (ebx >> 8) & 0xff;
|
|
|
|
minor_ver = ebx & 0xff;
|
|
|
|
if (pcibios_last_bus < 0)
|
|
|
|
pcibios_last_bus = ecx & 0xff;
|
|
|
|
DBG("PCI: BIOS probe returned s=%02x hw=%02x ver=%02x.%02x l=%02x\n",
|
|
|
|
status, hw_mech, major_ver, minor_ver, pcibios_last_bus);
|
|
|
|
if (status || signature != PCI_SIGNATURE) {
|
|
|
|
printk (KERN_ERR "PCI: BIOS BUG #%x[%08x] found\n",
|
|
|
|
status, signature);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
printk(KERN_INFO "PCI: PCI BIOS revision %x.%02x entry at 0x%lx, last bus=%d\n",
|
|
|
|
major_ver, minor_ver, pcibios_entry, pcibios_last_bus);
|
|
|
|
#ifdef CONFIG_PCI_DIRECT
|
|
|
|
if (!(hw_mech & PCIBIOS_HW_TYPE1))
|
|
|
|
pci_probe &= ~PCI_PROBE_CONF1;
|
|
|
|
if (!(hw_mech & PCIBIOS_HW_TYPE2))
|
|
|
|
pci_probe &= ~PCI_PROBE_CONF2;
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pci_bios_read(unsigned int seg, unsigned int bus,
|
|
|
|
unsigned int devfn, int reg, int len, u32 *value)
|
|
|
|
{
|
|
|
|
unsigned long result = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long bx = (bus << 8) | devfn;
|
2015-12-07 14:24:24 +00:00
|
|
|
u16 number = 0, mask = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
x86/PCI: config space accessor functions should not ignore the segment argument
Without this change, the majority of the raw PCI config space access
functions silently ignore a non-zero segment argument, which is
certainly wrong.
Apart from pci_direct_conf1, all other non-MMCFG access methods get
used only for non-extended accesses (i.e. assigned to raw_pci_ops
only). Consequently, with the way raw_pci_{read,write}() work, it would
be a coding error to call these functions with a non-zero segment (with
the current call flow this cannot happen afaict).
The access method 1 accessor, as it can be used for extended accesses
(on AMD systems) instead gets checks added for the passed in segment to
be zero. This would be the case when on such a system having multiple
PCI segments (don't know whether any exist in practice) MMCFG for some
reason is not usable, and method 1 gets selected for doing extended
accesses. Rather than accessing the wrong device's config space, the
function will now error out.
v2: Convert BUG_ON() to WARN_ON(), and extend description as per Ingo's
request.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
Reviewed-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2011-07-22 07:13:05 +00:00
|
|
|
WARN_ON(seg);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!value || (bus > 255) || (devfn > 255) || (reg > 255))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2010-02-17 14:35:25 +00:00
|
|
|
raw_spin_lock_irqsave(&pci_config_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
switch (len) {
|
|
|
|
case 1:
|
2015-12-07 14:24:24 +00:00
|
|
|
number = PCIBIOS_READ_CONFIG_BYTE;
|
|
|
|
mask = 0xff;
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2015-12-07 14:24:24 +00:00
|
|
|
number = PCIBIOS_READ_CONFIG_WORD;
|
|
|
|
mask = 0xffff;
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2015-12-07 14:24:24 +00:00
|
|
|
number = PCIBIOS_READ_CONFIG_DWORD;
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-12-07 14:24:24 +00:00
|
|
|
__asm__("lcall *(%%esi); cld\n\t"
|
|
|
|
"jc 1f\n\t"
|
|
|
|
"xor %%ah, %%ah\n"
|
|
|
|
"1:"
|
|
|
|
: "=c" (*value),
|
|
|
|
"=a" (result)
|
|
|
|
: "1" (number),
|
|
|
|
"b" (bx),
|
|
|
|
"D" ((long)reg),
|
|
|
|
"S" (&pci_indirect));
|
|
|
|
/*
|
|
|
|
* Zero-extend the result beyond 8 or 16 bits, do not trust the
|
|
|
|
* BIOS having done it:
|
|
|
|
*/
|
|
|
|
if (mask)
|
|
|
|
*value &= mask;
|
|
|
|
|
2010-02-17 14:35:25 +00:00
|
|
|
raw_spin_unlock_irqrestore(&pci_config_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return (int)((result & 0xff00) >> 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pci_bios_write(unsigned int seg, unsigned int bus,
|
|
|
|
unsigned int devfn, int reg, int len, u32 value)
|
|
|
|
{
|
|
|
|
unsigned long result = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long bx = (bus << 8) | devfn;
|
2015-12-07 14:24:24 +00:00
|
|
|
u16 number = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
x86/PCI: config space accessor functions should not ignore the segment argument
Without this change, the majority of the raw PCI config space access
functions silently ignore a non-zero segment argument, which is
certainly wrong.
Apart from pci_direct_conf1, all other non-MMCFG access methods get
used only for non-extended accesses (i.e. assigned to raw_pci_ops
only). Consequently, with the way raw_pci_{read,write}() work, it would
be a coding error to call these functions with a non-zero segment (with
the current call flow this cannot happen afaict).
The access method 1 accessor, as it can be used for extended accesses
(on AMD systems) instead gets checks added for the passed in segment to
be zero. This would be the case when on such a system having multiple
PCI segments (don't know whether any exist in practice) MMCFG for some
reason is not usable, and method 1 gets selected for doing extended
accesses. Rather than accessing the wrong device's config space, the
function will now error out.
v2: Convert BUG_ON() to WARN_ON(), and extend description as per Ingo's
request.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
Reviewed-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2011-07-22 07:13:05 +00:00
|
|
|
WARN_ON(seg);
|
2005-04-16 22:20:36 +00:00
|
|
|
if ((bus > 255) || (devfn > 255) || (reg > 255))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2010-02-17 14:35:25 +00:00
|
|
|
raw_spin_lock_irqsave(&pci_config_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
switch (len) {
|
|
|
|
case 1:
|
2015-12-07 14:24:24 +00:00
|
|
|
number = PCIBIOS_WRITE_CONFIG_BYTE;
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2015-12-07 14:24:24 +00:00
|
|
|
number = PCIBIOS_WRITE_CONFIG_WORD;
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2015-12-07 14:24:24 +00:00
|
|
|
number = PCIBIOS_WRITE_CONFIG_DWORD;
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-12-07 14:24:24 +00:00
|
|
|
__asm__("lcall *(%%esi); cld\n\t"
|
|
|
|
"jc 1f\n\t"
|
|
|
|
"xor %%ah, %%ah\n"
|
|
|
|
"1:"
|
|
|
|
: "=a" (result)
|
|
|
|
: "0" (number),
|
|
|
|
"c" (value),
|
|
|
|
"b" (bx),
|
|
|
|
"D" ((long)reg),
|
|
|
|
"S" (&pci_indirect));
|
|
|
|
|
2010-02-17 14:35:25 +00:00
|
|
|
raw_spin_unlock_irqrestore(&pci_config_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return (int)((result & 0xff00) >> 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function table for BIOS32 access
|
|
|
|
*/
|
|
|
|
|
2011-09-15 07:58:51 +00:00
|
|
|
static const struct pci_raw_ops pci_bios_access = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.read = pci_bios_read,
|
|
|
|
.write = pci_bios_write
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to find PCI BIOS.
|
|
|
|
*/
|
|
|
|
|
2014-08-25 21:26:39 +00:00
|
|
|
static const struct pci_raw_ops *__init pci_find_bios(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
union bios32 *check;
|
|
|
|
unsigned char sum;
|
|
|
|
int i, length;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Follow the standard procedure for locating the BIOS32 Service
|
|
|
|
* directory by scanning the permissible address range from
|
|
|
|
* 0xe0000 through 0xfffff for a valid BIOS32 structure.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (check = (union bios32 *) __va(0xe0000);
|
|
|
|
check <= (union bios32 *) __va(0xffff0);
|
|
|
|
++check) {
|
2006-12-07 01:14:08 +00:00
|
|
|
long sig;
|
|
|
|
if (probe_kernel_address(&check->fields.signature, sig))
|
|
|
|
continue;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (check->fields.signature != BIOS32_SIGNATURE)
|
|
|
|
continue;
|
|
|
|
length = check->fields.length * 16;
|
|
|
|
if (!length)
|
|
|
|
continue;
|
|
|
|
sum = 0;
|
|
|
|
for (i = 0; i < length ; ++i)
|
|
|
|
sum += check->chars[i];
|
|
|
|
if (sum != 0)
|
|
|
|
continue;
|
|
|
|
if (check->fields.revision != 0) {
|
|
|
|
printk("PCI: unsupported BIOS32 revision %d at 0x%p\n",
|
|
|
|
check->fields.revision, check);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
DBG("PCI: BIOS32 Service Directory structure at 0x%p\n", check);
|
|
|
|
if (check->fields.entry >= 0x100000) {
|
2006-12-07 01:14:08 +00:00
|
|
|
printk("PCI: BIOS32 entry (0x%p) in high memory, "
|
|
|
|
"cannot use.\n", check);
|
2005-04-16 22:20:36 +00:00
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
unsigned long bios32_entry = check->fields.entry;
|
2006-12-07 01:14:08 +00:00
|
|
|
DBG("PCI: BIOS32 Service Directory entry at 0x%lx\n",
|
|
|
|
bios32_entry);
|
2005-04-16 22:20:36 +00:00
|
|
|
bios32_indirect.address = bios32_entry + PAGE_OFFSET;
|
2010-11-16 21:31:26 +00:00
|
|
|
set_bios_x();
|
2005-04-16 22:20:36 +00:00
|
|
|
if (check_pcibios())
|
|
|
|
return &pci_bios_access;
|
|
|
|
}
|
|
|
|
break; /* Hopefully more than one BIOS32 cannot happen... */
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* BIOS Functions for IRQ Routing
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct irq_routing_options {
|
|
|
|
u16 size;
|
|
|
|
struct irq_info *table;
|
|
|
|
u16 segment;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2007-08-23 18:45:49 +00:00
|
|
|
struct irq_routing_table * pcibios_get_irq_routing_table(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct irq_routing_options opt;
|
|
|
|
struct irq_routing_table *rt = NULL;
|
|
|
|
int ret, map;
|
|
|
|
unsigned long page;
|
|
|
|
|
|
|
|
if (!pci_bios_present)
|
|
|
|
return NULL;
|
|
|
|
page = __get_free_page(GFP_KERNEL);
|
|
|
|
if (!page)
|
|
|
|
return NULL;
|
|
|
|
opt.table = (struct irq_info *) page;
|
|
|
|
opt.size = PAGE_SIZE;
|
|
|
|
opt.segment = __KERNEL_DS;
|
|
|
|
|
|
|
|
DBG("PCI: Fetching IRQ routing table... ");
|
|
|
|
__asm__("push %%es\n\t"
|
|
|
|
"push %%ds\n\t"
|
|
|
|
"pop %%es\n\t"
|
|
|
|
"lcall *(%%esi); cld\n\t"
|
|
|
|
"pop %%es\n\t"
|
|
|
|
"jc 1f\n\t"
|
|
|
|
"xor %%ah, %%ah\n"
|
|
|
|
"1:"
|
|
|
|
: "=a" (ret),
|
|
|
|
"=b" (map),
|
|
|
|
"=m" (opt)
|
|
|
|
: "0" (PCIBIOS_GET_ROUTING_OPTIONS),
|
|
|
|
"1" (0),
|
|
|
|
"D" ((long) &opt),
|
|
|
|
"S" (&pci_indirect),
|
|
|
|
"m" (opt)
|
|
|
|
: "memory");
|
|
|
|
DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
|
|
|
|
if (ret & 0xff00)
|
|
|
|
printk(KERN_ERR "PCI: Error %02x when fetching IRQ routing table.\n", (ret >> 8) & 0xff);
|
|
|
|
else if (opt.size) {
|
|
|
|
rt = kmalloc(sizeof(struct irq_routing_table) + opt.size, GFP_KERNEL);
|
|
|
|
if (rt) {
|
|
|
|
memset(rt, 0, sizeof(struct irq_routing_table));
|
|
|
|
rt->size = opt.size + sizeof(struct irq_routing_table);
|
|
|
|
rt->exclusive_irqs = map;
|
|
|
|
memcpy(rt->slots, (void *) page, opt.size);
|
|
|
|
printk(KERN_INFO "PCI: Using BIOS Interrupt Routing Table\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free_page(page);
|
|
|
|
return rt;
|
|
|
|
}
|
2005-06-23 07:08:33 +00:00
|
|
|
EXPORT_SYMBOL(pcibios_get_irq_routing_table);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
__asm__("lcall *(%%esi); cld\n\t"
|
|
|
|
"jc 1f\n\t"
|
|
|
|
"xor %%ah, %%ah\n"
|
|
|
|
"1:"
|
|
|
|
: "=a" (ret)
|
|
|
|
: "0" (PCIBIOS_SET_PCI_HW_INT),
|
|
|
|
"b" ((dev->bus->number << 8) | dev->devfn),
|
|
|
|
"c" ((irq << 8) | (pin + 10)),
|
|
|
|
"S" (&pci_indirect));
|
|
|
|
return !(ret & 0xff00);
|
|
|
|
}
|
2005-06-23 07:08:33 +00:00
|
|
|
EXPORT_SYMBOL(pcibios_set_irq_routing);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-03-23 22:35:12 +00:00
|
|
|
void __init pci_pcbios_init(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
if ((pci_probe & PCI_PROBE_BIOS)
|
|
|
|
&& ((raw_pci_ops = pci_find_bios()))) {
|
|
|
|
pci_bios_present = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|