diff options
author | 2023-02-21 18:24:12 -0800 | |
---|---|---|
committer | 2023-02-21 18:24:12 -0800 | |
commit | 5b7c4cabbb65f5c469464da6c5f614cbd7f730f2 (patch) | |
tree | cc5c2d0a898769fd59549594fedb3ee6f84e59a0 /drivers/nubus | |
download | linux-5b7c4cabbb65f5c469464da6c5f614cbd7f730f2.tar.gz linux-5b7c4cabbb65f5c469464da6c5f614cbd7f730f2.zip |
Merge tag 'net-next-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-nextgrafted
Pull networking updates from Jakub Kicinski:
"Core:
- Add dedicated kmem_cache for typical/small skb->head, avoid having
to access struct page at kfree time, and improve memory use.
- Introduce sysctl to set default RPS configuration for new netdevs.
- Define Netlink protocol specification format which can be used to
describe messages used by each family and auto-generate parsers.
Add tools for generating kernel data structures and uAPI headers.
- Expose all net/core sysctls inside netns.
- Remove 4s sleep in netpoll if carrier is instantly detected on
boot.
- Add configurable limit of MDB entries per port, and port-vlan.
- Continue populating drop reasons throughout the stack.
- Retire a handful of legacy Qdiscs and classifiers.
Protocols:
- Support IPv4 big TCP (TSO frames larger than 64kB).
- Add IP_LOCAL_PORT_RANGE socket option, to control local port range
on socket by socket basis.
- Track and report in procfs number of MPTCP sockets used.
- Support mixing IPv4 and IPv6 flows in the in-kernel MPTCP path
manager.
- IPv6: don't check net.ipv6.route.max_size and rely on garbage
collection to free memory (similarly to IPv4).
- Support Penultimate Segment Pop (PSP) flavor in SRv6 (RFC8986).
- ICMP: add per-rate limit counters.
- Add support for user scanning requests in ieee802154.
- Remove static WEP support.
- Support minimal Wi-Fi 7 Extremely High Throughput (EHT) rate
reporting.
- WiFi 7 EHT channel puncturing support (client & AP).
BPF:
- Add a rbtree data structure following the "next-gen data structure"
precedent set by recently added linked list, that is, by using
kfunc + kptr instead of adding a new BPF map type.
- Expose XDP hints via kfuncs with initial support for RX hash and
timestamp metadata.
- Add BPF_F_NO_TUNNEL_KEY extension to bpf_skb_set_tunnel_key to
better support decap on GRE tunnel devices not operating in collect
metadata.
- Improve x86 JIT's codegen for PROBE_MEM runtime error checks.
- Remove the need for trace_printk_lock for bpf_trace_printk and
bpf_trace_vprintk helpers.
- Extend libbpf's bpf_tracing.h support for tracing arguments of
kprobes/uprobes and syscall as a special case.
- Significantly reduce the search time for module symbols by
livepatch and BPF.
- Enable cpumasks to be used as kptrs, which is useful for tracing
programs tracking which tasks end up running on which CPUs in
different time intervals.
- Add support for BPF trampoline on s390x and riscv64.
- Add capability to export the XDP features supported by the NIC.
- Add __bpf_kfunc tag for marking kernel functions as kfuncs.
- Add cgroup.memory=nobpf kernel parameter option to disable BPF
memory accounting for container environments.
Netfilter:
- Remove the CLUSTERIP target. It has been marked as obsolete for
years, and we still have WARN splats wrt races of the out-of-band
/proc interface installed by this target.
- Add 'destroy' commands to nf_tables. They are identical to the
existing 'delete' commands, but do not return an error if the
referenced object (set, chain, rule...) did not exist.
Driver API:
- Improve cpumask_local_spread() locality to help NICs set the right
IRQ affinity on AMD platforms.
- Separate C22 and C45 MDIO bus transactions more clearly.
- Introduce new DCB table to control DSCP rewrite on egress.
- Support configuration of Physical Layer Collision Avoidance (PLCA)
Reconciliation Sublayer (RS) (802.3cg-2019). Modern version of
shared medium Ethernet.
- Support for MAC Merge layer (IEEE 802.3-2018 clause 99). Allowing
preemption of low priority frames by high priority frames.
- Add support for controlling MACSec offload using netlink SET.
- Rework devlink instance refcounts to allow registration and
de-registration under the instance lock. Split the code into
multiple files, drop some of the unnecessarily granular locks and
factor out common parts of netlink operation handling.
- Add TX frame aggregation parameters (for USB drivers).
- Add a new attr TCA_EXT_WARN_MSG to report TC (offload) warning
messages with notifications for debug.
- Allow offloading of UDP NEW connections via act_ct.
- Add support for per action HW stats in TC.
- Support hardware miss to TC action (continue processing in SW from
a specific point in the action chain).
- Warn if old Wireless Extension user space interface is used with
modern cfg80211/mac80211 drivers. Do not support Wireless
Extensions for Wi-Fi 7 devices at all. Everyone should switch to
using nl80211 interface instead.
- Improve the CAN bit timing configuration. Use extack to return
error messages directly to user space, update the SJW handling,
including the definition of a new default value that will benefit
CAN-FD controllers, by increasing their oscillator tolerance.
New hardware / drivers:
- Ethernet:
- nVidia BlueField-3 support (control traffic driver)
- Ethernet support for imx93 SoCs
- Motorcomm yt8531 gigabit Ethernet PHY
- onsemi NCN26000 10BASE-T1S PHY (with support for PLCA)
- Microchip LAN8841 PHY (incl. cable diagnostics and PTP)
- Amlogic gxl MDIO mux
- WiFi:
- RealTek RTL8188EU (rtl8xxxu)
- Qualcomm Wi-Fi 7 devices (ath12k)
- CAN:
- Renesas R-Car V4H
Drivers:
- Bluetooth:
- Set Per Platform Antenna Gain (PPAG) for Intel controllers.
- Ethernet NICs:
- Intel (1G, igc):
- support TSN / Qbv / packet scheduling features of i226 model
- Intel (100G, ice):
- use GNSS subsystem instead of TTY
- multi-buffer XDP support
- extend support for GPIO pins to E823 devices
- nVidia/Mellanox:
- update the shared buffer configuration on PFC commands
- implement PTP adjphase function for HW offset control
- TC support for Geneve and GRE with VF tunnel offload
- more efficient crypto key management method
- multi-port eswitch support
- Netronome/Corigine:
- add DCB IEEE support
- support IPsec offloading for NFP3800
- Freescale/NXP (enetc):
- support XDP_REDIRECT for XDP non-linear buffers
- improve reconfig, avoid link flap and waiting for idle
- support MAC Merge layer
- Other NICs:
- sfc/ef100: add basic devlink support for ef100
- ionic: rx_push mode operation (writing descriptors via MMIO)
- bnxt: use the auxiliary bus abstraction for RDMA
- r8169: disable ASPM and reset bus in case of tx timeout
- cpsw: support QSGMII mode for J721e CPSW9G
- cpts: support pulse-per-second output
- ngbe: add an mdio bus driver
- usbnet: optimize usbnet_bh() by avoiding unnecessary queuing
- r8152: handle devices with FW with NCM support
- amd-xgbe: support 10Mbps, 2.5GbE speeds and rx-adaptation
- virtio-net: support multi buffer XDP
- virtio/vsock: replace virtio_vsock_pkt with sk_buff
- tsnep: XDP support
- Ethernet high-speed switches:
- nVidia/Mellanox (mlxsw):
- add support for latency TLV (in FW control messages)
- Microchip (sparx5):
- separate explicit and implicit traffic forwarding rules, make
the implicit rules always active
- add support for egress DSCP rewrite
- IS0 VCAP support (Ingress Classification)
- IS2 VCAP filters (protos, L3 addrs, L4 ports, flags, ToS
etc.)
- ES2 VCAP support (Egress Access Control)
- support for Per-Stream Filtering and Policing (802.1Q,
8.6.5.1)
- Ethernet embedded switches:
- Marvell (mv88e6xxx):
- add MAB (port auth) offload support
- enable PTP receive for mv88e6390
- NXP (ocelot):
- support MAC Merge layer
- support for the the vsc7512 internal copper phys
- Microchip:
- lan9303: convert to PHYLINK
- lan966x: support TC flower filter statistics
- lan937x: PTP support for KSZ9563/KSZ8563 and LAN937x
- lan937x: support Credit Based Shaper configuration
- ksz9477: support Energy Efficient Ethernet
- other:
- qca8k: convert to regmap read/write API, use bulk operations
- rswitch: Improve TX timestamp accuracy
- Intel WiFi (iwlwifi):
- EHT (Wi-Fi 7) rate reporting
- STEP equalizer support: transfer some STEP (connection to radio
on platforms with integrated wifi) related parameters from the
BIOS to the firmware.
- Qualcomm 802.11ax WiFi (ath11k):
- IPQ5018 support
- Fine Timing Measurement (FTM) responder role support
- channel 177 support
- MediaTek WiFi (mt76):
- per-PHY LED support
- mt7996: EHT (Wi-Fi 7) support
- Wireless Ethernet Dispatch (WED) reset support
- switch to using page pool allocator
- RealTek WiFi (rtw89):
- support new version of Bluetooth co-existance
- Mobile:
- rmnet: support TX aggregation"
* tag 'net-next-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next: (1872 commits)
page_pool: add a comment explaining the fragment counter usage
net: ethtool: fix __ethtool_dev_mm_supported() implementation
ethtool: pse-pd: Fix double word in comments
xsk: add linux/vmalloc.h to xsk.c
sefltests: netdevsim: wait for devlink instance after netns removal
selftest: fib_tests: Always cleanup before exit
net/mlx5e: Align IPsec ASO result memory to be as required by hardware
net/mlx5e: TC, Set CT miss to the specific ct action instance
net/mlx5e: Rename CHAIN_TO_REG to MAPPED_OBJ_TO_REG
net/mlx5: Refactor tc miss handling to a single function
net/mlx5: Kconfig: Make tc offload depend on tc skb extension
net/sched: flower: Support hardware miss to tc action
net/sched: flower: Move filter handle initialization earlier
net/sched: cls_api: Support hardware miss to tc action
net/sched: Rename user cookie and act cookie
sfc: fix builds without CONFIG_RTC_LIB
sfc: clean up some inconsistent indentings
net/mlx4_en: Introduce flexible array to silence overflow warning
net: lan966x: Fix possible deadlock inside PTP
net/ulp: Remove redundant ->clone() test in inet_clone_ulp().
...
Diffstat (limited to 'drivers/nubus')
-rw-r--r-- | drivers/nubus/Makefile | 8 | ||||
-rw-r--r-- | drivers/nubus/bus.c | 113 | ||||
-rw-r--r-- | drivers/nubus/nubus.c | 885 | ||||
-rw-r--r-- | drivers/nubus/proc.c | 186 |
4 files changed, 1192 insertions, 0 deletions
diff --git a/drivers/nubus/Makefile b/drivers/nubus/Makefile new file mode 100644 index 000000000..0f03032d2 --- /dev/null +++ b/drivers/nubus/Makefile @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for the nubus specific drivers. +# + +obj-y := nubus.o bus.o + +obj-$(CONFIG_PROC_FS) += proc.o diff --git a/drivers/nubus/bus.c b/drivers/nubus/bus.c new file mode 100644 index 000000000..17fad6600 --- /dev/null +++ b/drivers/nubus/bus.c @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Bus implementation for the NuBus subsystem. +// +// Copyright (C) 2017 Finn Thain + +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/list.h> +#include <linux/nubus.h> +#include <linux/seq_file.h> +#include <linux/slab.h> + +#define to_nubus_board(d) container_of(d, struct nubus_board, dev) +#define to_nubus_driver(d) container_of(d, struct nubus_driver, driver) + +static int nubus_bus_match(struct device *dev, struct device_driver *driver) +{ + return 1; +} + +static int nubus_device_probe(struct device *dev) +{ + struct nubus_driver *ndrv = to_nubus_driver(dev->driver); + int err = -ENODEV; + + if (ndrv->probe) + err = ndrv->probe(to_nubus_board(dev)); + return err; +} + +static void nubus_device_remove(struct device *dev) +{ + struct nubus_driver *ndrv = to_nubus_driver(dev->driver); + + if (ndrv->remove) + ndrv->remove(to_nubus_board(dev)); +} + +struct bus_type nubus_bus_type = { + .name = "nubus", + .match = nubus_bus_match, + .probe = nubus_device_probe, + .remove = nubus_device_remove, +}; +EXPORT_SYMBOL(nubus_bus_type); + +int nubus_driver_register(struct nubus_driver *ndrv) +{ + ndrv->driver.bus = &nubus_bus_type; + return driver_register(&ndrv->driver); +} +EXPORT_SYMBOL(nubus_driver_register); + +void nubus_driver_unregister(struct nubus_driver *ndrv) +{ + driver_unregister(&ndrv->driver); +} +EXPORT_SYMBOL(nubus_driver_unregister); + +static struct device nubus_parent = { + .init_name = "nubus", +}; + +static int __init nubus_bus_register(void) +{ + return bus_register(&nubus_bus_type); +} +postcore_initcall(nubus_bus_register); + +int __init nubus_parent_device_register(void) +{ + return device_register(&nubus_parent); +} + +static void nubus_device_release(struct device *dev) +{ + struct nubus_board *board = to_nubus_board(dev); + struct nubus_rsrc *fres, *tmp; + + list_for_each_entry_safe(fres, tmp, &nubus_func_rsrcs, list) + if (fres->board == board) { + list_del(&fres->list); + kfree(fres); + } + kfree(board); +} + +int nubus_device_register(struct nubus_board *board) +{ + board->dev.parent = &nubus_parent; + board->dev.release = nubus_device_release; + board->dev.bus = &nubus_bus_type; + dev_set_name(&board->dev, "slot.%X", board->slot); + board->dev.dma_mask = &board->dev.coherent_dma_mask; + dma_set_mask(&board->dev, DMA_BIT_MASK(32)); + return device_register(&board->dev); +} + +static int nubus_print_device_name_fn(struct device *dev, void *data) +{ + struct nubus_board *board = to_nubus_board(dev); + struct seq_file *m = data; + + seq_printf(m, "Slot %X: %s\n", board->slot, board->name); + return 0; +} + +int nubus_proc_show(struct seq_file *m, void *data) +{ + return bus_for_each_dev(&nubus_bus_type, NULL, m, + nubus_print_device_name_fn); +} diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c new file mode 100644 index 000000000..f70ba58db --- /dev/null +++ b/drivers/nubus/nubus.c @@ -0,0 +1,885 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Macintosh Nubus Interface Code + * + * Originally by Alan Cox + * + * Mostly rewritten by David Huggins-Daines, C. Scott Ananian, + * and others. + */ + +#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/string.h> +#include <linux/nubus.h> +#include <linux/errno.h> +#include <linux/init.h> +#include <linux/module.h> +#include <linux/seq_file.h> +#include <linux/slab.h> +#include <asm/setup.h> +#include <asm/page.h> +#include <asm/hwtest.h> + +/* Constants */ + +/* This is, of course, the size in bytelanes, rather than the size in + actual bytes */ +#define FORMAT_BLOCK_SIZE 20 +#define ROM_DIR_OFFSET 0x24 + +#define NUBUS_TEST_PATTERN 0x5A932BC7 + +/* Globals */ + +LIST_HEAD(nubus_func_rsrcs); + +/* Meaning of "bytelanes": + + The card ROM may appear on any or all bytes of each long word in + NuBus memory. The low 4 bits of the "map" value found in the + format block (at the top of the slot address space, as well as at + the top of the MacOS ROM) tells us which bytelanes, i.e. which byte + offsets within each longword, are valid. Thus: + + A map of 0x0f, as found in the MacOS ROM, means that all bytelanes + are valid. + + A map of 0xf0 means that no bytelanes are valid (We pray that we + will never encounter this, but stranger things have happened) + + A map of 0xe1 means that only the MSB of each long word is actually + part of the card ROM. (We hope to never encounter NuBus on a + little-endian machine. Again, stranger things have happened) + + A map of 0x78 means that only the LSB of each long word is valid. + + Etcetera, etcetera. Hopefully this clears up some confusion over + what the following code actually does. */ + +static inline int not_useful(void *p, int map) +{ + unsigned long pv = (unsigned long)p; + + pv &= 3; + if (map & (1 << pv)) + return 0; + return 1; +} + +static unsigned long nubus_get_rom(unsigned char **ptr, int len, int map) +{ + /* This will hold the result */ + unsigned long v = 0; + unsigned char *p = *ptr; + + while (len) { + v <<= 8; + while (not_useful(p, map)) + p++; + v |= *p++; + len--; + } + *ptr = p; + return v; +} + +static void nubus_rewind(unsigned char **ptr, int len, int map) +{ + unsigned char *p = *ptr; + + while (len) { + do { + p--; + } while (not_useful(p, map)); + len--; + } + *ptr = p; +} + +static void nubus_advance(unsigned char **ptr, int len, int map) +{ + unsigned char *p = *ptr; + + while (len) { + while (not_useful(p, map)) + p++; + p++; + len--; + } + *ptr = p; +} + +static void nubus_move(unsigned char **ptr, int len, int map) +{ + unsigned long slot_space = (unsigned long)*ptr & 0xFF000000; + + if (len > 0) + nubus_advance(ptr, len, map); + else if (len < 0) + nubus_rewind(ptr, -len, map); + + if (((unsigned long)*ptr & 0xFF000000) != slot_space) + pr_err("%s: moved out of slot address space!\n", __func__); +} + +/* Now, functions to read the sResource tree */ + +/* Each sResource entry consists of a 1-byte ID and a 3-byte data + field. If that data field contains an offset, then obviously we + have to expand it from a 24-bit signed number to a 32-bit signed + number. */ + +static inline long nubus_expand32(long foo) +{ + if (foo & 0x00800000) /* 24bit negative */ + foo |= 0xFF000000; + return foo; +} + +static inline void *nubus_rom_addr(int slot) +{ + /* + * Returns the first byte after the card. We then walk + * backwards to get the lane register and the config + */ + return (void *)(0xF1000000 + (slot << 24)); +} + +unsigned char *nubus_dirptr(const struct nubus_dirent *nd) +{ + unsigned char *p = nd->base; + + /* Essentially, just step over the bytelanes using whatever + offset we might have found */ + nubus_move(&p, nubus_expand32(nd->data), nd->mask); + /* And return the value */ + return p; +} + +/* These two are for pulling resource data blocks (i.e. stuff that's + pointed to with offsets) out of the card ROM. */ + +void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent, + unsigned int len) +{ + unsigned char *t = dest; + unsigned char *p = nubus_dirptr(dirent); + + while (len) { + *t++ = nubus_get_rom(&p, 1, dirent->mask); + len--; + } +} +EXPORT_SYMBOL(nubus_get_rsrc_mem); + +unsigned int nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent, + unsigned int len) +{ + char *t = dest; + unsigned char *p = nubus_dirptr(dirent); + + while (len > 1) { + unsigned char c = nubus_get_rom(&p, 1, dirent->mask); + + if (!c) + break; + *t++ = c; + len--; + } + if (len > 0) + *t = '\0'; + return t - dest; +} +EXPORT_SYMBOL(nubus_get_rsrc_str); + +void nubus_seq_write_rsrc_mem(struct seq_file *m, + const struct nubus_dirent *dirent, + unsigned int len) +{ + unsigned long buf[32]; + unsigned int buf_size = sizeof(buf); + unsigned char *p = nubus_dirptr(dirent); + + /* If possible, write out full buffers */ + while (len >= buf_size) { + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(buf); i++) + buf[i] = nubus_get_rom(&p, sizeof(buf[0]), + dirent->mask); + seq_write(m, buf, buf_size); + len -= buf_size; + } + /* If not, write out individual bytes */ + while (len--) + seq_putc(m, nubus_get_rom(&p, 1, dirent->mask)); +} + +int nubus_get_root_dir(const struct nubus_board *board, + struct nubus_dir *dir) +{ + dir->ptr = dir->base = board->directory; + dir->done = 0; + dir->mask = board->lanes; + return 0; +} +EXPORT_SYMBOL(nubus_get_root_dir); + +/* This is a slyly renamed version of the above */ +int nubus_get_func_dir(const struct nubus_rsrc *fres, struct nubus_dir *dir) +{ + dir->ptr = dir->base = fres->directory; + dir->done = 0; + dir->mask = fres->board->lanes; + return 0; +} +EXPORT_SYMBOL(nubus_get_func_dir); + +int nubus_get_board_dir(const struct nubus_board *board, + struct nubus_dir *dir) +{ + struct nubus_dirent ent; + + dir->ptr = dir->base = board->directory; + dir->done = 0; + dir->mask = board->lanes; + + /* Now dereference it (the first directory is always the board + directory) */ + if (nubus_readdir(dir, &ent) == -1) + return -1; + if (nubus_get_subdir(&ent, dir) == -1) + return -1; + return 0; +} +EXPORT_SYMBOL(nubus_get_board_dir); + +int nubus_get_subdir(const struct nubus_dirent *ent, + struct nubus_dir *dir) +{ + dir->ptr = dir->base = nubus_dirptr(ent); + dir->done = 0; + dir->mask = ent->mask; + return 0; +} +EXPORT_SYMBOL(nubus_get_subdir); + +int nubus_readdir(struct nubus_dir *nd, struct nubus_dirent *ent) +{ + u32 resid; + + if (nd->done) + return -1; + + /* Do this first, otherwise nubus_rewind & co are off by 4 */ + ent->base = nd->ptr; + + /* This moves nd->ptr forward */ + resid = nubus_get_rom(&nd->ptr, 4, nd->mask); + + /* EOL marker, as per the Apple docs */ + if ((resid & 0xff000000) == 0xff000000) { + /* Mark it as done */ + nd->done = 1; + return -1; + } + + /* First byte is the resource ID */ + ent->type = resid >> 24; + /* Low 3 bytes might contain data (or might not) */ + ent->data = resid & 0xffffff; + ent->mask = nd->mask; + return 0; +} +EXPORT_SYMBOL(nubus_readdir); + +int nubus_rewinddir(struct nubus_dir *dir) +{ + dir->ptr = dir->base; + dir->done = 0; + return 0; +} +EXPORT_SYMBOL(nubus_rewinddir); + +/* Driver interface functions, more or less like in pci.c */ + +struct nubus_rsrc *nubus_first_rsrc_or_null(void) +{ + return list_first_entry_or_null(&nubus_func_rsrcs, struct nubus_rsrc, + list); +} +EXPORT_SYMBOL(nubus_first_rsrc_or_null); + +struct nubus_rsrc *nubus_next_rsrc_or_null(struct nubus_rsrc *from) +{ + if (list_is_last(&from->list, &nubus_func_rsrcs)) + return NULL; + return list_next_entry(from, list); +} +EXPORT_SYMBOL(nubus_next_rsrc_or_null); + +int +nubus_find_rsrc(struct nubus_dir *dir, unsigned char rsrc_type, + struct nubus_dirent *ent) +{ + while (nubus_readdir(dir, ent) != -1) { + if (ent->type == rsrc_type) + return 0; + } + return -1; +} +EXPORT_SYMBOL(nubus_find_rsrc); + +/* Initialization functions - decide which slots contain stuff worth + looking at, and print out lots and lots of information from the + resource blocks. */ + +static int __init nubus_get_block_rsrc_dir(struct nubus_board *board, + struct proc_dir_entry *procdir, + const struct nubus_dirent *parent) +{ + struct nubus_dir dir; + struct nubus_dirent ent; + + nubus_get_subdir(parent, &dir); + dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board); + + while (nubus_readdir(&dir, &ent) != -1) { + u32 size; + + nubus_get_rsrc_mem(&size, &ent, 4); + pr_debug(" block (0x%x), size %d\n", ent.type, size); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, size); + } + return 0; +} + +static int __init nubus_get_display_vidmode(struct nubus_board *board, + struct proc_dir_entry *procdir, + const struct nubus_dirent *parent) +{ + struct nubus_dir dir; + struct nubus_dirent ent; + + nubus_get_subdir(parent, &dir); + dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board); + + while (nubus_readdir(&dir, &ent) != -1) { + switch (ent.type) { + case 1: /* mVidParams */ + case 2: /* mTable */ + { + u32 size; + + nubus_get_rsrc_mem(&size, &ent, 4); + pr_debug(" block (0x%x), size %d\n", ent.type, + size); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, size); + break; + } + default: + pr_debug(" unknown resource 0x%02x, data 0x%06x\n", + ent.type, ent.data); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, 0); + } + } + return 0; +} + +static int __init nubus_get_display_resource(struct nubus_rsrc *fres, + struct proc_dir_entry *procdir, + const struct nubus_dirent *ent) +{ + switch (ent->type) { + case NUBUS_RESID_GAMMADIR: + pr_debug(" gamma directory offset: 0x%06x\n", ent->data); + nubus_get_block_rsrc_dir(fres->board, procdir, ent); + break; + case 0x0080 ... 0x0085: + pr_debug(" mode 0x%02x info offset: 0x%06x\n", + ent->type, ent->data); + nubus_get_display_vidmode(fres->board, procdir, ent); + break; + default: + pr_debug(" unknown resource 0x%02x, data 0x%06x\n", + ent->type, ent->data); + nubus_proc_add_rsrc_mem(procdir, ent, 0); + } + return 0; +} + +static int __init nubus_get_network_resource(struct nubus_rsrc *fres, + struct proc_dir_entry *procdir, + const struct nubus_dirent *ent) +{ + switch (ent->type) { + case NUBUS_RESID_MAC_ADDRESS: + { + char addr[6]; + + nubus_get_rsrc_mem(addr, ent, 6); + pr_debug(" MAC address: %pM\n", addr); + nubus_proc_add_rsrc_mem(procdir, ent, 6); + break; + } + default: + pr_debug(" unknown resource 0x%02x, data 0x%06x\n", + ent->type, ent->data); + nubus_proc_add_rsrc_mem(procdir, ent, 0); + } + return 0; +} + +static int __init nubus_get_cpu_resource(struct nubus_rsrc *fres, + struct proc_dir_entry *procdir, + const struct nubus_dirent *ent) +{ + switch (ent->type) { + case NUBUS_RESID_MEMINFO: + { + unsigned long meminfo[2]; + + nubus_get_rsrc_mem(&meminfo, ent, 8); + pr_debug(" memory: [ 0x%08lx 0x%08lx ]\n", + meminfo[0], meminfo[1]); + nubus_proc_add_rsrc_mem(procdir, ent, 8); + break; + } + case NUBUS_RESID_ROMINFO: + { + unsigned long rominfo[2]; + + nubus_get_rsrc_mem(&rominfo, ent, 8); + pr_debug(" ROM: [ 0x%08lx 0x%08lx ]\n", + rominfo[0], rominfo[1]); + nubus_proc_add_rsrc_mem(procdir, ent, 8); + break; + } + default: + pr_debug(" unknown resource 0x%02x, data 0x%06x\n", + ent->type, ent->data); + nubus_proc_add_rsrc_mem(procdir, ent, 0); + } + return 0; +} + +static int __init nubus_get_private_resource(struct nubus_rsrc *fres, + struct proc_dir_entry *procdir, + const struct nubus_dirent *ent) +{ + switch (fres->category) { + case NUBUS_CAT_DISPLAY: + nubus_get_display_resource(fres, procdir, ent); + break; + case NUBUS_CAT_NETWORK: + nubus_get_network_resource(fres, procdir, ent); + break; + case NUBUS_CAT_CPU: + nubus_get_cpu_resource(fres, procdir, ent); + break; + default: + pr_debug(" unknown resource 0x%02x, data 0x%06x\n", + ent->type, ent->data); + nubus_proc_add_rsrc_mem(procdir, ent, 0); + } + return 0; +} + +static struct nubus_rsrc * __init +nubus_get_functional_resource(struct nubus_board *board, int slot, + const struct nubus_dirent *parent) +{ + struct nubus_dir dir; + struct nubus_dirent ent; + struct nubus_rsrc *fres; + + pr_debug(" Functional resource 0x%02x:\n", parent->type); + nubus_get_subdir(parent, &dir); + dir.procdir = nubus_proc_add_rsrc_dir(board->procdir, parent, board); + + /* Actually we should probably panic if this fails */ + fres = kzalloc(sizeof(*fres), GFP_ATOMIC); + if (!fres) + return NULL; + fres->resid = parent->type; + fres->directory = dir.base; + fres->board = board; + + while (nubus_readdir(&dir, &ent) != -1) { + switch (ent.type) { + case NUBUS_RESID_TYPE: + { + unsigned short nbtdata[4]; + + nubus_get_rsrc_mem(nbtdata, &ent, 8); + fres->category = nbtdata[0]; + fres->type = nbtdata[1]; + fres->dr_sw = nbtdata[2]; + fres->dr_hw = nbtdata[3]; + pr_debug(" type: [cat 0x%x type 0x%x sw 0x%x hw 0x%x]\n", + nbtdata[0], nbtdata[1], nbtdata[2], nbtdata[3]); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, 8); + break; + } + case NUBUS_RESID_NAME: + { + char name[64]; + unsigned int len; + + len = nubus_get_rsrc_str(name, &ent, sizeof(name)); + pr_debug(" name: %s\n", name); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, len + 1); + break; + } + case NUBUS_RESID_DRVRDIR: + { + /* MacOS driver. If we were NetBSD we might + use this :-) */ + pr_debug(" driver directory offset: 0x%06x\n", + ent.data); + nubus_get_block_rsrc_dir(board, dir.procdir, &ent); + break; + } + case NUBUS_RESID_MINOR_BASEOS: + { + /* We will need this in order to support + multiple framebuffers. It might be handy + for Ethernet as well */ + u32 base_offset; + + nubus_get_rsrc_mem(&base_offset, &ent, 4); + pr_debug(" memory offset: 0x%08x\n", base_offset); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, 4); + break; + } + case NUBUS_RESID_MINOR_LENGTH: + { + /* Ditto */ + u32 length; + + nubus_get_rsrc_mem(&length, &ent, 4); + pr_debug(" memory length: 0x%08x\n", length); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, 4); + break; + } + case NUBUS_RESID_FLAGS: + pr_debug(" flags: 0x%06x\n", ent.data); + nubus_proc_add_rsrc(dir.procdir, &ent); + break; + case NUBUS_RESID_HWDEVID: + pr_debug(" hwdevid: 0x%06x\n", ent.data); + nubus_proc_add_rsrc(dir.procdir, &ent); + break; + default: + /* Local/Private resources have their own + function */ + nubus_get_private_resource(fres, dir.procdir, &ent); + } + } + + return fres; +} + +/* This is *really* cool. */ +static int __init nubus_get_icon(struct nubus_board *board, + struct proc_dir_entry *procdir, + const struct nubus_dirent *ent) +{ + /* Should be 32x32 if my memory serves me correctly */ + u32 icon[32]; + int i; + + nubus_get_rsrc_mem(&icon, ent, 128); + pr_debug(" icon:\n"); + for (i = 0; i < 8; i++) + pr_debug(" %08x %08x %08x %08x\n", + icon[i * 4 + 0], icon[i * 4 + 1], + icon[i * 4 + 2], icon[i * 4 + 3]); + nubus_proc_add_rsrc_mem(procdir, ent, 128); + + return 0; +} + +static int __init nubus_get_vendorinfo(struct nubus_board *board, + struct proc_dir_entry *procdir, + const struct nubus_dirent *parent) +{ + struct nubus_dir dir; + struct nubus_dirent ent; + static char *vendor_fields[6] = { "ID", "serial", "revision", + "part", "date", "unknown field" }; + + pr_debug(" vendor info:\n"); + nubus_get_subdir(parent, &dir); + dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board); + + while (nubus_readdir(&dir, &ent) != -1) { + char name[64]; + unsigned int len; + + /* These are all strings, we think */ + len = nubus_get_rsrc_str(name, &ent, sizeof(name)); + if (ent.type < 1 || ent.type > 5) + ent.type = 5; + pr_debug(" %s: %s\n", vendor_fields[ent.type - 1], name); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, len + 1); + } + return 0; +} + +static int __init nubus_get_board_resource(struct nubus_board *board, int slot, + const struct nubus_dirent *parent) +{ + struct nubus_dir dir; + struct nubus_dirent ent; + + pr_debug(" Board resource 0x%02x:\n", parent->type); + nubus_get_subdir(parent, &dir); + dir.procdir = nubus_proc_add_rsrc_dir(board->procdir, parent, board); + + while (nubus_readdir(&dir, &ent) != -1) { + switch (ent.type) { + case NUBUS_RESID_TYPE: + { + unsigned short nbtdata[4]; + /* This type is always the same, and is not + useful except insofar as it tells us that + we really are looking at a board resource. */ + nubus_get_rsrc_mem(nbtdata, &ent, 8); + pr_debug(" type: [cat 0x%x type 0x%x sw 0x%x hw 0x%x]\n", + nbtdata[0], nbtdata[1], nbtdata[2], nbtdata[3]); + if (nbtdata[0] != 1 || nbtdata[1] != 0 || + nbtdata[2] != 0 || nbtdata[3] != 0) + pr_err("Slot %X: sResource is not a board resource!\n", + slot); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, 8); + break; + } + case NUBUS_RESID_NAME: + { + unsigned int len; + + len = nubus_get_rsrc_str(board->name, &ent, + sizeof(board->name)); + pr_debug(" name: %s\n", board->name); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, len + 1); + break; + } + case NUBUS_RESID_ICON: + nubus_get_icon(board, dir.procdir, &ent); + break; + case NUBUS_RESID_BOARDID: + pr_debug(" board id: 0x%x\n", ent.data); + nubus_proc_add_rsrc(dir.procdir, &ent); + break; + case NUBUS_RESID_PRIMARYINIT: + pr_debug(" primary init offset: 0x%06x\n", ent.data); + nubus_proc_add_rsrc(dir.procdir, &ent); + break; + case NUBUS_RESID_VENDORINFO: + nubus_get_vendorinfo(board, dir.procdir, &ent); + break; + case NUBUS_RESID_FLAGS: + pr_debug(" flags: 0x%06x\n", ent.data); + nubus_proc_add_rsrc(dir.procdir, &ent); + break; + case NUBUS_RESID_HWDEVID: + pr_debug(" hwdevid: 0x%06x\n", ent.data); + nubus_proc_add_rsrc(dir.procdir, &ent); + break; + case NUBUS_RESID_SECONDINIT: + pr_debug(" secondary init offset: 0x%06x\n", + ent.data); + nubus_proc_add_rsrc(dir.procdir, &ent); + break; + /* WTF isn't this in the functional resources? */ + case NUBUS_RESID_VIDNAMES: + pr_debug(" vidnames directory offset: 0x%06x\n", + ent.data); + nubus_get_block_rsrc_dir(board, dir.procdir, &ent); + break; + /* Same goes for this */ + case NUBUS_RESID_VIDMODES: + pr_debug(" video mode parameter directory offset: 0x%06x\n", + ent.data); + nubus_proc_add_rsrc(dir.procdir, &ent); + break; + default: + pr_debug(" unknown resource 0x%02x, data 0x%06x\n", + ent.type, ent.data); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, 0); + } + } + return 0; +} + +static void __init nubus_add_board(int slot, int bytelanes) +{ + struct nubus_board *board; + unsigned char *rp; + unsigned long dpat; + struct nubus_dir dir; + struct nubus_dirent ent; + int prev_resid = -1; + + /* Move to the start of the format block */ + rp = nubus_rom_addr(slot); + nubus_rewind(&rp, FORMAT_BLOCK_SIZE, bytelanes); + + /* Actually we should probably panic if this fails */ + if ((board = kzalloc(sizeof(*board), GFP_ATOMIC)) == NULL) + return; + board->fblock = rp; + + /* Dump the format block for debugging purposes */ + pr_debug("Slot %X, format block at 0x%p:\n", slot, rp); + pr_debug("%08lx\n", nubus_get_rom(&rp, 4, bytelanes)); + pr_debug("%08lx\n", nubus_get_rom(&rp, 4, bytelanes)); + pr_debug("%08lx\n", nubus_get_rom(&rp, 4, bytelanes)); + pr_debug("%02lx\n", nubus_get_rom(&rp, 1, bytelanes)); + pr_debug("%02lx\n", nubus_get_rom(&rp, 1, bytelanes)); + pr_debug("%08lx\n", nubus_get_rom(&rp, 4, bytelanes)); + pr_debug("%02lx\n", nubus_get_rom(&rp, 1, bytelanes)); + pr_debug("%02lx\n", nubus_get_rom(&rp, 1, bytelanes)); + rp = board->fblock; + + board->slot = slot; + board->slot_addr = (unsigned long)nubus_slot_addr(slot); + board->doffset = nubus_get_rom(&rp, 4, bytelanes); + /* rom_length is *supposed* to be the total length of the + * ROM. In practice it is the "amount of ROM used to compute + * the CRC." So some jokers decide to set it to zero and + * set the crc to zero so they don't have to do any math. + * See the Performa 460 ROM, for example. Those Apple "engineers". + */ + board->rom_length = nubus_get_rom(&rp, 4, bytelanes); + board->crc = nubus_get_rom(&rp, 4, bytelanes); + board->rev = nubus_get_rom(&rp, 1, bytelanes); + board->format = nubus_get_rom(&rp, 1, bytelanes); + board->lanes = bytelanes; + + /* Directory offset should be small and negative... */ + if (!(board->doffset & 0x00FF0000)) + pr_warn("Slot %X: Dodgy doffset!\n", slot); + dpat = nubus_get_rom(&rp, 4, bytelanes); + if (dpat != NUBUS_TEST_PATTERN) + pr_warn("Slot %X: Wrong test pattern %08lx!\n", slot, dpat); + + /* + * I wonder how the CRC is meant to work - + * any takers ? + * CSA: According to MAC docs, not all cards pass the CRC anyway, + * since the initial Macintosh ROM releases skipped the check. + */ + + /* Set up the directory pointer */ + board->directory = board->fblock; + nubus_move(&board->directory, nubus_expand32(board->doffset), + board->lanes); + + nubus_get_root_dir(board, &dir); + + /* We're ready to rock */ + pr_debug("Slot %X resources:\n", slot); + + /* Each slot should have one board resource and any number of + * functional resources. So we'll fill in some fields in the + * struct nubus_board from the board resource, then walk down + * the list of functional resources, spinning out a nubus_rsrc + * for each of them. + */ + if (nubus_readdir(&dir, &ent) == -1) { + /* We can't have this! */ + pr_err("Slot %X: Board resource not found!\n", slot); + kfree(board); + return; + } + + if (ent.type < 1 || ent.type > 127) + pr_warn("Slot %X: Board resource ID is invalid!\n", slot); + + board->procdir = nubus_proc_add_board(board); + + nubus_get_board_resource(board, slot, &ent); + + while (nubus_readdir(&dir, &ent) != -1) { + struct nubus_rsrc *fres; + + fres = nubus_get_functional_resource(board, slot, &ent); + if (fres == NULL) + continue; + + /* Resources should appear in ascending ID order. This sanity + * check prevents duplicate resource IDs. + */ + if (fres->resid <= prev_resid) { + kfree(fres); + continue; + } + prev_resid = fres->resid; + + list_add_tail(&fres->list, &nubus_func_rsrcs); + } + + if (nubus_device_register(board)) + put_device(&board->dev); +} + +static void __init nubus_probe_slot(int slot) +{ + unsigned char dp; + unsigned char *rp; + int i; + + rp = nubus_rom_addr(slot); + for (i = 4; i; i--) { + rp--; + if (!hwreg_present(rp)) + continue; + + dp = *rp; + + /* The last byte of the format block consists of two + nybbles which are "mirror images" of each other. + These show us the valid bytelanes */ + if ((((dp >> 4) ^ dp) & 0x0F) != 0x0F) + continue; + /* Check that this value is actually *on* one of the + bytelanes it claims are valid! */ + if (not_useful(rp, dp)) + continue; + + /* Looks promising. Let's put it on the list. */ + nubus_add_board(slot, dp); + + return; + } +} + +static void __init nubus_scan_bus(void) +{ + int slot; + + pr_info("NuBus: Scanning NuBus slots.\n"); + for (slot = 9; slot < 15; slot++) { + nubus_probe_slot(slot); + } +} + +static int __init nubus_init(void) +{ + int err; + + if (!MACH_IS_MAC) + return 0; + + nubus_proc_init(); + err = nubus_parent_device_register(); + if (err) + return err; + nubus_scan_bus(); + return 0; +} + +subsys_initcall(nubus_init); diff --git a/drivers/nubus/proc.c b/drivers/nubus/proc.c new file mode 100644 index 000000000..1fd667852 --- /dev/null +++ b/drivers/nubus/proc.c @@ -0,0 +1,186 @@ +// SPDX-License-Identifier: GPL-2.0 +/* drivers/nubus/proc.c: Proc FS interface for NuBus. + + By David Huggins-Daines <dhd@debian.org> + + Much code and many ideas from drivers/pci/proc.c: + Copyright (c) 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz> + + This is initially based on the Zorro and PCI interfaces. However, + it works somewhat differently. The intent is to provide a + structure in /proc analogous to the structure of the NuBus ROM + resources. + + Therefore each board function gets a directory, which may in turn + contain subdirectories. Each slot resource is a file. Unrecognized + resources are empty files, since every resource ID requires a special + case (e.g. if the resource ID implies a directory or block, then its + value has to be interpreted as a slot ROM pointer etc.). + */ + +#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/nubus.h> +#include <linux/proc_fs.h> +#include <linux/seq_file.h> +#include <linux/slab.h> +#include <linux/init.h> +#include <linux/module.h> +#include <linux/uaccess.h> +#include <asm/byteorder.h> + +/* + * /proc/bus/nubus/devices stuff + */ + +static int +nubus_devices_proc_show(struct seq_file *m, void *v) +{ + struct nubus_rsrc *fres; + + for_each_func_rsrc(fres) + seq_printf(m, "%x\t%04x %04x %04x %04x\t%08lx\n", + fres->board->slot, fres->category, fres->type, + fres->dr_sw, fres->dr_hw, fres->board->slot_addr); + return 0; +} + +static struct proc_dir_entry *proc_bus_nubus_dir; + +/* + * /proc/bus/nubus/x/ stuff + */ + +struct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board) +{ + char name[2]; + + if (!proc_bus_nubus_dir) + return NULL; + snprintf(name, sizeof(name), "%x", board->slot); + return proc_mkdir(name, proc_bus_nubus_dir); +} + +/* The PDE private data for any directory under /proc/bus/nubus/x/ + * is the bytelanes value for the board in slot x. + */ + +struct proc_dir_entry *nubus_proc_add_rsrc_dir(struct proc_dir_entry *procdir, + const struct nubus_dirent *ent, + struct nubus_board *board) +{ + char name[9]; + int lanes = board->lanes; + + if (!procdir) + return NULL; + snprintf(name, sizeof(name), "%x", ent->type); + return proc_mkdir_data(name, 0555, procdir, (void *)lanes); +} + +/* The PDE private data for a file under /proc/bus/nubus/x/ is a pointer to + * an instance of the following structure, which gives the location and size + * of the resource data in the slot ROM. For slot resources which hold only a + * small integer, this integer value is stored directly and size is set to 0. + * A NULL private data pointer indicates an unrecognized resource. + */ + +struct nubus_proc_pde_data { + unsigned char *res_ptr; + unsigned int res_size; +}; + +static struct nubus_proc_pde_data * +nubus_proc_alloc_pde_data(unsigned char *ptr, unsigned int size) +{ + struct nubus_proc_pde_data *pded; + + pded = kmalloc(sizeof(*pded), GFP_KERNEL); + if (!pded) + return NULL; + + pded->res_ptr = ptr; + pded->res_size = size; + return pded; +} + +static int nubus_proc_rsrc_show(struct seq_file *m, void *v) +{ + struct inode *inode = m->private; + struct nubus_proc_pde_data *pded; + + pded = pde_data(inode); + if (!pded) + return 0; + + if (pded->res_size > m->size) + return -EFBIG; + + if (pded->res_size) { + int lanes = (int)proc_get_parent_data(inode); + struct nubus_dirent ent; + + if (!lanes) + return 0; + + ent.mask = lanes; + ent.base = pded->res_ptr; + ent.data = 0; + nubus_seq_write_rsrc_mem(m, &ent, pded->res_size); + } else { + unsigned int data = (unsigned int)pded->res_ptr; + + seq_putc(m, data >> 16); + seq_putc(m, data >> 8); + seq_putc(m, data >> 0); + } + return 0; +} + +void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir, + const struct nubus_dirent *ent, + unsigned int size) +{ + char name[9]; + struct nubus_proc_pde_data *pded; + + if (!procdir) + return; + + snprintf(name, sizeof(name), "%x", ent->type); + if (size) + pded = nubus_proc_alloc_pde_data(nubus_dirptr(ent), size); + else + pded = NULL; + proc_create_single_data(name, S_IFREG | 0444, procdir, + nubus_proc_rsrc_show, pded); +} + +void nubus_proc_add_rsrc(struct proc_dir_entry *procdir, + const struct nubus_dirent *ent) +{ + char name[9]; + unsigned char *data = (unsigned char *)ent->data; + + if (!procdir) + return; + + snprintf(name, sizeof(name), "%x", ent->type); + proc_create_single_data(name, S_IFREG | 0444, procdir, + nubus_proc_rsrc_show, + nubus_proc_alloc_pde_data(data, 0)); +} + +/* + * /proc/nubus stuff + */ + +void __init nubus_proc_init(void) +{ + proc_create_single("nubus", 0, NULL, nubus_proc_show); + proc_bus_nubus_dir = proc_mkdir("bus/nubus", NULL); + if (!proc_bus_nubus_dir) + return; + proc_create_single("devices", 0, proc_bus_nubus_dir, + nubus_devices_proc_show); +} |