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
|
|
|
/*
|
|
|
|
* core.c - contains all core device and protocol registration functions
|
|
|
|
*
|
|
|
|
* Copyright 2002 Adam Belay <ambx1@neo.rr.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/pnp.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/module.h>
|
2015-03-18 21:39:55 +00:00
|
|
|
#include <linux/mutex.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/errno.h>
|
2007-05-08 07:25:29 +00:00
|
|
|
#include <linux/dma-mapping.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include "base.h"
|
|
|
|
|
|
|
|
static LIST_HEAD(pnp_protocols);
|
|
|
|
LIST_HEAD(pnp_global);
|
2015-03-18 21:39:55 +00:00
|
|
|
DEFINE_MUTEX(pnp_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-05-08 07:35:54 +00:00
|
|
|
/*
|
|
|
|
* ACPI or PNPBIOS should tell us about all platform devices, so we can
|
|
|
|
* skip some blind probes. ISAPNP typically enumerates only plug-in ISA
|
|
|
|
* devices, not built-in things like COM ports.
|
|
|
|
*/
|
|
|
|
int pnp_platform_devices;
|
|
|
|
EXPORT_SYMBOL(pnp_platform_devices);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
void *pnp_alloc(long size)
|
|
|
|
{
|
|
|
|
void *result;
|
|
|
|
|
some kmalloc/memset ->kzalloc (tree wide)
Transform some calls to kmalloc/memset to a single kzalloc (or kcalloc).
Here is a short excerpt of the semantic patch performing
this transformation:
@@
type T2;
expression x;
identifier f,fld;
expression E;
expression E1,E2;
expression e1,e2,e3,y;
statement S;
@@
x =
- kmalloc
+ kzalloc
(E1,E2)
... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
- memset((T2)x,0,E1);
@@
expression E1,E2,E3;
@@
- kzalloc(E1 * E2,E3)
+ kcalloc(E1,E2,E3)
[akpm@linux-foundation.org: get kcalloc args the right way around]
Signed-off-by: Yoann Padioleau <padator@wanadoo.fr>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Acked-by: Russell King <rmk@arm.linux.org.uk>
Cc: Bryan Wu <bryan.wu@analog.com>
Acked-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Acked-by: Roland Dreier <rolandd@cisco.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Acked-by: Dmitry Torokhov <dtor@mail.ru>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Acked-by: Pierre Ossman <drzeus-list@drzeus.cx>
Cc: Jeff Garzik <jeff@garzik.org>
Cc: "David S. Miller" <davem@davemloft.net>
Acked-by: Greg KH <greg@kroah.com>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 08:49:03 +00:00
|
|
|
result = kzalloc(size, GFP_KERNEL);
|
2007-07-26 17:41:20 +00:00
|
|
|
if (!result) {
|
2005-04-16 22:20:36 +00:00
|
|
|
printk(KERN_ERR "pnp: Out of Memory\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-03-18 21:40:04 +00:00
|
|
|
static void pnp_remove_protocol(struct pnp_protocol *protocol)
|
|
|
|
{
|
|
|
|
mutex_lock(&pnp_lock);
|
|
|
|
list_del(&protocol->protocol_list);
|
|
|
|
mutex_unlock(&pnp_lock);
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/**
|
|
|
|
* pnp_protocol_register - adds a pnp protocol to the pnp layer
|
|
|
|
* @protocol: pointer to the corresponding pnp_protocol structure
|
|
|
|
*
|
|
|
|
* Ex protocols: ISAPNP, PNPBIOS, etc
|
|
|
|
*/
|
|
|
|
int pnp_register_protocol(struct pnp_protocol *protocol)
|
|
|
|
{
|
2007-07-26 17:41:20 +00:00
|
|
|
struct list_head *pos;
|
2015-03-18 21:40:04 +00:00
|
|
|
int nodenum, ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
INIT_LIST_HEAD(&protocol->devices);
|
|
|
|
INIT_LIST_HEAD(&protocol->cards);
|
|
|
|
nodenum = 0;
|
2015-03-18 21:40:04 +00:00
|
|
|
|
2015-03-18 21:39:55 +00:00
|
|
|
mutex_lock(&pnp_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* assign the lowest unused number */
|
2007-07-26 17:41:20 +00:00
|
|
|
list_for_each(pos, &pnp_protocols) {
|
|
|
|
struct pnp_protocol *cur = to_pnp_protocol(pos);
|
|
|
|
if (cur->number == nodenum) {
|
2005-04-16 22:20:36 +00:00
|
|
|
pos = &pnp_protocols;
|
|
|
|
nodenum++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-18 21:40:04 +00:00
|
|
|
protocol->number = nodenum;
|
|
|
|
dev_set_name(&protocol->dev, "pnp%d", nodenum);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
list_add_tail(&protocol->protocol_list, &pnp_protocols);
|
2015-03-18 21:40:04 +00:00
|
|
|
|
2015-03-18 21:39:55 +00:00
|
|
|
mutex_unlock(&pnp_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-03-18 21:40:04 +00:00
|
|
|
ret = device_register(&protocol->dev);
|
|
|
|
if (ret)
|
|
|
|
pnp_remove_protocol(protocol);
|
|
|
|
|
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pnp_protocol_unregister - removes a pnp protocol from the pnp layer
|
|
|
|
* @protocol: pointer to the corresponding pnp_protocol structure
|
|
|
|
*/
|
|
|
|
void pnp_unregister_protocol(struct pnp_protocol *protocol)
|
|
|
|
{
|
2015-03-18 21:40:04 +00:00
|
|
|
pnp_remove_protocol(protocol);
|
2005-04-16 22:20:36 +00:00
|
|
|
device_unregister(&protocol->dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pnp_free_ids(struct pnp_dev *dev)
|
|
|
|
{
|
2007-07-26 17:41:20 +00:00
|
|
|
struct pnp_id *id;
|
|
|
|
struct pnp_id *next;
|
2007-07-26 17:41:21 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
id = dev->id;
|
|
|
|
while (id) {
|
|
|
|
next = id->next;
|
|
|
|
kfree(id);
|
|
|
|
id = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
PNP: replace pnp_resource_table with dynamically allocated resources
PNP used to have a fixed-size pnp_resource_table for tracking the
resources used by a device. This table often overflowed, so we've
had to increase the table size, which wastes memory because most
devices have very few resources.
This patch replaces the table with a linked list of resources where
the entries are allocated on demand.
This removes messages like these:
pnpacpi: exceeded the max number of IO resources
00:01: too many I/O port resources
References:
http://bugzilla.kernel.org/show_bug.cgi?id=9535
http://bugzilla.kernel.org/show_bug.cgi?id=9740
http://lkml.org/lkml/2007/11/30/110
This patch also changes the way PNP uses the IORESOURCE_UNSET,
IORESOURCE_AUTO, and IORESOURCE_DISABLED flags.
Prior to this patch, the pnp_resource_table entries used the flags
like this:
IORESOURCE_UNSET
This table entry is unused and available for use. When this flag
is set, we shouldn't look at anything else in the resource structure.
This flag is set when a resource table entry is initialized.
IORESOURCE_AUTO
This resource was assigned automatically by pnp_assign_{io,mem,etc}().
This flag is set when a resource table entry is initialized and
cleared whenever we discover a resource setting by reading an ISAPNP
config register, parsing a PNPBIOS resource data stream, parsing an
ACPI _CRS list, or interpreting a sysfs "set" command.
Resources marked IORESOURCE_AUTO are reinitialized and marked as
IORESOURCE_UNSET by pnp_clean_resource_table() in these cases:
- before we attempt to assign resources automatically,
- if we fail to assign resources automatically,
- after disabling a device
IORESOURCE_DISABLED
Set by pnp_assign_{io,mem,etc}() when automatic assignment fails.
Also set by PNPBIOS and PNPACPI for:
- invalid IRQs or GSI registration failures
- invalid DMA channels
- I/O ports above 0x10000
- mem ranges with negative length
After this patch, there is no pnp_resource_table, and the resource list
entries use the flags like this:
IORESOURCE_UNSET
This flag is no longer used in PNP. Instead of keeping
IORESOURCE_UNSET entries in the resource list, we remove
entries from the list and free them.
IORESOURCE_AUTO
No change in meaning: it still means the resource was assigned
automatically by pnp_assign_{port,mem,etc}(), but these functions
now set the bit explicitly.
We still "clean" a device's resource list in the same places,
but rather than reinitializing IORESOURCE_AUTO entries, we
just remove them from the list.
Note that IORESOURCE_AUTO entries are always at the end of the
list, so removing them doesn't reorder other list entries.
This is because non-IORESOURCE_AUTO entries are added by the
ISAPNP, PNPBIOS, or PNPACPI "get resources" methods and by the
sysfs "set" command. In each of these cases, we completely free
the resource list first.
IORESOURCE_DISABLED
In addition to the cases where we used to set this flag, ISAPNP now
adds an IORESOURCE_DISABLED resource when it reads a configuration
register with a "disabled" value.
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
2008-06-27 22:56:57 +00:00
|
|
|
void pnp_free_resource(struct pnp_resource *pnp_res)
|
|
|
|
{
|
|
|
|
list_del(&pnp_res->list);
|
|
|
|
kfree(pnp_res);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pnp_free_resources(struct pnp_dev *dev)
|
|
|
|
{
|
|
|
|
struct pnp_resource *pnp_res, *tmp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(pnp_res, tmp, &dev->resources, list) {
|
|
|
|
pnp_free_resource(pnp_res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static void pnp_release_device(struct device *dmdev)
|
|
|
|
{
|
2007-07-26 17:41:20 +00:00
|
|
|
struct pnp_dev *dev = to_pnp_dev(dmdev);
|
2007-07-26 17:41:21 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
pnp_free_ids(dev);
|
PNP: replace pnp_resource_table with dynamically allocated resources
PNP used to have a fixed-size pnp_resource_table for tracking the
resources used by a device. This table often overflowed, so we've
had to increase the table size, which wastes memory because most
devices have very few resources.
This patch replaces the table with a linked list of resources where
the entries are allocated on demand.
This removes messages like these:
pnpacpi: exceeded the max number of IO resources
00:01: too many I/O port resources
References:
http://bugzilla.kernel.org/show_bug.cgi?id=9535
http://bugzilla.kernel.org/show_bug.cgi?id=9740
http://lkml.org/lkml/2007/11/30/110
This patch also changes the way PNP uses the IORESOURCE_UNSET,
IORESOURCE_AUTO, and IORESOURCE_DISABLED flags.
Prior to this patch, the pnp_resource_table entries used the flags
like this:
IORESOURCE_UNSET
This table entry is unused and available for use. When this flag
is set, we shouldn't look at anything else in the resource structure.
This flag is set when a resource table entry is initialized.
IORESOURCE_AUTO
This resource was assigned automatically by pnp_assign_{io,mem,etc}().
This flag is set when a resource table entry is initialized and
cleared whenever we discover a resource setting by reading an ISAPNP
config register, parsing a PNPBIOS resource data stream, parsing an
ACPI _CRS list, or interpreting a sysfs "set" command.
Resources marked IORESOURCE_AUTO are reinitialized and marked as
IORESOURCE_UNSET by pnp_clean_resource_table() in these cases:
- before we attempt to assign resources automatically,
- if we fail to assign resources automatically,
- after disabling a device
IORESOURCE_DISABLED
Set by pnp_assign_{io,mem,etc}() when automatic assignment fails.
Also set by PNPBIOS and PNPACPI for:
- invalid IRQs or GSI registration failures
- invalid DMA channels
- I/O ports above 0x10000
- mem ranges with negative length
After this patch, there is no pnp_resource_table, and the resource list
entries use the flags like this:
IORESOURCE_UNSET
This flag is no longer used in PNP. Instead of keeping
IORESOURCE_UNSET entries in the resource list, we remove
entries from the list and free them.
IORESOURCE_AUTO
No change in meaning: it still means the resource was assigned
automatically by pnp_assign_{port,mem,etc}(), but these functions
now set the bit explicitly.
We still "clean" a device's resource list in the same places,
but rather than reinitializing IORESOURCE_AUTO entries, we
just remove them from the list.
Note that IORESOURCE_AUTO entries are always at the end of the
list, so removing them doesn't reorder other list entries.
This is because non-IORESOURCE_AUTO entries are added by the
ISAPNP, PNPBIOS, or PNPACPI "get resources" methods and by the
sysfs "set" command. In each of these cases, we completely free
the resource list first.
IORESOURCE_DISABLED
In addition to the cases where we used to set this flag, ISAPNP now
adds an IORESOURCE_DISABLED resource when it reads a configuration
register with a "disabled" value.
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
2008-06-27 22:56:57 +00:00
|
|
|
pnp_free_resources(dev);
|
PNP: convert resource options to single linked list
ISAPNP, PNPBIOS, and ACPI describe the "possible resource settings" of
a device, i.e., the possibilities an OS bus driver has when it assigns
I/O port, MMIO, and other resources to the device.
PNP used to maintain this "possible resource setting" information in
one independent option structure and a list of dependent option
structures for each device. Each of these option structures had lists
of I/O, memory, IRQ, and DMA resources, for example:
dev
independent options
ind-io0 -> ind-io1 ...
ind-mem0 -> ind-mem1 ...
...
dependent option set 0
dep0-io0 -> dep0-io1 ...
dep0-mem0 -> dep0-mem1 ...
...
dependent option set 1
dep1-io0 -> dep1-io1 ...
dep1-mem0 -> dep1-mem1 ...
...
...
This data structure was designed for ISAPNP, where the OS configures
device resource settings by writing directly to configuration
registers. The OS can write the registers in arbitrary order much
like it writes PCI BARs.
However, for PNPBIOS and ACPI devices, the OS uses firmware interfaces
that perform device configuration, and it is important to pass the
desired settings to those interfaces in the correct order. The OS
learns the correct order by using firmware interfaces that return the
"current resource settings" and "possible resource settings," but the
option structures above doesn't store the ordering information.
This patch replaces the independent and dependent lists with a single
list of options. For example, a device might have possible resource
settings like this:
dev
options
ind-io0 -> dep0-io0 -> dep1->io0 -> ind-io1 ...
All the possible settings are in the same list, in the order they
come from the firmware "possible resource settings" list. Each entry
is tagged with an independent/dependent flag. Dependent entries also
have a "set number" and an optional priority value. All dependent
entries must be assigned from the same set. For example, the OS can
use all the entries from dependent set 0, or all the entries from
dependent set 1, but it cannot mix entries from set 0 with entries
from set 1.
Prior to this patch PNP didn't keep track of the order of this list,
and it assigned all independent options first, then all dependent
ones. Using the example above, that resulted in a "desired
configuration" list like this:
ind->io0 -> ind->io1 -> depN-io0 ...
instead of the list the firmware expects, which looks like this:
ind->io0 -> depN-io0 -> ind-io1 ...
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Rene Herman <rene.herman@gmail.com>
Signed-off-by: Len Brown <len.brown@intel.com>
2008-06-27 22:57:17 +00:00
|
|
|
pnp_free_options(dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree(dev);
|
|
|
|
}
|
|
|
|
|
2010-10-01 08:54:00 +00:00
|
|
|
struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id,
|
|
|
|
const char *pnpid)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-04-28 22:33:54 +00:00
|
|
|
struct pnp_dev *dev;
|
|
|
|
struct pnp_id *dev_id;
|
2007-07-26 17:41:21 +00:00
|
|
|
|
2008-04-28 22:33:54 +00:00
|
|
|
dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
|
|
|
|
if (!dev)
|
|
|
|
return NULL;
|
|
|
|
|
PNP: replace pnp_resource_table with dynamically allocated resources
PNP used to have a fixed-size pnp_resource_table for tracking the
resources used by a device. This table often overflowed, so we've
had to increase the table size, which wastes memory because most
devices have very few resources.
This patch replaces the table with a linked list of resources where
the entries are allocated on demand.
This removes messages like these:
pnpacpi: exceeded the max number of IO resources
00:01: too many I/O port resources
References:
http://bugzilla.kernel.org/show_bug.cgi?id=9535
http://bugzilla.kernel.org/show_bug.cgi?id=9740
http://lkml.org/lkml/2007/11/30/110
This patch also changes the way PNP uses the IORESOURCE_UNSET,
IORESOURCE_AUTO, and IORESOURCE_DISABLED flags.
Prior to this patch, the pnp_resource_table entries used the flags
like this:
IORESOURCE_UNSET
This table entry is unused and available for use. When this flag
is set, we shouldn't look at anything else in the resource structure.
This flag is set when a resource table entry is initialized.
IORESOURCE_AUTO
This resource was assigned automatically by pnp_assign_{io,mem,etc}().
This flag is set when a resource table entry is initialized and
cleared whenever we discover a resource setting by reading an ISAPNP
config register, parsing a PNPBIOS resource data stream, parsing an
ACPI _CRS list, or interpreting a sysfs "set" command.
Resources marked IORESOURCE_AUTO are reinitialized and marked as
IORESOURCE_UNSET by pnp_clean_resource_table() in these cases:
- before we attempt to assign resources automatically,
- if we fail to assign resources automatically,
- after disabling a device
IORESOURCE_DISABLED
Set by pnp_assign_{io,mem,etc}() when automatic assignment fails.
Also set by PNPBIOS and PNPACPI for:
- invalid IRQs or GSI registration failures
- invalid DMA channels
- I/O ports above 0x10000
- mem ranges with negative length
After this patch, there is no pnp_resource_table, and the resource list
entries use the flags like this:
IORESOURCE_UNSET
This flag is no longer used in PNP. Instead of keeping
IORESOURCE_UNSET entries in the resource list, we remove
entries from the list and free them.
IORESOURCE_AUTO
No change in meaning: it still means the resource was assigned
automatically by pnp_assign_{port,mem,etc}(), but these functions
now set the bit explicitly.
We still "clean" a device's resource list in the same places,
but rather than reinitializing IORESOURCE_AUTO entries, we
just remove them from the list.
Note that IORESOURCE_AUTO entries are always at the end of the
list, so removing them doesn't reorder other list entries.
This is because non-IORESOURCE_AUTO entries are added by the
ISAPNP, PNPBIOS, or PNPACPI "get resources" methods and by the
sysfs "set" command. In each of these cases, we completely free
the resource list first.
IORESOURCE_DISABLED
In addition to the cases where we used to set this flag, ISAPNP now
adds an IORESOURCE_DISABLED resource when it reads a configuration
register with a "disabled" value.
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
2008-06-27 22:56:57 +00:00
|
|
|
INIT_LIST_HEAD(&dev->resources);
|
PNP: convert resource options to single linked list
ISAPNP, PNPBIOS, and ACPI describe the "possible resource settings" of
a device, i.e., the possibilities an OS bus driver has when it assigns
I/O port, MMIO, and other resources to the device.
PNP used to maintain this "possible resource setting" information in
one independent option structure and a list of dependent option
structures for each device. Each of these option structures had lists
of I/O, memory, IRQ, and DMA resources, for example:
dev
independent options
ind-io0 -> ind-io1 ...
ind-mem0 -> ind-mem1 ...
...
dependent option set 0
dep0-io0 -> dep0-io1 ...
dep0-mem0 -> dep0-mem1 ...
...
dependent option set 1
dep1-io0 -> dep1-io1 ...
dep1-mem0 -> dep1-mem1 ...
...
...
This data structure was designed for ISAPNP, where the OS configures
device resource settings by writing directly to configuration
registers. The OS can write the registers in arbitrary order much
like it writes PCI BARs.
However, for PNPBIOS and ACPI devices, the OS uses firmware interfaces
that perform device configuration, and it is important to pass the
desired settings to those interfaces in the correct order. The OS
learns the correct order by using firmware interfaces that return the
"current resource settings" and "possible resource settings," but the
option structures above doesn't store the ordering information.
This patch replaces the independent and dependent lists with a single
list of options. For example, a device might have possible resource
settings like this:
dev
options
ind-io0 -> dep0-io0 -> dep1->io0 -> ind-io1 ...
All the possible settings are in the same list, in the order they
come from the firmware "possible resource settings" list. Each entry
is tagged with an independent/dependent flag. Dependent entries also
have a "set number" and an optional priority value. All dependent
entries must be assigned from the same set. For example, the OS can
use all the entries from dependent set 0, or all the entries from
dependent set 1, but it cannot mix entries from set 0 with entries
from set 1.
Prior to this patch PNP didn't keep track of the order of this list,
and it assigned all independent options first, then all dependent
ones. Using the example above, that resulted in a "desired
configuration" list like this:
ind->io0 -> ind->io1 -> depN-io0 ...
instead of the list the firmware expects, which looks like this:
ind->io0 -> depN-io0 -> ind-io1 ...
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Rene Herman <rene.herman@gmail.com>
Signed-off-by: Len Brown <len.brown@intel.com>
2008-06-27 22:57:17 +00:00
|
|
|
INIT_LIST_HEAD(&dev->options);
|
2008-04-28 22:33:54 +00:00
|
|
|
dev->protocol = protocol;
|
|
|
|
dev->number = id;
|
2009-04-07 02:01:18 +00:00
|
|
|
dev->dma_mask = DMA_BIT_MASK(24);
|
2008-04-28 22:33:54 +00:00
|
|
|
|
|
|
|
dev->dev.parent = &dev->protocol->dev;
|
2005-04-16 22:20:36 +00:00
|
|
|
dev->dev.bus = &pnp_bus_type;
|
2007-05-08 07:25:29 +00:00
|
|
|
dev->dev.dma_mask = &dev->dma_mask;
|
2008-04-28 22:33:54 +00:00
|
|
|
dev->dev.coherent_dma_mask = dev->dma_mask;
|
2005-04-16 22:20:36 +00:00
|
|
|
dev->dev.release = &pnp_release_device;
|
2008-04-28 22:33:54 +00:00
|
|
|
|
2009-01-06 18:44:38 +00:00
|
|
|
dev_set_name(&dev->dev, "%02x:%02x", dev->protocol->number, dev->number);
|
2008-04-28 22:33:54 +00:00
|
|
|
|
|
|
|
dev_id = pnp_add_id(dev, pnpid);
|
|
|
|
if (!dev_id) {
|
|
|
|
kfree(dev);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
2015-03-18 21:40:04 +00:00
|
|
|
static void pnp_delist_device(struct pnp_dev *dev)
|
|
|
|
{
|
|
|
|
mutex_lock(&pnp_lock);
|
|
|
|
list_del(&dev->global_list);
|
|
|
|
list_del(&dev->protocol_list);
|
|
|
|
mutex_unlock(&pnp_lock);
|
|
|
|
}
|
|
|
|
|
2008-04-28 22:33:54 +00:00
|
|
|
int __pnp_add_device(struct pnp_dev *dev)
|
|
|
|
{
|
2015-03-18 21:40:04 +00:00
|
|
|
int ret;
|
|
|
|
|
2008-04-28 22:33:54 +00:00
|
|
|
pnp_fixup_device(dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
dev->status = PNP_READY;
|
2015-03-18 21:40:04 +00:00
|
|
|
|
2015-03-18 21:39:55 +00:00
|
|
|
mutex_lock(&pnp_lock);
|
2015-03-18 21:40:04 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
list_add_tail(&dev->global_list, &pnp_global);
|
|
|
|
list_add_tail(&dev->protocol_list, &dev->protocol->devices);
|
2015-03-18 21:40:04 +00:00
|
|
|
|
2015-03-18 21:39:55 +00:00
|
|
|
mutex_unlock(&pnp_lock);
|
2015-03-18 21:40:04 +00:00
|
|
|
|
|
|
|
ret = device_register(&dev->dev);
|
|
|
|
if (ret)
|
|
|
|
pnp_delist_device(dev);
|
|
|
|
else if (dev->protocol->can_wakeup)
|
2010-06-29 20:49:24 +00:00
|
|
|
device_set_wakeup_capable(&dev->dev,
|
|
|
|
dev->protocol->can_wakeup(dev));
|
2015-03-18 21:40:04 +00:00
|
|
|
|
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pnp_add_device - adds a pnp device to the pnp layer
|
|
|
|
* @dev: pointer to dev to add
|
|
|
|
*
|
|
|
|
* adds to driver model, name database, fixups, interface, etc.
|
|
|
|
*/
|
|
|
|
int pnp_add_device(struct pnp_dev *dev)
|
|
|
|
{
|
2007-10-17 06:31:12 +00:00
|
|
|
int ret;
|
2008-08-19 22:53:36 +00:00
|
|
|
char buf[128];
|
|
|
|
int len = 0;
|
|
|
|
struct pnp_id *id;
|
2007-10-17 06:31:12 +00:00
|
|
|
|
2007-08-15 16:32:13 +00:00
|
|
|
if (dev->card)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
2007-10-17 06:31:12 +00:00
|
|
|
|
|
|
|
ret = __pnp_add_device(dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2008-08-19 22:53:36 +00:00
|
|
|
buf[0] = '\0';
|
|
|
|
for (id = dev->id; id; id = id->next)
|
|
|
|
len += scnprintf(buf + len, sizeof(buf) - len, " %s", id->id);
|
2007-10-17 06:31:12 +00:00
|
|
|
|
2010-09-29 18:24:23 +00:00
|
|
|
dev_printk(KERN_DEBUG, &dev->dev, "%s device, IDs%s (%s)\n",
|
|
|
|
dev->protocol->name, buf,
|
|
|
|
dev->active ? "active" : "disabled");
|
2007-10-17 06:31:12 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __pnp_remove_device(struct pnp_dev *dev)
|
|
|
|
{
|
2015-03-18 21:40:04 +00:00
|
|
|
pnp_delist_device(dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
device_unregister(&dev->dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init pnp_init(void)
|
|
|
|
{
|
|
|
|
return bus_register(&pnp_bus_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
subsys_initcall(pnp_init);
|
2008-08-19 22:53:41 +00:00
|
|
|
|
|
|
|
int pnp_debug;
|
|
|
|
|
|
|
|
#if defined(CONFIG_PNP_DEBUG_MESSAGES)
|
2010-10-25 19:11:16 +00:00
|
|
|
module_param_named(debug, pnp_debug, int, 0644);
|
2008-08-19 22:53:41 +00:00
|
|
|
#endif
|