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
|
|
|
/*
|
|
|
|
* Setup routines for AGP 3.5 compliant bridges.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/agp_backend.h>
|
|
|
|
#include <linux/module.h>
|
2005-10-31 07:03:48 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include "agp.h"
|
|
|
|
|
|
|
|
/* Generic AGP 3.5 enabling routines */
|
|
|
|
|
|
|
|
struct agp_3_5_dev {
|
|
|
|
struct list_head list;
|
|
|
|
u8 capndx;
|
|
|
|
u32 maxbw;
|
|
|
|
struct pci_dev *dev;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void agp_3_5_dev_list_insert(struct list_head *head, struct list_head *new)
|
|
|
|
{
|
|
|
|
struct agp_3_5_dev *cur, *n = list_entry(new, struct agp_3_5_dev, list);
|
|
|
|
struct list_head *pos;
|
|
|
|
|
|
|
|
list_for_each(pos, head) {
|
|
|
|
cur = list_entry(pos, struct agp_3_5_dev, list);
|
2006-02-28 13:54:25 +08:00
|
|
|
if (cur->maxbw > n->maxbw)
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
list_add_tail(new, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void agp_3_5_dev_list_sort(struct agp_3_5_dev *list, unsigned int ndevs)
|
|
|
|
{
|
|
|
|
struct agp_3_5_dev *cur;
|
|
|
|
struct pci_dev *dev;
|
|
|
|
struct list_head *pos, *tmp, *head = &list->list, *start = head->next;
|
|
|
|
u32 nistat;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(head);
|
|
|
|
|
|
|
|
for (pos=start; pos!=head; ) {
|
|
|
|
cur = list_entry(pos, struct agp_3_5_dev, list);
|
|
|
|
dev = cur->dev;
|
|
|
|
|
|
|
|
pci_read_config_dword(dev, cur->capndx+AGPNISTAT, &nistat);
|
|
|
|
cur->maxbw = (nistat >> 16) & 0xff;
|
|
|
|
|
|
|
|
tmp = pos;
|
|
|
|
pos = pos->next;
|
|
|
|
agp_3_5_dev_list_insert(head, tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-28 13:54:25 +08:00
|
|
|
/*
|
|
|
|
* Initialize all isochronous transfer parameters for an AGP 3.0
|
|
|
|
* node (i.e. a host bridge in combination with the adapters
|
2005-04-17 06:20:36 +08:00
|
|
|
* lying behind it...)
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int agp_3_5_isochronous_node_enable(struct agp_bridge_data *bridge,
|
|
|
|
struct agp_3_5_dev *dev_list, unsigned int ndevs)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Convenience structure to make the calculations clearer
|
|
|
|
* here. The field names come straight from the AGP 3.0 spec.
|
|
|
|
*/
|
|
|
|
struct isoch_data {
|
|
|
|
u32 maxbw;
|
|
|
|
u32 n;
|
|
|
|
u32 y;
|
|
|
|
u32 l;
|
|
|
|
u32 rq;
|
|
|
|
struct agp_3_5_dev *dev;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pci_dev *td = bridge->dev, *dev;
|
|
|
|
struct list_head *head = &dev_list->list, *pos;
|
|
|
|
struct agp_3_5_dev *cur;
|
|
|
|
struct isoch_data *master, target;
|
|
|
|
unsigned int cdev = 0;
|
|
|
|
u32 mnistat, tnistat, tstatus, mcmd;
|
|
|
|
u16 tnicmd, mnicmd;
|
|
|
|
u8 mcapndx;
|
|
|
|
u32 tot_bw = 0, tot_n = 0, tot_rq = 0, y_max, rq_isoch, rq_async;
|
|
|
|
u32 step, rem, rem_isoch, rem_async;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We'll work with an array of isoch_data's (one for each
|
|
|
|
* device in dev_list) throughout this function.
|
|
|
|
*/
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 04:55:00 +08:00
|
|
|
master = kmalloc_array(ndevs, sizeof(*master), GFP_KERNEL);
|
|
|
|
if (master == NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto get_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sort the device list by maxbw. We need to do this because the
|
|
|
|
* spec suggests that the devices with the smallest requirements
|
|
|
|
* have their resources allocated first, with all remaining resources
|
|
|
|
* falling to the device with the largest requirement.
|
|
|
|
*
|
|
|
|
* We don't exactly do this, we divide target resources by ndevs
|
|
|
|
* and split them amongst the AGP 3.0 devices. The remainder of such
|
|
|
|
* division operations are dropped on the last device, sort of like
|
|
|
|
* the spec mentions it should be done.
|
|
|
|
*
|
|
|
|
* We can't do this sort when we initially construct the dev_list
|
|
|
|
* because we don't know until this function whether isochronous
|
|
|
|
* transfers are enabled and consequently whether maxbw will mean
|
|
|
|
* anything.
|
|
|
|
*/
|
|
|
|
agp_3_5_dev_list_sort(dev_list, ndevs);
|
|
|
|
|
|
|
|
pci_read_config_dword(td, bridge->capndx+AGPNISTAT, &tnistat);
|
|
|
|
pci_read_config_dword(td, bridge->capndx+AGPSTAT, &tstatus);
|
|
|
|
|
|
|
|
/* Extract power-on defaults from the target */
|
|
|
|
target.maxbw = (tnistat >> 16) & 0xff;
|
|
|
|
target.n = (tnistat >> 8) & 0xff;
|
|
|
|
target.y = (tnistat >> 6) & 0x3;
|
|
|
|
target.l = (tnistat >> 3) & 0x7;
|
|
|
|
target.rq = (tstatus >> 24) & 0xff;
|
|
|
|
|
|
|
|
y_max = target.y;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Extract power-on defaults for each device in dev_list. Along
|
|
|
|
* the way, calculate the total isochronous bandwidth required
|
|
|
|
* by these devices and the largest requested payload size.
|
|
|
|
*/
|
|
|
|
list_for_each(pos, head) {
|
|
|
|
cur = list_entry(pos, struct agp_3_5_dev, list);
|
|
|
|
dev = cur->dev;
|
|
|
|
|
|
|
|
mcapndx = cur->capndx;
|
|
|
|
|
|
|
|
pci_read_config_dword(dev, cur->capndx+AGPNISTAT, &mnistat);
|
|
|
|
|
|
|
|
master[cdev].maxbw = (mnistat >> 16) & 0xff;
|
|
|
|
master[cdev].n = (mnistat >> 8) & 0xff;
|
|
|
|
master[cdev].y = (mnistat >> 6) & 0x3;
|
|
|
|
master[cdev].dev = cur;
|
|
|
|
|
|
|
|
tot_bw += master[cdev].maxbw;
|
|
|
|
y_max = max(y_max, master[cdev].y);
|
|
|
|
|
|
|
|
cdev++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this configuration has any chance of working */
|
|
|
|
if (tot_bw > target.maxbw) {
|
2008-07-31 03:26:51 +08:00
|
|
|
dev_err(&td->dev, "isochronous bandwidth required "
|
2005-04-17 06:20:36 +08:00
|
|
|
"by AGP 3.0 devices exceeds that which is supported by "
|
|
|
|
"the AGP 3.0 bridge!\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto free_and_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
target.y = y_max;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the calculated payload size into the target's NICMD
|
|
|
|
* register. Doing this directly effects the ISOCH_N value
|
|
|
|
* in the target's NISTAT register, so we need to do this now
|
|
|
|
* to get an accurate value for ISOCH_N later.
|
|
|
|
*/
|
|
|
|
pci_read_config_word(td, bridge->capndx+AGPNICMD, &tnicmd);
|
|
|
|
tnicmd &= ~(0x3 << 6);
|
|
|
|
tnicmd |= target.y << 6;
|
|
|
|
pci_write_config_word(td, bridge->capndx+AGPNICMD, tnicmd);
|
|
|
|
|
|
|
|
/* Reread the target's ISOCH_N */
|
|
|
|
pci_read_config_dword(td, bridge->capndx+AGPNISTAT, &tnistat);
|
|
|
|
target.n = (tnistat >> 8) & 0xff;
|
|
|
|
|
|
|
|
/* Calculate the minimum ISOCH_N needed by each master */
|
|
|
|
for (cdev=0; cdev<ndevs; cdev++) {
|
|
|
|
master[cdev].y = target.y;
|
|
|
|
master[cdev].n = master[cdev].maxbw / (master[cdev].y + 1);
|
|
|
|
|
|
|
|
tot_n += master[cdev].n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Exit if the minimal ISOCH_N allocation among the masters is more
|
|
|
|
* than the target can handle. */
|
|
|
|
if (tot_n > target.n) {
|
2008-07-31 03:26:51 +08:00
|
|
|
dev_err(&td->dev, "number of isochronous "
|
2005-04-17 06:20:36 +08:00
|
|
|
"transactions per period required by AGP 3.0 devices "
|
|
|
|
"exceeds that which is supported by the AGP 3.0 "
|
|
|
|
"bridge!\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto free_and_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate left over ISOCH_N capability in the target. We'll give
|
|
|
|
* this to the hungriest device (as per the spec) */
|
|
|
|
rem = target.n - tot_n;
|
|
|
|
|
2006-02-28 13:54:25 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Calculate the minimum isochronous RQ depth needed by each master.
|
|
|
|
* Along the way, distribute the extra ISOCH_N capability calculated
|
|
|
|
* above.
|
|
|
|
*/
|
|
|
|
for (cdev=0; cdev<ndevs; cdev++) {
|
|
|
|
/*
|
|
|
|
* This is a little subtle. If ISOCH_Y > 64B, then ISOCH_Y
|
|
|
|
* byte isochronous writes will be broken into 64B pieces.
|
|
|
|
* This means we need to budget more RQ depth to account for
|
|
|
|
* these kind of writes (each isochronous write is actually
|
|
|
|
* many writes on the AGP bus).
|
|
|
|
*/
|
|
|
|
master[cdev].rq = master[cdev].n;
|
2006-02-28 13:54:25 +08:00
|
|
|
if (master[cdev].y > 0x1)
|
2005-04-17 06:20:36 +08:00
|
|
|
master[cdev].rq *= (1 << (master[cdev].y - 1));
|
|
|
|
|
|
|
|
tot_rq += master[cdev].rq;
|
|
|
|
}
|
2005-12-24 00:18:54 +08:00
|
|
|
master[ndevs-1].n += rem;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Figure the number of isochronous and asynchronous RQ slots the
|
|
|
|
* target is providing. */
|
|
|
|
rq_isoch = (target.y > 0x1) ? target.n * (1 << (target.y - 1)) : target.n;
|
|
|
|
rq_async = target.rq - rq_isoch;
|
|
|
|
|
|
|
|
/* Exit if the minimal RQ needs of the masters exceeds what the target
|
|
|
|
* can provide. */
|
|
|
|
if (tot_rq > rq_isoch) {
|
2008-07-31 03:26:51 +08:00
|
|
|
dev_err(&td->dev, "number of request queue slots "
|
2005-04-17 06:20:36 +08:00
|
|
|
"required by the isochronous bandwidth requested by "
|
|
|
|
"AGP 3.0 devices exceeds the number provided by the "
|
|
|
|
"AGP 3.0 bridge!\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto free_and_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate asynchronous RQ capability in the target (per master) as
|
|
|
|
* well as the total number of leftover isochronous RQ slots. */
|
|
|
|
step = rq_async / ndevs;
|
|
|
|
rem_async = step + (rq_async % ndevs);
|
|
|
|
rem_isoch = rq_isoch - tot_rq;
|
|
|
|
|
|
|
|
/* Distribute the extra RQ slots calculated above and write our
|
|
|
|
* isochronous settings out to the actual devices. */
|
|
|
|
for (cdev=0; cdev<ndevs; cdev++) {
|
|
|
|
cur = master[cdev].dev;
|
|
|
|
dev = cur->dev;
|
|
|
|
|
|
|
|
mcapndx = cur->capndx;
|
|
|
|
|
|
|
|
master[cdev].rq += (cdev == ndevs - 1)
|
|
|
|
? (rem_async + rem_isoch) : step;
|
|
|
|
|
|
|
|
pci_read_config_word(dev, cur->capndx+AGPNICMD, &mnicmd);
|
|
|
|
pci_read_config_dword(dev, cur->capndx+AGPCMD, &mcmd);
|
|
|
|
|
|
|
|
mnicmd &= ~(0xff << 8);
|
|
|
|
mnicmd &= ~(0x3 << 6);
|
|
|
|
mcmd &= ~(0xff << 24);
|
|
|
|
|
|
|
|
mnicmd |= master[cdev].n << 8;
|
|
|
|
mnicmd |= master[cdev].y << 6;
|
|
|
|
mcmd |= master[cdev].rq << 24;
|
|
|
|
|
|
|
|
pci_write_config_dword(dev, cur->capndx+AGPCMD, mcmd);
|
|
|
|
pci_write_config_word(dev, cur->capndx+AGPNICMD, mnicmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
free_and_exit:
|
|
|
|
kfree(master);
|
|
|
|
|
|
|
|
get_out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function basically allocates request queue slots among the
|
|
|
|
* AGP 3.0 systems in nonisochronous nodes. The algorithm is
|
|
|
|
* pretty stupid, divide the total number of RQ slots provided by the
|
|
|
|
* target by ndevs. Distribute this many slots to each AGP 3.0 device,
|
|
|
|
* giving any left over slots to the last device in dev_list.
|
|
|
|
*/
|
|
|
|
static void agp_3_5_nonisochronous_node_enable(struct agp_bridge_data *bridge,
|
|
|
|
struct agp_3_5_dev *dev_list, unsigned int ndevs)
|
|
|
|
{
|
|
|
|
struct agp_3_5_dev *cur;
|
|
|
|
struct list_head *head = &dev_list->list, *pos;
|
|
|
|
u32 tstatus, mcmd;
|
|
|
|
u32 trq, mrq, rem;
|
|
|
|
unsigned int cdev = 0;
|
|
|
|
|
|
|
|
pci_read_config_dword(bridge->dev, bridge->capndx+AGPSTAT, &tstatus);
|
|
|
|
|
|
|
|
trq = (tstatus >> 24) & 0xff;
|
|
|
|
mrq = trq / ndevs;
|
|
|
|
|
|
|
|
rem = mrq + (trq % ndevs);
|
|
|
|
|
|
|
|
for (pos=head->next; cdev<ndevs; cdev++, pos=pos->next) {
|
|
|
|
cur = list_entry(pos, struct agp_3_5_dev, list);
|
|
|
|
|
|
|
|
pci_read_config_dword(cur->dev, cur->capndx+AGPCMD, &mcmd);
|
|
|
|
mcmd &= ~(0xff << 24);
|
|
|
|
mcmd |= ((cdev == ndevs - 1) ? rem : mrq) << 24;
|
|
|
|
pci_write_config_dword(cur->dev, cur->capndx+AGPCMD, mcmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fully configure and enable an AGP 3.0 host bridge and all the devices
|
|
|
|
* lying behind it.
|
|
|
|
*/
|
|
|
|
int agp_3_5_enable(struct agp_bridge_data *bridge)
|
|
|
|
{
|
|
|
|
struct pci_dev *td = bridge->dev, *dev = NULL;
|
|
|
|
u8 mcapndx;
|
|
|
|
u32 isoch, arqsz;
|
|
|
|
u32 tstatus, mstatus, ncapid;
|
|
|
|
u32 mmajor;
|
|
|
|
u16 mpstat;
|
|
|
|
struct agp_3_5_dev *dev_list, *cur;
|
|
|
|
struct list_head *head, *pos;
|
|
|
|
unsigned int ndevs = 0;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* Extract some power-on defaults from the target */
|
|
|
|
pci_read_config_dword(td, bridge->capndx+AGPSTAT, &tstatus);
|
|
|
|
isoch = (tstatus >> 17) & 0x1;
|
|
|
|
if (isoch == 0) /* isoch xfers not available, bail out. */
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
arqsz = (tstatus >> 13) & 0x7;
|
|
|
|
|
2006-02-28 13:54:25 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Allocate a head for our AGP 3.5 device list
|
2006-02-28 13:54:25 +08:00
|
|
|
* (multiple AGP v3 devices are allowed behind a single bridge).
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
if ((dev_list = kmalloc(sizeof(*dev_list), GFP_KERNEL)) == NULL) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto get_out;
|
|
|
|
}
|
|
|
|
head = &dev_list->list;
|
|
|
|
INIT_LIST_HEAD(head);
|
|
|
|
|
|
|
|
/* Find all AGP devices, and add them to dev_list. */
|
|
|
|
for_each_pci_dev(dev) {
|
|
|
|
mcapndx = pci_find_capability(dev, PCI_CAP_ID_AGP);
|
|
|
|
if (mcapndx == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch ((dev->class >>8) & 0xff00) {
|
|
|
|
case 0x0600: /* Bridge */
|
|
|
|
/* Skip bridges. We should call this function for each one. */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case 0x0001: /* Unclassified device */
|
|
|
|
/* Don't know what this is, but log it for investigation. */
|
|
|
|
if (mcapndx != 0) {
|
2008-07-31 03:26:51 +08:00
|
|
|
dev_info(&td->dev, "wacky, found unclassified AGP device %s [%04x/%04x]\n",
|
|
|
|
pci_name(dev),
|
|
|
|
dev->vendor, dev->device);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case 0x0300: /* Display controller */
|
|
|
|
case 0x0400: /* Multimedia controller */
|
2006-02-28 13:54:25 +08:00
|
|
|
if ((cur = kmalloc(sizeof(*cur), GFP_KERNEL)) == NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto free_and_exit;
|
|
|
|
}
|
|
|
|
cur->dev = dev;
|
|
|
|
|
|
|
|
pos = &cur->list;
|
|
|
|
list_add(pos, head);
|
|
|
|
ndevs++;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take an initial pass through the devices lying behind our host
|
|
|
|
* bridge. Make sure each one is actually an AGP 3.0 device, otherwise
|
|
|
|
* exit with an error message. Along the way store the AGP 3.0
|
|
|
|
* cap_ptr for each device
|
|
|
|
*/
|
|
|
|
list_for_each(pos, head) {
|
|
|
|
cur = list_entry(pos, struct agp_3_5_dev, list);
|
|
|
|
dev = cur->dev;
|
2006-02-28 13:54:25 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
pci_read_config_word(dev, PCI_STATUS, &mpstat);
|
|
|
|
if ((mpstat & PCI_STATUS_CAP_LIST) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pci_read_config_byte(dev, PCI_CAPABILITY_LIST, &mcapndx);
|
|
|
|
if (mcapndx != 0) {
|
|
|
|
do {
|
|
|
|
pci_read_config_dword(dev, mcapndx, &ncapid);
|
|
|
|
if ((ncapid & 0xff) != 2)
|
|
|
|
mcapndx = (ncapid >> 8) & 0xff;
|
|
|
|
}
|
|
|
|
while (((ncapid & 0xff) != 2) && (mcapndx != 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mcapndx == 0) {
|
2008-07-31 03:26:51 +08:00
|
|
|
dev_err(&td->dev, "woah! Non-AGP device %s on "
|
|
|
|
"secondary bus of AGP 3.5 bridge!\n",
|
|
|
|
pci_name(dev));
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto free_and_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
mmajor = (ncapid >> AGP_MAJOR_VERSION_SHIFT) & 0xf;
|
|
|
|
if (mmajor < 3) {
|
2008-07-31 03:26:51 +08:00
|
|
|
dev_err(&td->dev, "woah! AGP 2.0 device %s on "
|
|
|
|
"secondary bus of AGP 3.5 bridge operating "
|
|
|
|
"with AGP 3.0 electricals!\n", pci_name(dev));
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto free_and_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur->capndx = mcapndx;
|
|
|
|
|
|
|
|
pci_read_config_dword(dev, cur->capndx+AGPSTAT, &mstatus);
|
|
|
|
|
|
|
|
if (((mstatus >> 3) & 0x1) == 0) {
|
2008-07-31 03:26:51 +08:00
|
|
|
dev_err(&td->dev, "woah! AGP 3.x device %s not "
|
|
|
|
"operating in AGP 3.x mode on secondary bus "
|
|
|
|
"of AGP 3.5 bridge operating with AGP 3.0 "
|
|
|
|
"electricals!\n", pci_name(dev));
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto free_and_exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call functions to divide target resources amongst the AGP 3.0
|
|
|
|
* masters. This process is dramatically different depending on
|
|
|
|
* whether isochronous transfers are supported.
|
|
|
|
*/
|
|
|
|
if (isoch) {
|
|
|
|
ret = agp_3_5_isochronous_node_enable(bridge, dev_list, ndevs);
|
|
|
|
if (ret) {
|
2008-07-31 03:26:51 +08:00
|
|
|
dev_info(&td->dev, "something bad happened setting "
|
|
|
|
"up isochronous xfers; falling back to "
|
|
|
|
"non-isochronous xfer mode\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
goto free_and_exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
agp_3_5_nonisochronous_node_enable(bridge, dev_list, ndevs);
|
|
|
|
|
|
|
|
free_and_exit:
|
|
|
|
/* Be sure to free the dev_list */
|
|
|
|
for (pos=head->next; pos!=head; ) {
|
|
|
|
cur = list_entry(pos, struct agp_3_5_dev, list);
|
|
|
|
|
|
|
|
pos = pos->next;
|
|
|
|
kfree(cur);
|
|
|
|
}
|
|
|
|
kfree(dev_list);
|
|
|
|
|
|
|
|
get_out:
|
|
|
|
return ret;
|
|
|
|
}
|