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
|
|
|
/*
|
|
|
|
* Device driver for the Apple Desktop Bus
|
|
|
|
* and the /dev/adb device on macintoshes.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1996 Paul Mackerras.
|
|
|
|
*
|
|
|
|
* Modified to declare controllers as structures, added
|
|
|
|
* client notification of bus reset and handles PowerBook
|
|
|
|
* sleep, by Benjamin Herrenschmidt.
|
|
|
|
*
|
|
|
|
* To do:
|
|
|
|
*
|
|
|
|
* - /sys/bus/adb to list the devices and infos
|
|
|
|
* - more /dev/adb to allow userland to receive the
|
|
|
|
* flow of auto-polling datas from a given device.
|
|
|
|
* - move bus probe to a kernel thread
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/mm.h>
|
2017-02-02 18:15:33 +00:00
|
|
|
#include <linux/sched/signal.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/adb.h>
|
|
|
|
#include <linux/cuda.h>
|
|
|
|
#include <linux/pmu.h>
|
|
|
|
#include <linux/notifier.h>
|
|
|
|
#include <linux/wait.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/device.h>
|
2007-12-13 04:11:22 +00:00
|
|
|
#include <linux/kthread.h>
|
2008-02-03 15:49:09 +00:00
|
|
|
#include <linux/platform_device.h>
|
2008-05-02 20:34:03 +00:00
|
|
|
#include <linux/mutex.h>
|
2022-04-01 17:15:53 +00:00
|
|
|
#include <linux/of.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-01-28 01:43:17 +00:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#ifdef CONFIG_PPC
|
2006-03-28 12:15:54 +00:00
|
|
|
#include <asm/machdep.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(adb_client_list);
|
|
|
|
|
|
|
|
extern struct adb_driver via_macii_driver;
|
|
|
|
extern struct adb_driver via_cuda_driver;
|
|
|
|
extern struct adb_driver adb_iop_driver;
|
|
|
|
extern struct adb_driver via_pmu_driver;
|
|
|
|
extern struct adb_driver macio_adb_driver;
|
|
|
|
|
2010-06-02 12:28:52 +00:00
|
|
|
static DEFINE_MUTEX(adb_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
static struct adb_driver *adb_driver_list[] = {
|
|
|
|
#ifdef CONFIG_ADB_MACII
|
|
|
|
&via_macii_driver,
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_ADB_CUDA
|
|
|
|
&via_cuda_driver,
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_ADB_IOP
|
|
|
|
&adb_iop_driver,
|
|
|
|
#endif
|
2018-07-02 08:21:19 +00:00
|
|
|
#ifdef CONFIG_ADB_PMU
|
2005-04-16 22:20:36 +00:00
|
|
|
&via_pmu_driver,
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_ADB_MACIO
|
|
|
|
&macio_adb_driver,
|
|
|
|
#endif
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2005-03-23 18:01:41 +00:00
|
|
|
static struct class *adb_dev_class;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-06-23 17:46:57 +00:00
|
|
|
static struct adb_driver *adb_controller;
|
[PATCH] Notifier chain update: API changes
The kernel's implementation of notifier chains is unsafe. There is no
protection against entries being added to or removed from a chain while the
chain is in use. The issues were discussed in this thread:
http://marc.theaimsgroup.com/?l=linux-kernel&m=113018709002036&w=2
We noticed that notifier chains in the kernel fall into two basic usage
classes:
"Blocking" chains are always called from a process context
and the callout routines are allowed to sleep;
"Atomic" chains can be called from an atomic context and
the callout routines are not allowed to sleep.
We decided to codify this distinction and make it part of the API. Therefore
this set of patches introduces three new, parallel APIs: one for blocking
notifiers, one for atomic notifiers, and one for "raw" notifiers (which is
really just the old API under a new name). New kinds of data structures are
used for the heads of the chains, and new routines are defined for
registration, unregistration, and calling a chain. The three APIs are
explained in include/linux/notifier.h and their implementation is in
kernel/sys.c.
With atomic and blocking chains, the implementation guarantees that the chain
links will not be corrupted and that chain callers will not get messed up by
entries being added or removed. For raw chains the implementation provides no
guarantees at all; users of this API must provide their own protections. (The
idea was that situations may come up where the assumptions of the atomic and
blocking APIs are not appropriate, so it should be possible for users to
handle these things in their own way.)
There are some limitations, which should not be too hard to live with. For
atomic/blocking chains, registration and unregistration must always be done in
a process context since the chain is protected by a mutex/rwsem. Also, a
callout routine for a non-raw chain must not try to register or unregister
entries on its own chain. (This did happen in a couple of places and the code
had to be changed to avoid it.)
Since atomic chains may be called from within an NMI handler, they cannot use
spinlocks for synchronization. Instead we use RCU. The overhead falls almost
entirely in the unregister routine, which is okay since unregistration is much
less frequent that calling a chain.
Here is the list of chains that we adjusted and their classifications. None
of them use the raw API, so for the moment it is only a placeholder.
ATOMIC CHAINS
-------------
arch/i386/kernel/traps.c: i386die_chain
arch/ia64/kernel/traps.c: ia64die_chain
arch/powerpc/kernel/traps.c: powerpc_die_chain
arch/sparc64/kernel/traps.c: sparc64die_chain
arch/x86_64/kernel/traps.c: die_chain
drivers/char/ipmi/ipmi_si_intf.c: xaction_notifier_list
kernel/panic.c: panic_notifier_list
kernel/profile.c: task_free_notifier
net/bluetooth/hci_core.c: hci_notifier
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_chain
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_expect_chain
net/ipv6/addrconf.c: inet6addr_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_expect_chain
net/netlink/af_netlink.c: netlink_chain
BLOCKING CHAINS
---------------
arch/powerpc/platforms/pseries/reconfig.c: pSeries_reconfig_chain
arch/s390/kernel/process.c: idle_chain
arch/x86_64/kernel/process.c idle_notifier
drivers/base/memory.c: memory_chain
drivers/cpufreq/cpufreq.c cpufreq_policy_notifier_list
drivers/cpufreq/cpufreq.c cpufreq_transition_notifier_list
drivers/macintosh/adb.c: adb_client_list
drivers/macintosh/via-pmu.c sleep_notifier_list
drivers/macintosh/via-pmu68k.c sleep_notifier_list
drivers/macintosh/windfarm_core.c wf_client_list
drivers/usb/core/notify.c usb_notifier_list
drivers/video/fbmem.c fb_notifier_list
kernel/cpu.c cpu_chain
kernel/module.c module_notify_list
kernel/profile.c munmap_notifier
kernel/profile.c task_exit_notifier
kernel/sys.c reboot_notifier_list
net/core/dev.c netdev_chain
net/decnet/dn_dev.c: dnaddr_chain
net/ipv4/devinet.c: inetaddr_chain
It's possible that some of these classifications are wrong. If they are,
please let us know or submit a patch to fix them. Note that any chain that
gets called very frequently should be atomic, because the rwsem read-locking
used for blocking chains is very likely to incur cache misses on SMP systems.
(However, if the chain's callout routines may sleep then the chain cannot be
atomic.)
The patch set was written by Alan Stern and Chandra Seetharaman, incorporating
material written by Keith Owens and suggestions from Paul McKenney and Andrew
Morton.
[jes@sgi.com: restructure the notifier chain initialization macros]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: Jes Sorensen <jes@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-27 09:16:30 +00:00
|
|
|
BLOCKING_NOTIFIER_HEAD(adb_client_list);
|
2005-04-16 22:20:36 +00:00
|
|
|
static int adb_got_sleep;
|
|
|
|
static int adb_inited;
|
2010-09-07 14:33:40 +00:00
|
|
|
static DEFINE_SEMAPHORE(adb_probe_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
static int sleepy_trackpad;
|
|
|
|
static int autopoll_devs;
|
|
|
|
int __adb_probe_sync;
|
|
|
|
|
|
|
|
static int adb_scan_bus(void);
|
|
|
|
static int do_adb_reset_bus(void);
|
|
|
|
static void adbdev_init(void);
|
|
|
|
static int try_handler_change(int, int);
|
|
|
|
|
|
|
|
static struct adb_handler {
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
void (*handler)(unsigned char *, int, int);
|
2005-04-16 22:20:36 +00:00
|
|
|
int original_address;
|
|
|
|
int handler_id;
|
|
|
|
int busy;
|
|
|
|
} adb_handler[16];
|
|
|
|
|
|
|
|
/*
|
2008-05-02 20:34:03 +00:00
|
|
|
* The adb_handler_mutex mutex protects all accesses to the original_address
|
2005-04-16 22:20:36 +00:00
|
|
|
* and handler_id fields of adb_handler[i] for all i, and changes to the
|
|
|
|
* handler field.
|
|
|
|
* Accesses to the handler field are protected by the adb_handler_lock
|
|
|
|
* rwlock. It is held across all calls to any handler, so that by the
|
|
|
|
* time adb_unregister returns, we know that the old handler isn't being
|
|
|
|
* called.
|
|
|
|
*/
|
2008-05-02 20:34:03 +00:00
|
|
|
static DEFINE_MUTEX(adb_handler_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
static DEFINE_RWLOCK(adb_handler_lock);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static void printADBreply(struct adb_request *req)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printk("adb reply (%d)", req->reply_len);
|
|
|
|
for(i = 0; i < req->reply_len; i++)
|
|
|
|
printk(" %x", req->reply[i]);
|
|
|
|
printk("\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int adb_scan_bus(void)
|
|
|
|
{
|
|
|
|
int i, highFree=0, noMovement;
|
|
|
|
int devmask = 0;
|
|
|
|
struct adb_request req;
|
|
|
|
|
|
|
|
/* assumes adb_handler[] is all zeroes at this point */
|
|
|
|
for (i = 1; i < 16; i++) {
|
|
|
|
/* see if there is anything at address i */
|
|
|
|
adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
|
|
|
|
(i << 4) | 0xf);
|
|
|
|
if (req.reply_len > 1)
|
|
|
|
/* one or more devices at this address */
|
|
|
|
adb_handler[i].original_address = i;
|
|
|
|
else if (i > highFree)
|
|
|
|
highFree = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note we reset noMovement to 0 each time we move a device */
|
|
|
|
for (noMovement = 1; noMovement < 2 && highFree > 0; noMovement++) {
|
|
|
|
for (i = 1; i < 16; i++) {
|
|
|
|
if (adb_handler[i].original_address == 0)
|
|
|
|
continue;
|
|
|
|
/*
|
|
|
|
* Send a "talk register 3" command to address i
|
|
|
|
* to provoke a collision if there is more than
|
|
|
|
* one device at this address.
|
|
|
|
*/
|
|
|
|
adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
|
|
|
|
(i << 4) | 0xf);
|
|
|
|
/*
|
|
|
|
* Move the device(s) which didn't detect a
|
|
|
|
* collision to address `highFree'. Hopefully
|
|
|
|
* this only moves one device.
|
|
|
|
*/
|
|
|
|
adb_request(&req, NULL, ADBREQ_SYNC, 3,
|
|
|
|
(i<< 4) | 0xb, (highFree | 0x60), 0xfe);
|
|
|
|
/*
|
|
|
|
* See if anybody actually moved. This is suggested
|
|
|
|
* by HW TechNote 01:
|
|
|
|
*
|
2020-07-17 18:35:22 +00:00
|
|
|
* https://developer.apple.com/technotes/hw/hw_01.html
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
|
|
|
|
(highFree << 4) | 0xf);
|
|
|
|
if (req.reply_len <= 1) continue;
|
|
|
|
/*
|
|
|
|
* Test whether there are any device(s) left
|
|
|
|
* at address i.
|
|
|
|
*/
|
|
|
|
adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
|
|
|
|
(i << 4) | 0xf);
|
|
|
|
if (req.reply_len > 1) {
|
|
|
|
/*
|
|
|
|
* There are still one or more devices
|
|
|
|
* left at address i. Register the one(s)
|
|
|
|
* we moved to `highFree', and find a new
|
|
|
|
* value for highFree.
|
|
|
|
*/
|
|
|
|
adb_handler[highFree].original_address =
|
|
|
|
adb_handler[i].original_address;
|
|
|
|
while (highFree > 0 &&
|
|
|
|
adb_handler[highFree].original_address)
|
|
|
|
highFree--;
|
|
|
|
if (highFree <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
noMovement = 0;
|
2014-01-28 01:43:17 +00:00
|
|
|
} else {
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* No devices left at address i; move the
|
|
|
|
* one(s) we moved to `highFree' back to i.
|
|
|
|
*/
|
|
|
|
adb_request(&req, NULL, ADBREQ_SYNC, 3,
|
|
|
|
(highFree << 4) | 0xb,
|
|
|
|
(i | 0x60), 0xfe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now fill in the handler_id field of the adb_handler entries. */
|
|
|
|
for (i = 1; i < 16; i++) {
|
|
|
|
if (adb_handler[i].original_address == 0)
|
|
|
|
continue;
|
|
|
|
adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
|
|
|
|
(i << 4) | 0xf);
|
|
|
|
adb_handler[i].handler_id = req.reply[2];
|
2018-09-12 00:18:44 +00:00
|
|
|
printk(KERN_DEBUG "adb device [%d]: %d 0x%X\n", i,
|
|
|
|
adb_handler[i].original_address,
|
|
|
|
adb_handler[i].handler_id);
|
2005-04-16 22:20:36 +00:00
|
|
|
devmask |= 1 << i;
|
|
|
|
}
|
|
|
|
return devmask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This kernel task handles ADB probing. It dies once probing is
|
|
|
|
* completed.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
adb_probe_task(void *x)
|
|
|
|
{
|
2016-11-28 20:29:07 +00:00
|
|
|
pr_debug("adb: starting probe task...\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
do_adb_reset_bus();
|
2016-11-28 20:29:07 +00:00
|
|
|
pr_debug("adb: finished probe task...\n");
|
2007-07-16 06:41:29 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
up(&adb_probe_mutex);
|
2007-07-16 06:41:29 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-12-06 18:41:45 +00:00
|
|
|
__adb_probe_task(struct work_struct *bullshit)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-12-13 04:11:22 +00:00
|
|
|
kthread_run(adb_probe_task, NULL, "kadbprobe");
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-12-06 18:41:45 +00:00
|
|
|
static DECLARE_WORK(adb_reset_work, __adb_probe_task);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
adb_reset_bus(void)
|
|
|
|
{
|
|
|
|
if (__adb_probe_sync) {
|
|
|
|
do_adb_reset_bus();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
down(&adb_probe_mutex);
|
|
|
|
schedule_work(&adb_reset_work);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-11 14:21:25 +00:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
/*
|
|
|
|
* notify clients before sleep
|
|
|
|
*/
|
2014-02-10 16:12:27 +00:00
|
|
|
static int __adb_suspend(struct platform_device *dev, pm_message_t state)
|
2007-12-11 14:21:25 +00:00
|
|
|
{
|
|
|
|
adb_got_sleep = 1;
|
|
|
|
/* We need to get a lock on the probe thread */
|
|
|
|
down(&adb_probe_mutex);
|
|
|
|
/* Stop autopoll */
|
|
|
|
if (adb_controller->autopoll)
|
|
|
|
adb_controller->autopoll(0);
|
|
|
|
blocking_notifier_call_chain(&adb_client_list, ADB_MSG_POWERDOWN, NULL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-10 16:12:27 +00:00
|
|
|
static int adb_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
return __adb_suspend(to_platform_device(dev), PMSG_SUSPEND);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adb_freeze(struct device *dev)
|
|
|
|
{
|
|
|
|
return __adb_suspend(to_platform_device(dev), PMSG_FREEZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adb_poweroff(struct device *dev)
|
|
|
|
{
|
|
|
|
return __adb_suspend(to_platform_device(dev), PMSG_HIBERNATE);
|
|
|
|
}
|
|
|
|
|
2007-12-11 14:21:25 +00:00
|
|
|
/*
|
|
|
|
* reset bus after sleep
|
|
|
|
*/
|
2014-02-10 16:12:27 +00:00
|
|
|
static int __adb_resume(struct platform_device *dev)
|
2007-12-11 14:21:25 +00:00
|
|
|
{
|
|
|
|
adb_got_sleep = 0;
|
|
|
|
up(&adb_probe_mutex);
|
|
|
|
adb_reset_bus();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-02-10 16:12:27 +00:00
|
|
|
|
|
|
|
static int adb_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
return __adb_resume(to_platform_device(dev));
|
|
|
|
}
|
2007-12-11 14:21:25 +00:00
|
|
|
#endif /* CONFIG_PM */
|
|
|
|
|
2008-06-23 17:46:57 +00:00
|
|
|
static int __init adb_init(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct adb_driver *driver;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
#ifdef CONFIG_PPC32
|
2006-03-28 12:15:54 +00:00
|
|
|
if (!machine_is(chrp) && !machine_is(powermac))
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_MAC
|
|
|
|
if (!MACH_IS_MAC)
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* xmon may do early-init */
|
|
|
|
if (adb_inited)
|
|
|
|
return 0;
|
|
|
|
adb_inited = 1;
|
|
|
|
|
|
|
|
adb_controller = NULL;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while ((driver = adb_driver_list[i++]) != NULL) {
|
|
|
|
if (!driver->probe()) {
|
|
|
|
adb_controller = driver;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-11-17 09:03:05 +00:00
|
|
|
if (adb_controller != NULL && adb_controller->init &&
|
|
|
|
adb_controller->init())
|
2005-04-16 22:20:36 +00:00
|
|
|
adb_controller = NULL;
|
2009-11-17 09:03:05 +00:00
|
|
|
if (adb_controller == NULL) {
|
2016-11-28 20:29:07 +00:00
|
|
|
pr_warn("Warning: no ADB interface detected\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
|
|
|
#ifdef CONFIG_PPC
|
2010-02-02 04:34:14 +00:00
|
|
|
if (of_machine_is_compatible("AAPL,PowerBook1998") ||
|
|
|
|
of_machine_is_compatible("PowerBook1,1"))
|
2005-04-16 22:20:36 +00:00
|
|
|
sleepy_trackpad = 1;
|
|
|
|
#endif /* CONFIG_PPC */
|
2007-12-11 14:21:25 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
adbdev_init();
|
|
|
|
adb_reset_bus();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-14 23:12:53 +00:00
|
|
|
device_initcall(adb_init);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
do_adb_reset_bus(void)
|
|
|
|
{
|
2007-03-19 10:53:55 +00:00
|
|
|
int ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (adb_controller == NULL)
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
if (adb_controller->autopoll)
|
|
|
|
adb_controller->autopoll(0);
|
|
|
|
|
2007-03-19 10:53:55 +00:00
|
|
|
blocking_notifier_call_chain(&adb_client_list,
|
|
|
|
ADB_MSG_PRE_RESET, NULL);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (sleepy_trackpad) {
|
|
|
|
/* Let the trackpad settle down */
|
2007-12-13 04:11:22 +00:00
|
|
|
msleep(500);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-05-02 20:34:03 +00:00
|
|
|
mutex_lock(&adb_handler_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
write_lock_irq(&adb_handler_lock);
|
|
|
|
memset(adb_handler, 0, sizeof(adb_handler));
|
|
|
|
write_unlock_irq(&adb_handler_lock);
|
|
|
|
|
|
|
|
/* That one is still a bit synchronous, oh well... */
|
|
|
|
if (adb_controller->reset_bus)
|
|
|
|
ret = adb_controller->reset_bus();
|
|
|
|
else
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
if (sleepy_trackpad) {
|
|
|
|
/* Let the trackpad settle down */
|
2007-12-13 04:11:22 +00:00
|
|
|
msleep(1500);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
autopoll_devs = adb_scan_bus();
|
|
|
|
if (adb_controller->autopoll)
|
|
|
|
adb_controller->autopoll(autopoll_devs);
|
|
|
|
}
|
2008-05-02 20:34:03 +00:00
|
|
|
mutex_unlock(&adb_handler_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-03-19 10:53:55 +00:00
|
|
|
blocking_notifier_call_chain(&adb_client_list,
|
|
|
|
ADB_MSG_POST_RESET, NULL);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
adb_poll(void)
|
|
|
|
{
|
|
|
|
if ((adb_controller == NULL)||(adb_controller->poll == NULL))
|
|
|
|
return;
|
|
|
|
adb_controller->poll();
|
|
|
|
}
|
2014-08-19 22:00:00 +00:00
|
|
|
EXPORT_SYMBOL(adb_poll);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-12-13 04:11:22 +00:00
|
|
|
static void adb_sync_req_done(struct adb_request *req)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-12-13 04:11:22 +00:00
|
|
|
struct completion *comp = req->arg;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-12-13 04:11:22 +00:00
|
|
|
complete(comp);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
adb_request(struct adb_request *req, void (*done)(struct adb_request *),
|
|
|
|
int flags, int nbytes, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
2007-12-13 04:11:22 +00:00
|
|
|
int i;
|
2005-04-16 22:20:36 +00:00
|
|
|
int rc;
|
2007-12-13 04:11:22 +00:00
|
|
|
struct completion comp;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if ((adb_controller == NULL) || (adb_controller->send_request == NULL))
|
|
|
|
return -ENXIO;
|
|
|
|
if (nbytes < 1)
|
|
|
|
return -EINVAL;
|
2007-12-13 04:11:22 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
req->nbytes = nbytes+1;
|
|
|
|
req->done = done;
|
|
|
|
req->reply_expected = flags & ADBREQ_REPLY;
|
|
|
|
req->data[0] = ADB_PACKET;
|
|
|
|
va_start(list, nbytes);
|
|
|
|
for (i = 0; i < nbytes; ++i)
|
|
|
|
req->data[i+1] = va_arg(list, int);
|
|
|
|
va_end(list);
|
|
|
|
|
|
|
|
if (flags & ADBREQ_NOSEND)
|
|
|
|
return 0;
|
|
|
|
|
2007-12-13 04:11:22 +00:00
|
|
|
/* Synchronous requests block using an on-stack completion */
|
|
|
|
if (flags & ADBREQ_SYNC) {
|
|
|
|
WARN_ON(done);
|
|
|
|
req->done = adb_sync_req_done;
|
|
|
|
req->arg = ∁
|
|
|
|
init_completion(&comp);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-12-13 04:11:22 +00:00
|
|
|
rc = adb_controller->send_request(req, 0);
|
|
|
|
|
|
|
|
if ((flags & ADBREQ_SYNC) && !rc && !req->complete)
|
|
|
|
wait_for_completion(&comp);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
2014-08-19 22:00:00 +00:00
|
|
|
EXPORT_SYMBOL(adb_request);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Ultimately this should return the number of devices with
|
|
|
|
the given default id.
|
|
|
|
And it does it now ! Note: changed behaviour: This function
|
|
|
|
will now register if default_id _and_ handler_id both match
|
|
|
|
but handler_id can be left to 0 to match with default_id only.
|
|
|
|
When handler_id is set, this function will try to adjust
|
|
|
|
the handler_id id it doesn't match. */
|
|
|
|
int
|
|
|
|
adb_register(int default_id, int handler_id, struct adb_ids *ids,
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
void (*handler)(unsigned char *, int, int))
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2008-05-02 20:34:03 +00:00
|
|
|
mutex_lock(&adb_handler_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
ids->nids = 0;
|
|
|
|
for (i = 1; i < 16; i++) {
|
|
|
|
if ((adb_handler[i].original_address == default_id) &&
|
|
|
|
(!handler_id || (handler_id == adb_handler[i].handler_id) ||
|
|
|
|
try_handler_change(i, handler_id))) {
|
|
|
|
if (adb_handler[i].handler != 0) {
|
2016-11-28 20:29:07 +00:00
|
|
|
pr_err("Two handlers for ADB device %d\n",
|
2005-04-16 22:20:36 +00:00
|
|
|
default_id);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
write_lock_irq(&adb_handler_lock);
|
|
|
|
adb_handler[i].handler = handler;
|
|
|
|
write_unlock_irq(&adb_handler_lock);
|
|
|
|
ids->id[ids->nids++] = i;
|
|
|
|
}
|
|
|
|
}
|
2008-05-02 20:34:03 +00:00
|
|
|
mutex_unlock(&adb_handler_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
return ids->nids;
|
|
|
|
}
|
2014-08-19 22:00:00 +00:00
|
|
|
EXPORT_SYMBOL(adb_register);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
adb_unregister(int index)
|
|
|
|
{
|
|
|
|
int ret = -ENODEV;
|
|
|
|
|
2008-05-02 20:34:03 +00:00
|
|
|
mutex_lock(&adb_handler_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
write_lock_irq(&adb_handler_lock);
|
|
|
|
if (adb_handler[index].handler) {
|
|
|
|
while(adb_handler[index].busy) {
|
|
|
|
write_unlock_irq(&adb_handler_lock);
|
|
|
|
yield();
|
|
|
|
write_lock_irq(&adb_handler_lock);
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
adb_handler[index].handler = NULL;
|
|
|
|
}
|
|
|
|
write_unlock_irq(&adb_handler_lock);
|
2008-05-02 20:34:03 +00:00
|
|
|
mutex_unlock(&adb_handler_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2014-08-19 22:00:00 +00:00
|
|
|
EXPORT_SYMBOL(adb_unregister);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
void
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
adb_input(unsigned char *buf, int nb, int autopoll)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i, id;
|
2014-01-28 01:43:17 +00:00
|
|
|
static int dump_adb_input;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
void (*handler)(unsigned char *, int, int);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* We skip keystrokes and mouse moves when the sleep process
|
|
|
|
* has been started. We stop autopoll, but this is another security
|
|
|
|
*/
|
|
|
|
if (adb_got_sleep)
|
|
|
|
return;
|
|
|
|
|
|
|
|
id = buf[0] >> 4;
|
|
|
|
if (dump_adb_input) {
|
2016-11-28 20:29:07 +00:00
|
|
|
pr_info("adb packet: ");
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < nb; ++i)
|
2016-11-28 20:29:07 +00:00
|
|
|
pr_cont(" %x", buf[i]);
|
|
|
|
pr_cont(", id = %d\n", id);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
write_lock_irqsave(&adb_handler_lock, flags);
|
|
|
|
handler = adb_handler[id].handler;
|
|
|
|
if (handler != NULL)
|
|
|
|
adb_handler[id].busy = 1;
|
|
|
|
write_unlock_irqrestore(&adb_handler_lock, flags);
|
|
|
|
if (handler != NULL) {
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
(*handler)(buf, nb, autopoll);
|
2005-04-16 22:20:36 +00:00
|
|
|
wmb();
|
|
|
|
adb_handler[id].busy = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to change handler to new_id. Will return 1 if successful. */
|
|
|
|
static int try_handler_change(int address, int new_id)
|
|
|
|
{
|
|
|
|
struct adb_request req;
|
|
|
|
|
|
|
|
if (adb_handler[address].handler_id == new_id)
|
|
|
|
return 1;
|
|
|
|
adb_request(&req, NULL, ADBREQ_SYNC, 3,
|
|
|
|
ADB_WRITEREG(address, 3), address | 0x20, new_id);
|
|
|
|
adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
|
|
|
|
ADB_READREG(address, 3));
|
|
|
|
if (req.reply_len < 2)
|
|
|
|
return 0;
|
|
|
|
if (req.reply[2] != new_id)
|
|
|
|
return 0;
|
|
|
|
adb_handler[address].handler_id = req.reply[2];
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
adb_try_handler_change(int address, int new_id)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2008-05-02 20:34:03 +00:00
|
|
|
mutex_lock(&adb_handler_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = try_handler_change(address, new_id);
|
2008-05-02 20:34:03 +00:00
|
|
|
mutex_unlock(&adb_handler_mutex);
|
2018-09-12 00:18:44 +00:00
|
|
|
if (ret)
|
|
|
|
pr_debug("adb handler change: [%d] 0x%X\n", address, new_id);
|
2005-04-16 22:20:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2014-08-19 22:00:00 +00:00
|
|
|
EXPORT_SYMBOL(adb_try_handler_change);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
adb_get_infos(int address, int *original_address, int *handler_id)
|
|
|
|
{
|
2008-05-02 20:34:03 +00:00
|
|
|
mutex_lock(&adb_handler_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
*original_address = adb_handler[address].original_address;
|
|
|
|
*handler_id = adb_handler[address].handler_id;
|
2008-05-02 20:34:03 +00:00
|
|
|
mutex_unlock(&adb_handler_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return (*original_address != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* /dev/adb device driver.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ADB_MAJOR 56 /* major number for /dev/adb */
|
|
|
|
|
|
|
|
struct adbdev_state {
|
|
|
|
spinlock_t lock;
|
|
|
|
atomic_t n_pending;
|
|
|
|
struct adb_request *completed;
|
|
|
|
wait_queue_head_t wait_queue;
|
|
|
|
int inuse;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void adb_write_done(struct adb_request *req)
|
|
|
|
{
|
|
|
|
struct adbdev_state *state = (struct adbdev_state *) req->arg;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (!req->complete) {
|
|
|
|
req->reply_len = 0;
|
|
|
|
req->complete = 1;
|
|
|
|
}
|
|
|
|
spin_lock_irqsave(&state->lock, flags);
|
|
|
|
atomic_dec(&state->n_pending);
|
|
|
|
if (!state->inuse) {
|
|
|
|
kfree(req);
|
|
|
|
if (atomic_read(&state->n_pending) == 0) {
|
|
|
|
spin_unlock_irqrestore(&state->lock, flags);
|
|
|
|
kfree(state);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct adb_request **ap = &state->completed;
|
|
|
|
while (*ap != NULL)
|
|
|
|
ap = &(*ap)->next;
|
|
|
|
req->next = NULL;
|
|
|
|
*ap = req;
|
|
|
|
wake_up_interruptible(&state->wait_queue);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&state->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
do_adb_query(struct adb_request *req)
|
|
|
|
{
|
|
|
|
int ret = -EINVAL;
|
|
|
|
|
2014-01-28 01:43:17 +00:00
|
|
|
switch(req->data[1]) {
|
2005-04-16 22:20:36 +00:00
|
|
|
case ADB_QUERY_GETDEVINFO:
|
2022-07-13 15:37:34 +00:00
|
|
|
if (req->nbytes < 3 || req->data[2] >= 16)
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
2008-05-02 20:34:03 +00:00
|
|
|
mutex_lock(&adb_handler_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
req->reply[0] = adb_handler[req->data[2]].original_address;
|
|
|
|
req->reply[1] = adb_handler[req->data[2]].handler_id;
|
2008-05-02 20:34:03 +00:00
|
|
|
mutex_unlock(&adb_handler_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
req->complete = 1;
|
|
|
|
req->reply_len = 2;
|
|
|
|
adb_write_done(req);
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adb_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct adbdev_state *state;
|
2008-05-16 20:19:56 +00:00
|
|
|
int ret = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_lock(&adb_mutex);
|
2008-05-16 20:19:56 +00:00
|
|
|
if (iminor(inode) > 0 || adb_controller == NULL) {
|
|
|
|
ret = -ENXIO;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
state = kmalloc(sizeof(struct adbdev_state), GFP_KERNEL);
|
2008-05-16 20:19:56 +00:00
|
|
|
if (state == 0) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
file->private_data = state;
|
|
|
|
spin_lock_init(&state->lock);
|
|
|
|
atomic_set(&state->n_pending, 0);
|
|
|
|
state->completed = NULL;
|
|
|
|
init_waitqueue_head(&state->wait_queue);
|
|
|
|
state->inuse = 1;
|
|
|
|
|
2008-05-16 20:19:56 +00:00
|
|
|
out:
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_unlock(&adb_mutex);
|
2008-05-16 20:19:56 +00:00
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int adb_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct adbdev_state *state = file->private_data;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_lock(&adb_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (state) {
|
|
|
|
file->private_data = NULL;
|
|
|
|
spin_lock_irqsave(&state->lock, flags);
|
|
|
|
if (atomic_read(&state->n_pending) == 0
|
|
|
|
&& state->completed == NULL) {
|
|
|
|
spin_unlock_irqrestore(&state->lock, flags);
|
|
|
|
kfree(state);
|
|
|
|
} else {
|
|
|
|
state->inuse = 0;
|
|
|
|
spin_unlock_irqrestore(&state->lock, flags);
|
|
|
|
}
|
|
|
|
}
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_unlock(&adb_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t adb_read(struct file *file, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct adbdev_state *state = file->private_data;
|
|
|
|
struct adb_request *req;
|
2014-01-28 01:43:17 +00:00
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (count < 2)
|
|
|
|
return -EINVAL;
|
|
|
|
if (count > sizeof(req->reply))
|
|
|
|
count = sizeof(req->reply);
|
|
|
|
|
|
|
|
req = NULL;
|
|
|
|
spin_lock_irqsave(&state->lock, flags);
|
|
|
|
add_wait_queue(&state->wait_queue, &wait);
|
2012-02-03 14:35:59 +00:00
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
req = state->completed;
|
|
|
|
if (req != NULL)
|
|
|
|
state->completed = req->next;
|
|
|
|
else if (atomic_read(&state->n_pending) == 0)
|
|
|
|
ret = -EIO;
|
|
|
|
if (req != NULL || ret != 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (file->f_flags & O_NONBLOCK) {
|
|
|
|
ret = -EAGAIN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (signal_pending(current)) {
|
|
|
|
ret = -ERESTARTSYS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&state->lock, flags);
|
|
|
|
schedule();
|
|
|
|
spin_lock_irqsave(&state->lock, flags);
|
|
|
|
}
|
|
|
|
|
2012-02-03 14:35:59 +00:00
|
|
|
set_current_state(TASK_RUNNING);
|
2005-04-16 22:20:36 +00:00
|
|
|
remove_wait_queue(&state->wait_queue, &wait);
|
|
|
|
spin_unlock_irqrestore(&state->lock, flags);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = req->reply_len;
|
|
|
|
if (ret > count)
|
|
|
|
ret = count;
|
|
|
|
if (ret > 0 && copy_to_user(buf, req->reply, ret))
|
|
|
|
ret = -EFAULT;
|
|
|
|
|
|
|
|
kfree(req);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t adb_write(struct file *file, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
int ret/*, i*/;
|
|
|
|
struct adbdev_state *state = file->private_data;
|
|
|
|
struct adb_request *req;
|
|
|
|
|
|
|
|
if (count < 2 || count > sizeof(req->data))
|
|
|
|
return -EINVAL;
|
|
|
|
if (adb_controller == NULL)
|
|
|
|
return -ENXIO;
|
|
|
|
|
2006-12-13 08:35:56 +00:00
|
|
|
req = kmalloc(sizeof(struct adb_request),
|
2005-04-16 22:20:36 +00:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (req == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
req->nbytes = count;
|
|
|
|
req->done = adb_write_done;
|
|
|
|
req->arg = (void *) state;
|
|
|
|
req->complete = 0;
|
|
|
|
|
|
|
|
ret = -EFAULT;
|
|
|
|
if (copy_from_user(req->data, buf, count))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
atomic_inc(&state->n_pending);
|
|
|
|
|
|
|
|
/* If a probe is in progress or we are sleeping, wait for it to complete */
|
|
|
|
down(&adb_probe_mutex);
|
|
|
|
|
|
|
|
/* Queries are special requests sent to the ADB driver itself */
|
|
|
|
if (req->data[0] == ADB_QUERY) {
|
|
|
|
if (count > 1)
|
|
|
|
ret = do_adb_query(req);
|
|
|
|
else
|
|
|
|
ret = -EINVAL;
|
|
|
|
up(&adb_probe_mutex);
|
|
|
|
}
|
|
|
|
/* Special case for ADB_BUSRESET request, all others are sent to
|
|
|
|
the controller */
|
2014-01-28 01:43:17 +00:00
|
|
|
else if ((req->data[0] == ADB_PACKET) && (count > 1)
|
|
|
|
&& (req->data[1] == ADB_BUSRESET)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = do_adb_reset_bus();
|
|
|
|
up(&adb_probe_mutex);
|
|
|
|
atomic_dec(&state->n_pending);
|
|
|
|
if (ret == 0)
|
|
|
|
ret = count;
|
|
|
|
goto out;
|
|
|
|
} else {
|
|
|
|
req->reply_expected = ((req->data[1] & 0xc) == 0xc);
|
|
|
|
if (adb_controller && adb_controller->send_request)
|
|
|
|
ret = adb_controller->send_request(req, 0);
|
|
|
|
else
|
|
|
|
ret = -ENXIO;
|
|
|
|
up(&adb_probe_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
atomic_dec(&state->n_pending);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
|
|
|
|
out:
|
|
|
|
kfree(req);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-02-12 08:55:33 +00:00
|
|
|
static const struct file_operations adb_fops = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
.read = adb_read,
|
|
|
|
.write = adb_write,
|
|
|
|
.open = adb_open,
|
|
|
|
.release = adb_release,
|
|
|
|
};
|
|
|
|
|
2014-02-10 16:12:27 +00:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
static const struct dev_pm_ops adb_dev_pm_ops = {
|
|
|
|
.suspend = adb_suspend,
|
|
|
|
.resume = adb_resume,
|
|
|
|
/* Hibernate hooks */
|
|
|
|
.freeze = adb_freeze,
|
|
|
|
.thaw = adb_resume,
|
|
|
|
.poweroff = adb_poweroff,
|
|
|
|
.restore = adb_resume,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2007-12-11 14:21:25 +00:00
|
|
|
static struct platform_driver adb_pfdrv = {
|
|
|
|
.driver = {
|
|
|
|
.name = "adb",
|
|
|
|
#ifdef CONFIG_PM
|
2014-02-10 16:12:27 +00:00
|
|
|
.pm = &adb_dev_pm_ops,
|
2007-12-11 14:21:25 +00:00
|
|
|
#endif
|
2014-02-10 16:12:27 +00:00
|
|
|
},
|
2007-12-11 14:21:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_device adb_pfdev = {
|
|
|
|
.name = "adb",
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init
|
|
|
|
adb_dummy_probe(struct platform_device *dev)
|
|
|
|
{
|
|
|
|
if (dev == &adb_pfdev)
|
|
|
|
return 0;
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init
|
2005-04-16 22:20:36 +00:00
|
|
|
adbdev_init(void)
|
|
|
|
{
|
|
|
|
if (register_chrdev(ADB_MAJOR, "adb", &adb_fops)) {
|
2016-11-28 20:29:07 +00:00
|
|
|
pr_err("adb: unable to get major %d\n", ADB_MAJOR);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-03-23 18:01:41 +00:00
|
|
|
adb_dev_class = class_create(THIS_MODULE, "adb");
|
|
|
|
if (IS_ERR(adb_dev_class))
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
2008-07-22 03:03:34 +00:00
|
|
|
device_create(adb_dev_class, NULL, MKDEV(ADB_MAJOR, 0), NULL, "adb");
|
2007-12-11 14:21:25 +00:00
|
|
|
|
|
|
|
platform_device_register(&adb_pfdev);
|
|
|
|
platform_driver_probe(&adb_pfdrv, adb_dummy_probe);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|