OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [block/] [triton.c] - Blame information for rev 1626

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/*
2
 *  linux/drivers/block/triton.c        Version 1.13  Aug 12, 1996
3
 *                                      Version 1.13a June 1998 - new chipsets
4
 *                                      Version 1.13b July 1998 - DMA blacklist
5
 *
6
 *  Copyright (c) 1995-1996  Mark Lord
7
 *  May be copied or modified under the terms of the GNU General Public License
8
 */
9
 
10
/*
11
 * This module provides support for Bus Master IDE DMA functions in various
12
 * motherboard chipsets and PCI controller cards.
13
 * Please check /Documentation/ide.txt and /Documentation/udma.txt for details.
14
 */
15
 
16
#include <linux/config.h>
17
#include <linux/types.h>
18
#include <linux/kernel.h>
19
#include <linux/timer.h>
20
#include <linux/mm.h>
21
#include <linux/ioport.h>
22
#include <linux/interrupt.h>
23
#include <linux/blkdev.h>
24
#include <linux/hdreg.h>
25
#include <linux/pci.h>
26
#include <linux/bios32.h>
27
 
28
#include <asm/io.h>
29
#include <asm/dma.h>
30
 
31
#include "ide.h"
32
 
33
#undef DISPLAY_TRITON_TIMINGS   /* define this to display timings */
34
#undef DISPLAY_APOLLO_TIMINGS   /* define this for extensive debugging information */
35
 
36
#if defined(CONFIG_PROC_FS) && defined(DISPLAY_APOLLO_TIMINGS)
37
#include <linux/stat.h>
38
#include <linux/proc_fs.h>
39
#include <linux/via_ide_dma.h>
40
#endif
41
 
42
/*
43
 * good_dma_drives() lists the model names (from "hdparm -i")
44
 * of drives which do not support mword2 DMA but which are
45
 * known to work fine with this interface under Linux.
46
 */
47
const char *good_dma_drives[] = {"Micropolis 2112A",
48
                                 "CONNER CTMA 4000",
49
                                 "CONNER CTT8000-A",
50
                                 NULL};
51
 
52
/*
53
 * bad_dma_drives() lists the model names (from "hdparm -i")
54
 * of drives which supposedly support (U)DMA but which are
55
 * known to corrupt data with this interface under Linux.
56
 *
57
 * Note: the list was generated by statistical analysis of problem
58
 * reports. It's not clear if there are problems with the drives,
59
 * or with some combination of drive/controller or what.
60
 *
61
 * You can forcibly override this if you wish. This is the kernel
62
 * 'Tread carefully' list.
63
 *
64
 * Finally see http://www.wdc.com/quality/err-rec.html if you have
65
 * one of the listed drives.
66
 */
67
const char *bad_dma_drives[] = {"WDC AC11000H",
68
                                "WDC AC22100H",
69
                                "WDC AC32500H",
70
                                "WDC AC33100H",
71
                                 NULL};
72
 
73
/*
74
 * Our Physical Region Descriptor (PRD) table should be large enough
75
 * to handle the biggest I/O request we are likely to see.  Since requests
76
 * can have no more than 256 sectors, and since the typical blocksize is
77
 * two sectors, we could get by with a limit of 128 entries here for the
78
 * usual worst case.  Most requests seem to include some contiguous blocks,
79
 * further reducing the number of table entries required.
80
 *
81
 * The driver reverts to PIO mode for individual requests that exceed
82
 * this limit (possible with 512 byte blocksizes, eg. MSDOS f/s), so handling
83
 * 100% of all crazy scenarios here is not necessary.
84
 *
85
 * As it turns out though, we must allocate a full 4KB page for this,
86
 * so the two PRD tables (ide0 & ide1) will each get half of that,
87
 * allowing each to have about 256 entries (8 bytes each) from this.
88
 */
89
#define PRD_BYTES       8
90
#define PRD_ENTRIES     (PAGE_SIZE / (2 * PRD_BYTES))
91
#define DEFAULT_BMIBA   0xe800  /* in case BIOS did not init it */
92
#define DEFAULT_BMCRBA  0xcc00  /* VIA's default value */
93
 
94
/*
95
 * dma_intr() is the handler for disk read/write DMA interrupts
96
 */
97
static void dma_intr (ide_drive_t *drive)
98
{
99
        byte stat, dma_stat;
100
        int i;
101
        struct request *rq = HWGROUP(drive)->rq;
102
        unsigned short dma_base = HWIF(drive)->dma_base;
103
 
104
        outb(inb(dma_base)&~1, dma_base);       /* stop DMA operation */
105
        dma_stat = inb(dma_base+2);             /* get DMA status */
106
        stat = GET_STAT();                      /* get drive status */
107
        if (OK_STAT(stat,DRIVE_READY,drive->bad_wstat|DRQ_STAT)) {
108
                if ((dma_stat & 7) == 4) {      /* verify good DMA status */
109
                        rq = HWGROUP(drive)->rq;
110
                        for (i = rq->nr_sectors; i > 0;) {
111
                                i -= rq->current_nr_sectors;
112
                                ide_end_request(1, HWGROUP(drive));
113
                        }
114
                        return;
115
                }
116
                printk("%s: bad DMA status: 0x%02x\n", drive->name, dma_stat);
117
        }
118
        sti();
119
        ide_error(drive, "dma_intr", stat);
120
}
121
 
122
/*
123
 * build_dmatable() prepares a dma request.
124
 * Returns 0 if all went okay, returns 1 otherwise.
125
 */
126
static int build_dmatable (ide_drive_t *drive)
127
{
128
        struct request *rq = HWGROUP(drive)->rq;
129
        struct buffer_head *bh = rq->bh;
130
        unsigned long size, addr, *table = HWIF(drive)->dmatable;
131
        unsigned int count = 0;
132
 
133
        do {
134
                /*
135
                 * Determine addr and size of next buffer area.  We assume that
136
                 * individual virtual buffers are always composed linearly in
137
                 * physical memory.  For example, we assume that any 8kB buffer
138
                 * is always composed of two adjacent physical 4kB pages rather
139
                 * than two possibly non-adjacent physical 4kB pages.
140
                 */
141
                if (bh == NULL) {  /* paging and tape requests have (rq->bh == NULL) */
142
                        addr = virt_to_bus (rq->buffer);
143
#ifdef CONFIG_BLK_DEV_IDETAPE
144
                        if (drive->media == ide_tape)
145
                                size = drive->tape.pc->request_transfer;
146
                        else
147
#endif /* CONFIG_BLK_DEV_IDETAPE */     
148
                        size = rq->nr_sectors << 9;
149
                } else {
150
                        /* group sequential buffers into one large buffer */
151
                        addr = virt_to_bus (bh->b_data);
152
                        size = bh->b_size;
153
                        while ((bh = bh->b_reqnext) != NULL) {
154
                                if ((addr + size) != virt_to_bus (bh->b_data))
155
                                        break;
156
                                size += bh->b_size;
157
                        }
158
                }
159
 
160
                /*
161
                 * Fill in the dma table, without crossing any 64kB boundaries.
162
                 * We assume 16-bit alignment of all blocks.
163
                 */
164
                while (size) {
165
                        if (++count >= PRD_ENTRIES) {
166
                                printk("%s: DMA table too small\n", drive->name);
167
                                return 1; /* revert to PIO for this request */
168
                        } else {
169
                                unsigned long bcount = 0x10000 - (addr & 0xffff);
170
                                if (bcount > size)
171
                                        bcount = size;
172
                                *table++ = addr;
173
                                *table++ = bcount & 0xffff;
174
                                addr += bcount;
175
                                size -= bcount;
176
                        }
177
                }
178
        } while (bh != NULL);
179
        if (count) {
180
                *--table |= 0x80000000; /* set End-Of-Table (EOT) bit */
181
                return 0;
182
        }
183
        printk("%s: empty DMA table?\n", drive->name);
184
        return 1;       /* let the PIO routines handle this weirdness */
185
}
186
 
187
/*
188
 * We will only enable drives with multi-word (mode2) (U)DMA capabilities,
189
 * and ignore the very rare cases of drives that can only do single-word
190
 * (modes 0 & 1) (U)DMA transfers. We also discard "blacklisted" hard disks.
191
 */
192
static int config_drive_for_dma (ide_drive_t *drive)
193
{
194
        const char **list;
195
        struct hd_driveid *id = drive->id;
196
 
197
        if (id && (id->capability & 1)) {
198
                /* Consult the list of known "bad" drives */
199
                list = bad_dma_drives;
200
                while (*list) {
201
                        if (!strcmp(*list++,id->model)) {
202
                                drive->using_dma = 0;   /* no DMA */
203
                                printk("ide: Disabling DMA modes on %s drive (%s).\n", drive->name, id->model);
204
                                return 1;       /* DMA disabled */
205
                        }
206
                }
207
                /* Enable DMA on any drive that has mode 2 UltraDMA enabled */
208
                if (id->field_valid & 4)        /* UltraDMA */
209
                        if  ((id->dma_ultra & 0x404) == 0x404) {
210
                                drive->using_dma = 1;
211
                                return 0;        /* DMA enabled */
212
                        }
213
                /* Enable DMA on any drive that has mode2 DMA enabled */
214
                if (id->field_valid & 2)        /* regular DMA */
215
                        if  ((id->dma_mword & 0x404) == 0x404) {
216
                                drive->using_dma = 1;
217
                                return 0;        /* DMA enabled */
218
                        }
219
                /* Consult the list of known "good" drives */
220
                list = good_dma_drives;
221
                while (*list) {
222
                        if (!strcmp(*list++,id->model)) {
223
                                drive->using_dma = 1;
224
                                return 0;        /* DMA enabled */
225
                        }
226
                }
227
        }
228
        return 1;       /* DMA not enabled */
229
}
230
 
231
/*
232
 * triton_dmaproc() initiates/aborts DMA read/write operations on a drive.
233
 *
234
 * The caller is assumed to have selected the drive and programmed the drive's
235
 * sector address using CHS or LBA.  All that remains is to prepare for DMA
236
 * and then issue the actual read/write DMA/PIO command to the drive.
237
 *
238
 * For ATAPI devices, we just prepare for DMA and return. The caller should
239
 * then issue the packet command to the drive and call us again with
240
 * ide_dma_begin afterwards.
241
 *
242
 * Returns 0 if all went well.
243
 * Returns 1 if DMA read/write could not be started, in which case
244
 * the caller should revert to PIO for the current request.
245
 */
246
static int triton_dmaproc (ide_dma_action_t func, ide_drive_t *drive)
247
{
248
        unsigned long dma_base = HWIF(drive)->dma_base;
249
        unsigned int reading = (1 << 3);
250
 
251
        switch (func) {
252
                case ide_dma_abort:
253
                        outb(inb(dma_base)&~1, dma_base);       /* stop DMA */
254
                        return 0;
255
                case ide_dma_check:
256
                        return config_drive_for_dma (drive);
257
                case ide_dma_write:
258
                        reading = 0;
259
                case ide_dma_read:
260
                        break;
261
                case ide_dma_status_bad:
262
                        return ((inb(dma_base+2) & 7) != 4);    /* verify good DMA status */
263
                case ide_dma_transferred:
264
#if 0
265
                        return (number of bytes actually transferred);
266
#else
267
                        return (0);
268
#endif
269
                case ide_dma_begin:
270
                        outb(inb(dma_base)|1, dma_base);        /* begin DMA */
271
                        return 0;
272
                default:
273
                        printk("triton_dmaproc: unsupported func: %d\n", func);
274
                        return 1;
275
        }
276
        if (build_dmatable (drive))
277
                return 1;
278
        outl(virt_to_bus (HWIF(drive)->dmatable), dma_base + 4); /* PRD table */
279
        outb(reading, dma_base);                        /* specify r/w */
280
        outb(inb(dma_base+2)|0x06, dma_base+2);         /* clear status bits */
281
#ifdef CONFIG_BLK_DEV_IDEATAPI
282
        if (drive->media != ide_disk)
283
                return 0;
284
#endif /* CONFIG_BLK_DEV_IDEATAPI */    
285
        ide_set_handler(drive, &dma_intr, WAIT_CMD);    /* issue cmd to drive */
286
        OUT_BYTE(reading ? WIN_READDMA : WIN_WRITEDMA, IDE_COMMAND_REG);
287
        outb(inb(dma_base)|1, dma_base);                /* begin DMA */
288
        return 0;
289
}
290
 
291
#ifdef DISPLAY_TRITON_TIMINGS
292
/*
293
 * print_triton_drive_flags() displays the currently programmed options
294
 * in the i82371 (Triton) for a given drive.
295
 *
296
 *      If fastDMA  is "no", then slow ISA timings are used for DMA data xfers.
297
 *      If fastPIO  is "no", then slow ISA timings are used for PIO data xfers.
298
 *      If IORDY    is "no", then IORDY is assumed to always be asserted.
299
 *      If PreFetch is "no", then data pre-fetch/post are not used.
300
 *
301
 * When "fastPIO" and/or "fastDMA" are "yes", then faster PCI timings and
302
 * back-to-back 16-bit data transfers are enabled, using the sample_CLKs
303
 * and recovery_CLKs (PCI clock cycles) timing parameters for that interface.
304
 */
305
static void print_triton_drive_flags (unsigned int unit, byte flags)
306
{
307
        printk("         %s ", unit ? "slave :" : "master:");
308
        printk( "fastDMA=%s",   (flags&9)       ? "on " : "off");
309
        printk(" PreFetch=%s",  (flags&4)       ? "on " : "off");
310
        printk(" IORDY=%s",     (flags&2)       ? "on " : "off");
311
        printk(" fastPIO=%s\n", ((flags&9)==1)  ? "on " : "off");
312
}
313
#endif /* DISPLAY_TRITON_TIMINGS */
314
 
315
static void init_triton_dma (ide_hwif_t *hwif, unsigned short base)
316
{
317
        static unsigned long dmatable = 0;
318
 
319
        printk("    %s: BM-DMA at 0x%04x-0x%04x", hwif->name, base, base+7);
320
        if (check_region(base, 8)) {
321
                printk(" -- ERROR, PORTS ALREADY IN USE");
322
        } else {
323
                request_region(base, 8, "IDE DMA");
324
                hwif->dma_base = base;
325
                if (!dmatable) {
326
                        /*
327
                         * The BM-DMA uses a full 32-bits, so we can
328
                         * safely use __get_free_page() here instead
329
                         * of __get_dma_pages() -- no ISA limitations.
330
                         */
331
                        dmatable = __get_free_pages(GFP_KERNEL, 1, 0);
332
                }
333
                if (dmatable) {
334
                        hwif->dmatable = (unsigned long *) dmatable;
335
                        dmatable += (PRD_ENTRIES * PRD_BYTES);
336
                        outl(virt_to_bus(hwif->dmatable), base + 4);
337
                        hwif->dmaproc  = &triton_dmaproc;
338
                }
339
        }
340
        printk("\n");
341
}
342
 
343
/*
344
 *  Set VIA Chipset Timings for (U)DMA modes enabled.
345
 */
346
static int set_via_timings (byte bus, byte fn, byte post, byte flush)
347
{
348
        byte via_config = 0;
349
        int rc = 0;
350
 
351
        /* setting IDE read prefetch buffer and IDE post write buffer */
352
        if ((rc = pcibios_read_config_byte(bus, fn, 0x41, &via_config)))
353
                return (1);
354
        if ((rc = pcibios_write_config_byte(bus, fn, 0x41, via_config | post)))
355
                return (1);
356
 
357
        /* setting Channel read and End-of-sector FIFO flush: */
358
        if ((rc = pcibios_read_config_byte(bus, fn, 0x46, &via_config)))
359
                return (1);
360
        if ((rc = pcibios_write_config_byte(bus, fn, 0x46, via_config | flush)))
361
                return (1);
362
 
363
        return (0);
364
}
365
 
366
/*
367
 * ide_init_triton() prepares the IDE driver for DMA operation.
368
 * This routine is called once, from ide.c during driver initialization,
369
 * for each BM-DMA chipset which is found (rarely more than one).
370
 */
371
void ide_init_triton (byte bus, byte fn)
372
{
373
        int rc = 0, h;
374
        int dma_enabled = 0;
375
        unsigned short io[6], count = 0, step_count = 0;
376
        unsigned short pcicmd, vendor, device, class;
377
        unsigned int bmiba, timings, reg, tmp;
378
        unsigned int addressbios = 0;
379
 
380
#ifdef DISPLAY_APOLLO_TIMINGS
381
        bmide_bus = bus;
382
        bmide_fn = fn;
383
#endif /* DISPLAY_APOLLO_TIMINGS */
384
 
385
/*
386
 *  We pick up the vendor, device, and class info for selecting the correct
387
 *  controller that is supported.  Since we can access this routine more than
388
 *  once with the use of onboard and off-board EIDE controllers, a method
389
 *  of determining "who is who for what" is needed.
390
 */
391
 
392
        pcibios_read_config_word (bus, fn, PCI_VENDOR_ID, &vendor);
393
        pcibios_read_config_word (bus, fn, PCI_DEVICE_ID, &device);
394
        pcibios_read_config_word (bus, fn, PCI_CLASS_DEVICE, &class);
395
 
396
        switch(vendor) {
397
                case PCI_VENDOR_ID_INTEL:
398
                   printk("ide: Intel 82371 (single FIFO) DMA Bus Mastering IDE ");
399
                   break;
400
                case PCI_VENDOR_ID_SI:
401
                        printk("ide: SiS 5513 (dual FIFO) DMA Bus Mastering IDE ");
402
                        break;
403
                case PCI_VENDOR_ID_VIA:
404
                   printk("ide: VIA VT82C586B (split FIFO) UDMA Bus Mastering IDE ");
405
                   break;
406
                case PCI_VENDOR_ID_PROMISE:
407
                        /*      PCI_CLASS_STORAGE_RAID == class */
408
                        /*
409
                         *  I have been able to make my Promise Ultra33 UDMA card change class.
410
                         *  It has reported as both PCI_CLASS_STORAGE_RAID and PCI_CLASS_STORAGE_IDE.
411
                         *  Since the PCI_CLASS_STORAGE_RAID mode should automatically mirror the
412
                         *  two halves of the PCI_CONFIG register data, but sometimes it forgets.
413
                         *  Thus we guarantee that they are identical, with a quick check and
414
                         *  correction if needed.
415
                         *  PDC20246 (primary) PDC20247 (secondary) IDE hwif's.
416
                         *
417
                         *  Note that Promise "stories,fibs,..." about this device not being
418
                         *  capable of ATAPI and AT devices.
419
                         */
420
                        if (PCI_CLASS_STORAGE_RAID == class) {
421
                                unsigned char irq1 = 0, irq2 = 0;
422
                                pcibios_read_config_byte (bus, fn, PCI_INTERRUPT_LINE, &irq1);
423
                                pcibios_read_config_byte (bus, fn, (PCI_INTERRUPT_LINE)|0x80, &irq2);
424
                                if (irq1 != irq2) {
425
                                        pcibios_write_config_byte(bus, fn, (PCI_INTERRUPT_LINE)|0x80, irq1);
426
                                }
427
                        }
428
                case PCI_VENDOR_ID_ARTOP:
429
                        /*      PCI_CLASS_STORAGE_SCSI == class */
430
                        /*
431
                         *  I have found that by stroking rom_enable_bit on both the AEC6210U/UF and
432
                         *  PDC20246 controller cards, the features desired are almost guaranteed
433
                         *  to be enabled and compatible.  This ROM may not be registered in the
434
                         *  config data, but it can be turned on.  Registration failure has only
435
                         *  been observed if and only if Linux sets up the pci_io_address in the
436
                         *  0x6000 range.  If they are setup in the 0xef00 range it is reported.
437
                         *  WHY??? got me.........
438
                         */
439
                        printk("ide: %s UDMA Bus Mastering ",
440
                                (vendor == PCI_VENDOR_ID_ARTOP) ? "AEC6210" : "PDC20246");
441
                        pcibios_read_config_dword(bus, fn, PCI_ROM_ADDRESS, &addressbios);
442
                        if (addressbios) {
443
                                pcibios_write_config_byte(bus, fn, PCI_ROM_ADDRESS, addressbios | PCI_ROM_ADDRESS_ENABLE);
444
                                printk("with ROM enabled at 0x%08x", addressbios);
445
                        }
446
                        /*
447
                         *  This was stripped out of 2.1.XXX kernel code and parts from a patch called
448
                         *  promise_update.  This finds the PCI_BASE_ADDRESS spaces and makes them
449
                         *  available for configuration later.
450
                         *  PCI_BASE_ADDRESS_0  hwif0->io_base
451
                         *  PCI_BASE_ADDRESS_1  hwif0->ctl_port
452
                         *  PCI_BASE_ADDRESS_2  hwif1->io_base
453
                         *  PCI_BASE_ADDRESS_3  hwif1->ctl_port
454
                         *  PCI_BASE_ADDRESS_4  bmiba
455
                         */
456
                        memset(io, 0, 6 * sizeof(unsigned short));
457
                        for (reg = PCI_BASE_ADDRESS_0; reg <= PCI_BASE_ADDRESS_5; reg += 4) {
458
                                pcibios_read_config_dword(bus, fn, reg, &tmp);
459
                                if (tmp & PCI_BASE_ADDRESS_SPACE_IO)
460
                                        io[count++] = tmp & PCI_BASE_ADDRESS_IO_MASK;
461
                        }
462
                        break;
463
                default:
464
                        return;
465
        }
466
 
467
        printk("\n    Controller on PCI bus %d function %d\n", bus, fn);
468
 
469
        /*
470
         * See if IDE and BM-DMA features are enabled:
471
         */
472
        if ((rc = pcibios_read_config_word(bus, fn, PCI_COMMAND, &pcicmd)))
473
                goto quit;
474
        if ((pcicmd & 1) == 0)  {
475
                printk("ide: ports are not enabled (BIOS)\n");
476
                goto quit;
477
        }
478
        if ((pcicmd & 4) == 0) {
479
                printk("ide: BM-DMA feature is not enabled (BIOS)\n");
480
        } else {
481
                /*
482
                 * Get the bmiba base address
483
                 */
484
                int try_again = 1;
485
                do {
486
                        if ((rc = pcibios_read_config_dword(bus, fn, PCI_BASE_ADDRESS_4, &bmiba)))
487
                                goto quit;
488
                        bmiba &= 0xfff0;        /* extract port base address */
489
                        if (bmiba) {
490
                                dma_enabled = 1;
491
                                break;
492
                        } else {
493
                                printk("ide: BM-DMA base register is invalid (0x%04x, PnP BIOS problem)\n", bmiba);
494
                                if (inb(((vendor == PCI_VENDOR_ID_VIA) ? DEFAULT_BMCRBA : DEFAULT_BMIBA)) != 0xff || !try_again)
495
                                        break;
496
                                printk("ide: setting BM-DMA base register to 0x%04x\n", ((vendor == PCI_VENDOR_ID_VIA) ? DEFAULT_BMCRBA : DEFAULT_BMIBA));
497
                                if ((rc = pcibios_write_config_word(bus, fn, PCI_COMMAND, pcicmd&~1)))
498
                                        goto quit;
499
                                rc = pcibios_write_config_dword(bus, fn, 0x20, ((vendor == PCI_VENDOR_ID_VIA) ? DEFAULT_BMCRBA : DEFAULT_BMIBA)|1);
500
                                if (pcibios_write_config_word(bus, fn, PCI_COMMAND, pcicmd|5) || rc)
501
                                        goto quit;
502
                        }
503
                } while (try_again--);
504
        }
505
 
506
        /*
507
         * See if ide port(s) are enabled
508
         */
509
        if ((rc = pcibios_read_config_dword(bus, fn,
510
                (vendor == PCI_VENDOR_ID_PROMISE) ? 0x50 :
511
                (vendor == PCI_VENDOR_ID_ARTOP) ? 0x54 :
512
                0x40, &timings)))
513
                goto quit;
514
        /*
515
         * We do a vendor check since the Ultra33 and AEC6210
516
         * holds their timings in a different location.
517
         */
518
        printk("ide: timings == %08x\n", timings);
519
 
520
        /*
521
         *  The switch preserves some stuff that was original.
522
         */
523
        switch(vendor) {
524
                case PCI_VENDOR_ID_INTEL:
525
                        if (!(timings & 0x80008000)) {
526
                                printk("ide: INTEL: neither port is enabled\n");
527
                                goto quit;
528
                        }
529
                        break;
530
                case PCI_VENDOR_ID_VIA:
531
                        if(!(timings & 0x03)) {
532
                                printk("ide: VIA: neither port is enabled\n");
533
                                goto quit;
534
                        }
535
                        break;
536
                case PCI_VENDOR_ID_SI:
537
                case PCI_VENDOR_ID_PROMISE:
538
                case PCI_VENDOR_ID_ARTOP:
539
                default:
540
                        break;
541
        }
542
 
543
        /*
544
         * Save the dma_base port addr for each interface
545
         */
546
        for (h = 0; h < MAX_HWIFS; ++h) {
547
                ide_hwif_t *hwif = &ide_hwifs[h];
548
 
549
                /*
550
                 *  This prevents the first contoller from accidentally
551
                 *  initalizing the hwif's that it does not use and block
552
                 *  an off-board ide-pci from getting in the game.
553
                 */
554
                if (step_count >= 2) {
555
                        goto quit;
556
                }
557
#ifdef CONFIG_BLK_DEV_OFFBOARD
558
                /*
559
                 *  This is a forced override for the onboard ide controller
560
                 *  to be enabled, if one chooses to have an offboard ide-pci
561
                 *  card as the primary booting device.  This beasty is
562
                 *  for offboard UDMA upgrades with hard disks, but saving
563
                 *  the onboard DMA2 controllers for CDROMS, TAPES, ZIPS, etc...
564
                 */
565
                if ((vendor == PCI_VENDOR_ID_INTEL) ||
566
                    (vendor == PCI_VENDOR_ID_SI) ||
567
                    (vendor == PCI_VENDOR_ID_VIA)) {
568
                        if (h == 2) {
569
                                hwif->io_base = 0x1f0;
570
                                hwif->ctl_port = 0x3f6;
571
                                hwif->irq = 14;
572
                                hwif->noprobe = 0;
573
                        }
574
                        if (h == 3) {
575
                                hwif->io_base = 0x170;
576
                                hwif->ctl_port = 0x376;
577
                                hwif->irq = 15;
578
                                hwif->noprobe = 0;
579
                        }
580
                }
581
#endif /* CONFIG_BLK_DEV_OFFBOARD */
582
                /*
583
                 *  If the chipset is listed as "ide_unknown", lets get a
584
                 *  hwif while they last.  This does the first check on
585
                 *  the current availability of the ide_hwifs[h] in question.
586
                 */
587
                if (hwif->chipset != ide_unknown) {
588
                        continue;
589
                } else if (vendor == PCI_VENDOR_ID_INTEL) {
590
                        unsigned short time;
591
#ifdef DISPLAY_TRITON_TIMINGS
592
                        byte s_clks, r_clks;
593
                        unsigned short devid;
594
#endif /* DISPLAY_TRITON_TIMINGS */
595
                        if (hwif->io_base == 0x1f0) {
596
                                time = timings & 0xffff;
597
                                if ((time & 0x8000) == 0)        /* interface enabled? */
598
                                        continue;
599
                                hwif->chipset = ide_triton;
600
                                if (dma_enabled)
601
                                        init_triton_dma(hwif, bmiba);
602
                                step_count++;
603
                        } else if (hwif->io_base == 0x170) {
604
                                time = timings >> 16;
605
                                if ((time & 0x8000) == 0)        /* interface enabled? */
606
                                        continue;
607
                                hwif->chipset = ide_triton;
608
                                if (dma_enabled)
609
                                        init_triton_dma(hwif, bmiba + 8);
610
                                step_count++;
611
                        } else {
612
                                continue;
613
                        }
614
#ifdef DISPLAY_TRITON_TIMINGS
615
                        s_clks = ((~time >> 12) & 3) + 2;
616
                        r_clks = ((~time >>  8) & 3) + 1;
617
                        printk("    %s timing: (0x%04x) sample_CLKs=%d, recovery_CLKs=%d\n",
618
                                hwif->name, time, s_clks, r_clks);
619
                        if ((time & 0x40) && !pcibios_read_config_word(bus, fn, PCI_DEVICE_ID, &devid)
620
                                && devid == PCI_DEVICE_ID_INTEL_82371SB_1) {
621
                                byte stime;
622
                                if (pcibios_read_config_byte(bus, fn, 0x44, &stime)) {
623
                                        if (hwif->io_base == 0x1f0) {
624
                                                s_clks = ~stime >> 6;
625
                                                r_clks = ~stime >> 4;
626
                                        } else {
627
                                                s_clks = ~stime >> 2;
628
                                                r_clks = ~stime;
629
                                        }
630
                                        s_clks = (s_clks & 3) + 2;
631
                                        r_clks = (r_clks & 3) + 1;
632
                                        printk("                   slave: sample_CLKs=%d, recovery_CLKs=%d\n",
633
                                                s_clks, r_clks);
634
                                }
635
                        }
636
                        print_triton_drive_flags (0, time & 0xf);
637
                        print_triton_drive_flags (1, (time >> 4) & 0xf);
638
#endif /* DISPLAY_TRITON_TIMINGS */
639
                } else if (vendor == PCI_VENDOR_ID_SI) {
640
                        if (hwif->io_base == 0x1f0) {
641
                                hwif->chipset = ide_triton;
642
                                if (dma_enabled)
643
                                        init_triton_dma(hwif, bmiba);
644
                                step_count++;
645
                        } else if (hwif->io_base == 0x170) {
646
                                hwif->chipset = ide_triton;
647
                                if (dma_enabled)
648
                                        init_triton_dma(hwif, bmiba + 8);
649
                                step_count++;
650
                        } else {
651
                                continue;
652
                        }
653
                } else if(vendor == PCI_VENDOR_ID_VIA) {
654
                        if (hwif->io_base == 0x1f0) {
655
                                if((timings & 0x02) == 0)
656
                                        continue;
657
                                hwif->chipset = ide_triton;
658
                                if (dma_enabled)
659
                                        init_triton_dma(hwif, bmiba);
660
                                if (set_via_timings(bus, fn, 0xc0, 0xa0))
661
                                        goto quit;
662
#ifdef DISPLAY_APOLLO_TIMINGS
663
                                proc_register_dynamic(&proc_root, &via_proc_entry);
664
#endif /* DISPLAY_APOLLO_TIMINGS */
665
                                step_count++;
666
                        } else if (hwif->io_base == 0x170) {
667
                                if((timings & 0x01) == 0)
668
                                        continue;
669
                                hwif->chipset = ide_triton;
670
                                if (dma_enabled)
671
                                        init_triton_dma(hwif, bmiba + 8);
672
                                if (set_via_timings(bus, fn, 0x30, 0x50))
673
                                        goto quit;
674
                                step_count++;
675
                        } else {
676
                                continue;
677
                        }
678
                } else if ((vendor == PCI_VENDOR_ID_PROMISE) ||
679
                           (vendor == PCI_VENDOR_ID_ARTOP)) {
680
        /*
681
         *  This silly tmp = h routine allows an off-board ide-pci card to
682
         *  be booted as primary hwifgroup, provided that the onboard
683
         *  controllers are disabled.  If they are active, then we wait our
684
         *  turn for hwif assignment.
685
         */
686
                        unsigned char irq = 0;
687
                        pcibios_read_config_byte (bus, fn, PCI_INTERRUPT_LINE, &irq);
688
                        if ((h == 0) || (h == 1)) {
689
                                tmp = h * 2;
690
                        } else {
691
                                tmp = (h - 2) * 2;
692
                        }
693
                        hwif->io_base = io[tmp];
694
                        hwif->ctl_port = io[tmp + 1] + 2;
695
                        hwif->irq = irq;
696
                        hwif->noprobe = 0;
697
 
698
                        if (vendor == PCI_VENDOR_ID_ARTOP) {
699
                                hwif->serialized = 1;
700
                        }
701
 
702
                        if (dma_enabled) {
703
                                if (!check_region(bmiba, 8)) {
704
                                        hwif->chipset = ide_udma;
705
                                        init_triton_dma(hwif, bmiba);
706
                                        step_count++;
707
                                } else if (!check_region((bmiba + 0x08), 8)) {
708
                                        if ((vendor == PCI_VENDOR_ID_PROMISE) &&
709
                                            (!check_region(bmiba+16, 16))) {
710
                                                request_region(bmiba+16, 16, "PDC20246");
711
                                        }
712
                                        hwif->chipset = ide_udma;
713
                                        init_triton_dma(hwif, bmiba + 8);
714
                                        step_count++;
715
                                } else {
716
                                        continue;
717
                                }
718
                        }
719
                }
720
        }
721
 
722
        quit: if (rc) printk("ide: pcibios access failed - %s\n", pcibios_strerror(rc));
723
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.