blob: 4a481610ad3884acc4cee25927263414891dee89 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 nubus.h: various definitions and prototypes for NuBus drivers to use.
4
5 Originally written by Alan Cox.
6
7 Hacked to death by C. Scott Ananian and David Huggins-Daines.
Finn Thain1ff27752018-01-13 17:37:13 -05008*/
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#ifndef LINUX_NUBUS_H
11#define LINUX_NUBUS_H
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <asm/nubus.h>
David Howells607ca462012-10-13 10:46:48 +010014#include <uapi/linux/nubus.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Finn Thain2f7dd072018-01-13 17:37:13 -050016struct proc_dir_entry;
17struct seq_file;
18
Finn Thain1ff27752018-01-13 17:37:13 -050019struct nubus_dir {
20 unsigned char *base;
21 unsigned char *ptr;
22 int done;
23 int mask;
Finn Thain2f7dd072018-01-13 17:37:13 -050024 struct proc_dir_entry *procdir;
Finn Thain1ff27752018-01-13 17:37:13 -050025};
26
27struct nubus_dirent {
28 unsigned char *base;
29 unsigned char type;
30 __u32 data; /* Actually 24 bits used */
31 int mask;
32};
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034struct nubus_board {
Finn Thain4bccc4b2018-01-13 17:37:13 -050035 struct nubus_board *next;
Finn Thain189e19e2018-01-13 17:37:13 -050036 struct nubus_rsrc *first_func_rsrc;
Finn Thain4bccc4b2018-01-13 17:37:13 -050037
Finn Thainf8779582007-05-01 22:32:53 +020038 /* Only 9-E actually exist, though 0-8 are also theoretically
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 possible, and 0 is a special case which represents the
40 motherboard and onboard peripherals (Ethernet, video) */
41 int slot;
42 /* For slot 0, this is bogus. */
43 char name[64];
44
45 /* Format block */
Finn Thain4bccc4b2018-01-13 17:37:13 -050046 unsigned char *fblock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 /* Root directory (does *not* always equal fblock + doffset!) */
Finn Thain4bccc4b2018-01-13 17:37:13 -050048 unsigned char *directory;
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 unsigned long slot_addr;
51 /* Offset to root directory (sometimes) */
52 unsigned long doffset;
53 /* Length over which to compute the crc */
54 unsigned long rom_length;
55 /* Completely useless most of the time */
56 unsigned long crc;
57 unsigned char rev;
58 unsigned char format;
59 unsigned char lanes;
Finn Thain6c8b89e2018-01-13 17:37:13 -050060
61 /* Directory entry in /proc/bus/nubus */
62 struct proc_dir_entry *procdir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063};
64
Finn Thain189e19e2018-01-13 17:37:13 -050065struct nubus_rsrc {
66 /* Next link in list */
67 struct nubus_rsrc *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Finn Thain189e19e2018-01-13 17:37:13 -050069 /* The functional resource ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 unsigned char resid;
71 /* These are mostly here for convenience; we could always read
72 them from the ROMs if we wanted to */
73 unsigned short category;
74 unsigned short type;
75 unsigned short dr_sw;
76 unsigned short dr_hw;
Finn Thain4bccc4b2018-01-13 17:37:13 -050077
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 /* Functional directory */
Finn Thain4bccc4b2018-01-13 17:37:13 -050079 unsigned char *directory;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 /* Much of our info comes from here */
Finn Thain4bccc4b2018-01-13 17:37:13 -050081 struct nubus_board *board;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082};
83
Finn Thain189e19e2018-01-13 17:37:13 -050084/* This is all NuBus functional resources (used to find devices later on) */
85extern struct nubus_rsrc *nubus_func_rsrcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086/* This is all NuBus cards */
Finn Thain4bccc4b2018-01-13 17:37:13 -050087extern struct nubus_board *nubus_boards;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89/* Generic NuBus interface functions, modelled after the PCI interface */
David Howells11db6562013-04-10 15:05:38 +010090#ifdef CONFIG_PROC_FS
Finn Thain2f7dd072018-01-13 17:37:13 -050091void nubus_proc_init(void);
92struct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board);
93struct proc_dir_entry *nubus_proc_add_rsrc_dir(struct proc_dir_entry *procdir,
94 const struct nubus_dirent *ent,
95 struct nubus_board *board);
96void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir,
97 const struct nubus_dirent *ent,
98 unsigned int size);
99void nubus_proc_add_rsrc(struct proc_dir_entry *procdir,
100 const struct nubus_dirent *ent);
David Howells11db6562013-04-10 15:05:38 +0100101#else
102static inline void nubus_proc_init(void) {}
Finn Thain2f7dd072018-01-13 17:37:13 -0500103static inline
104struct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board)
105{ return NULL; }
106static inline
107struct proc_dir_entry *nubus_proc_add_rsrc_dir(struct proc_dir_entry *procdir,
108 const struct nubus_dirent *ent,
109 struct nubus_board *board)
110{ return NULL; }
111static inline void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir,
112 const struct nubus_dirent *ent,
113 unsigned int size) {}
114static inline void nubus_proc_add_rsrc(struct proc_dir_entry *procdir,
115 const struct nubus_dirent *ent) {}
David Howells11db6562013-04-10 15:05:38 +0100116#endif
Finn Thain9f979772018-01-13 17:37:13 -0500117
Finn Thain189e19e2018-01-13 17:37:13 -0500118struct nubus_rsrc *nubus_find_type(unsigned short category,
119 unsigned short type,
120 const struct nubus_rsrc *from);
121
122struct nubus_rsrc *nubus_find_slot(unsigned int slot,
123 const struct nubus_rsrc *from);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125/* These are somewhat more NuBus-specific. They all return 0 for
126 success and -1 for failure, as you'd expect. */
127
128/* The root directory which contains the board and functional
129 directories */
Finn Thain4bccc4b2018-01-13 17:37:13 -0500130int nubus_get_root_dir(const struct nubus_board *board,
131 struct nubus_dir *dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132/* The board directory */
Finn Thain4bccc4b2018-01-13 17:37:13 -0500133int nubus_get_board_dir(const struct nubus_board *board,
134 struct nubus_dir *dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135/* The functional directory */
Finn Thain189e19e2018-01-13 17:37:13 -0500136int nubus_get_func_dir(const struct nubus_rsrc *fres, struct nubus_dir *dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138/* These work on any directory gotten via the above */
Finn Thain4bccc4b2018-01-13 17:37:13 -0500139int nubus_readdir(struct nubus_dir *dir,
140 struct nubus_dirent *ent);
141int nubus_find_rsrc(struct nubus_dir *dir,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 unsigned char rsrc_type,
Finn Thain4bccc4b2018-01-13 17:37:13 -0500143 struct nubus_dirent *ent);
144int nubus_rewinddir(struct nubus_dir *dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146/* Things to do with directory entries */
Finn Thain4bccc4b2018-01-13 17:37:13 -0500147int nubus_get_subdir(const struct nubus_dirent *ent,
148 struct nubus_dir *dir);
Finn Thain2f828fb2018-01-13 17:37:13 -0500149void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent,
150 unsigned int len);
Finn Thain2f7dd072018-01-13 17:37:13 -0500151unsigned int nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
152 unsigned int len);
153void nubus_seq_write_rsrc_mem(struct seq_file *m,
154 const struct nubus_dirent *dirent,
155 unsigned int len);
156unsigned char *nubus_dirptr(const struct nubus_dirent *nd);
Finn Thain1ff27752018-01-13 17:37:13 -0500157
158/* Returns a pointer to the "standard" slot space. */
159static inline void *nubus_slot_addr(int slot)
160{
161 return (void *)(0xF0000000 | (slot << 24));
162}
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164#endif /* LINUX_NUBUS_H */