1 #ifndef _BLK_H
2 #define _BLK_H
3
4 #include <linux/blkdev.h>
5 #include <linux/locks.h>
6 #include <linux/config.h>
7 #include <linux/spinlock.h>
8
9 /*
10 * Spinlock for protecting the request queue which
11 * is mucked around with in interrupts on potentially
12 * multiple CPU's..
13 */
14 extern spinlock_t io_request_lock;
15
16 /*
17 * Initialization functions.
18 */
19 extern int isp16_init(void);
20 extern int cdu31a_init(void);
21 extern int acsi_init(void);
22 extern int mcd_init(void);
23 extern int mcdx_init(void);
24 extern int sbpcd_init(void);
25 extern int aztcd_init(void);
26 extern int sony535_init(void);
27 extern int gscd_init(void);
28 extern int cm206_init(void);
29 extern int optcd_init(void);
30 extern int sjcd_init(void);
31 extern int cdi_init(void);
32 extern int hd_init(void);
33 extern int ide_init(void);
34 extern int xd_init(void);
35 extern int mfm_init(void);
36 extern int loop_init(void);
37 extern int md_init(void);
38 extern int ap_init(void);
39 extern int ddv_init(void);
40 extern int z2_init(void);
41 extern int swim3_init(void);
42 extern int swimiop_init(void);
43 extern int amiga_floppy_init(void);
44 extern int atari_floppy_init(void);
45 extern int ez_init(void);
46 extern int bpcd_init(void);
47 extern int ps2esdi_init(void);
48 extern int jsfd_init(void);
49 extern int viodasd_init(void);
50 extern int viocd_init(void);
51
52 #if defined(CONFIG_ARCH_S390)
53 extern int dasd_init(void);
54 extern int xpram_init(void);
55 extern int tapeblock_init(void);
56 #endif /* CONFIG_ARCH_S390 */
57
58 extern void set_device_ro(kdev_t dev,int flag);
59 void add_blkdev_randomness(int major);
60
61 extern int floppy_init(void);
62 extern int rd_doload; /* 1 = load ramdisk, 0 = don't load */
63 extern int rd_prompt; /* 1 = prompt for ramdisk, 0 = don't prompt */
64 extern int rd_image_start; /* starting block # of image */
65
66 #ifdef CONFIG_BLK_DEV_INITRD
67
68 #define INITRD_MINOR 250 /* shouldn't collide with /dev/ram* too soon ... */
69
70 extern unsigned long initrd_start,initrd_end;
71 extern int initrd_below_start_ok; /* 1 if it is not an error if initrd_start < memory_start */
72 void initrd_init(void);
73
74 #endif
75
76
77 /*
78 * end_request() and friends. Must be called with the request queue spinlock
79 * acquired. All functions called within end_request() _must_be_ atomic.
80 *
81 * Several drivers define their own end_request and call
82 * end_that_request_first() and end_that_request_last()
83 * for parts of the original function. This prevents
84 * code duplication in drivers.
85 */
86
blkdev_dequeue_request(struct request * req)87 static inline void blkdev_dequeue_request(struct request * req)
88 {
89 list_del(&req->queue);
90 }
91
92 int end_that_request_first(struct request *req, int uptodate, char *name);
93 void end_that_request_last(struct request *req);
94
95 #if defined(MAJOR_NR) || defined(IDE_DRIVER)
96
97 #undef DEVICE_ON
98 #undef DEVICE_OFF
99
100 /*
101 * Add entries as needed.
102 */
103
104 #ifdef IDE_DRIVER
105
106 #define DEVICE_NR(device) (MINOR(device) >> PARTN_BITS)
107 #define DEVICE_NAME "ide"
108
109 #elif (MAJOR_NR == RAMDISK_MAJOR)
110
111 /* ram disk */
112 #define DEVICE_NAME "ramdisk"
113 #define DEVICE_NR(device) (MINOR(device))
114 #define DEVICE_NO_RANDOM
115
116 #elif (MAJOR_NR == Z2RAM_MAJOR)
117
118 /* Zorro II Ram */
119 #define DEVICE_NAME "Z2RAM"
120 #define DEVICE_REQUEST do_z2_request
121 #define DEVICE_NR(device) (MINOR(device))
122
123 #elif (MAJOR_NR == FLOPPY_MAJOR)
124
125 static void floppy_off(unsigned int nr);
126
127 #define DEVICE_NAME "floppy"
128 #define DEVICE_INTR do_floppy
129 #define DEVICE_REQUEST do_fd_request
130 #define DEVICE_NR(device) ( (MINOR(device) & 3) | ((MINOR(device) & 0x80 ) >> 5 ))
131 #define DEVICE_OFF(device) floppy_off(DEVICE_NR(device))
132
133 #elif (MAJOR_NR == HD_MAJOR)
134
135 /* Hard disk: timeout is 6 seconds. */
136 #define DEVICE_NAME "hard disk"
137 #define DEVICE_INTR do_hd
138 #define TIMEOUT_VALUE (6*HZ)
139 #define DEVICE_REQUEST do_hd_request
140 #define DEVICE_NR(device) (MINOR(device)>>6)
141
142 #elif (SCSI_DISK_MAJOR(MAJOR_NR))
143
144 #define DEVICE_NAME "scsidisk"
145 #define TIMEOUT_VALUE (2*HZ)
146 #define DEVICE_NR(device) (((MAJOR(device) & SD_MAJOR_MASK) << (8 - 4)) + (MINOR(device) >> 4))
147
148 /* Kludge to use the same number for both char and block major numbers */
149 #elif (MAJOR_NR == MD_MAJOR) && defined(MD_DRIVER)
150
151 #define DEVICE_NAME "Multiple devices driver"
152 #define DEVICE_REQUEST do_md_request
153 #define DEVICE_NR(device) (MINOR(device))
154
155 #elif (MAJOR_NR == SCSI_TAPE_MAJOR)
156
157 #define DEVICE_NAME "scsitape"
158 #define DEVICE_INTR do_st
159 #define DEVICE_NR(device) (MINOR(device) & 0x7f)
160
161 #elif (MAJOR_NR == OSST_MAJOR)
162
163 #define DEVICE_NAME "onstream"
164 #define DEVICE_INTR do_osst
165 #define DEVICE_NR(device) (MINOR(device) & 0x7f)
166 #define DEVICE_ON(device)
167 #define DEVICE_OFF(device)
168
169 #elif (MAJOR_NR == SCSI_CDROM_MAJOR)
170
171 #define DEVICE_NAME "CD-ROM"
172 #define DEVICE_NR(device) (MINOR(device))
173
174 #elif (MAJOR_NR == XT_DISK_MAJOR)
175
176 #define DEVICE_NAME "xt disk"
177 #define DEVICE_REQUEST do_xd_request
178 #define DEVICE_NR(device) (MINOR(device) >> 6)
179
180 #elif (MAJOR_NR == PS2ESDI_MAJOR)
181
182 #define DEVICE_NAME "PS/2 ESDI"
183 #define DEVICE_REQUEST do_ps2esdi_request
184 #define DEVICE_NR(device) (MINOR(device) >> 6)
185
186 #elif (MAJOR_NR == CDU31A_CDROM_MAJOR)
187
188 #define DEVICE_NAME "CDU31A"
189 #define DEVICE_REQUEST do_cdu31a_request
190 #define DEVICE_NR(device) (MINOR(device))
191
192 #elif (MAJOR_NR == ACSI_MAJOR) && (defined(CONFIG_ATARI_ACSI) || defined(CONFIG_ATARI_ACSI_MODULE))
193
194 #define DEVICE_NAME "ACSI"
195 #define DEVICE_INTR do_acsi
196 #define DEVICE_REQUEST do_acsi_request
197 #define DEVICE_NR(device) (MINOR(device) >> 4)
198
199 #elif (MAJOR_NR == MITSUMI_CDROM_MAJOR)
200
201 #define DEVICE_NAME "Mitsumi CD-ROM"
202 /* #define DEVICE_INTR do_mcd */
203 #define DEVICE_REQUEST do_mcd_request
204 #define DEVICE_NR(device) (MINOR(device))
205
206 #elif (MAJOR_NR == MITSUMI_X_CDROM_MAJOR)
207
208 #define DEVICE_NAME "Mitsumi CD-ROM"
209 /* #define DEVICE_INTR do_mcdx */
210 #define DEVICE_REQUEST do_mcdx_request
211 #define DEVICE_NR(device) (MINOR(device))
212
213 #elif (MAJOR_NR == MATSUSHITA_CDROM_MAJOR)
214
215 #define DEVICE_NAME "Matsushita CD-ROM controller #1"
216 #define DEVICE_REQUEST do_sbpcd_request
217 #define DEVICE_NR(device) (MINOR(device))
218
219 #elif (MAJOR_NR == MATSUSHITA_CDROM2_MAJOR)
220
221 #define DEVICE_NAME "Matsushita CD-ROM controller #2"
222 #define DEVICE_REQUEST do_sbpcd2_request
223 #define DEVICE_NR(device) (MINOR(device))
224
225 #elif (MAJOR_NR == MATSUSHITA_CDROM3_MAJOR)
226
227 #define DEVICE_NAME "Matsushita CD-ROM controller #3"
228 #define DEVICE_REQUEST do_sbpcd3_request
229 #define DEVICE_NR(device) (MINOR(device))
230
231 #elif (MAJOR_NR == MATSUSHITA_CDROM4_MAJOR)
232
233 #define DEVICE_NAME "Matsushita CD-ROM controller #4"
234 #define DEVICE_REQUEST do_sbpcd4_request
235 #define DEVICE_NR(device) (MINOR(device))
236
237 #elif (MAJOR_NR == AZTECH_CDROM_MAJOR)
238
239 #define DEVICE_NAME "Aztech CD-ROM"
240 #define DEVICE_REQUEST do_aztcd_request
241 #define DEVICE_NR(device) (MINOR(device))
242
243 #elif (MAJOR_NR == CDU535_CDROM_MAJOR)
244
245 #define DEVICE_NAME "SONY-CDU535"
246 #define DEVICE_INTR do_cdu535
247 #define DEVICE_REQUEST do_cdu535_request
248 #define DEVICE_NR(device) (MINOR(device))
249
250 #elif (MAJOR_NR == GOLDSTAR_CDROM_MAJOR)
251
252 #define DEVICE_NAME "Goldstar R420"
253 #define DEVICE_REQUEST do_gscd_request
254 #define DEVICE_NR(device) (MINOR(device))
255
256 #elif (MAJOR_NR == CM206_CDROM_MAJOR)
257 #define DEVICE_NAME "Philips/LMS CD-ROM cm206"
258 #define DEVICE_REQUEST do_cm206_request
259 #define DEVICE_NR(device) (MINOR(device))
260
261 #elif (MAJOR_NR == OPTICS_CDROM_MAJOR)
262
263 #define DEVICE_NAME "DOLPHIN 8000AT CD-ROM"
264 #define DEVICE_REQUEST do_optcd_request
265 #define DEVICE_NR(device) (MINOR(device))
266
267 #elif (MAJOR_NR == SANYO_CDROM_MAJOR)
268
269 #define DEVICE_NAME "Sanyo H94A CD-ROM"
270 #define DEVICE_REQUEST do_sjcd_request
271 #define DEVICE_NR(device) (MINOR(device))
272
273 #elif (MAJOR_NR == APBLOCK_MAJOR)
274
275 #define DEVICE_NAME "apblock"
276 #define DEVICE_REQUEST ap_request
277 #define DEVICE_NR(device) (MINOR(device))
278
279 #elif (MAJOR_NR == DDV_MAJOR)
280
281 #define DEVICE_NAME "ddv"
282 #define DEVICE_REQUEST ddv_request
283 #define DEVICE_NR(device) (MINOR(device)>>PARTN_BITS)
284
285 #elif (MAJOR_NR == MFM_ACORN_MAJOR)
286
287 #define DEVICE_NAME "mfm disk"
288 #define DEVICE_INTR do_mfm
289 #define DEVICE_REQUEST do_mfm_request
290 #define DEVICE_NR(device) (MINOR(device) >> 6)
291
292 #elif (MAJOR_NR == NBD_MAJOR)
293
294 #define DEVICE_NAME "nbd"
295 #define DEVICE_REQUEST do_nbd_request
296 #define DEVICE_NR(device) (MINOR(device))
297
298 #elif (MAJOR_NR == MDISK_MAJOR)
299
300 #define DEVICE_NAME "mdisk"
301 #define DEVICE_REQUEST mdisk_request
302 #define DEVICE_NR(device) (MINOR(device))
303
304 #elif (MAJOR_NR == DASD_MAJOR)
305
306 #define DEVICE_NAME "dasd"
307 #define DEVICE_REQUEST do_dasd_request
308 #define DEVICE_NR(device) (MINOR(device) >> PARTN_BITS)
309
310 #elif (MAJOR_NR == I2O_MAJOR)
311
312 #define DEVICE_NAME "I2O block"
313 #define DEVICE_REQUEST i2ob_request
314 #define DEVICE_NR(device) (MINOR(device)>>4)
315
316 #elif (MAJOR_NR == COMPAQ_SMART2_MAJOR)
317
318 #define DEVICE_NAME "ida"
319 #define TIMEOUT_VALUE (25*HZ)
320 #define DEVICE_REQUEST do_ida_request
321 #define DEVICE_NR(device) (MINOR(device) >> 4)
322
323 #endif /* MAJOR_NR == whatever */
324
325 /* provide DEVICE_xxx defaults, if not explicitly defined
326 * above in the MAJOR_NR==xxx if-elif tree */
327 #ifndef DEVICE_ON
328 #define DEVICE_ON(device) do {} while (0)
329 #endif
330 #ifndef DEVICE_OFF
331 #define DEVICE_OFF(device) do {} while (0)
332 #endif
333
334 #if (MAJOR_NR != SCSI_TAPE_MAJOR) && (MAJOR_NR != OSST_MAJOR)
335 #if !defined(IDE_DRIVER)
336
337 #ifndef CURRENT
338 #define CURRENT blkdev_entry_next_request(&blk_dev[MAJOR_NR].request_queue.queue_head)
339 #endif
340 #ifndef QUEUE_EMPTY
341 #define QUEUE_EMPTY list_empty(&blk_dev[MAJOR_NR].request_queue.queue_head)
342 #endif
343
344 #ifndef DEVICE_NAME
345 #define DEVICE_NAME "unknown"
346 #endif
347
348 #define CURRENT_DEV DEVICE_NR(CURRENT->rq_dev)
349
350 #ifdef DEVICE_INTR
351 static void (*DEVICE_INTR)(void) = NULL;
352 #endif
353
354 #define SET_INTR(x) (DEVICE_INTR = (x))
355
356 #ifdef DEVICE_REQUEST
357 static void (DEVICE_REQUEST)(request_queue_t *);
358 #endif
359
360 #ifdef DEVICE_INTR
361 #define CLEAR_INTR SET_INTR(NULL)
362 #else
363 #define CLEAR_INTR
364 #endif
365
366 #define INIT_REQUEST \
367 if (QUEUE_EMPTY) {\
368 CLEAR_INTR; \
369 return; \
370 } \
371 if (MAJOR(CURRENT->rq_dev) != MAJOR_NR) \
372 panic(DEVICE_NAME ": request list destroyed"); \
373 if (CURRENT->bh) { \
374 if (!buffer_locked(CURRENT->bh)) \
375 panic(DEVICE_NAME ": block not locked"); \
376 }
377
378 #endif /* !defined(IDE_DRIVER) */
379
380
381 #ifndef LOCAL_END_REQUEST /* If we have our own end_request, we do not want to include this mess */
382
383 #if ! SCSI_BLK_MAJOR(MAJOR_NR) && (MAJOR_NR != COMPAQ_SMART2_MAJOR)
384
end_request(int uptodate)385 static inline void end_request(int uptodate) {
386 struct request *req = CURRENT;
387
388 if (end_that_request_first(req, uptodate, DEVICE_NAME))
389 return;
390
391 #ifndef DEVICE_NO_RANDOM
392 add_blkdev_randomness(MAJOR(req->rq_dev));
393 #endif
394 DEVICE_OFF(req->rq_dev);
395 blkdev_dequeue_request(req);
396 end_that_request_last(req);
397 }
398
399 #endif /* ! SCSI_BLK_MAJOR(MAJOR_NR) */
400 #endif /* LOCAL_END_REQUEST */
401
402 #endif /* (MAJOR_NR != SCSI_TAPE_MAJOR) */
403 #endif /* defined(MAJOR_NR) || defined(IDE_DRIVER) */
404
405 #endif /* _BLK_H */
406