Changes in 4.9.233 xfs: catch inode allocation state mismatch corruption xfs: validate cached inodes are free when allocated xfs: don't call xfs_da_shrink_inode with NULL bp net: phy: mdio-bcm-unimac: fix potential NULL dereference in unimac_mdio_probe() crypto: ccp - Release all allocated memory if sha type is invalid media: rc: prevent memory leak in cx23888_ir_probe ath9k_htc: release allocated buffer if timed out ath9k: release allocated buffer if timed out PCI/ASPM: Disable ASPM on ASMedia ASM1083/1085 PCIe-to-PCI bridge ARM: 8986/1: hw_breakpoint: Don't invoke overflow handler on uaccess watchpoints drm/amdgpu: Prevent kernel-infoleak in amdgpu_info_ioctl() drm: hold gem reference until object is no longer accessed f2fs: check memory boundary by insane namelen f2fs: check if file namelen exceeds max value 9p/trans_fd: abort p9_read_work if req status changed 9p/trans_fd: Fix concurrency del of req_list in p9_fd_cancelled/p9_read_work x86/build/lto: Fix truncated .bss with -fdata-sections x86, vmlinux.lds: Page-align end of ..page_aligned sections fbdev: Detect integer underflow at "struct fbcon_ops"->clear_margins. rds: Prevent kernel-infoleak in rds_notify_queue_get() xfs: fix missed wakeup on l_flush_wait uapi: includes linux/types.h before exporting files install several missing uapi headers net/x25: Fix x25_neigh refcnt leak when x25 disconnect net/x25: Fix null-ptr-deref in x25_disconnect sh: Fix validation of system call number net: lan78xx: add missing endpoint sanity check net: lan78xx: fix transfer-buffer memory leak mlx4: disable device on shutdown mlxsw: core: Increase scope of RCU read-side critical section mlxsw: core: Free EMAD transactions using kfree_rcu() ibmvnic: Fix IRQ mapping disposal in error path mac80211: mesh: Free ie data when leaving mesh mac80211: mesh: Free pending skb when destroying a mpath arm64: csum: Fix handling of bad packets usb: hso: Fix debug compile warning on sparc32 qed: Disable "MFW indication via attention" SPAM every 5 minutes nfc: s3fwrn5: add missing release on skb in s3fwrn5_recv_frame parisc: add support for cmpxchg on u8 pointers net: ethernet: ravb: exit if re-initialization fails in tx timeout Revert "i2c: cadence: Fix the hold bit setting" xen-netfront: fix potential deadlock in xennet_remove() KVM: LAPIC: Prevent setting the tscdeadline timer if the lapic is hw disabled x86/i8259: Use printk_deferred() to prevent deadlock random32: update the net random state on interrupt and activity ARM: percpu.h: fix build error random: fix circular include dependency on arm64 after addition of percpu.h random32: remove net_rand_state from the latent entropy gcc plugin random32: move the pseudo-random 32-bit definitions to prandom.h ext4: fix direct I/O read error USB: serial: qcserial: add EM7305 QDL product ID net/mlx5e: Don't support phys switch id if not in switchdev mode ALSA: seq: oss: Serialize ioctls Bluetooth: Fix slab-out-of-bounds read in hci_extended_inquiry_result_evt() Bluetooth: Prevent out-of-bounds read in hci_inquiry_result_evt() Bluetooth: Prevent out-of-bounds read in hci_inquiry_result_with_rssi_evt() omapfb: dss: Fix max fclk divider for omap36xx vgacon: Fix for missing check in scrollback handling mtd: properly check all write ioctls for permissions leds: wm831x-status: fix use-after-free on unbind leds: da903x: fix use-after-free on unbind leds: lm3533: fix use-after-free on unbind leds: 88pm860x: fix use-after-free on unbind net/9p: validate fds in p9_fd_open drm/nouveau/fbcon: fix module unload when fbcon init has failed for some reason cfg80211: check vendor command doit pointer before use igb: reinit_locked() should be called with rtnl_lock atm: fix atm_dev refcnt leaks in atmtcp_remove_persistent tools lib traceevent: Fix memory leak in process_dynamic_array_len xattr: break delegations in {set,remove}xattr binder: Prevent context manager from incrementing ref 0 ipv4: Silence suspicious RCU usage warning ipv6: fix memory leaks on IPV6_ADDRFORM path vxlan: Ensure FDB dump is performed under RCU net: lan78xx: replace bogus endpoint lookup Revert "vxlan: fix tos value before xmit" usb: hso: check for return value in hso_serial_common_create() Smack: fix use-after-free in smk_write_relabel_self() tracepoint: Mark __tracepoint_string's __used gpio: fix oops resulting from calling of_get_named_gpio(NULL, ...) cgroup: add missing skcd->no_refcnt check in cgroup_sk_clone() EDAC: Fix reference count leaks arm64: dts: qcom: msm8916: Replace invalid bias-pull-none property arm64: dts: exynos: Fix silent hang after boot on Espresso m68k: mac: Don't send IOP message until channel is idle m68k: mac: Fix IOP status/control register writes platform/x86: intel-hid: Fix return value check in check_acpi_dev() platform/x86: intel-vbtn: Fix return value check in check_acpi_dev() ARM: at91: pm: add missing put_device() call in at91_pm_sram_init() ARM: socfpga: PM: add missing put_device() call in socfpga_setup_ocram_self_refresh() drm/tilcdc: fix leak & null ref in panel_connector_get_modes Bluetooth: add a mutex lock to avoid UAF in do_enale_set fs/btrfs: Add cond_resched() for try_release_extent_mapping() stalls drm/radeon: Fix reference count leaks caused by pm_runtime_get_sync video: fbdev: neofb: fix memory leak in neo_scan_monitor() md-cluster: fix wild pointer of unlock_all_bitmaps() drm/nouveau: fix multiple instances of reference count leaks drm/debugfs: fix plain echo to connector "force" attribute mm/mmap.c: Add cond_resched() for exit_mmap() CPU stalls brcmfmac: To fix Bss Info flag definition Bug iwlegacy: Check the return value of pcie_capability_read_*() usb: gadget: net2280: fix memory leak on probe error handling paths bdc: Fix bug causing crash after multiple disconnects dyndbg: fix a BUG_ON in ddebug_describe_flags bcache: fix super block seq numbers comparision in register_cache_set() ACPICA: Do not increment operation_region reference counts for field units agp/intel: Fix a memory leak on module initialisation failure video: fbdev: sm712fb: fix an issue about iounmap for a wrong address console: newport_con: fix an issue about leak related system resources video: pxafb: Fix the function used to balance a 'dma_alloc_coherent()' call iio: improve IIO_CONCENTRATION channel type description leds: lm355x: avoid enum conversion warning media: omap3isp: Add missed v4l2_ctrl_handler_free() for preview_init_entities() scsi: cumana_2: Fix different dev_id between request_irq() and free_irq() drm/mipi: use dcs write for mipi_dsi_dcs_set_tear_scanline cxl: Fix kobject memleak drm/radeon: fix array out-of-bounds read and write issues scsi: powertec: Fix different dev_id between request_irq() and free_irq() scsi: eesox: Fix different dev_id between request_irq() and free_irq() media: firewire: Using uninitialized values in node_probe() media: exynos4-is: Add missed check for pinctrl_lookup_state() xfs: fix reflink quota reservation accounting error PCI: Fix pci_cfg_wait queue locking problem leds: core: Flush scheduled work for system suspend drm: panel: simple: Fix bpc for LG LB070WV8 panel scsi: scsi_debug: Add check for sdebug_max_queue during module init mwifiex: Prevent memory corruption handling keys powerpc/vdso: Fix vdso cpu truncation staging: rtl8192u: fix a dubious looking mask before a shift PCI/ASPM: Add missing newline in sysfs 'policy' drm/imx: tve: fix regulator_disable error path USB: serial: iuu_phoenix: fix led-activity helpers usb: dwc2: Fix error path in gadget registration scsi: mesh: Fix panic after host or bus reset Smack: fix another vsscanf out of bounds Smack: prevent underflow in smk_set_cipso() power: supply: check if calc_soc succeeded in pm860x_init_battery selftests/powerpc: Fix CPU affinity for child process selftests/powerpc: Fix online CPU selection s390/qeth: don't process empty bridge port events wl1251: fix always return 0 error net: spider_net: Fix the size used in a 'dma_free_coherent()' call fsl/fman: use 32-bit unsigned integer fsl/fman: fix dereference null return value fsl/fman: fix unreachable code fsl/fman: check dereferencing null pointer fsl/fman: fix eth hash table allocation dlm: Fix kobject memleak pinctrl-single: fix pcs_parse_pinconf() return value drivers/net/wan/lapbether: Added needed_headroom and a skb->len check net/nfc/rawsock.c: add CAP_NET_RAW check. net: Set fput_needed iff FDPUT_FPUT is set USB: serial: cp210x: re-enable auto-RTS on open USB: serial: cp210x: enable usb generic throttle/unthrottle ALSA: usb-audio: Creative USB X-Fi Pro SB1095 volume knob support ALSA: usb-audio: fix overeager device match for MacroSilicon MS2109 ALSA: usb-audio: add quirk for Pioneer DDJ-RB crypto: qat - fix double free in qat_uclo_create_batch_init_list crypto: ccp - Fix use of merged scatterlists fs/minix: check return value of sb_getblk() fs/minix: don't allow getting deleted inodes fs/minix: reject too-large maximum file size ALSA: usb-audio: work around streaming quirk for MacroSilicon MS2109 9p: Fix memory leak in v9fs_mount parisc: mask out enable and reserved bits from sba imask ARM: 8992/1: Fix unwind_frame for clang-built kernels xen/balloon: fix accounting in alloc_xenballooned_pages error path xen/balloon: make the balloon wait interruptible smb3: warn on confusing error scenario with sec=krb5 PCI: hotplug: ACPI: Fix context refcounting in acpiphp_grab_context() btrfs: don't allocate anonymous block device for user invisible roots btrfs: only search for left_info if there is no right_info in try_merge_free_space btrfs: fix memory leaks after failure to lookup checksums during inode logging iio: dac: ad5592r: fix unbalanced mutex unlocks in ad5592r_read_raw() xtensa: fix xtensa_pmu_setup prototype powerpc: Fix circular dependency between percpu.h and mmu.h net: ethernet: stmmac: Disable hardware multicast filter net: stmmac: dwmac1000: provide multicast filter fallback net/compat: Add missing sock updates for SCM_RIGHTS md/raid5: Fix Force reconstruct-write io stuck in degraded raid5 bcache: allocate meta data pages as compound pages mac80211: fix misplaced while instead of if MIPS: CPU#0 is not hotpluggable ext2: fix missing percpu_counter_inc ocfs2: change slot number type s16 to u16 ftrace: Setup correct FTRACE_FL_REGS flags for module kprobes: Fix NULL pointer dereference at kprobe_ftrace_handler watchdog: f71808e_wdt: indicate WDIOF_CARDRESET support in watchdog_info.options watchdog: f71808e_wdt: remove use of wrong watchdog_info option watchdog: f71808e_wdt: clear watchdog timeout occurred flag pseries: Fix 64 bit logical memory block panic mfd: arizona: Ensure 32k clock is put on driver unbind and error USB: serial: ftdi_sio: make process-packet buffer unsigned USB: serial: ftdi_sio: clean up receive processing gpu: ipu-v3: image-convert: Combine rotate/no-rotate irq handlers iommu/omap: Check for failure of a call to omap_iommu_dump_ctx iommu/vt-d: Enforce PASID devTLB field mask i2c: rcar: slave: only send STOP event when we have been addressed clk: clk-atlas6: fix return value check in atlas6_clk_init() pwm: bcm-iproc: handle clk_get_rate() return Input: sentelic - fix error return when fsp_reg_write fails drm/vmwgfx: Fix two list_for_each loop exit tests net: qcom/emac: add missed clk_disable_unprepare in error path of emac_clks_phase1_init nfs: Fix getxattr kernel panic and memory overflow fs/ufs: avoid potential u32 multiplication overflow mfd: dln2: Run event handler loop under spinlock ALSA: echoaudio: Fix potential Oops in snd_echo_resume() sh: landisk: Add missing initialization of sh_io_port_base khugepaged: retract_page_tables() remember to test exit mm: Avoid calling build_all_zonelists_init under hotplug context Linux 4.9.233 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: Ied62cb0768f5bd8e989d75e7c2ccf6f1e6f2efd4
615 lines
17 KiB
C
615 lines
17 KiB
C
/*
|
|
* I/O Processor (IOP) management
|
|
* Written and (C) 1999 by Joshua M. Thompson (funaho@jurai.org)
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice and this list of conditions.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice and this list of conditions in the documentation and/or other
|
|
* materials provided with the distribution.
|
|
*/
|
|
|
|
/*
|
|
* The IOP chips are used in the IIfx and some Quadras (900, 950) to manage
|
|
* serial and ADB. They are actually a 6502 processor and some glue logic.
|
|
*
|
|
* 990429 (jmt) - Initial implementation, just enough to knock the SCC IOP
|
|
* into compatible mode so nobody has to fiddle with the
|
|
* Serial Switch control panel anymore.
|
|
* 990603 (jmt) - Added code to grab the correct ISM IOP interrupt for OSS
|
|
* and non-OSS machines (at least I hope it's correct on a
|
|
* non-OSS machine -- someone with a Q900 or Q950 needs to
|
|
* check this.)
|
|
* 990605 (jmt) - Rearranged things a bit wrt IOP detection; iop_present is
|
|
* gone, IOP base addresses are now in an array and the
|
|
* globally-visible functions take an IOP number instead of an
|
|
* an actual base address.
|
|
* 990610 (jmt) - Finished the message passing framework and it seems to work.
|
|
* Sending _definitely_ works; my adb-bus.c mods can send
|
|
* messages and receive the MSG_COMPLETED status back from the
|
|
* IOP. The trick now is figuring out the message formats.
|
|
* 990611 (jmt) - More cleanups. Fixed problem where unclaimed messages on a
|
|
* receive channel were never properly acknowledged. Bracketed
|
|
* the remaining debug printk's with #ifdef's and disabled
|
|
* debugging. I can now type on the console.
|
|
* 990612 (jmt) - Copyright notice added. Reworked the way replies are handled.
|
|
* It turns out that replies are placed back in the send buffer
|
|
* for that channel; messages on the receive channels are always
|
|
* unsolicited messages from the IOP (and our replies to them
|
|
* should go back in the receive channel.) Also added tracking
|
|
* of device names to the listener functions ala the interrupt
|
|
* handlers.
|
|
* 990729 (jmt) - Added passing of pt_regs structure to IOP handlers. This is
|
|
* used by the new unified ADB driver.
|
|
*
|
|
* TODO:
|
|
*
|
|
* o Something should be periodically checking iop_alive() to make sure the
|
|
* IOP hasn't died.
|
|
* o Some of the IOP manager routines need better error checking and
|
|
* return codes. Nothing major, just prettying up.
|
|
*/
|
|
|
|
/*
|
|
* -----------------------
|
|
* IOP Message Passing 101
|
|
* -----------------------
|
|
*
|
|
* The host talks to the IOPs using a rather simple message-passing scheme via
|
|
* a shared memory area in the IOP RAM. Each IOP has seven "channels"; each
|
|
* channel is connected to a specific software driver on the IOP. For example
|
|
* on the SCC IOP there is one channel for each serial port. Each channel has
|
|
* an incoming and and outgoing message queue with a depth of one.
|
|
*
|
|
* A message is 32 bytes plus a state byte for the channel (MSG_IDLE, MSG_NEW,
|
|
* MSG_RCVD, MSG_COMPLETE). To send a message you copy the message into the
|
|
* buffer, set the state to MSG_NEW and signal the IOP by setting the IRQ flag
|
|
* in the IOP control to 1. The IOP will move the state to MSG_RCVD when it
|
|
* receives the message and then to MSG_COMPLETE when the message processing
|
|
* has completed. It is the host's responsibility at that point to read the
|
|
* reply back out of the send channel buffer and reset the channel state back
|
|
* to MSG_IDLE.
|
|
*
|
|
* To receive message from the IOP the same procedure is used except the roles
|
|
* are reversed. That is, the IOP puts message in the channel with a state of
|
|
* MSG_NEW, and the host receives the message and move its state to MSG_RCVD
|
|
* and then to MSG_COMPLETE when processing is completed and the reply (if any)
|
|
* has been placed back in the receive channel. The IOP will then reset the
|
|
* channel state to MSG_IDLE.
|
|
*
|
|
* Two sets of host interrupts are provided, INT0 and INT1. Both appear on one
|
|
* interrupt level; they are distinguished by a pair of bits in the IOP status
|
|
* register. The IOP will raise INT0 when one or more messages in the send
|
|
* channels have gone to the MSG_COMPLETE state and it will raise INT1 when one
|
|
* or more messages on the receive channels have gone to the MSG_NEW state.
|
|
*
|
|
* Since each channel handles only one message we have to implement a small
|
|
* interrupt-driven queue on our end. Messages to be sent are placed on the
|
|
* queue for sending and contain a pointer to an optional callback function.
|
|
* The handler for a message is called when the message state goes to
|
|
* MSG_COMPLETE.
|
|
*
|
|
* For receiving message we maintain a list of handler functions to call when
|
|
* a message is received on that IOP/channel combination. The handlers are
|
|
* called much like an interrupt handler and are passed a copy of the message
|
|
* from the IOP. The message state will be in MSG_RCVD while the handler runs;
|
|
* it is the handler's responsibility to call iop_complete_message() when
|
|
* finished; this function moves the message state to MSG_COMPLETE and signals
|
|
* the IOP. This two-step process is provided to allow the handler to defer
|
|
* message processing to a bottom-half handler if the processing will take
|
|
* a significant amount of time (handlers are called at interrupt time so they
|
|
* should execute quickly.)
|
|
*/
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/init.h>
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <asm/macintosh.h>
|
|
#include <asm/macints.h>
|
|
#include <asm/mac_iop.h>
|
|
|
|
/*#define DEBUG_IOP*/
|
|
|
|
/* Non-zero if the IOPs are present */
|
|
|
|
int iop_scc_present, iop_ism_present;
|
|
|
|
/* structure for tracking channel listeners */
|
|
|
|
struct listener {
|
|
const char *devname;
|
|
void (*handler)(struct iop_msg *);
|
|
};
|
|
|
|
/*
|
|
* IOP structures for the two IOPs
|
|
*
|
|
* The SCC IOP controls both serial ports (A and B) as its two functions.
|
|
* The ISM IOP controls the SWIM (floppy drive) and ADB.
|
|
*/
|
|
|
|
static volatile struct mac_iop *iop_base[NUM_IOPS];
|
|
|
|
/*
|
|
* IOP message queues
|
|
*/
|
|
|
|
static struct iop_msg iop_msg_pool[NUM_IOP_MSGS];
|
|
static struct iop_msg *iop_send_queue[NUM_IOPS][NUM_IOP_CHAN];
|
|
static struct listener iop_listeners[NUM_IOPS][NUM_IOP_CHAN];
|
|
|
|
irqreturn_t iop_ism_irq(int, void *);
|
|
|
|
/*
|
|
* Private access functions
|
|
*/
|
|
|
|
static __inline__ void iop_loadaddr(volatile struct mac_iop *iop, __u16 addr)
|
|
{
|
|
iop->ram_addr_lo = addr;
|
|
iop->ram_addr_hi = addr >> 8;
|
|
}
|
|
|
|
static __inline__ __u8 iop_readb(volatile struct mac_iop *iop, __u16 addr)
|
|
{
|
|
iop->ram_addr_lo = addr;
|
|
iop->ram_addr_hi = addr >> 8;
|
|
return iop->ram_data;
|
|
}
|
|
|
|
static __inline__ void iop_writeb(volatile struct mac_iop *iop, __u16 addr, __u8 data)
|
|
{
|
|
iop->ram_addr_lo = addr;
|
|
iop->ram_addr_hi = addr >> 8;
|
|
iop->ram_data = data;
|
|
}
|
|
|
|
static __inline__ void iop_stop(volatile struct mac_iop *iop)
|
|
{
|
|
iop->status_ctrl = IOP_AUTOINC;
|
|
}
|
|
|
|
static __inline__ void iop_start(volatile struct mac_iop *iop)
|
|
{
|
|
iop->status_ctrl = IOP_RUN | IOP_AUTOINC;
|
|
}
|
|
|
|
static __inline__ void iop_interrupt(volatile struct mac_iop *iop)
|
|
{
|
|
iop->status_ctrl = IOP_IRQ | IOP_RUN | IOP_AUTOINC;
|
|
}
|
|
|
|
static int iop_alive(volatile struct mac_iop *iop)
|
|
{
|
|
int retval;
|
|
|
|
retval = (iop_readb(iop, IOP_ADDR_ALIVE) == 0xFF);
|
|
iop_writeb(iop, IOP_ADDR_ALIVE, 0);
|
|
return retval;
|
|
}
|
|
|
|
static struct iop_msg *iop_alloc_msg(void)
|
|
{
|
|
int i;
|
|
unsigned long flags;
|
|
|
|
local_irq_save(flags);
|
|
|
|
for (i = 0 ; i < NUM_IOP_MSGS ; i++) {
|
|
if (iop_msg_pool[i].status == IOP_MSGSTATUS_UNUSED) {
|
|
iop_msg_pool[i].status = IOP_MSGSTATUS_WAITING;
|
|
local_irq_restore(flags);
|
|
return &iop_msg_pool[i];
|
|
}
|
|
}
|
|
|
|
local_irq_restore(flags);
|
|
return NULL;
|
|
}
|
|
|
|
static void iop_free_msg(struct iop_msg *msg)
|
|
{
|
|
msg->status = IOP_MSGSTATUS_UNUSED;
|
|
}
|
|
|
|
/*
|
|
* This is called by the startup code before anything else. Its purpose
|
|
* is to find and initialize the IOPs early in the boot sequence, so that
|
|
* the serial IOP can be placed into bypass mode _before_ we try to
|
|
* initialize the serial console.
|
|
*/
|
|
|
|
void __init iop_preinit(void)
|
|
{
|
|
if (macintosh_config->scc_type == MAC_SCC_IOP) {
|
|
if (macintosh_config->ident == MAC_MODEL_IIFX) {
|
|
iop_base[IOP_NUM_SCC] = (struct mac_iop *) SCC_IOP_BASE_IIFX;
|
|
} else {
|
|
iop_base[IOP_NUM_SCC] = (struct mac_iop *) SCC_IOP_BASE_QUADRA;
|
|
}
|
|
iop_scc_present = 1;
|
|
} else {
|
|
iop_base[IOP_NUM_SCC] = NULL;
|
|
iop_scc_present = 0;
|
|
}
|
|
if (macintosh_config->adb_type == MAC_ADB_IOP) {
|
|
if (macintosh_config->ident == MAC_MODEL_IIFX) {
|
|
iop_base[IOP_NUM_ISM] = (struct mac_iop *) ISM_IOP_BASE_IIFX;
|
|
} else {
|
|
iop_base[IOP_NUM_ISM] = (struct mac_iop *) ISM_IOP_BASE_QUADRA;
|
|
}
|
|
iop_stop(iop_base[IOP_NUM_ISM]);
|
|
iop_ism_present = 1;
|
|
} else {
|
|
iop_base[IOP_NUM_ISM] = NULL;
|
|
iop_ism_present = 0;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Initialize the IOPs, if present.
|
|
*/
|
|
|
|
void __init iop_init(void)
|
|
{
|
|
int i;
|
|
|
|
if (iop_scc_present) {
|
|
printk("IOP: detected SCC IOP at %p\n", iop_base[IOP_NUM_SCC]);
|
|
}
|
|
if (iop_ism_present) {
|
|
printk("IOP: detected ISM IOP at %p\n", iop_base[IOP_NUM_ISM]);
|
|
iop_start(iop_base[IOP_NUM_ISM]);
|
|
iop_alive(iop_base[IOP_NUM_ISM]); /* clears the alive flag */
|
|
}
|
|
|
|
/* Make the whole pool available and empty the queues */
|
|
|
|
for (i = 0 ; i < NUM_IOP_MSGS ; i++) {
|
|
iop_msg_pool[i].status = IOP_MSGSTATUS_UNUSED;
|
|
}
|
|
|
|
for (i = 0 ; i < NUM_IOP_CHAN ; i++) {
|
|
iop_send_queue[IOP_NUM_SCC][i] = NULL;
|
|
iop_send_queue[IOP_NUM_ISM][i] = NULL;
|
|
iop_listeners[IOP_NUM_SCC][i].devname = NULL;
|
|
iop_listeners[IOP_NUM_SCC][i].handler = NULL;
|
|
iop_listeners[IOP_NUM_ISM][i].devname = NULL;
|
|
iop_listeners[IOP_NUM_ISM][i].handler = NULL;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Register the interrupt handler for the IOPs.
|
|
* TODO: might be wrong for non-OSS machines. Anyone?
|
|
*/
|
|
|
|
void __init iop_register_interrupts(void)
|
|
{
|
|
if (iop_ism_present) {
|
|
if (macintosh_config->ident == MAC_MODEL_IIFX) {
|
|
if (request_irq(IRQ_MAC_ADB, iop_ism_irq, 0,
|
|
"ISM IOP", (void *)IOP_NUM_ISM))
|
|
pr_err("Couldn't register ISM IOP interrupt\n");
|
|
} else {
|
|
if (request_irq(IRQ_VIA2_0, iop_ism_irq, 0, "ISM IOP",
|
|
(void *)IOP_NUM_ISM))
|
|
pr_err("Couldn't register ISM IOP interrupt\n");
|
|
}
|
|
if (!iop_alive(iop_base[IOP_NUM_ISM])) {
|
|
printk("IOP: oh my god, they killed the ISM IOP!\n");
|
|
} else {
|
|
printk("IOP: the ISM IOP seems to be alive.\n");
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Register or unregister a listener for a specific IOP and channel
|
|
*
|
|
* If the handler pointer is NULL the current listener (if any) is
|
|
* unregistered. Otherwise the new listener is registered provided
|
|
* there is no existing listener registered.
|
|
*/
|
|
|
|
int iop_listen(uint iop_num, uint chan,
|
|
void (*handler)(struct iop_msg *),
|
|
const char *devname)
|
|
{
|
|
if ((iop_num >= NUM_IOPS) || !iop_base[iop_num]) return -EINVAL;
|
|
if (chan >= NUM_IOP_CHAN) return -EINVAL;
|
|
if (iop_listeners[iop_num][chan].handler && handler) return -EINVAL;
|
|
iop_listeners[iop_num][chan].devname = devname;
|
|
iop_listeners[iop_num][chan].handler = handler;
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Complete reception of a message, which just means copying the reply
|
|
* into the buffer, setting the channel state to MSG_COMPLETE and
|
|
* notifying the IOP.
|
|
*/
|
|
|
|
void iop_complete_message(struct iop_msg *msg)
|
|
{
|
|
int iop_num = msg->iop_num;
|
|
int chan = msg->channel;
|
|
int i,offset;
|
|
|
|
#ifdef DEBUG_IOP
|
|
printk("iop_complete(%p): iop %d chan %d\n", msg, msg->iop_num, msg->channel);
|
|
#endif
|
|
|
|
offset = IOP_ADDR_RECV_MSG + (msg->channel * IOP_MSG_LEN);
|
|
|
|
for (i = 0 ; i < IOP_MSG_LEN ; i++, offset++) {
|
|
iop_writeb(iop_base[iop_num], offset, msg->reply[i]);
|
|
}
|
|
|
|
iop_writeb(iop_base[iop_num],
|
|
IOP_ADDR_RECV_STATE + chan, IOP_MSG_COMPLETE);
|
|
iop_interrupt(iop_base[msg->iop_num]);
|
|
|
|
iop_free_msg(msg);
|
|
}
|
|
|
|
/*
|
|
* Actually put a message into a send channel buffer
|
|
*/
|
|
|
|
static void iop_do_send(struct iop_msg *msg)
|
|
{
|
|
volatile struct mac_iop *iop = iop_base[msg->iop_num];
|
|
int i,offset;
|
|
|
|
offset = IOP_ADDR_SEND_MSG + (msg->channel * IOP_MSG_LEN);
|
|
|
|
for (i = 0 ; i < IOP_MSG_LEN ; i++, offset++) {
|
|
iop_writeb(iop, offset, msg->message[i]);
|
|
}
|
|
|
|
iop_writeb(iop, IOP_ADDR_SEND_STATE + msg->channel, IOP_MSG_NEW);
|
|
|
|
iop_interrupt(iop);
|
|
}
|
|
|
|
/*
|
|
* Handle sending a message on a channel that
|
|
* has gone into the IOP_MSG_COMPLETE state.
|
|
*/
|
|
|
|
static void iop_handle_send(uint iop_num, uint chan)
|
|
{
|
|
volatile struct mac_iop *iop = iop_base[iop_num];
|
|
struct iop_msg *msg,*msg2;
|
|
int i,offset;
|
|
|
|
#ifdef DEBUG_IOP
|
|
printk("iop_handle_send: iop %d channel %d\n", iop_num, chan);
|
|
#endif
|
|
|
|
iop_writeb(iop, IOP_ADDR_SEND_STATE + chan, IOP_MSG_IDLE);
|
|
|
|
if (!(msg = iop_send_queue[iop_num][chan])) return;
|
|
|
|
msg->status = IOP_MSGSTATUS_COMPLETE;
|
|
offset = IOP_ADDR_SEND_MSG + (chan * IOP_MSG_LEN);
|
|
for (i = 0 ; i < IOP_MSG_LEN ; i++, offset++) {
|
|
msg->reply[i] = iop_readb(iop, offset);
|
|
}
|
|
if (msg->handler) (*msg->handler)(msg);
|
|
msg2 = msg;
|
|
msg = msg->next;
|
|
iop_free_msg(msg2);
|
|
|
|
iop_send_queue[iop_num][chan] = msg;
|
|
if (msg && iop_readb(iop, IOP_ADDR_SEND_STATE + chan) == IOP_MSG_IDLE)
|
|
iop_do_send(msg);
|
|
}
|
|
|
|
/*
|
|
* Handle reception of a message on a channel that has
|
|
* gone into the IOP_MSG_NEW state.
|
|
*/
|
|
|
|
static void iop_handle_recv(uint iop_num, uint chan)
|
|
{
|
|
volatile struct mac_iop *iop = iop_base[iop_num];
|
|
int i,offset;
|
|
struct iop_msg *msg;
|
|
|
|
#ifdef DEBUG_IOP
|
|
printk("iop_handle_recv: iop %d channel %d\n", iop_num, chan);
|
|
#endif
|
|
|
|
msg = iop_alloc_msg();
|
|
msg->iop_num = iop_num;
|
|
msg->channel = chan;
|
|
msg->status = IOP_MSGSTATUS_UNSOL;
|
|
msg->handler = iop_listeners[iop_num][chan].handler;
|
|
|
|
offset = IOP_ADDR_RECV_MSG + (chan * IOP_MSG_LEN);
|
|
|
|
for (i = 0 ; i < IOP_MSG_LEN ; i++, offset++) {
|
|
msg->message[i] = iop_readb(iop, offset);
|
|
}
|
|
|
|
iop_writeb(iop, IOP_ADDR_RECV_STATE + chan, IOP_MSG_RCVD);
|
|
|
|
/* If there is a listener, call it now. Otherwise complete */
|
|
/* the message ourselves to avoid possible stalls. */
|
|
|
|
if (msg->handler) {
|
|
(*msg->handler)(msg);
|
|
} else {
|
|
#ifdef DEBUG_IOP
|
|
printk("iop_handle_recv: unclaimed message on iop %d channel %d\n", iop_num, chan);
|
|
printk("iop_handle_recv:");
|
|
for (i = 0 ; i < IOP_MSG_LEN ; i++) {
|
|
printk(" %02X", (uint) msg->message[i]);
|
|
}
|
|
printk("\n");
|
|
#endif
|
|
iop_complete_message(msg);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Send a message
|
|
*
|
|
* The message is placed at the end of the send queue. Afterwards if the
|
|
* channel is idle we force an immediate send of the next message in the
|
|
* queue.
|
|
*/
|
|
|
|
int iop_send_message(uint iop_num, uint chan, void *privdata,
|
|
uint msg_len, __u8 *msg_data,
|
|
void (*handler)(struct iop_msg *))
|
|
{
|
|
struct iop_msg *msg, *q;
|
|
|
|
if ((iop_num >= NUM_IOPS) || !iop_base[iop_num]) return -EINVAL;
|
|
if (chan >= NUM_IOP_CHAN) return -EINVAL;
|
|
if (msg_len > IOP_MSG_LEN) return -EINVAL;
|
|
|
|
msg = iop_alloc_msg();
|
|
if (!msg) return -ENOMEM;
|
|
|
|
msg->next = NULL;
|
|
msg->status = IOP_MSGSTATUS_WAITING;
|
|
msg->iop_num = iop_num;
|
|
msg->channel = chan;
|
|
msg->caller_priv = privdata;
|
|
memcpy(msg->message, msg_data, msg_len);
|
|
msg->handler = handler;
|
|
|
|
if (!(q = iop_send_queue[iop_num][chan])) {
|
|
iop_send_queue[iop_num][chan] = msg;
|
|
iop_do_send(msg);
|
|
} else {
|
|
while (q->next) q = q->next;
|
|
q->next = msg;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Upload code to the shared RAM of an IOP.
|
|
*/
|
|
|
|
void iop_upload_code(uint iop_num, __u8 *code_start,
|
|
uint code_len, __u16 shared_ram_start)
|
|
{
|
|
if ((iop_num >= NUM_IOPS) || !iop_base[iop_num]) return;
|
|
|
|
iop_loadaddr(iop_base[iop_num], shared_ram_start);
|
|
|
|
while (code_len--) {
|
|
iop_base[iop_num]->ram_data = *code_start++;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Download code from the shared RAM of an IOP.
|
|
*/
|
|
|
|
void iop_download_code(uint iop_num, __u8 *code_start,
|
|
uint code_len, __u16 shared_ram_start)
|
|
{
|
|
if ((iop_num >= NUM_IOPS) || !iop_base[iop_num]) return;
|
|
|
|
iop_loadaddr(iop_base[iop_num], shared_ram_start);
|
|
|
|
while (code_len--) {
|
|
*code_start++ = iop_base[iop_num]->ram_data;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Compare the code in the shared RAM of an IOP with a copy in system memory
|
|
* and return 0 on match or the first nonmatching system memory address on
|
|
* failure.
|
|
*/
|
|
|
|
__u8 *iop_compare_code(uint iop_num, __u8 *code_start,
|
|
uint code_len, __u16 shared_ram_start)
|
|
{
|
|
if ((iop_num >= NUM_IOPS) || !iop_base[iop_num]) return code_start;
|
|
|
|
iop_loadaddr(iop_base[iop_num], shared_ram_start);
|
|
|
|
while (code_len--) {
|
|
if (*code_start != iop_base[iop_num]->ram_data) {
|
|
return code_start;
|
|
}
|
|
code_start++;
|
|
}
|
|
return (__u8 *) 0;
|
|
}
|
|
|
|
/*
|
|
* Handle an ISM IOP interrupt
|
|
*/
|
|
|
|
irqreturn_t iop_ism_irq(int irq, void *dev_id)
|
|
{
|
|
uint iop_num = (uint) dev_id;
|
|
volatile struct mac_iop *iop = iop_base[iop_num];
|
|
int i,state;
|
|
|
|
#ifdef DEBUG_IOP
|
|
printk("iop_ism_irq: status = %02X\n", (uint) iop->status_ctrl);
|
|
#endif
|
|
|
|
/* INT0 indicates a state change on an outgoing message channel */
|
|
|
|
if (iop->status_ctrl & IOP_INT0) {
|
|
iop->status_ctrl = IOP_INT0 | IOP_RUN | IOP_AUTOINC;
|
|
#ifdef DEBUG_IOP
|
|
printk("iop_ism_irq: new status = %02X, send states",
|
|
(uint) iop->status_ctrl);
|
|
#endif
|
|
for (i = 0 ; i < NUM_IOP_CHAN ; i++) {
|
|
state = iop_readb(iop, IOP_ADDR_SEND_STATE + i);
|
|
#ifdef DEBUG_IOP
|
|
printk(" %02X", state);
|
|
#endif
|
|
if (state == IOP_MSG_COMPLETE) {
|
|
iop_handle_send(iop_num, i);
|
|
}
|
|
}
|
|
#ifdef DEBUG_IOP
|
|
printk("\n");
|
|
#endif
|
|
}
|
|
|
|
if (iop->status_ctrl & IOP_INT1) { /* INT1 for incoming msgs */
|
|
iop->status_ctrl = IOP_INT1 | IOP_RUN | IOP_AUTOINC;
|
|
#ifdef DEBUG_IOP
|
|
printk("iop_ism_irq: new status = %02X, recv states",
|
|
(uint) iop->status_ctrl);
|
|
#endif
|
|
for (i = 0 ; i < NUM_IOP_CHAN ; i++) {
|
|
state = iop_readb(iop, IOP_ADDR_RECV_STATE + i);
|
|
#ifdef DEBUG_IOP
|
|
printk(" %02X", state);
|
|
#endif
|
|
if (state == IOP_MSG_NEW) {
|
|
iop_handle_recv(iop_num, i);
|
|
}
|
|
}
|
|
#ifdef DEBUG_IOP
|
|
printk("\n");
|
|
#endif
|
|
}
|
|
return IRQ_HANDLED;
|
|
}
|