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
|
|
|
/*
|
|
|
|
* Macintosh Nubus Interface Code
|
|
|
|
*
|
|
|
|
* Originally by Alan Cox
|
|
|
|
*
|
|
|
|
* Mostly rewritten by David Huggins-Daines, C. Scott Ananian,
|
|
|
|
* and others.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/nubus.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/init.h>
|
2008-02-05 14:30:23 +08:00
|
|
|
#include <linux/module.h>
|
2018-01-14 06:37:13 +08:00
|
|
|
#include <linux/seq_file.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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/setup.h>
|
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/hwtest.h>
|
|
|
|
|
|
|
|
/* Constants */
|
|
|
|
|
|
|
|
/* This is, of course, the size in bytelanes, rather than the size in
|
|
|
|
actual bytes */
|
|
|
|
#define FORMAT_BLOCK_SIZE 20
|
|
|
|
#define ROM_DIR_OFFSET 0x24
|
|
|
|
|
|
|
|
#define NUBUS_TEST_PATTERN 0x5A932BC7
|
|
|
|
|
|
|
|
/* Globals */
|
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
LIST_HEAD(nubus_func_rsrcs);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Meaning of "bytelanes":
|
|
|
|
|
|
|
|
The card ROM may appear on any or all bytes of each long word in
|
|
|
|
NuBus memory. The low 4 bits of the "map" value found in the
|
|
|
|
format block (at the top of the slot address space, as well as at
|
|
|
|
the top of the MacOS ROM) tells us which bytelanes, i.e. which byte
|
|
|
|
offsets within each longword, are valid. Thus:
|
|
|
|
|
|
|
|
A map of 0x0f, as found in the MacOS ROM, means that all bytelanes
|
|
|
|
are valid.
|
|
|
|
|
|
|
|
A map of 0xf0 means that no bytelanes are valid (We pray that we
|
|
|
|
will never encounter this, but stranger things have happened)
|
|
|
|
|
|
|
|
A map of 0xe1 means that only the MSB of each long word is actually
|
|
|
|
part of the card ROM. (We hope to never encounter NuBus on a
|
|
|
|
little-endian machine. Again, stranger things have happened)
|
|
|
|
|
|
|
|
A map of 0x78 means that only the LSB of each long word is valid.
|
|
|
|
|
|
|
|
Etcetera, etcetera. Hopefully this clears up some confusion over
|
|
|
|
what the following code actually does. */
|
2017-04-09 07:51:15 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static inline int not_useful(void *p, int map)
|
|
|
|
{
|
2017-04-09 07:51:15 +08:00
|
|
|
unsigned long pv = (unsigned long)p;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
pv &= 3;
|
2017-04-09 07:51:15 +08:00
|
|
|
if (map & (1 << pv))
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
2017-04-09 07:51:15 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static unsigned long nubus_get_rom(unsigned char **ptr, int len, int map)
|
|
|
|
{
|
|
|
|
/* This will hold the result */
|
|
|
|
unsigned long v = 0;
|
|
|
|
unsigned char *p = *ptr;
|
|
|
|
|
2017-04-09 07:51:15 +08:00
|
|
|
while (len) {
|
2005-04-17 06:20:36 +08:00
|
|
|
v <<= 8;
|
2017-04-09 07:51:15 +08:00
|
|
|
while (not_useful(p, map))
|
2005-04-17 06:20:36 +08:00
|
|
|
p++;
|
|
|
|
v |= *p++;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
*ptr = p;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nubus_rewind(unsigned char **ptr, int len, int map)
|
|
|
|
{
|
2017-04-09 07:51:15 +08:00
|
|
|
unsigned char *p = *ptr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-09 07:51:15 +08:00
|
|
|
while (len) {
|
|
|
|
do {
|
2005-04-17 06:20:36 +08:00
|
|
|
p--;
|
2017-04-09 07:51:15 +08:00
|
|
|
} while (not_useful(p, map));
|
2005-04-17 06:20:36 +08:00
|
|
|
len--;
|
|
|
|
}
|
2017-04-09 07:51:15 +08:00
|
|
|
*ptr = p;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void nubus_advance(unsigned char **ptr, int len, int map)
|
|
|
|
{
|
|
|
|
unsigned char *p = *ptr;
|
2017-04-09 07:51:15 +08:00
|
|
|
|
|
|
|
while (len) {
|
|
|
|
while (not_useful(p, map))
|
2005-04-17 06:20:36 +08:00
|
|
|
p++;
|
2008-10-16 13:01:31 +08:00
|
|
|
p++;
|
2005-04-17 06:20:36 +08:00
|
|
|
len--;
|
|
|
|
}
|
|
|
|
*ptr = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nubus_move(unsigned char **ptr, int len, int map)
|
|
|
|
{
|
2017-04-23 09:24:16 +08:00
|
|
|
unsigned long slot_space = (unsigned long)*ptr & 0xFF000000;
|
|
|
|
|
2017-04-09 07:51:15 +08:00
|
|
|
if (len > 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
nubus_advance(ptr, len, map);
|
2017-04-09 07:51:15 +08:00
|
|
|
else if (len < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
nubus_rewind(ptr, -len, map);
|
2017-04-23 09:24:16 +08:00
|
|
|
|
|
|
|
if (((unsigned long)*ptr & 0xFF000000) != slot_space)
|
|
|
|
pr_err("%s: moved out of slot address space!\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, functions to read the sResource tree */
|
|
|
|
|
|
|
|
/* Each sResource entry consists of a 1-byte ID and a 3-byte data
|
|
|
|
field. If that data field contains an offset, then obviously we
|
|
|
|
have to expand it from a 24-bit signed number to a 32-bit signed
|
|
|
|
number. */
|
|
|
|
|
|
|
|
static inline long nubus_expand32(long foo)
|
|
|
|
{
|
2017-04-09 07:51:15 +08:00
|
|
|
if (foo & 0x00800000) /* 24bit negative */
|
2005-04-17 06:20:36 +08:00
|
|
|
foo |= 0xFF000000;
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *nubus_rom_addr(int slot)
|
2017-04-09 07:51:15 +08:00
|
|
|
{
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Returns the first byte after the card. We then walk
|
|
|
|
* backwards to get the lane register and the config
|
|
|
|
*/
|
2017-04-09 07:51:15 +08:00
|
|
|
return (void *)(0xF1000000 + (slot << 24));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
unsigned char *nubus_dirptr(const struct nubus_dirent *nd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned char *p = nd->base;
|
2017-04-09 07:51:15 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Essentially, just step over the bytelanes using whatever
|
|
|
|
offset we might have found */
|
|
|
|
nubus_move(&p, nubus_expand32(nd->data), nd->mask);
|
|
|
|
/* And return the value */
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* These two are for pulling resource data blocks (i.e. stuff that's
|
|
|
|
pointed to with offsets) out of the card ROM. */
|
|
|
|
|
2017-04-09 07:51:15 +08:00
|
|
|
void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent,
|
2018-01-14 06:37:13 +08:00
|
|
|
unsigned int len)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned char *t = (unsigned char *)dest;
|
|
|
|
unsigned char *p = nubus_dirptr(dirent);
|
2017-04-09 07:51:15 +08:00
|
|
|
|
|
|
|
while (len) {
|
2005-04-17 06:20:36 +08:00
|
|
|
*t++ = nubus_get_rom(&p, 1, dirent->mask);
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
}
|
2008-02-05 14:30:23 +08:00
|
|
|
EXPORT_SYMBOL(nubus_get_rsrc_mem);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
unsigned int nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
|
|
|
|
unsigned int len)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-01-14 06:37:13 +08:00
|
|
|
char *t = dest;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned char *p = nubus_dirptr(dirent);
|
2017-04-09 07:51:15 +08:00
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
while (len > 1) {
|
|
|
|
unsigned char c = nubus_get_rom(&p, 1, dirent->mask);
|
|
|
|
|
|
|
|
if (!c)
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2018-01-14 06:37:13 +08:00
|
|
|
*t++ = c;
|
2005-04-17 06:20:36 +08:00
|
|
|
len--;
|
|
|
|
}
|
2018-01-14 06:37:13 +08:00
|
|
|
if (len > 0)
|
|
|
|
*t = '\0';
|
2018-01-14 06:37:13 +08:00
|
|
|
return t - dest;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-02-05 14:30:23 +08:00
|
|
|
EXPORT_SYMBOL(nubus_get_rsrc_str);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
void nubus_seq_write_rsrc_mem(struct seq_file *m,
|
|
|
|
const struct nubus_dirent *dirent,
|
|
|
|
unsigned int len)
|
|
|
|
{
|
|
|
|
unsigned long buf[32];
|
|
|
|
unsigned int buf_size = sizeof(buf);
|
|
|
|
unsigned char *p = nubus_dirptr(dirent);
|
|
|
|
|
|
|
|
/* If possible, write out full buffers */
|
|
|
|
while (len >= buf_size) {
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(buf); i++)
|
|
|
|
buf[i] = nubus_get_rom(&p, sizeof(buf[0]),
|
|
|
|
dirent->mask);
|
|
|
|
seq_write(m, buf, buf_size);
|
|
|
|
len -= buf_size;
|
|
|
|
}
|
|
|
|
/* If not, write out individual bytes */
|
|
|
|
while (len--)
|
|
|
|
seq_putc(m, nubus_get_rom(&p, 1, dirent->mask));
|
|
|
|
}
|
|
|
|
|
2017-04-09 07:51:15 +08:00
|
|
|
int nubus_get_root_dir(const struct nubus_board *board,
|
|
|
|
struct nubus_dir *dir)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
dir->ptr = dir->base = board->directory;
|
|
|
|
dir->done = 0;
|
|
|
|
dir->mask = board->lanes;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-02-05 14:30:23 +08:00
|
|
|
EXPORT_SYMBOL(nubus_get_root_dir);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* This is a slyly renamed version of the above */
|
2018-01-14 06:37:13 +08:00
|
|
|
int nubus_get_func_dir(const struct nubus_rsrc *fres, struct nubus_dir *dir)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-01-14 06:37:13 +08:00
|
|
|
dir->ptr = dir->base = fres->directory;
|
2005-04-17 06:20:36 +08:00
|
|
|
dir->done = 0;
|
2018-01-14 06:37:13 +08:00
|
|
|
dir->mask = fres->board->lanes;
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2008-02-05 14:30:23 +08:00
|
|
|
EXPORT_SYMBOL(nubus_get_func_dir);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-09 07:51:15 +08:00
|
|
|
int nubus_get_board_dir(const struct nubus_board *board,
|
|
|
|
struct nubus_dir *dir)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct nubus_dirent ent;
|
2017-04-09 07:51:15 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
dir->ptr = dir->base = board->directory;
|
|
|
|
dir->done = 0;
|
|
|
|
dir->mask = board->lanes;
|
|
|
|
|
|
|
|
/* Now dereference it (the first directory is always the board
|
|
|
|
directory) */
|
|
|
|
if (nubus_readdir(dir, &ent) == -1)
|
|
|
|
return -1;
|
|
|
|
if (nubus_get_subdir(&ent, dir) == -1)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-02-05 14:30:23 +08:00
|
|
|
EXPORT_SYMBOL(nubus_get_board_dir);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
int nubus_get_subdir(const struct nubus_dirent *ent,
|
|
|
|
struct nubus_dir *dir)
|
|
|
|
{
|
|
|
|
dir->ptr = dir->base = nubus_dirptr(ent);
|
|
|
|
dir->done = 0;
|
|
|
|
dir->mask = ent->mask;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-02-05 14:30:23 +08:00
|
|
|
EXPORT_SYMBOL(nubus_get_subdir);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
int nubus_readdir(struct nubus_dir *nd, struct nubus_dirent *ent)
|
|
|
|
{
|
|
|
|
u32 resid;
|
2017-04-09 07:51:15 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (nd->done)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Do this first, otherwise nubus_rewind & co are off by 4 */
|
|
|
|
ent->base = nd->ptr;
|
|
|
|
|
|
|
|
/* This moves nd->ptr forward */
|
|
|
|
resid = nubus_get_rom(&nd->ptr, 4, nd->mask);
|
|
|
|
|
|
|
|
/* EOL marker, as per the Apple docs */
|
2017-04-09 07:51:15 +08:00
|
|
|
if ((resid & 0xff000000) == 0xff000000) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Mark it as done */
|
|
|
|
nd->done = 1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* First byte is the resource ID */
|
2017-04-09 07:51:15 +08:00
|
|
|
ent->type = resid >> 24;
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Low 3 bytes might contain data (or might not) */
|
|
|
|
ent->data = resid & 0xffffff;
|
2017-04-09 07:51:15 +08:00
|
|
|
ent->mask = nd->mask;
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2008-02-05 14:30:23 +08:00
|
|
|
EXPORT_SYMBOL(nubus_readdir);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-09 07:51:15 +08:00
|
|
|
int nubus_rewinddir(struct nubus_dir *dir)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
dir->ptr = dir->base;
|
2017-04-09 07:51:15 +08:00
|
|
|
dir->done = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2008-02-05 14:30:23 +08:00
|
|
|
EXPORT_SYMBOL(nubus_rewinddir);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Driver interface functions, more or less like in pci.c */
|
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
struct nubus_rsrc *nubus_first_rsrc_or_null(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-01-14 06:37:13 +08:00
|
|
|
return list_first_entry_or_null(&nubus_func_rsrcs, struct nubus_rsrc,
|
|
|
|
list);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2018-01-14 06:37:13 +08:00
|
|
|
EXPORT_SYMBOL(nubus_first_rsrc_or_null);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
struct nubus_rsrc *nubus_next_rsrc_or_null(struct nubus_rsrc *from)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-01-14 06:37:13 +08:00
|
|
|
if (list_is_last(&from->list, &nubus_func_rsrcs))
|
|
|
|
return NULL;
|
|
|
|
return list_next_entry(from, list);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2018-01-14 06:37:13 +08:00
|
|
|
EXPORT_SYMBOL(nubus_next_rsrc_or_null);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
int
|
2017-04-09 07:51:15 +08:00
|
|
|
nubus_find_rsrc(struct nubus_dir *dir, unsigned char rsrc_type,
|
|
|
|
struct nubus_dirent *ent)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
while (nubus_readdir(dir, ent) != -1) {
|
|
|
|
if (ent->type == rsrc_type)
|
|
|
|
return 0;
|
2017-04-09 07:51:15 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2008-02-05 14:30:23 +08:00
|
|
|
EXPORT_SYMBOL(nubus_find_rsrc);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Initialization functions - decide which slots contain stuff worth
|
|
|
|
looking at, and print out lots and lots of information from the
|
|
|
|
resource blocks. */
|
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
static int __init nubus_get_block_rsrc_dir(struct nubus_board *board,
|
2018-01-14 06:37:13 +08:00
|
|
|
struct proc_dir_entry *procdir,
|
2018-01-14 06:37:13 +08:00
|
|
|
const struct nubus_dirent *parent)
|
|
|
|
{
|
|
|
|
struct nubus_dir dir;
|
|
|
|
struct nubus_dirent ent;
|
|
|
|
|
|
|
|
nubus_get_subdir(parent, &dir);
|
2018-01-14 06:37:13 +08:00
|
|
|
dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board);
|
2018-01-14 06:37:13 +08:00
|
|
|
|
|
|
|
while (nubus_readdir(&dir, &ent) != -1) {
|
|
|
|
u32 size;
|
|
|
|
|
|
|
|
nubus_get_rsrc_mem(&size, &ent, 4);
|
|
|
|
pr_debug(" block (0x%x), size %d\n", ent.type, size);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(dir.procdir, &ent, size);
|
2018-01-14 06:37:13 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init nubus_get_display_vidmode(struct nubus_board *board,
|
2018-01-14 06:37:13 +08:00
|
|
|
struct proc_dir_entry *procdir,
|
2018-01-14 06:37:13 +08:00
|
|
|
const struct nubus_dirent *parent)
|
|
|
|
{
|
|
|
|
struct nubus_dir dir;
|
|
|
|
struct nubus_dirent ent;
|
|
|
|
|
|
|
|
nubus_get_subdir(parent, &dir);
|
2018-01-14 06:37:13 +08:00
|
|
|
dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board);
|
2018-01-14 06:37:13 +08:00
|
|
|
|
|
|
|
while (nubus_readdir(&dir, &ent) != -1) {
|
|
|
|
switch (ent.type) {
|
|
|
|
case 1: /* mVidParams */
|
|
|
|
case 2: /* mTable */
|
|
|
|
{
|
|
|
|
u32 size;
|
|
|
|
|
|
|
|
nubus_get_rsrc_mem(&size, &ent, 4);
|
|
|
|
pr_debug(" block (0x%x), size %d\n", ent.type,
|
|
|
|
size);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(dir.procdir, &ent, size);
|
2018-01-14 06:37:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
pr_debug(" unknown resource 0x%02x, data 0x%06x\n",
|
|
|
|
ent.type, ent.data);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(dir.procdir, &ent, 0);
|
2018-01-14 06:37:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
static int __init nubus_get_display_resource(struct nubus_rsrc *fres,
|
2018-01-14 06:37:13 +08:00
|
|
|
struct proc_dir_entry *procdir,
|
2018-01-14 06:37:13 +08:00
|
|
|
const struct nubus_dirent *ent)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
switch (ent->type) {
|
|
|
|
case NUBUS_RESID_GAMMADIR:
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" gamma directory offset: 0x%06x\n", ent->data);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_get_block_rsrc_dir(fres->board, procdir, ent);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 0x0080 ... 0x0085:
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" mode 0x%02x info offset: 0x%06x\n",
|
|
|
|
ent->type, ent->data);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_get_display_vidmode(fres->board, procdir, ent);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
default:
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" unknown resource 0x%02x, data 0x%06x\n",
|
|
|
|
ent->type, ent->data);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(procdir, ent, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
static int __init nubus_get_network_resource(struct nubus_rsrc *fres,
|
2018-01-14 06:37:13 +08:00
|
|
|
struct proc_dir_entry *procdir,
|
2018-01-14 06:37:13 +08:00
|
|
|
const struct nubus_dirent *ent)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
switch (ent->type) {
|
|
|
|
case NUBUS_RESID_MAC_ADDRESS:
|
|
|
|
{
|
|
|
|
char addr[6];
|
2017-04-09 07:51:15 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
nubus_get_rsrc_mem(addr, ent, 6);
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" MAC address: %pM\n", addr);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(procdir, ent, 6);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" unknown resource 0x%02x, data 0x%06x\n",
|
|
|
|
ent->type, ent->data);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(procdir, ent, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
static int __init nubus_get_cpu_resource(struct nubus_rsrc *fres,
|
2018-01-14 06:37:13 +08:00
|
|
|
struct proc_dir_entry *procdir,
|
2018-01-14 06:37:13 +08:00
|
|
|
const struct nubus_dirent *ent)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
switch (ent->type) {
|
|
|
|
case NUBUS_RESID_MEMINFO:
|
|
|
|
{
|
|
|
|
unsigned long meminfo[2];
|
2017-04-09 07:51:15 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
nubus_get_rsrc_mem(&meminfo, ent, 8);
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" memory: [ 0x%08lx 0x%08lx ]\n",
|
|
|
|
meminfo[0], meminfo[1]);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(procdir, ent, 8);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NUBUS_RESID_ROMINFO:
|
|
|
|
{
|
|
|
|
unsigned long rominfo[2];
|
2017-04-09 07:51:15 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
nubus_get_rsrc_mem(&rominfo, ent, 8);
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" ROM: [ 0x%08lx 0x%08lx ]\n",
|
|
|
|
rominfo[0], rominfo[1]);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(procdir, ent, 8);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" unknown resource 0x%02x, data 0x%06x\n",
|
|
|
|
ent->type, ent->data);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(procdir, ent, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
static int __init nubus_get_private_resource(struct nubus_rsrc *fres,
|
2018-01-14 06:37:13 +08:00
|
|
|
struct proc_dir_entry *procdir,
|
2018-01-14 06:37:13 +08:00
|
|
|
const struct nubus_dirent *ent)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-01-14 06:37:13 +08:00
|
|
|
switch (fres->category) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case NUBUS_CAT_DISPLAY:
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_get_display_resource(fres, procdir, ent);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case NUBUS_CAT_NETWORK:
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_get_network_resource(fres, procdir, ent);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case NUBUS_CAT_CPU:
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_get_cpu_resource(fres, procdir, ent);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
default:
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" unknown resource 0x%02x, data 0x%06x\n",
|
|
|
|
ent->type, ent->data);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(procdir, ent, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
static struct nubus_rsrc * __init
|
2017-04-09 07:51:15 +08:00
|
|
|
nubus_get_functional_resource(struct nubus_board *board, int slot,
|
|
|
|
const struct nubus_dirent *parent)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2017-04-09 07:51:15 +08:00
|
|
|
struct nubus_dir dir;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct nubus_dirent ent;
|
2018-01-14 06:37:13 +08:00
|
|
|
struct nubus_rsrc *fres;
|
2017-04-09 07:51:15 +08:00
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" Functional resource 0x%02x:\n", parent->type);
|
2005-04-17 06:20:36 +08:00
|
|
|
nubus_get_subdir(parent, &dir);
|
2018-01-14 06:37:13 +08:00
|
|
|
dir.procdir = nubus_proc_add_rsrc_dir(board->procdir, parent, board);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Actually we should probably panic if this fails */
|
2018-01-14 06:37:13 +08:00
|
|
|
fres = kzalloc(sizeof(*fres), GFP_ATOMIC);
|
|
|
|
if (!fres)
|
2017-04-09 07:51:15 +08:00
|
|
|
return NULL;
|
2018-01-14 06:37:13 +08:00
|
|
|
fres->resid = parent->type;
|
|
|
|
fres->directory = dir.base;
|
|
|
|
fres->board = board;
|
2017-04-09 07:51:15 +08:00
|
|
|
|
|
|
|
while (nubus_readdir(&dir, &ent) != -1) {
|
|
|
|
switch (ent.type) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case NUBUS_RESID_TYPE:
|
|
|
|
{
|
|
|
|
unsigned short nbtdata[4];
|
2017-04-09 07:51:15 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
nubus_get_rsrc_mem(nbtdata, &ent, 8);
|
2018-01-14 06:37:13 +08:00
|
|
|
fres->category = nbtdata[0];
|
|
|
|
fres->type = nbtdata[1];
|
|
|
|
fres->dr_sw = nbtdata[2];
|
|
|
|
fres->dr_hw = nbtdata[3];
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" type: [cat 0x%x type 0x%x sw 0x%x hw 0x%x]\n",
|
|
|
|
nbtdata[0], nbtdata[1], nbtdata[2], nbtdata[3]);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(dir.procdir, &ent, 8);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NUBUS_RESID_NAME:
|
|
|
|
{
|
2018-01-14 06:37:13 +08:00
|
|
|
char name[64];
|
2018-01-14 06:37:13 +08:00
|
|
|
unsigned int len;
|
2018-01-14 06:37:13 +08:00
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
len = nubus_get_rsrc_str(name, &ent, sizeof(name));
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" name: %s\n", name);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(dir.procdir, &ent, len + 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NUBUS_RESID_DRVRDIR:
|
|
|
|
{
|
|
|
|
/* MacOS driver. If we were NetBSD we might
|
|
|
|
use this :-) */
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" driver directory offset: 0x%06x\n",
|
|
|
|
ent.data);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_get_block_rsrc_dir(board, dir.procdir, &ent);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NUBUS_RESID_MINOR_BASEOS:
|
2018-01-14 06:37:13 +08:00
|
|
|
{
|
2005-04-17 06:20:36 +08:00
|
|
|
/* We will need this in order to support
|
|
|
|
multiple framebuffers. It might be handy
|
|
|
|
for Ethernet as well */
|
2018-01-14 06:37:13 +08:00
|
|
|
u32 base_offset;
|
|
|
|
|
|
|
|
nubus_get_rsrc_mem(&base_offset, &ent, 4);
|
|
|
|
pr_debug(" memory offset: 0x%08x\n", base_offset);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(dir.procdir, &ent, 4);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2018-01-14 06:37:13 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
case NUBUS_RESID_MINOR_LENGTH:
|
2018-01-14 06:37:13 +08:00
|
|
|
{
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Ditto */
|
2018-01-14 06:37:13 +08:00
|
|
|
u32 length;
|
|
|
|
|
|
|
|
nubus_get_rsrc_mem(&length, &ent, 4);
|
|
|
|
pr_debug(" memory length: 0x%08x\n", length);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(dir.procdir, &ent, 4);
|
2017-04-09 07:51:15 +08:00
|
|
|
break;
|
2018-01-14 06:37:13 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
case NUBUS_RESID_FLAGS:
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" flags: 0x%06x\n", ent.data);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc(dir.procdir, &ent);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case NUBUS_RESID_HWDEVID:
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" hwdevid: 0x%06x\n", ent.data);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc(dir.procdir, &ent);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Local/Private resources have their own
|
|
|
|
function */
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_get_private_resource(fres, dir.procdir, &ent);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2017-04-09 07:51:15 +08:00
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
return fres;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This is *really* cool. */
|
2017-04-09 07:51:15 +08:00
|
|
|
static int __init nubus_get_icon(struct nubus_board *board,
|
2018-01-14 06:37:13 +08:00
|
|
|
struct proc_dir_entry *procdir,
|
2017-04-09 07:51:15 +08:00
|
|
|
const struct nubus_dirent *ent)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/* Should be 32x32 if my memory serves me correctly */
|
2018-01-14 06:37:13 +08:00
|
|
|
u32 icon[32];
|
|
|
|
int i;
|
2017-04-09 07:51:15 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
nubus_get_rsrc_mem(&icon, ent, 128);
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" icon:\n");
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
pr_debug(" %08x %08x %08x %08x\n",
|
|
|
|
icon[i * 4 + 0], icon[i * 4 + 1],
|
|
|
|
icon[i * 4 + 2], icon[i * 4 + 3]);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(procdir, ent, 128);
|
2018-01-14 06:37:13 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-09 07:51:15 +08:00
|
|
|
static int __init nubus_get_vendorinfo(struct nubus_board *board,
|
2018-01-14 06:37:13 +08:00
|
|
|
struct proc_dir_entry *procdir,
|
2017-04-09 07:51:15 +08:00
|
|
|
const struct nubus_dirent *parent)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2017-04-09 07:51:15 +08:00
|
|
|
struct nubus_dir dir;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct nubus_dirent ent;
|
2017-04-09 07:51:15 +08:00
|
|
|
static char *vendor_fields[6] = { "ID", "serial", "revision",
|
|
|
|
"part", "date", "unknown field" };
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" vendor info:\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
nubus_get_subdir(parent, &dir);
|
2018-01-14 06:37:13 +08:00
|
|
|
dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-09 07:51:15 +08:00
|
|
|
while (nubus_readdir(&dir, &ent) != -1) {
|
2005-04-17 06:20:36 +08:00
|
|
|
char name[64];
|
2018-01-14 06:37:13 +08:00
|
|
|
unsigned int len;
|
2017-04-09 07:51:15 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* These are all strings, we think */
|
2018-01-14 06:37:13 +08:00
|
|
|
len = nubus_get_rsrc_str(name, &ent, sizeof(name));
|
2018-01-14 06:37:13 +08:00
|
|
|
if (ent.type < 1 || ent.type > 5)
|
2005-04-17 06:20:36 +08:00
|
|
|
ent.type = 5;
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" %s: %s\n", vendor_fields[ent.type - 1], name);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(dir.procdir, &ent, len + 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-09 07:51:15 +08:00
|
|
|
static int __init nubus_get_board_resource(struct nubus_board *board, int slot,
|
|
|
|
const struct nubus_dirent *parent)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2017-04-09 07:51:15 +08:00
|
|
|
struct nubus_dir dir;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct nubus_dirent ent;
|
2017-04-09 07:51:15 +08:00
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" Board resource 0x%02x:\n", parent->type);
|
2005-04-17 06:20:36 +08:00
|
|
|
nubus_get_subdir(parent, &dir);
|
2018-01-14 06:37:13 +08:00
|
|
|
dir.procdir = nubus_proc_add_rsrc_dir(board->procdir, parent, board);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-09 07:51:15 +08:00
|
|
|
while (nubus_readdir(&dir, &ent) != -1) {
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (ent.type) {
|
|
|
|
case NUBUS_RESID_TYPE:
|
|
|
|
{
|
|
|
|
unsigned short nbtdata[4];
|
|
|
|
/* This type is always the same, and is not
|
|
|
|
useful except insofar as it tells us that
|
|
|
|
we really are looking at a board resource. */
|
|
|
|
nubus_get_rsrc_mem(nbtdata, &ent, 8);
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" type: [cat 0x%x type 0x%x sw 0x%x hw 0x%x]\n",
|
|
|
|
nbtdata[0], nbtdata[1], nbtdata[2], nbtdata[3]);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (nbtdata[0] != 1 || nbtdata[1] != 0 ||
|
|
|
|
nbtdata[2] != 0 || nbtdata[3] != 0)
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_err("Slot %X: sResource is not a board resource!\n",
|
|
|
|
slot);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(dir.procdir, &ent, 8);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NUBUS_RESID_NAME:
|
2018-01-14 06:37:13 +08:00
|
|
|
{
|
|
|
|
unsigned int len;
|
|
|
|
|
|
|
|
len = nubus_get_rsrc_str(board->name, &ent,
|
|
|
|
sizeof(board->name));
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" name: %s\n", board->name);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(dir.procdir, &ent, len + 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2018-01-14 06:37:13 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
case NUBUS_RESID_ICON:
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_get_icon(board, dir.procdir, &ent);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case NUBUS_RESID_BOARDID:
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" board id: 0x%x\n", ent.data);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc(dir.procdir, &ent);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case NUBUS_RESID_PRIMARYINIT:
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" primary init offset: 0x%06x\n", ent.data);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc(dir.procdir, &ent);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case NUBUS_RESID_VENDORINFO:
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_get_vendorinfo(board, dir.procdir, &ent);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case NUBUS_RESID_FLAGS:
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" flags: 0x%06x\n", ent.data);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc(dir.procdir, &ent);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case NUBUS_RESID_HWDEVID:
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" hwdevid: 0x%06x\n", ent.data);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc(dir.procdir, &ent);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case NUBUS_RESID_SECONDINIT:
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" secondary init offset: 0x%06x\n",
|
|
|
|
ent.data);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc(dir.procdir, &ent);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2017-04-09 07:51:15 +08:00
|
|
|
/* WTF isn't this in the functional resources? */
|
2005-04-17 06:20:36 +08:00
|
|
|
case NUBUS_RESID_VIDNAMES:
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" vidnames directory offset: 0x%06x\n",
|
|
|
|
ent.data);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_get_block_rsrc_dir(board, dir.procdir, &ent);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
/* Same goes for this */
|
|
|
|
case NUBUS_RESID_VIDMODES:
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" video mode parameter directory offset: 0x%06x\n",
|
|
|
|
ent.data);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc(dir.procdir, &ent);
|
2017-04-09 07:51:15 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
default:
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug(" unknown resource 0x%02x, data 0x%06x\n",
|
|
|
|
ent.type, ent.data);
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_proc_add_rsrc_mem(dir.procdir, &ent, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-14 06:37:14 +08:00
|
|
|
static void __init nubus_add_board(int slot, int bytelanes)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2017-04-09 07:51:15 +08:00
|
|
|
struct nubus_board *board;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned char *rp;
|
|
|
|
unsigned long dpat;
|
|
|
|
struct nubus_dir dir;
|
|
|
|
struct nubus_dirent ent;
|
2018-01-14 06:37:13 +08:00
|
|
|
int prev_resid = -1;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Move to the start of the format block */
|
2017-04-09 07:51:15 +08:00
|
|
|
rp = nubus_rom_addr(slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
nubus_rewind(&rp, FORMAT_BLOCK_SIZE, bytelanes);
|
|
|
|
|
|
|
|
/* Actually we should probably panic if this fails */
|
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 16:49:03 +08:00
|
|
|
if ((board = kzalloc(sizeof(*board), GFP_ATOMIC)) == NULL)
|
2018-01-14 06:37:14 +08:00
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
board->fblock = rp;
|
|
|
|
|
|
|
|
/* Dump the format block for debugging purposes */
|
2017-04-09 07:51:15 +08:00
|
|
|
pr_debug("Slot %X, format block at 0x%p:\n", slot, rp);
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug("%08lx\n", nubus_get_rom(&rp, 4, bytelanes));
|
|
|
|
pr_debug("%08lx\n", nubus_get_rom(&rp, 4, bytelanes));
|
|
|
|
pr_debug("%08lx\n", nubus_get_rom(&rp, 4, bytelanes));
|
2017-04-09 07:51:15 +08:00
|
|
|
pr_debug("%02lx\n", nubus_get_rom(&rp, 1, bytelanes));
|
|
|
|
pr_debug("%02lx\n", nubus_get_rom(&rp, 1, bytelanes));
|
|
|
|
pr_debug("%08lx\n", nubus_get_rom(&rp, 4, bytelanes));
|
|
|
|
pr_debug("%02lx\n", nubus_get_rom(&rp, 1, bytelanes));
|
|
|
|
pr_debug("%02lx\n", nubus_get_rom(&rp, 1, bytelanes));
|
|
|
|
rp = board->fblock;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
board->slot = slot;
|
2017-04-09 07:51:15 +08:00
|
|
|
board->slot_addr = (unsigned long)nubus_slot_addr(slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
board->doffset = nubus_get_rom(&rp, 4, bytelanes);
|
|
|
|
/* rom_length is *supposed* to be the total length of the
|
|
|
|
* ROM. In practice it is the "amount of ROM used to compute
|
|
|
|
* the CRC." So some jokers decide to set it to zero and
|
|
|
|
* set the crc to zero so they don't have to do any math.
|
|
|
|
* See the Performa 460 ROM, for example. Those Apple "engineers".
|
|
|
|
*/
|
|
|
|
board->rom_length = nubus_get_rom(&rp, 4, bytelanes);
|
|
|
|
board->crc = nubus_get_rom(&rp, 4, bytelanes);
|
|
|
|
board->rev = nubus_get_rom(&rp, 1, bytelanes);
|
2017-04-09 07:51:15 +08:00
|
|
|
board->format = nubus_get_rom(&rp, 1, bytelanes);
|
2005-04-17 06:20:36 +08:00
|
|
|
board->lanes = bytelanes;
|
|
|
|
|
|
|
|
/* Directory offset should be small and negative... */
|
2017-04-09 07:51:15 +08:00
|
|
|
if (!(board->doffset & 0x00FF0000))
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_warn("Slot %X: Dodgy doffset!\n", slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
dpat = nubus_get_rom(&rp, 4, bytelanes);
|
2017-04-09 07:51:15 +08:00
|
|
|
if (dpat != NUBUS_TEST_PATTERN)
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_warn("Slot %X: Wrong test pattern %08lx!\n", slot, dpat);
|
2017-04-09 07:51:15 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* I wonder how the CRC is meant to work -
|
|
|
|
* any takers ?
|
|
|
|
* CSA: According to MAC docs, not all cards pass the CRC anyway,
|
|
|
|
* since the initial Macintosh ROM releases skipped the check.
|
|
|
|
*/
|
|
|
|
|
2017-04-23 09:24:16 +08:00
|
|
|
/* Set up the directory pointer */
|
|
|
|
board->directory = board->fblock;
|
|
|
|
nubus_move(&board->directory, nubus_expand32(board->doffset),
|
|
|
|
board->lanes);
|
|
|
|
|
2017-04-09 07:51:15 +08:00
|
|
|
nubus_get_root_dir(board, &dir);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* We're ready to rock */
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_debug("Slot %X resources:\n", slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Each slot should have one board resource and any number of
|
2018-01-14 06:37:13 +08:00
|
|
|
* functional resources. So we'll fill in some fields in the
|
|
|
|
* struct nubus_board from the board resource, then walk down
|
|
|
|
* the list of functional resources, spinning out a nubus_rsrc
|
|
|
|
* for each of them.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
if (nubus_readdir(&dir, &ent) == -1) {
|
|
|
|
/* We can't have this! */
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_err("Slot %X: Board resource not found!\n", slot);
|
2018-01-14 06:37:14 +08:00
|
|
|
kfree(board);
|
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
if (ent.type < 1 || ent.type > 127)
|
|
|
|
pr_warn("Slot %X: Board resource ID is invalid!\n", slot);
|
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
board->procdir = nubus_proc_add_board(board);
|
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_get_board_resource(board, slot, &ent);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
while (nubus_readdir(&dir, &ent) != -1) {
|
2018-01-14 06:37:13 +08:00
|
|
|
struct nubus_rsrc *fres;
|
2017-04-09 07:51:15 +08:00
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
fres = nubus_get_functional_resource(board, slot, &ent);
|
|
|
|
if (fres == NULL)
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
/* Resources should appear in ascending ID order. This sanity
|
|
|
|
* check prevents duplicate resource IDs.
|
|
|
|
*/
|
2018-01-14 06:37:13 +08:00
|
|
|
if (fres->resid <= prev_resid) {
|
|
|
|
kfree(fres);
|
2018-01-14 06:37:13 +08:00
|
|
|
continue;
|
|
|
|
}
|
2018-01-14 06:37:13 +08:00
|
|
|
prev_resid = fres->resid;
|
2018-01-14 06:37:13 +08:00
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
list_add_tail(&fres->list, &nubus_func_rsrcs);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-01-14 06:37:14 +08:00
|
|
|
if (nubus_device_register(board))
|
|
|
|
put_device(&board->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
static void __init nubus_probe_slot(int slot)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned char dp;
|
2017-04-09 07:51:15 +08:00
|
|
|
unsigned char *rp;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
|
2017-04-09 07:51:15 +08:00
|
|
|
rp = nubus_rom_addr(slot);
|
|
|
|
for (i = 4; i; i--) {
|
2005-04-17 06:20:36 +08:00
|
|
|
rp--;
|
2018-01-14 06:37:13 +08:00
|
|
|
if (!hwreg_present(rp))
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
dp = *rp;
|
|
|
|
|
|
|
|
/* The last byte of the format block consists of two
|
|
|
|
nybbles which are "mirror images" of each other.
|
|
|
|
These show us the valid bytelanes */
|
2017-04-09 07:51:15 +08:00
|
|
|
if ((((dp >> 4) ^ dp) & 0x0F) != 0x0F)
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
|
|
|
/* Check that this value is actually *on* one of the
|
|
|
|
bytelanes it claims are valid! */
|
2017-04-23 09:24:16 +08:00
|
|
|
if (not_useful(rp, dp))
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Looks promising. Let's put it on the list. */
|
|
|
|
nubus_add_board(slot, dp);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
static void __init nubus_scan_bus(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int slot;
|
2017-04-09 07:51:15 +08:00
|
|
|
|
2018-01-14 06:37:13 +08:00
|
|
|
pr_info("NuBus: Scanning NuBus slots.\n");
|
2017-04-09 07:51:15 +08:00
|
|
|
for (slot = 9; slot < 15; slot++) {
|
2005-04-17 06:20:36 +08:00
|
|
|
nubus_probe_slot(slot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init nubus_init(void)
|
|
|
|
{
|
2018-01-14 06:37:14 +08:00
|
|
|
int err;
|
|
|
|
|
2017-04-09 07:51:15 +08:00
|
|
|
if (!MACH_IS_MAC)
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
nubus_proc_init();
|
2018-01-14 06:37:14 +08:00
|
|
|
err = nubus_bus_register();
|
|
|
|
if (err)
|
|
|
|
return err;
|
2018-01-14 06:37:13 +08:00
|
|
|
nubus_scan_bus();
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
subsys_initcall(nubus_init);
|