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 08:07:57 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
2016-12-31 17:56:26 -07:00
|
|
|
* Device driver for the Cuda and Egret system controllers found on PowerMacs
|
|
|
|
* and 68k Macs.
|
2005-04-16 16:20:36 -06:00
|
|
|
*
|
2016-12-31 17:56:26 -07:00
|
|
|
* The Cuda or Egret is a 6805 microcontroller interfaced to the 6522 VIA.
|
|
|
|
* This MCU controls system power, Parameter RAM, Real Time Clock and the
|
|
|
|
* Apple Desktop Bus (ADB) that connects to the keyboard and mouse.
|
2005-04-16 16:20:36 -06:00
|
|
|
*
|
|
|
|
* Copyright (C) 1996 Paul Mackerras.
|
|
|
|
*/
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/adb.h>
|
|
|
|
#include <linux/cuda.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#ifdef CONFIG_PPC
|
|
|
|
#include <asm/prom.h>
|
|
|
|
#include <asm/machdep.h>
|
|
|
|
#else
|
|
|
|
#include <asm/macintosh.h>
|
|
|
|
#include <asm/macints.h>
|
|
|
|
#include <asm/mac_via.h>
|
|
|
|
#endif
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
|
|
|
static volatile unsigned char __iomem *via;
|
|
|
|
static DEFINE_SPINLOCK(cuda_lock);
|
|
|
|
|
|
|
|
/* VIA registers - spaced 0x200 bytes apart */
|
|
|
|
#define RS 0x200 /* skip between registers */
|
|
|
|
#define B 0 /* B-side data */
|
|
|
|
#define A RS /* A-side data */
|
|
|
|
#define DIRB (2*RS) /* B-side direction (1=output) */
|
|
|
|
#define DIRA (3*RS) /* A-side direction (1=output) */
|
|
|
|
#define T1CL (4*RS) /* Timer 1 ctr/latch (low 8 bits) */
|
|
|
|
#define T1CH (5*RS) /* Timer 1 counter (high 8 bits) */
|
|
|
|
#define T1LL (6*RS) /* Timer 1 latch (low 8 bits) */
|
|
|
|
#define T1LH (7*RS) /* Timer 1 latch (high 8 bits) */
|
|
|
|
#define T2CL (8*RS) /* Timer 2 ctr/latch (low 8 bits) */
|
|
|
|
#define T2CH (9*RS) /* Timer 2 counter (high 8 bits) */
|
|
|
|
#define SR (10*RS) /* Shift register */
|
|
|
|
#define ACR (11*RS) /* Auxiliary control register */
|
|
|
|
#define PCR (12*RS) /* Peripheral control register */
|
|
|
|
#define IFR (13*RS) /* Interrupt flag register */
|
|
|
|
#define IER (14*RS) /* Interrupt enable register */
|
|
|
|
#define ANH (15*RS) /* A-side data, no handshake */
|
|
|
|
|
2016-12-31 17:56:26 -07:00
|
|
|
/*
|
|
|
|
* When the Cuda design replaced the Egret, some signal names and
|
|
|
|
* logic sense changed. They all serve the same purposes, however.
|
|
|
|
*
|
|
|
|
* VIA pin | Egret pin
|
|
|
|
* ----------------+------------------------------------------
|
|
|
|
* PB3 (input) | Transceiver session (active low)
|
|
|
|
* PB4 (output) | VIA full (active high)
|
|
|
|
* PB5 (output) | System session (active high)
|
|
|
|
*
|
|
|
|
* VIA pin | Cuda pin
|
|
|
|
* ----------------+------------------------------------------
|
|
|
|
* PB3 (input) | Transfer request (active low)
|
|
|
|
* PB4 (output) | Byte acknowledge (active low)
|
|
|
|
* PB5 (output) | Transfer in progress (active low)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Bits in Port B data register */
|
|
|
|
#define TREQ 0x08 /* Transfer request */
|
|
|
|
#define TACK 0x10 /* Transfer acknowledge */
|
|
|
|
#define TIP 0x20 /* Transfer in progress */
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* Bits in ACR */
|
|
|
|
#define SR_CTRL 0x1c /* Shift register control bits */
|
|
|
|
#define SR_EXT 0x0c /* Shift on external clock */
|
|
|
|
#define SR_OUT 0x10 /* Shift out if 1 */
|
|
|
|
|
|
|
|
/* Bits in IFR and IER */
|
|
|
|
#define IER_SET 0x80 /* set bits in IER */
|
|
|
|
#define IER_CLR 0 /* clear bits in IER */
|
|
|
|
#define SR_INT 0x04 /* Shift register full/empty */
|
|
|
|
|
2016-12-31 17:56:26 -07:00
|
|
|
/* Duration of byte acknowledgement pulse (us) */
|
|
|
|
#define EGRET_TACK_ASSERTED_DELAY 300
|
|
|
|
#define EGRET_TACK_NEGATED_DELAY 400
|
|
|
|
|
|
|
|
/* Interval from interrupt to start of session (us) */
|
|
|
|
#define EGRET_SESSION_DELAY 450
|
|
|
|
|
|
|
|
#ifdef CONFIG_PPC
|
|
|
|
#define mcu_is_egret false
|
|
|
|
#else
|
|
|
|
static bool mcu_is_egret;
|
|
|
|
#endif
|
|
|
|
|
2016-12-31 17:56:26 -07:00
|
|
|
static inline bool TREQ_asserted(u8 portb)
|
|
|
|
{
|
|
|
|
return !(portb & TREQ);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void assert_TIP(void)
|
|
|
|
{
|
2016-12-31 17:56:26 -07:00
|
|
|
if (mcu_is_egret) {
|
|
|
|
udelay(EGRET_SESSION_DELAY);
|
|
|
|
out_8(&via[B], in_8(&via[B]) | TIP);
|
|
|
|
} else
|
|
|
|
out_8(&via[B], in_8(&via[B]) & ~TIP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void assert_TIP_and_TACK(void)
|
|
|
|
{
|
|
|
|
if (mcu_is_egret) {
|
|
|
|
udelay(EGRET_SESSION_DELAY);
|
|
|
|
out_8(&via[B], in_8(&via[B]) | TIP | TACK);
|
|
|
|
} else
|
|
|
|
out_8(&via[B], in_8(&via[B]) & ~(TIP | TACK));
|
2016-12-31 17:56:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void assert_TACK(void)
|
|
|
|
{
|
2016-12-31 17:56:26 -07:00
|
|
|
if (mcu_is_egret) {
|
|
|
|
udelay(EGRET_TACK_NEGATED_DELAY);
|
|
|
|
out_8(&via[B], in_8(&via[B]) | TACK);
|
|
|
|
} else
|
|
|
|
out_8(&via[B], in_8(&via[B]) & ~TACK);
|
2016-12-31 17:56:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void toggle_TACK(void)
|
|
|
|
{
|
|
|
|
out_8(&via[B], in_8(&via[B]) ^ TACK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void negate_TACK(void)
|
|
|
|
{
|
2016-12-31 17:56:26 -07:00
|
|
|
if (mcu_is_egret) {
|
|
|
|
udelay(EGRET_TACK_ASSERTED_DELAY);
|
|
|
|
out_8(&via[B], in_8(&via[B]) & ~TACK);
|
|
|
|
} else
|
|
|
|
out_8(&via[B], in_8(&via[B]) | TACK);
|
2016-12-31 17:56:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void negate_TIP_and_TACK(void)
|
|
|
|
{
|
2016-12-31 17:56:26 -07:00
|
|
|
if (mcu_is_egret) {
|
|
|
|
udelay(EGRET_TACK_ASSERTED_DELAY);
|
|
|
|
out_8(&via[B], in_8(&via[B]) & ~(TIP | TACK));
|
|
|
|
} else
|
|
|
|
out_8(&via[B], in_8(&via[B]) | TIP | TACK);
|
2016-12-31 17:56:26 -07:00
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
static enum cuda_state {
|
|
|
|
idle,
|
|
|
|
sent_first_byte,
|
|
|
|
sending,
|
|
|
|
reading,
|
|
|
|
read_done,
|
|
|
|
awaiting_reply
|
|
|
|
} cuda_state;
|
|
|
|
|
|
|
|
static struct adb_request *current_req;
|
|
|
|
static struct adb_request *last_req;
|
|
|
|
static unsigned char cuda_rbuf[16];
|
|
|
|
static unsigned char *reply_ptr;
|
|
|
|
static int reading_reply;
|
|
|
|
static int data_index;
|
2007-05-01 14:33:00 -06:00
|
|
|
static int cuda_irq;
|
2005-04-16 16:20:36 -06:00
|
|
|
#ifdef CONFIG_PPC
|
|
|
|
static struct device_node *vias;
|
|
|
|
#endif
|
2007-02-10 13:35:12 -07:00
|
|
|
static int cuda_fully_inited;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#ifdef CONFIG_ADB
|
|
|
|
static int cuda_probe(void);
|
|
|
|
static int cuda_send_request(struct adb_request *req, int sync);
|
|
|
|
static int cuda_adb_autopoll(int devs);
|
|
|
|
static int cuda_reset_adb_bus(void);
|
|
|
|
#endif /* CONFIG_ADB */
|
|
|
|
|
|
|
|
static int cuda_init_via(void);
|
|
|
|
static void cuda_start(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 07:55:46 -06:00
|
|
|
static irqreturn_t cuda_interrupt(int irq, void *arg);
|
|
|
|
static void cuda_input(unsigned char *buf, int nb);
|
2005-04-16 16:20:36 -06:00
|
|
|
void cuda_poll(void);
|
|
|
|
static int cuda_write(struct adb_request *req);
|
|
|
|
|
|
|
|
int cuda_request(struct adb_request *req,
|
|
|
|
void (*done)(struct adb_request *), int nbytes, ...);
|
|
|
|
|
|
|
|
#ifdef CONFIG_ADB
|
|
|
|
struct adb_driver via_cuda_driver = {
|
2009-11-17 02:03:05 -07:00
|
|
|
.name = "CUDA",
|
|
|
|
.probe = cuda_probe,
|
|
|
|
.send_request = cuda_send_request,
|
|
|
|
.autopoll = cuda_adb_autopoll,
|
|
|
|
.poll = cuda_poll,
|
|
|
|
.reset_bus = cuda_reset_adb_bus,
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
#endif /* CONFIG_ADB */
|
|
|
|
|
2009-11-17 02:03:05 -07:00
|
|
|
#ifdef CONFIG_MAC
|
|
|
|
int __init find_via_cuda(void)
|
|
|
|
{
|
|
|
|
struct adb_request req;
|
|
|
|
int err;
|
|
|
|
|
2016-12-31 17:56:26 -07:00
|
|
|
if (macintosh_config->adb_type != MAC_ADB_CUDA &&
|
|
|
|
macintosh_config->adb_type != MAC_ADB_EGRET)
|
2009-11-17 02:03:05 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
via = via1;
|
|
|
|
cuda_state = idle;
|
2016-12-31 17:56:26 -07:00
|
|
|
mcu_is_egret = macintosh_config->adb_type == MAC_ADB_EGRET;
|
2009-11-17 02:03:05 -07:00
|
|
|
|
|
|
|
err = cuda_init_via();
|
|
|
|
if (err) {
|
|
|
|
printk(KERN_ERR "cuda_init_via() failed\n");
|
|
|
|
via = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* enable autopoll */
|
|
|
|
cuda_request(&req, NULL, 3, CUDA_PACKET, CUDA_AUTOPOLL, 1);
|
|
|
|
while (!req.complete)
|
|
|
|
cuda_poll();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#else
|
2005-11-22 23:57:25 -07:00
|
|
|
int __init find_via_cuda(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct adb_request req;
|
2005-11-22 23:57:25 -07:00
|
|
|
phys_addr_t taddr;
|
2006-07-11 23:40:29 -06:00
|
|
|
const u32 *reg;
|
2005-11-22 23:57:25 -07:00
|
|
|
int err;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (vias != 0)
|
|
|
|
return 1;
|
2005-11-22 23:57:25 -07:00
|
|
|
vias = of_find_node_by_name(NULL, "via-cuda");
|
2005-04-16 16:20:36 -06:00
|
|
|
if (vias == 0)
|
|
|
|
return 0;
|
|
|
|
|
2007-04-26 21:41:15 -06:00
|
|
|
reg = of_get_property(vias, "reg", NULL);
|
2005-11-22 23:57:25 -07:00
|
|
|
if (reg == NULL) {
|
|
|
|
printk(KERN_ERR "via-cuda: No \"reg\" property !\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
taddr = of_translate_address(vias, reg);
|
|
|
|
if (taddr == 0) {
|
|
|
|
printk(KERN_ERR "via-cuda: Can't translate address !\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
via = ioremap(taddr, 0x2000);
|
|
|
|
if (via == NULL) {
|
|
|
|
printk(KERN_ERR "via-cuda: Can't map address !\n");
|
|
|
|
goto fail;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
cuda_state = idle;
|
|
|
|
sys_ctrler = SYS_CTRLER_CUDA;
|
|
|
|
|
|
|
|
err = cuda_init_via();
|
|
|
|
if (err) {
|
|
|
|
printk(KERN_ERR "cuda_init_via() failed\n");
|
|
|
|
via = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear and enable interrupts, but only on PPC. On 68K it's done */
|
|
|
|
/* for us by the main VIA driver in arch/m68k/mac/via.c */
|
|
|
|
|
|
|
|
out_8(&via[IFR], 0x7f); /* clear interrupts by writing 1s */
|
|
|
|
out_8(&via[IER], IER_SET|SR_INT); /* enable interrupt from SR */
|
|
|
|
|
|
|
|
/* enable autopoll */
|
|
|
|
cuda_request(&req, NULL, 3, CUDA_PACKET, CUDA_AUTOPOLL, 1);
|
|
|
|
while (!req.complete)
|
|
|
|
cuda_poll();
|
|
|
|
|
|
|
|
return 1;
|
2005-11-22 23:57:25 -07:00
|
|
|
|
|
|
|
fail:
|
|
|
|
of_node_put(vias);
|
|
|
|
vias = NULL;
|
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2009-11-17 02:03:05 -07:00
|
|
|
#endif /* !defined CONFIG_MAC */
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
static int __init via_cuda_start(void)
|
|
|
|
{
|
|
|
|
if (via == NULL)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2006-07-03 05:36:01 -06:00
|
|
|
#ifdef CONFIG_MAC
|
2007-05-01 14:33:00 -06:00
|
|
|
cuda_irq = IRQ_MAC_ADB;
|
2009-11-17 02:03:05 -07:00
|
|
|
#else
|
2007-05-01 14:33:00 -06:00
|
|
|
cuda_irq = irq_of_parse_and_map(vias, 0);
|
2016-09-06 05:53:24 -06:00
|
|
|
if (!cuda_irq) {
|
2017-07-18 15:43:12 -06:00
|
|
|
printk(KERN_ERR "via-cuda: can't map interrupts for %pOF\n",
|
|
|
|
vias);
|
2006-07-03 05:36:01 -06:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2009-11-17 02:03:05 -07:00
|
|
|
#endif
|
2006-07-03 05:36:01 -06:00
|
|
|
|
2007-05-01 14:33:00 -06:00
|
|
|
if (request_irq(cuda_irq, cuda_interrupt, 0, "ADB", cuda_interrupt)) {
|
|
|
|
printk(KERN_ERR "via-cuda: can't request irq %d\n", cuda_irq);
|
2005-04-16 16:20:36 -06:00
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
2016-12-31 17:56:26 -07:00
|
|
|
pr_info("Macintosh Cuda and Egret driver.\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
cuda_fully_inited = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_initcall(via_cuda_start);
|
|
|
|
|
|
|
|
#ifdef CONFIG_ADB
|
|
|
|
static int
|
|
|
|
cuda_probe(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_PPC
|
|
|
|
if (sys_ctrler != SYS_CTRLER_CUDA)
|
|
|
|
return -ENODEV;
|
|
|
|
#else
|
2016-12-31 17:56:26 -07:00
|
|
|
if (macintosh_config->adb_type != MAC_ADB_CUDA &&
|
|
|
|
macintosh_config->adb_type != MAC_ADB_EGRET)
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENODEV;
|
|
|
|
#endif
|
|
|
|
if (via == NULL)
|
|
|
|
return -ENODEV;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_ADB */
|
|
|
|
|
2016-12-31 17:56:26 -07:00
|
|
|
static int __init sync_egret(void)
|
|
|
|
{
|
|
|
|
if (TREQ_asserted(in_8(&via[B]))) {
|
|
|
|
/* Complete the inbound transfer */
|
|
|
|
assert_TIP_and_TACK();
|
|
|
|
while (1) {
|
|
|
|
negate_TACK();
|
|
|
|
mdelay(1);
|
|
|
|
(void)in_8(&via[SR]);
|
|
|
|
assert_TACK();
|
|
|
|
if (!TREQ_asserted(in_8(&via[B])))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
negate_TIP_and_TACK();
|
|
|
|
} else if (in_8(&via[B]) & TIP) {
|
|
|
|
/* Terminate the outbound transfer */
|
|
|
|
negate_TACK();
|
|
|
|
assert_TACK();
|
|
|
|
mdelay(1);
|
|
|
|
negate_TIP_and_TACK();
|
|
|
|
}
|
|
|
|
/* Clear shift register interrupt */
|
|
|
|
if (in_8(&via[IFR]) & SR_INT)
|
|
|
|
(void)in_8(&via[SR]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#define WAIT_FOR(cond, what) \
|
|
|
|
do { \
|
|
|
|
int x; \
|
|
|
|
for (x = 1000; !(cond); --x) { \
|
|
|
|
if (x == 0) { \
|
2016-12-31 17:56:26 -07:00
|
|
|
pr_err("Timeout waiting for " what "\n"); \
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENXIO; \
|
|
|
|
} \
|
|
|
|
udelay(100); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static int
|
2013-06-30 04:03:23 -06:00
|
|
|
__init cuda_init_via(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2007-05-01 14:33:00 -06:00
|
|
|
#ifdef CONFIG_PPC
|
2005-04-16 16:20:36 -06:00
|
|
|
out_8(&via[IER], 0x7f); /* disable interrupts from VIA */
|
|
|
|
(void)in_8(&via[IER]);
|
2007-05-01 14:33:00 -06:00
|
|
|
#else
|
|
|
|
out_8(&via[IER], SR_INT); /* disable SR interrupt from VIA */
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
|
2016-12-31 17:56:26 -07:00
|
|
|
out_8(&via[DIRB], (in_8(&via[DIRB]) | TACK | TIP) & ~TREQ); /* TACK & TIP out */
|
|
|
|
out_8(&via[ACR], (in_8(&via[ACR]) & ~SR_CTRL) | SR_EXT); /* SR data in */
|
|
|
|
(void)in_8(&via[SR]); /* clear any left-over data */
|
|
|
|
|
|
|
|
if (mcu_is_egret)
|
|
|
|
return sync_egret();
|
|
|
|
|
|
|
|
negate_TIP_and_TACK();
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/* delay 4ms and then clear any pending interrupt */
|
|
|
|
mdelay(4);
|
|
|
|
(void)in_8(&via[SR]);
|
2007-05-01 14:33:00 -06:00
|
|
|
out_8(&via[IFR], SR_INT);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* sync with the CUDA - assert TACK without TIP */
|
2016-12-31 17:56:26 -07:00
|
|
|
assert_TACK();
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* wait for the CUDA to assert TREQ in response */
|
2016-12-31 17:56:26 -07:00
|
|
|
WAIT_FOR(TREQ_asserted(in_8(&via[B])), "CUDA response to sync");
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* wait for the interrupt and then clear it */
|
|
|
|
WAIT_FOR(in_8(&via[IFR]) & SR_INT, "CUDA response to sync (2)");
|
|
|
|
(void)in_8(&via[SR]);
|
2007-05-01 14:33:00 -06:00
|
|
|
out_8(&via[IFR], SR_INT);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* finish the sync by negating TACK */
|
2016-12-31 17:56:26 -07:00
|
|
|
negate_TACK();
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* wait for the CUDA to negate TREQ and the corresponding interrupt */
|
2016-12-31 17:56:26 -07:00
|
|
|
WAIT_FOR(!TREQ_asserted(in_8(&via[B])), "CUDA response to sync (3)");
|
2005-04-16 16:20:36 -06:00
|
|
|
WAIT_FOR(in_8(&via[IFR]) & SR_INT, "CUDA response to sync (4)");
|
|
|
|
(void)in_8(&via[SR]);
|
2007-05-01 14:33:00 -06:00
|
|
|
out_8(&via[IFR], SR_INT);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_ADB
|
|
|
|
/* Send an ADB command */
|
|
|
|
static int
|
|
|
|
cuda_send_request(struct adb_request *req, int sync)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if ((via == NULL) || !cuda_fully_inited) {
|
|
|
|
req->complete = 1;
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->reply_expected = 1;
|
|
|
|
|
|
|
|
i = cuda_write(req);
|
|
|
|
if (i)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
if (sync) {
|
|
|
|
while (!req->complete)
|
|
|
|
cuda_poll();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Enable/disable autopolling */
|
|
|
|
static int
|
|
|
|
cuda_adb_autopoll(int devs)
|
|
|
|
{
|
|
|
|
struct adb_request req;
|
|
|
|
|
|
|
|
if ((via == NULL) || !cuda_fully_inited)
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
cuda_request(&req, NULL, 3, CUDA_PACKET, CUDA_AUTOPOLL, (devs? 1: 0));
|
|
|
|
while (!req.complete)
|
|
|
|
cuda_poll();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset adb bus - how do we do this?? */
|
|
|
|
static int
|
|
|
|
cuda_reset_adb_bus(void)
|
|
|
|
{
|
|
|
|
struct adb_request req;
|
|
|
|
|
|
|
|
if ((via == NULL) || !cuda_fully_inited)
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
cuda_request(&req, NULL, 2, ADB_PACKET, 0); /* maybe? */
|
|
|
|
while (!req.complete)
|
|
|
|
cuda_poll();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_ADB */
|
2016-12-31 17:56:26 -07:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/* Construct and send a cuda request */
|
|
|
|
int
|
|
|
|
cuda_request(struct adb_request *req, void (*done)(struct adb_request *),
|
|
|
|
int nbytes, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (via == NULL) {
|
|
|
|
req->complete = 1;
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->nbytes = nbytes;
|
|
|
|
req->done = done;
|
|
|
|
va_start(list, nbytes);
|
|
|
|
for (i = 0; i < nbytes; ++i)
|
|
|
|
req->data[i] = va_arg(list, int);
|
|
|
|
va_end(list);
|
|
|
|
req->reply_expected = 1;
|
|
|
|
return cuda_write(req);
|
|
|
|
}
|
2014-08-19 16:00:01 -06:00
|
|
|
EXPORT_SYMBOL(cuda_request);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
static int
|
|
|
|
cuda_write(struct adb_request *req)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (req->nbytes < 2 || req->data[0] > CUDA_PACKET) {
|
|
|
|
req->complete = 1;
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
req->next = NULL;
|
|
|
|
req->sent = 0;
|
|
|
|
req->complete = 0;
|
|
|
|
req->reply_len = 0;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&cuda_lock, flags);
|
|
|
|
if (current_req != 0) {
|
|
|
|
last_req->next = req;
|
|
|
|
last_req = req;
|
|
|
|
} else {
|
|
|
|
current_req = req;
|
|
|
|
last_req = req;
|
|
|
|
if (cuda_state == idle)
|
|
|
|
cuda_start();
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&cuda_lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cuda_start(void)
|
|
|
|
{
|
|
|
|
/* assert cuda_state == idle */
|
2016-12-31 17:56:26 -07:00
|
|
|
if (current_req == NULL)
|
2005-04-16 16:20:36 -06:00
|
|
|
return;
|
2016-12-31 17:56:26 -07:00
|
|
|
data_index = 0;
|
2016-12-31 17:56:26 -07:00
|
|
|
if (TREQ_asserted(in_8(&via[B])))
|
2005-04-16 16:20:36 -06:00
|
|
|
return; /* a byte is coming in from the CUDA */
|
|
|
|
|
|
|
|
/* set the shift register to shift out and send a byte */
|
|
|
|
out_8(&via[ACR], in_8(&via[ACR]) | SR_OUT);
|
2016-12-31 17:56:26 -07:00
|
|
|
out_8(&via[SR], current_req->data[data_index++]);
|
2016-12-31 17:56:26 -07:00
|
|
|
if (mcu_is_egret)
|
|
|
|
assert_TIP_and_TACK();
|
|
|
|
else
|
|
|
|
assert_TIP();
|
2005-04-16 16:20:36 -06:00
|
|
|
cuda_state = sent_first_byte;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cuda_poll(void)
|
|
|
|
{
|
2016-12-31 17:56:26 -07:00
|
|
|
cuda_interrupt(0, NULL);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2014-08-19 16:00:01 -06:00
|
|
|
EXPORT_SYMBOL(cuda_poll);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2016-12-31 17:56:26 -07:00
|
|
|
#define ARRAY_FULL(a, p) ((p) - (a) == ARRAY_SIZE(a))
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
static irqreturn_t
|
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 07:55:46 -06:00
|
|
|
cuda_interrupt(int irq, void *arg)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2016-12-31 17:56:26 -07:00
|
|
|
unsigned long flags;
|
2016-12-31 17:56:26 -07:00
|
|
|
u8 status;
|
2005-04-16 16:20:36 -06:00
|
|
|
struct adb_request *req = NULL;
|
|
|
|
unsigned char ibuf[16];
|
|
|
|
int ibuf_len = 0;
|
|
|
|
int complete = 0;
|
|
|
|
|
2016-12-31 17:56:26 -07:00
|
|
|
spin_lock_irqsave(&cuda_lock, flags);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-11-17 02:03:05 -07:00
|
|
|
/* On powermacs, this handler is registered for the VIA IRQ. But they use
|
2007-05-01 14:33:00 -06:00
|
|
|
* just the shift register IRQ -- other VIA interrupt sources are disabled.
|
|
|
|
* On m68k macs, the VIA IRQ sources are dispatched individually. Unless
|
|
|
|
* we are polling, the shift register IRQ flag has already been cleared.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_MAC
|
|
|
|
if (!arg)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if ((in_8(&via[IFR]) & SR_INT) == 0) {
|
2016-12-31 17:56:26 -07:00
|
|
|
spin_unlock_irqrestore(&cuda_lock, flags);
|
2007-05-01 14:33:00 -06:00
|
|
|
return IRQ_NONE;
|
|
|
|
} else {
|
|
|
|
out_8(&via[IFR], SR_INT);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2016-12-31 17:56:26 -07:00
|
|
|
|
|
|
|
status = in_8(&via[B]) & (TIP | TACK | TREQ);
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
switch (cuda_state) {
|
|
|
|
case idle:
|
2016-12-31 17:56:26 -07:00
|
|
|
/* System controller has unsolicited data for us */
|
2005-04-16 16:20:36 -06:00
|
|
|
(void)in_8(&via[SR]);
|
2016-12-31 17:56:26 -07:00
|
|
|
idle_state:
|
2016-12-31 17:56:26 -07:00
|
|
|
assert_TIP();
|
2005-04-16 16:20:36 -06:00
|
|
|
cuda_state = reading;
|
|
|
|
reply_ptr = cuda_rbuf;
|
|
|
|
reading_reply = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case awaiting_reply:
|
2016-12-31 17:56:26 -07:00
|
|
|
/* System controller has reply data for us */
|
2005-04-16 16:20:36 -06:00
|
|
|
(void)in_8(&via[SR]);
|
2016-12-31 17:56:26 -07:00
|
|
|
assert_TIP();
|
2005-04-16 16:20:36 -06:00
|
|
|
cuda_state = reading;
|
|
|
|
reply_ptr = current_req->reply;
|
|
|
|
reading_reply = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sent_first_byte:
|
2016-12-31 17:56:26 -07:00
|
|
|
if (TREQ_asserted(status)) {
|
2005-04-16 16:20:36 -06:00
|
|
|
/* collision */
|
|
|
|
out_8(&via[ACR], in_8(&via[ACR]) & ~SR_OUT);
|
|
|
|
(void)in_8(&via[SR]);
|
2016-12-31 17:56:26 -07:00
|
|
|
negate_TIP_and_TACK();
|
2005-04-16 16:20:36 -06:00
|
|
|
cuda_state = idle;
|
2016-12-31 17:56:26 -07:00
|
|
|
/* Egret does not raise an "aborted" interrupt */
|
|
|
|
if (mcu_is_egret)
|
|
|
|
goto idle_state;
|
2005-04-16 16:20:36 -06:00
|
|
|
} else {
|
2016-12-31 17:56:26 -07:00
|
|
|
out_8(&via[SR], current_req->data[data_index++]);
|
2016-12-31 17:56:26 -07:00
|
|
|
toggle_TACK();
|
2016-12-31 17:56:26 -07:00
|
|
|
if (mcu_is_egret)
|
|
|
|
assert_TACK();
|
2005-04-16 16:20:36 -06:00
|
|
|
cuda_state = sending;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sending:
|
|
|
|
req = current_req;
|
|
|
|
if (data_index >= req->nbytes) {
|
|
|
|
out_8(&via[ACR], in_8(&via[ACR]) & ~SR_OUT);
|
|
|
|
(void)in_8(&via[SR]);
|
2016-12-31 17:56:26 -07:00
|
|
|
negate_TIP_and_TACK();
|
2005-04-16 16:20:36 -06:00
|
|
|
req->sent = 1;
|
|
|
|
if (req->reply_expected) {
|
|
|
|
cuda_state = awaiting_reply;
|
|
|
|
} else {
|
|
|
|
current_req = req->next;
|
|
|
|
complete = 1;
|
|
|
|
/* not sure about this */
|
|
|
|
cuda_state = idle;
|
|
|
|
cuda_start();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out_8(&via[SR], req->data[data_index++]);
|
2016-12-31 17:56:26 -07:00
|
|
|
toggle_TACK();
|
2016-12-31 17:56:26 -07:00
|
|
|
if (mcu_is_egret)
|
|
|
|
assert_TACK();
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case reading:
|
2016-12-31 17:56:26 -07:00
|
|
|
if (reading_reply ? ARRAY_FULL(current_req->reply, reply_ptr)
|
|
|
|
: ARRAY_FULL(cuda_rbuf, reply_ptr))
|
|
|
|
(void)in_8(&via[SR]);
|
|
|
|
else
|
|
|
|
*reply_ptr++ = in_8(&via[SR]);
|
2016-12-31 17:56:26 -07:00
|
|
|
if (!TREQ_asserted(status)) {
|
2016-12-31 17:56:26 -07:00
|
|
|
if (mcu_is_egret)
|
|
|
|
assert_TACK();
|
2005-04-16 16:20:36 -06:00
|
|
|
/* that's all folks */
|
2016-12-31 17:56:26 -07:00
|
|
|
negate_TIP_and_TACK();
|
2005-04-16 16:20:36 -06:00
|
|
|
cuda_state = read_done;
|
2016-12-31 17:56:26 -07:00
|
|
|
/* Egret does not raise a "read done" interrupt */
|
|
|
|
if (mcu_is_egret)
|
|
|
|
goto read_done_state;
|
2005-04-16 16:20:36 -06:00
|
|
|
} else {
|
2016-12-31 17:56:26 -07:00
|
|
|
toggle_TACK();
|
2016-12-31 17:56:26 -07:00
|
|
|
if (mcu_is_egret)
|
|
|
|
negate_TACK();
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case read_done:
|
|
|
|
(void)in_8(&via[SR]);
|
2016-12-31 17:56:26 -07:00
|
|
|
read_done_state:
|
2005-04-16 16:20:36 -06:00
|
|
|
if (reading_reply) {
|
|
|
|
req = current_req;
|
|
|
|
req->reply_len = reply_ptr - req->reply;
|
|
|
|
if (req->data[0] == ADB_PACKET) {
|
|
|
|
/* Have to adjust the reply from ADB commands */
|
|
|
|
if (req->reply_len <= 2 || (req->reply[1] & 2) != 0) {
|
|
|
|
/* the 0x2 bit indicates no response */
|
|
|
|
req->reply_len = 0;
|
|
|
|
} else {
|
|
|
|
/* leave just the command and result bytes in the reply */
|
|
|
|
req->reply_len -= 2;
|
|
|
|
memmove(req->reply, req->reply + 2, req->reply_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
current_req = req->next;
|
|
|
|
complete = 1;
|
2016-12-31 17:56:26 -07:00
|
|
|
reading_reply = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
} else {
|
|
|
|
/* This is tricky. We must break the spinlock to call
|
|
|
|
* cuda_input. However, doing so means we might get
|
|
|
|
* re-entered from another CPU getting an interrupt
|
|
|
|
* or calling cuda_poll(). I ended up using the stack
|
|
|
|
* (it's only for 16 bytes) and moving the actual
|
|
|
|
* call to cuda_input to outside of the lock.
|
|
|
|
*/
|
|
|
|
ibuf_len = reply_ptr - cuda_rbuf;
|
|
|
|
memcpy(ibuf, cuda_rbuf, ibuf_len);
|
|
|
|
}
|
2016-12-31 17:56:26 -07:00
|
|
|
reply_ptr = cuda_rbuf;
|
2016-12-31 17:56:26 -07:00
|
|
|
cuda_state = idle;
|
|
|
|
cuda_start();
|
|
|
|
if (cuda_state == idle && TREQ_asserted(in_8(&via[B]))) {
|
2016-12-31 17:56:26 -07:00
|
|
|
assert_TIP();
|
2005-04-16 16:20:36 -06:00
|
|
|
cuda_state = reading;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-12-31 17:56:26 -07:00
|
|
|
pr_err("cuda_interrupt: unknown cuda_state %d?\n", cuda_state);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2016-12-31 17:56:26 -07:00
|
|
|
spin_unlock_irqrestore(&cuda_lock, flags);
|
2005-04-16 16:20:36 -06:00
|
|
|
if (complete && req) {
|
|
|
|
void (*done)(struct adb_request *) = req->done;
|
|
|
|
mb();
|
|
|
|
req->complete = 1;
|
|
|
|
/* Here, we assume that if the request has a done member, the
|
|
|
|
* struct request will survive to setting req->complete to 1
|
|
|
|
*/
|
|
|
|
if (done)
|
|
|
|
(*done)(req);
|
|
|
|
}
|
|
|
|
if (ibuf_len)
|
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 07:55:46 -06:00
|
|
|
cuda_input(ibuf, ibuf_len);
|
2005-04-16 16:20:36 -06:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static 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 07:55:46 -06:00
|
|
|
cuda_input(unsigned char *buf, int nb)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
switch (buf[0]) {
|
|
|
|
case ADB_PACKET:
|
|
|
|
#ifdef CONFIG_XMON
|
|
|
|
if (nb == 5 && buf[2] == 0x2c) {
|
|
|
|
extern int xmon_wants_key, xmon_adb_keycode;
|
|
|
|
if (xmon_wants_key) {
|
|
|
|
xmon_adb_keycode = buf[3];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_XMON */
|
|
|
|
#ifdef CONFIG_ADB
|
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 07:55:46 -06:00
|
|
|
adb_input(buf+2, nb-2, buf[1] & 0x40);
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif /* CONFIG_ADB */
|
|
|
|
break;
|
|
|
|
|
2016-12-31 17:56:26 -07:00
|
|
|
case TIMER_PACKET:
|
|
|
|
/* Egret sends these periodically. Might be useful as a 'heartbeat'
|
|
|
|
* to trigger a recovery for the VIA shift register errata.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
default:
|
2016-12-31 17:56:26 -07:00
|
|
|
print_hex_dump(KERN_INFO, "cuda_input: ", DUMP_PREFIX_NONE, 32, 1,
|
|
|
|
buf, nb, false);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
2018-09-11 18:18:44 -06:00
|
|
|
|
|
|
|
/* Offset between Unix time (1970-based) and Mac time (1904-based) */
|
|
|
|
#define RTC_OFFSET 2082844800
|
|
|
|
|
|
|
|
time64_t cuda_get_time(void)
|
|
|
|
{
|
|
|
|
struct adb_request req;
|
|
|
|
u32 now;
|
|
|
|
|
|
|
|
if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME) < 0)
|
|
|
|
return 0;
|
|
|
|
while (!req.complete)
|
|
|
|
cuda_poll();
|
|
|
|
if (req.reply_len != 7)
|
|
|
|
pr_err("%s: got %d byte reply\n", __func__, req.reply_len);
|
|
|
|
now = (req.reply[3] << 24) + (req.reply[4] << 16) +
|
|
|
|
(req.reply[5] << 8) + req.reply[6];
|
|
|
|
return (time64_t)now - RTC_OFFSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cuda_set_rtc_time(struct rtc_time *tm)
|
|
|
|
{
|
|
|
|
u32 now;
|
|
|
|
struct adb_request req;
|
|
|
|
|
|
|
|
now = lower_32_bits(rtc_tm_to_time64(tm) + RTC_OFFSET);
|
|
|
|
if (cuda_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME,
|
|
|
|
now >> 24, now >> 16, now >> 8, now) < 0)
|
|
|
|
return -ENXIO;
|
|
|
|
while (!req.complete)
|
|
|
|
cuda_poll();
|
|
|
|
if ((req.reply_len != 3) && (req.reply_len != 7))
|
|
|
|
pr_err("%s: got %d byte reply\n", __func__, req.reply_len);
|
|
|
|
return 0;
|
|
|
|
}
|