1132451Sroberto/* SPDX-License-Identifier: GPL-2.0 */ 2132451Sroberto/* 3182007Sroberto nubus.h: various definitions and prototypes for NuBus drivers to use. 4182007Sroberto 5182007Sroberto Originally written by Alan Cox. 6132451Sroberto 7132451Sroberto Hacked to death by C. Scott Ananian and David Huggins-Daines. 8132451Sroberto*/ 9132451Sroberto 10132451Sroberto#ifndef LINUX_NUBUS_H 11132451Sroberto#define LINUX_NUBUS_H 12132451Sroberto 13132451Sroberto#include <linux/device.h> 14132451Sroberto#include <asm/nubus.h> 15132451Sroberto#include <uapi/linux/nubus.h> 16132451Sroberto 17132451Srobertostruct proc_dir_entry; 18132451Srobertostruct seq_file; 19132451Sroberto 20132451Srobertostruct nubus_dir { 21132451Sroberto unsigned char *base; 22132451Sroberto unsigned char *ptr; 23132451Sroberto int done; 24132451Sroberto int mask; 25132451Sroberto struct proc_dir_entry *procdir; 26132451Sroberto}; 27132451Sroberto 28132451Srobertostruct nubus_dirent { 29132451Sroberto unsigned char *base; 30132451Sroberto unsigned char type; 31132451Sroberto __u32 data; /* Actually 24 bits used */ 32132451Sroberto int mask; 33132451Sroberto}; 34132451Sroberto 35132451Srobertostruct nubus_board { 36132451Sroberto struct device dev; 37132451Sroberto 38132451Sroberto /* Only 9-E actually exist, though 0-8 are also theoretically 39132451Sroberto possible, and 0 is a special case which represents the 40132451Sroberto motherboard and onboard peripherals (Ethernet, video) */ 41132451Sroberto int slot; 42132451Sroberto /* For slot 0, this is bogus. */ 43132451Sroberto char name[64]; 44132451Sroberto 45132451Sroberto /* Format block */ 46132451Sroberto unsigned char *fblock; 47132451Sroberto /* Root directory (does *not* always equal fblock + doffset!) */ 48132451Sroberto unsigned char *directory; 49132451Sroberto 50132451Sroberto unsigned long slot_addr; 51132451Sroberto /* Offset to root directory (sometimes) */ 52132451Sroberto unsigned long doffset; 53132451Sroberto /* Length over which to compute the crc */ 54132451Sroberto unsigned long rom_length; 55132451Sroberto /* Completely useless most of the time */ 56132451Sroberto unsigned long crc; 57132451Sroberto unsigned char rev; 58132451Sroberto unsigned char format; 59132451Sroberto unsigned char lanes; 60132451Sroberto 61132451Sroberto /* Directory entry in /proc/bus/nubus */ 62182007Sroberto struct proc_dir_entry *procdir; 63182007Sroberto}; 64182007Sroberto 65132451Srobertostruct nubus_rsrc { 66132451Sroberto struct list_head list; 67182007Sroberto 68182007Sroberto /* The functional resource ID */ 69182007Sroberto unsigned char resid; 70182007Sroberto /* These are mostly here for convenience; we could always read 71182007Sroberto them from the ROMs if we wanted to */ 72132451Sroberto unsigned short category; 73182007Sroberto unsigned short type; 74182007Sroberto unsigned short dr_sw; 75182007Sroberto unsigned short dr_hw; 76182007Sroberto 77132451Sroberto /* Functional directory */ 78182007Sroberto unsigned char *directory; 79182007Sroberto /* Much of our info comes from here */ 80182007Sroberto struct nubus_board *board; 81132451Sroberto}; 82182007Sroberto 83182007Sroberto/* This is all NuBus functional resources (used to find devices later on) */ 84182007Srobertoextern struct list_head nubus_func_rsrcs; 85182007Sroberto 86182007Srobertostruct nubus_driver { 87182007Sroberto struct device_driver driver; 88182007Sroberto int (*probe)(struct nubus_board *board); 89182007Sroberto void (*remove)(struct nubus_board *board); 90182007Sroberto}; 91182007Sroberto 92182007Sroberto/* Generic NuBus interface functions, modelled after the PCI interface */ 93132451Sroberto#ifdef CONFIG_PROC_FS 94182007Srobertoextern bool nubus_populate_procfs; 95182007Srobertovoid nubus_proc_init(void); 96182007Srobertostruct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board); 97132451Srobertostruct proc_dir_entry *nubus_proc_add_rsrc_dir(struct proc_dir_entry *procdir, 98182007Sroberto const struct nubus_dirent *ent, 99182007Sroberto struct nubus_board *board); 100182007Srobertovoid nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir, 101182007Sroberto const struct nubus_dirent *ent, 102132451Sroberto unsigned int size); 103182007Srobertovoid nubus_proc_add_rsrc(struct proc_dir_entry *procdir, 104182007Sroberto const struct nubus_dirent *ent); 105182007Sroberto#else 106132451Srobertostatic inline void nubus_proc_init(void) {} 107182007Srobertostatic inline 108182007Srobertostruct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board) 109182007Sroberto{ return NULL; } 110182007Srobertostatic inline 111132451Srobertostruct proc_dir_entry *nubus_proc_add_rsrc_dir(struct proc_dir_entry *procdir, 112182007Sroberto const struct nubus_dirent *ent, 113132451Sroberto struct nubus_board *board) 114182007Sroberto{ return NULL; } 115182007Srobertostatic inline void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir, 116182007Sroberto const struct nubus_dirent *ent, 117182007Sroberto unsigned int size) {} 118132451Srobertostatic inline void nubus_proc_add_rsrc(struct proc_dir_entry *procdir, 119182007Sroberto const struct nubus_dirent *ent) {} 120182007Sroberto#endif 121182007Sroberto 122182007Srobertostruct nubus_rsrc *nubus_first_rsrc_or_null(void); 123132451Srobertostruct nubus_rsrc *nubus_next_rsrc_or_null(struct nubus_rsrc *from); 124182007Sroberto 125182007Sroberto#define for_each_func_rsrc(f) \ 126182007Sroberto for (f = nubus_first_rsrc_or_null(); f; f = nubus_next_rsrc_or_null(f)) 127132451Sroberto 128182007Sroberto#define for_each_board_func_rsrc(b, f) \ 129182007Sroberto for_each_func_rsrc(f) if (f->board != b) {} else 130182007Sroberto 131182007Sroberto/* These are somewhat more NuBus-specific. They all return 0 for 132132451Sroberto success and -1 for failure, as you'd expect. */ 133182007Sroberto 134182007Sroberto/* The root directory which contains the board and functional 135182007Sroberto directories */ 136132451Srobertoint nubus_get_root_dir(const struct nubus_board *board, 137182007Sroberto struct nubus_dir *dir); 138132451Sroberto/* The board directory */ 139182007Srobertoint nubus_get_board_dir(const struct nubus_board *board, 140182007Sroberto struct nubus_dir *dir); 141182007Sroberto/* The functional directory */ 142182007Srobertoint nubus_get_func_dir(const struct nubus_rsrc *fres, struct nubus_dir *dir); 143182007Sroberto 144182007Sroberto/* These work on any directory gotten via the above */ 145182007Srobertoint nubus_readdir(struct nubus_dir *dir, 146182007Sroberto struct nubus_dirent *ent); 147182007Srobertoint nubus_find_rsrc(struct nubus_dir *dir, 148182007Sroberto unsigned char rsrc_type, 149182007Sroberto struct nubus_dirent *ent); 150182007Srobertoint nubus_rewinddir(struct nubus_dir *dir); 151182007Sroberto 152182007Sroberto/* Things to do with directory entries */ 153182007Srobertoint nubus_get_subdir(const struct nubus_dirent *ent, 154182007Sroberto struct nubus_dir *dir); 155182007Srobertovoid nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent, 156132451Sroberto unsigned int len); 157182007Srobertounsigned int nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent, 158182007Sroberto unsigned int len); 159182007Srobertovoid nubus_seq_write_rsrc_mem(struct seq_file *m, 160182007Sroberto const struct nubus_dirent *dirent, 161182007Sroberto unsigned int len); 162182007Srobertounsigned char *nubus_dirptr(const struct nubus_dirent *nd); 163182007Sroberto 164182007Sroberto/* Declarations relating to driver model objects */ 165132451Srobertoint nubus_parent_device_register(void); 166132451Srobertoint nubus_device_register(struct nubus_board *board); 167182007Srobertoint nubus_driver_register(struct nubus_driver *ndrv); 168182007Srobertovoid nubus_driver_unregister(struct nubus_driver *ndrv); 169182007Srobertoint nubus_proc_show(struct seq_file *m, void *data); 170182007Sroberto 171182007Srobertostatic inline void nubus_set_drvdata(struct nubus_board *board, void *data) 172182007Sroberto{ 173132451Sroberto dev_set_drvdata(&board->dev, data); 174182007Sroberto} 175182007Sroberto 176182007Srobertostatic inline void *nubus_get_drvdata(struct nubus_board *board) 177132451Sroberto{ 178182007Sroberto return dev_get_drvdata(&board->dev); 179182007Sroberto} 180182007Sroberto 181182007Sroberto/* Returns a pointer to the "standard" slot space. */ 182182007Srobertostatic inline void *nubus_slot_addr(int slot) 183182007Sroberto{ 184182007Sroberto return (void *)(0xF0000000 | (slot << 24)); 185182007Sroberto} 186182007Sroberto 187182007Sroberto#endif /* LINUX_NUBUS_H */ 188182007Sroberto