summaryrefslogtreecommitdiffstats
path: root/drivers/macintosh/macio-adb.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2026-08-30 09:22:00 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2026-08-30 09:22:00 -0700
commit034dd340b08be1f2f0477ad16131d609f9dbd53c (patch)
tree2536f4b2d7893ccd916b5abdf3c454ad6edc03c2 /drivers/macintosh/macio-adb.c
downloadlinux-stable-034dd340b08be1f2f0477ad16131d609f9dbd53c.tar.gz
linux-stable-034dd340b08be1f2f0477ad16131d609f9dbd53c.zip
Merge tag 'trace-v7.3-2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-tracegrafted
Pull tracing fixes from Steven Rostedt: - Fix error output of boot instance creation failure Currently if a boot instance creation fails, instead of printing out the name of the instance that failed, it prints "(null)". That is because it prints "cur_str" that had already been processed by strsep(). Print the saved name instead. While at it, print the error code of the failure. - Fix use-after-free for same named historgrams Histograms can be named so that they can be used in multiple events. But if the named histogram has a variable attached, the second event that uses the named histogram which duplicates it and needs to free the original after duplication leaves the old variable in place and still visible. If another histogram uses than variable, it will use the stale one which will try to reference the freed duplicate histogram and crash the kernel. Free the duplicate variables along with the duplicated histogram data. - Check return value of kthread_run() in event self test The events self tests uses a kthread for testing but does not check if it succeeded in creating a kthread. If the kthread creation were to fail, the code will still try to call kthread_stop() on the error returned. - Fix race between reading trace_pipe and updating subbuffer size If a user is reading the trace_pipe file at the same time they update the ring buffer sub-buffer size, can cause the trace_pipe read to read stale data. Add trace_access_lock() around updating the ring buffer sub-buffer size. - Fix eventfs_inode on failure path in creation of the events directory In the creation of the "events" directory, if after allocating the eventfs_inode a failure is detected, it calls cleanup_ei() which calls free_ei(). The free_ei() will test if eventfs_inode being freed has no children. It is a bug if it does. But on the failure case of the creation of the "events" directory, the children lists have not yet been initialized and the free will trigger a warning because list_empty() on an uninitialized list returns false. Move the initialization into init_ei() where it makes more sense and makes sure that a created eventfs_inode has its lists initialized upon creation. - Check return value of kthread_run() in ftrace direct sample code The sample code that shows how to use the ftrace direct calls does not test the return of kthread_run() to see if it succeeds. Return a failure if the kthread_run() doesn't succeed. - Clear user events state on fork in case of alloc failure On fork, the child gets a pointer to the parent's user events state. It makes a copy of it then updates the child's pointer to it. But if the allocation fails, the duplication function leaves the child with a pointer to its parent's descriptor. When the child cleans up its data, it will free the parent's descriptor while the parent is still using it. In the duplication function, set the child's user_event_mm to NULL before testing if the allocation succeeded, and when it exits it will not free the parent's descriptor. - Fix retry exhaustion in simple ring buffer reader swap simple_ring_buffer_swap_reader_page() starts with retry set to 8 and post-decrements it only after a failed link replacement. On the final attempt, a successful replacement leaves retry at zero, while a failed replacement leaves it at -1. But the check for success expects the retry value to be non-zero and exits with an error on zero. This is the opposite result. Fix it. - Fail nicely when the remote swap_reader_page() returns an error Currently, if the swap_reader_page() of a remote buffer fails, it triggers a WARN_ON_ONCE() and continues normally. Instead, have it exit with an error and a pr_warn() print instead of a full WARNING. * tag 'trace-v7.3-2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: ring-buffer: Stop remote reader update when page swap fails tracing: Fix retry exhaustion in simple ring buffer reader swap tracing/user_events: Clear copied tracing state before fork duplication samples/ftrace: Fix kthread_stop() on ERR_PTR in ftrace-direct-multi-modify samples/ftrace: Fix kthread_stop() on ERR_PTR in ftrace-direct-modify eventfs: Initialize ei->children and ei->list in init_ei() tracing: Fix use-after-free in trace_pipe read on sub-buffer order change tracing: Fix crash passing ERR_PTR to kthread_stop() tracing: Fix use-after-free with same-name named triggers tracing: Fix logged instance name on creation failure
Diffstat (limited to 'drivers/macintosh/macio-adb.c')
-rw-r--r--drivers/macintosh/macio-adb.c288
1 files changed, 288 insertions, 0 deletions
diff --git a/drivers/macintosh/macio-adb.c b/drivers/macintosh/macio-adb.c
new file mode 100644
index 000000000..19c63959e
--- /dev/null
+++ b/drivers/macintosh/macio-adb.c
@@ -0,0 +1,288 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for the ADB controller in the Mac I/O (Hydra) chip.
+ */
+#include <linux/types.h>
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/delay.h>
+#include <linux/spinlock.h>
+#include <linux/interrupt.h>
+#include <linux/pgtable.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/adb.h>
+
+#include <asm/io.h>
+#include <asm/hydra.h>
+#include <asm/irq.h>
+#include <linux/init.h>
+#include <linux/ioport.h>
+
+struct preg {
+ unsigned char r;
+ char pad[15];
+};
+
+struct adb_regs {
+ struct preg intr;
+ struct preg data[9];
+ struct preg intr_enb;
+ struct preg dcount;
+ struct preg error;
+ struct preg ctrl;
+ struct preg autopoll;
+ struct preg active_hi;
+ struct preg active_lo;
+ struct preg test;
+};
+
+/* Bits in intr and intr_enb registers */
+#define DFB 1 /* data from bus */
+#define TAG 2 /* transfer access grant */
+
+/* Bits in dcount register */
+#define HMB 0x0f /* how many bytes */
+#define APD 0x10 /* auto-poll data */
+
+/* Bits in error register */
+#define NRE 1 /* no response error */
+#define DLE 2 /* data lost error */
+
+/* Bits in ctrl register */
+#define TAR 1 /* transfer access request */
+#define DTB 2 /* data to bus */
+#define CRE 4 /* command response expected */
+#define ADB_RST 8 /* ADB reset */
+
+/* Bits in autopoll register */
+#define APE 1 /* autopoll enable */
+
+static volatile struct adb_regs __iomem *adb;
+static struct adb_request *current_req, *last_req;
+static DEFINE_SPINLOCK(macio_lock);
+
+static int macio_probe(void);
+static int macio_init(void);
+static irqreturn_t macio_adb_interrupt(int irq, void *arg);
+static int macio_send_request(struct adb_request *req, int sync);
+static int macio_adb_autopoll(int devs);
+static void macio_adb_poll(void);
+static int macio_adb_reset_bus(void);
+
+struct adb_driver macio_adb_driver = {
+ .name = "MACIO",
+ .probe = macio_probe,
+ .init = macio_init,
+ .send_request = macio_send_request,
+ .autopoll = macio_adb_autopoll,
+ .poll = macio_adb_poll,
+ .reset_bus = macio_adb_reset_bus,
+};
+
+int macio_probe(void)
+{
+ struct device_node *np __free(device_node) =
+ of_find_compatible_node(NULL, "adb", "chrp,adb0");
+
+ if (np)
+ return 0;
+
+ return -ENODEV;
+}
+
+int macio_init(void)
+{
+ struct device_node *adbs __free(device_node) =
+ of_find_compatible_node(NULL, "adb", "chrp,adb0");
+ struct resource r;
+ unsigned int irq;
+
+ if (!adbs)
+ return -ENXIO;
+
+ if (of_address_to_resource(adbs, 0, &r))
+ return -ENXIO;
+
+ adb = ioremap(r.start, sizeof(struct adb_regs));
+ if (!adb)
+ return -ENOMEM;
+
+
+ out_8(&adb->ctrl.r, 0);
+ out_8(&adb->intr.r, 0);
+ out_8(&adb->error.r, 0);
+ out_8(&adb->active_hi.r, 0xff); /* for now, set all devices active */
+ out_8(&adb->active_lo.r, 0xff);
+ out_8(&adb->autopoll.r, APE);
+
+ irq = irq_of_parse_and_map(adbs, 0);
+ if (request_irq(irq, macio_adb_interrupt, 0, "ADB", (void *)0)) {
+ iounmap(adb);
+ printk(KERN_ERR "ADB: can't get irq %d\n", irq);
+ return -EAGAIN;
+ }
+ out_8(&adb->intr_enb.r, DFB | TAG);
+
+ printk("adb: mac-io driver 1.0 for unified ADB\n");
+
+ return 0;
+}
+
+static int macio_adb_autopoll(int devs)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&macio_lock, flags);
+ out_8(&adb->active_hi.r, devs >> 8);
+ out_8(&adb->active_lo.r, devs);
+ out_8(&adb->autopoll.r, devs? APE: 0);
+ spin_unlock_irqrestore(&macio_lock, flags);
+ return 0;
+}
+
+static int macio_adb_reset_bus(void)
+{
+ unsigned long flags;
+ int timeout = 1000000;
+
+ /* Hrm... we may want to not lock interrupts for so
+ * long ... oh well, who uses that chip anyway ? :)
+ * That function will be seldom used during boot
+ * on rare machines, so...
+ */
+ spin_lock_irqsave(&macio_lock, flags);
+ out_8(&adb->ctrl.r, in_8(&adb->ctrl.r) | ADB_RST);
+ while ((in_8(&adb->ctrl.r) & ADB_RST) != 0) {
+ if (--timeout == 0) {
+ out_8(&adb->ctrl.r, in_8(&adb->ctrl.r) & ~ADB_RST);
+ spin_unlock_irqrestore(&macio_lock, flags);
+ return -1;
+ }
+ }
+ spin_unlock_irqrestore(&macio_lock, flags);
+ return 0;
+}
+
+/* Send an ADB command */
+static int macio_send_request(struct adb_request *req, int sync)
+{
+ unsigned long flags;
+ int i;
+
+ if (req->data[0] != ADB_PACKET)
+ return -EINVAL;
+
+ for (i = 0; i < req->nbytes - 1; ++i)
+ req->data[i] = req->data[i+1];
+ --req->nbytes;
+
+ req->next = NULL;
+ req->sent = 0;
+ req->complete = 0;
+ req->reply_len = 0;
+
+ spin_lock_irqsave(&macio_lock, flags);
+ if (current_req) {
+ last_req->next = req;
+ last_req = req;
+ } else {
+ current_req = last_req = req;
+ out_8(&adb->ctrl.r, in_8(&adb->ctrl.r) | TAR);
+ }
+ spin_unlock_irqrestore(&macio_lock, flags);
+
+ if (sync) {
+ while (!req->complete)
+ macio_adb_poll();
+ }
+
+ return 0;
+}
+
+static irqreturn_t macio_adb_interrupt(int irq, void *arg)
+{
+ int i, n, err;
+ struct adb_request *req = NULL;
+ unsigned char ibuf[16];
+ int ibuf_len = 0;
+ int complete = 0;
+ int autopoll = 0;
+ int handled = 0;
+
+ spin_lock(&macio_lock);
+ if (in_8(&adb->intr.r) & TAG) {
+ handled = 1;
+ req = current_req;
+ if (req) {
+ /* put the current request in */
+ for (i = 0; i < req->nbytes; ++i)
+ out_8(&adb->data[i].r, req->data[i]);
+ out_8(&adb->dcount.r, req->nbytes & HMB);
+ req->sent = 1;
+ if (req->reply_expected) {
+ out_8(&adb->ctrl.r, DTB + CRE);
+ } else {
+ out_8(&adb->ctrl.r, DTB);
+ current_req = req->next;
+ complete = 1;
+ if (current_req)
+ out_8(&adb->ctrl.r, in_8(&adb->ctrl.r) | TAR);
+ }
+ }
+ out_8(&adb->intr.r, 0);
+ }
+
+ if (in_8(&adb->intr.r) & DFB) {
+ handled = 1;
+ err = in_8(&adb->error.r);
+ if (current_req && current_req->sent) {
+ /* this is the response to a command */
+ req = current_req;
+ if (err == 0) {
+ req->reply_len = in_8(&adb->dcount.r) & HMB;
+ for (i = 0; i < req->reply_len; ++i)
+ req->reply[i] = in_8(&adb->data[i].r);
+ }
+ current_req = req->next;
+ complete = 1;
+ if (current_req)
+ out_8(&adb->ctrl.r, in_8(&adb->ctrl.r) | TAR);
+ } else if (err == 0) {
+ /* autopoll data */
+ n = in_8(&adb->dcount.r) & HMB;
+ for (i = 0; i < n; ++i)
+ ibuf[i] = in_8(&adb->data[i].r);
+ ibuf_len = n;
+ autopoll = (in_8(&adb->dcount.r) & APD) != 0;
+ }
+ out_8(&adb->error.r, 0);
+ out_8(&adb->intr.r, 0);
+ }
+ spin_unlock(&macio_lock);
+ 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)
+ adb_input(ibuf, ibuf_len, autopoll);
+
+ return IRQ_RETVAL(handled);
+}
+
+static void macio_adb_poll(void)
+{
+ unsigned long flags;
+
+ local_irq_save(flags);
+ if (in_8(&adb->intr.r) != 0)
+ macio_adb_interrupt(0, NULL);
+ local_irq_restore(flags);
+}