Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003   nubus.h: various definitions and prototypes for NuBus drivers to use.
0004 
0005   Originally written by Alan Cox.
0006 
0007   Hacked to death by C. Scott Ananian and David Huggins-Daines.
0008 */
0009 
0010 #ifndef LINUX_NUBUS_H
0011 #define LINUX_NUBUS_H
0012 
0013 #include <linux/device.h>
0014 #include <asm/nubus.h>
0015 #include <uapi/linux/nubus.h>
0016 
0017 struct proc_dir_entry;
0018 struct seq_file;
0019 
0020 struct nubus_dir {
0021     unsigned char *base;
0022     unsigned char *ptr;
0023     int done;
0024     int mask;
0025     struct proc_dir_entry *procdir;
0026 };
0027 
0028 struct nubus_dirent {
0029     unsigned char *base;
0030     unsigned char type;
0031     __u32 data; /* Actually 24 bits used */
0032     int mask;
0033 };
0034 
0035 struct nubus_board {
0036     struct device dev;
0037 
0038     /* Only 9-E actually exist, though 0-8 are also theoretically
0039        possible, and 0 is a special case which represents the
0040        motherboard and onboard peripherals (Ethernet, video) */
0041     int slot;
0042     /* For slot 0, this is bogus. */
0043     char name[64];
0044 
0045     /* Format block */
0046     unsigned char *fblock;
0047     /* Root directory (does *not* always equal fblock + doffset!) */
0048     unsigned char *directory;
0049 
0050     unsigned long slot_addr;
0051     /* Offset to root directory (sometimes) */
0052     unsigned long doffset;
0053     /* Length over which to compute the crc */
0054     unsigned long rom_length;
0055     /* Completely useless most of the time */
0056     unsigned long crc;
0057     unsigned char rev;
0058     unsigned char format;
0059     unsigned char lanes;
0060 
0061     /* Directory entry in /proc/bus/nubus */
0062     struct proc_dir_entry *procdir;
0063 };
0064 
0065 struct nubus_rsrc {
0066     struct list_head list;
0067 
0068     /* The functional resource ID */
0069     unsigned char resid;
0070     /* These are mostly here for convenience; we could always read
0071        them from the ROMs if we wanted to */
0072     unsigned short category;
0073     unsigned short type;
0074     unsigned short dr_sw;
0075     unsigned short dr_hw;
0076 
0077     /* Functional directory */
0078     unsigned char *directory;
0079     /* Much of our info comes from here */
0080     struct nubus_board *board;
0081 };
0082 
0083 /* This is all NuBus functional resources (used to find devices later on) */
0084 extern struct list_head nubus_func_rsrcs;
0085 
0086 struct nubus_driver {
0087     struct device_driver driver;
0088     int (*probe)(struct nubus_board *board);
0089     void (*remove)(struct nubus_board *board);
0090 };
0091 
0092 extern struct bus_type nubus_bus_type;
0093 
0094 /* Generic NuBus interface functions, modelled after the PCI interface */
0095 #ifdef CONFIG_PROC_FS
0096 void nubus_proc_init(void);
0097 struct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board);
0098 struct proc_dir_entry *nubus_proc_add_rsrc_dir(struct proc_dir_entry *procdir,
0099                            const struct nubus_dirent *ent,
0100                            struct nubus_board *board);
0101 void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir,
0102                  const struct nubus_dirent *ent,
0103                  unsigned int size);
0104 void nubus_proc_add_rsrc(struct proc_dir_entry *procdir,
0105              const struct nubus_dirent *ent);
0106 #else
0107 static inline void nubus_proc_init(void) {}
0108 static inline
0109 struct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board)
0110 { return NULL; }
0111 static inline
0112 struct proc_dir_entry *nubus_proc_add_rsrc_dir(struct proc_dir_entry *procdir,
0113                            const struct nubus_dirent *ent,
0114                            struct nubus_board *board)
0115 { return NULL; }
0116 static inline void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir,
0117                        const struct nubus_dirent *ent,
0118                        unsigned int size) {}
0119 static inline void nubus_proc_add_rsrc(struct proc_dir_entry *procdir,
0120                        const struct nubus_dirent *ent) {}
0121 #endif
0122 
0123 struct nubus_rsrc *nubus_first_rsrc_or_null(void);
0124 struct nubus_rsrc *nubus_next_rsrc_or_null(struct nubus_rsrc *from);
0125 
0126 #define for_each_func_rsrc(f) \
0127     for (f = nubus_first_rsrc_or_null(); f; f = nubus_next_rsrc_or_null(f))
0128 
0129 #define for_each_board_func_rsrc(b, f) \
0130     for_each_func_rsrc(f) if (f->board != b) {} else
0131 
0132 /* These are somewhat more NuBus-specific.  They all return 0 for
0133    success and -1 for failure, as you'd expect. */
0134 
0135 /* The root directory which contains the board and functional
0136    directories */
0137 int nubus_get_root_dir(const struct nubus_board *board,
0138                struct nubus_dir *dir);
0139 /* The board directory */
0140 int nubus_get_board_dir(const struct nubus_board *board,
0141             struct nubus_dir *dir);
0142 /* The functional directory */
0143 int nubus_get_func_dir(const struct nubus_rsrc *fres, struct nubus_dir *dir);
0144 
0145 /* These work on any directory gotten via the above */
0146 int nubus_readdir(struct nubus_dir *dir,
0147           struct nubus_dirent *ent);
0148 int nubus_find_rsrc(struct nubus_dir *dir,
0149             unsigned char rsrc_type,
0150             struct nubus_dirent *ent);
0151 int nubus_rewinddir(struct nubus_dir *dir);
0152 
0153 /* Things to do with directory entries */
0154 int nubus_get_subdir(const struct nubus_dirent *ent,
0155              struct nubus_dir *dir);
0156 void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent,
0157             unsigned int len);
0158 unsigned int nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
0159                 unsigned int len);
0160 void nubus_seq_write_rsrc_mem(struct seq_file *m,
0161                   const struct nubus_dirent *dirent,
0162                   unsigned int len);
0163 unsigned char *nubus_dirptr(const struct nubus_dirent *nd);
0164 
0165 /* Declarations relating to driver model objects */
0166 int nubus_parent_device_register(void);
0167 int nubus_device_register(struct nubus_board *board);
0168 int nubus_driver_register(struct nubus_driver *ndrv);
0169 void nubus_driver_unregister(struct nubus_driver *ndrv);
0170 int nubus_proc_show(struct seq_file *m, void *data);
0171 
0172 static inline void nubus_set_drvdata(struct nubus_board *board, void *data)
0173 {
0174     dev_set_drvdata(&board->dev, data);
0175 }
0176 
0177 static inline void *nubus_get_drvdata(struct nubus_board *board)
0178 {
0179     return dev_get_drvdata(&board->dev);
0180 }
0181 
0182 /* Returns a pointer to the "standard" slot space. */
0183 static inline void *nubus_slot_addr(int slot)
0184 {
0185     return (void *)(0xF0000000 | (slot << 24));
0186 }
0187 
0188 #endif /* LINUX_NUBUS_H */