📄 cmd_ide.c
字号:
if (ide_preinit ()) { puts ("ide_preinit failed\n"); return; }#endif /* CONFIG_IDE_PREINIT */#ifdef CONFIG_IDE_8xx_PCCARD extern int pcmcia_on (void); extern int ide_devices_found; /* Initialized in check_ide_device() */ WATCHDOG_RESET(); ide_devices_found = 0; /* initialize the PCMCIA IDE adapter card */ pcmcia_on(); if (!ide_devices_found) return; udelay (1000000); /* 1 s */#endif /* CONFIG_IDE_8xx_PCCARD */ WATCHDOG_RESET();#ifdef CONFIG_IDE_8xx_DIRECT /* Initialize PIO timing tables */ for (i=0; i <= IDE_MAX_PIO_MODE; ++i) { pio_config_clk[i].t_setup = PCMCIA_MK_CLKS(pio_config_ns[i].t_setup, gd->bus_clk); pio_config_clk[i].t_length = PCMCIA_MK_CLKS(pio_config_ns[i].t_length, gd->bus_clk); pio_config_clk[i].t_hold = PCMCIA_MK_CLKS(pio_config_ns[i].t_hold, gd->bus_clk); PRINTF ("PIO Mode %d: setup=%2d ns/%d clk" " len=%3d ns/%d clk" " hold=%2d ns/%d clk\n", i, pio_config_ns[i].t_setup, pio_config_clk[i].t_setup, pio_config_ns[i].t_length, pio_config_clk[i].t_length, pio_config_ns[i].t_hold, pio_config_clk[i].t_hold); }#endif /* CONFIG_IDE_8xx_DIRECT */ /* Reset the IDE just to be sure. * Light LED's to show */ ide_led ((LED_IDE1 | LED_IDE2), 1); /* LED's on */ ide_reset (); /* ATAPI Drives seems to need a proper IDE Reset */#ifdef CONFIG_IDE_8xx_DIRECT /* PCMCIA / IDE initialization for common mem space */ pcmp->pcmc_pgcrb = 0; /* start in PIO mode 0 - most relaxed timings */ pio_mode = 0; set_pcmcia_timing (pio_mode);#endif /* CONFIG_IDE_8xx_DIRECT */ /* * Wait for IDE to get ready. * According to spec, this can take up to 31 seconds! */#ifndef CONFIG_AMIGAONEG3SE for (bus=0; bus<CFG_IDE_MAXBUS; ++bus) { int dev = bus * (CFG_IDE_MAXDEVICE / CFG_IDE_MAXBUS);#else s = getenv("ide_maxbus"); if (s) max_bus_scan = simple_strtol(s, NULL, 10); else max_bus_scan = CFG_IDE_MAXBUS; for (bus=0; bus<max_bus_scan; ++bus) { int dev = bus * (CFG_IDE_MAXDEVICE / max_bus_scan);#endif#ifdef CONFIG_IDE_8xx_PCCARD /* Skip non-ide devices from probing */ if ((ide_devices_found & (1 << bus)) == 0) { ide_led ((LED_IDE1 | LED_IDE2), 0); /* LED's off */ continue; }#endif printf ("Bus %d: ", bus); ide_bus_ok[bus] = 0; /* Select device */ udelay (100000); /* 100 ms */ ide_outb (dev, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(dev)); udelay (100000); /* 100 ms */#ifdef CONFIG_AMIGAONEG3SE ata_reset_time = ATA_RESET_TIME; s = getenv("ide_reset_timeout"); if (s) ata_reset_time = 2*simple_strtol(s, NULL, 10);#endif i = 0; do { udelay (10000); /* 10 ms */ c = ide_inb (dev, ATA_STATUS); i++;#ifdef CONFIG_AMIGAONEG3SE if (i > (ata_reset_time * 100)) {#else if (i > (ATA_RESET_TIME * 100)) {#endif puts ("** Timeout **\n"); ide_led ((LED_IDE1 | LED_IDE2), 0); /* LED's off */#ifdef CONFIG_AMIGAONEG3SE /* If this is the second bus, the first one was OK */ if (bus != 0) { ide_bus_ok[bus] = 0; goto skip_bus; }#endif return; } if ((i >= 100) && ((i%100)==0)) { putc ('.'); } } while (c & ATA_STAT_BUSY); if (c & (ATA_STAT_BUSY | ATA_STAT_FAULT)) { puts ("not available "); PRINTF ("Status = 0x%02X ", c);#ifndef CONFIG_ATAPI /* ATAPI Devices do not set DRDY */ } else if ((c & ATA_STAT_READY) == 0) { puts ("not available "); PRINTF ("Status = 0x%02X ", c);#endif } else { puts ("OK "); ide_bus_ok[bus] = 1; } WATCHDOG_RESET(); }#ifdef CONFIG_AMIGAONEG3SE skip_bus:#endif putc ('\n'); ide_led ((LED_IDE1 | LED_IDE2), 0); /* LED's off */ curr_device = -1; for (i=0; i<CFG_IDE_MAXDEVICE; ++i) {#ifdef CONFIG_IDE_LED int led = (IDE_BUS(i) == 0) ? LED_IDE1 : LED_IDE2;#endif ide_dev_desc[i].type=DEV_TYPE_UNKNOWN; ide_dev_desc[i].if_type=IF_TYPE_IDE; ide_dev_desc[i].dev=i; ide_dev_desc[i].part_type=PART_TYPE_UNKNOWN; ide_dev_desc[i].blksz=0; ide_dev_desc[i].lba=0; ide_dev_desc[i].block_read=ide_read; if (!ide_bus_ok[IDE_BUS(i)]) continue; ide_led (led, 1); /* LED on */ ide_ident(&ide_dev_desc[i]); ide_led (led, 0); /* LED off */ dev_print(&ide_dev_desc[i]);/* ide_print (i); */ if ((ide_dev_desc[i].lba > 0) && (ide_dev_desc[i].blksz > 0)) { init_part (&ide_dev_desc[i]); /* initialize partition type */ if (curr_device < 0) curr_device = i; } } WATCHDOG_RESET();}/* ------------------------------------------------------------------------- */block_dev_desc_t * ide_get_dev(int dev){ return ((block_dev_desc_t *)&ide_dev_desc[dev]);}#ifdef CONFIG_IDE_8xx_DIRECTstatic voidset_pcmcia_timing (int pmode){ volatile immap_t *immr = (immap_t *)CFG_IMMR; volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia); ulong timings; PRINTF ("Set timing for PIO Mode %d\n", pmode); timings = PCMCIA_SHT(pio_config_clk[pmode].t_hold) | PCMCIA_SST(pio_config_clk[pmode].t_setup) | PCMCIA_SL (pio_config_clk[pmode].t_length) ; /* IDE 0 */ pcmp->pcmc_pbr0 = CFG_PCMCIA_PBR0; pcmp->pcmc_por0 = CFG_PCMCIA_POR0#if (CFG_PCMCIA_POR0 != 0) | timings#endif ; PRINTF ("PBR0: %08x POR0: %08x\n", pcmp->pcmc_pbr0, pcmp->pcmc_por0); pcmp->pcmc_pbr1 = CFG_PCMCIA_PBR1; pcmp->pcmc_por1 = CFG_PCMCIA_POR1#if (CFG_PCMCIA_POR1 != 0) | timings#endif ; PRINTF ("PBR1: %08x POR1: %08x\n", pcmp->pcmc_pbr1, pcmp->pcmc_por1); pcmp->pcmc_pbr2 = CFG_PCMCIA_PBR2; pcmp->pcmc_por2 = CFG_PCMCIA_POR2#if (CFG_PCMCIA_POR2 != 0) | timings#endif ; PRINTF ("PBR2: %08x POR2: %08x\n", pcmp->pcmc_pbr2, pcmp->pcmc_por2); pcmp->pcmc_pbr3 = CFG_PCMCIA_PBR3; pcmp->pcmc_por3 = CFG_PCMCIA_POR3#if (CFG_PCMCIA_POR3 != 0) | timings#endif ; PRINTF ("PBR3: %08x POR3: %08x\n", pcmp->pcmc_pbr3, pcmp->pcmc_por3); /* IDE 1 */ pcmp->pcmc_pbr4 = CFG_PCMCIA_PBR4; pcmp->pcmc_por4 = CFG_PCMCIA_POR4#if (CFG_PCMCIA_POR4 != 0) | timings#endif ; PRINTF ("PBR4: %08x POR4: %08x\n", pcmp->pcmc_pbr4, pcmp->pcmc_por4); pcmp->pcmc_pbr5 = CFG_PCMCIA_PBR5; pcmp->pcmc_por5 = CFG_PCMCIA_POR5#if (CFG_PCMCIA_POR5 != 0) | timings#endif ; PRINTF ("PBR5: %08x POR5: %08x\n", pcmp->pcmc_pbr5, pcmp->pcmc_por5); pcmp->pcmc_pbr6 = CFG_PCMCIA_PBR6; pcmp->pcmc_por6 = CFG_PCMCIA_POR6#if (CFG_PCMCIA_POR6 != 0) | timings#endif ; PRINTF ("PBR6: %08x POR6: %08x\n", pcmp->pcmc_pbr6, pcmp->pcmc_por6); pcmp->pcmc_pbr7 = CFG_PCMCIA_PBR7; pcmp->pcmc_por7 = CFG_PCMCIA_POR7#if (CFG_PCMCIA_POR7 != 0) | timings#endif ; PRINTF ("PBR7: %08x POR7: %08x\n", pcmp->pcmc_pbr7, pcmp->pcmc_por7);}#endif /* CONFIG_IDE_8xx_DIRECT *//* ------------------------------------------------------------------------- */#if defined(__PPC__) || defined(CONFIG_PXA_PCMCIA)static void __inline__ide_outb(int dev, int port, unsigned char val){ PRINTF ("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n", dev, port, val, (ATA_CURR_BASE(dev)+port)); /* Ensure I/O operations complete */ EIEIO; *((uchar *)(ATA_CURR_BASE(dev)+port)) = val;}#else /* ! __PPC__ */static void __inline__ide_outb(int dev, int port, unsigned char val){ outb(val, ATA_CURR_BASE(dev)+port);}#endif /* __PPC__ */#if defined(__PPC__) || defined(CONFIG_PXA_PCMCIA)static unsigned char __inline__ide_inb(int dev, int port){ uchar val; /* Ensure I/O operations complete */ EIEIO; val = *((uchar *)(ATA_CURR_BASE(dev)+port)); PRINTF ("ide_inb (dev= %d, port= 0x%x) : @ 0x%08lx -> 0x%02x\n", dev, port, (ATA_CURR_BASE(dev)+port), val); return (val);}#else /* ! __PPC__ */static unsigned char __inline__ide_inb(int dev, int port){ return inb(ATA_CURR_BASE(dev)+port);}#endif /* __PPC__ */#ifdef __PPC__# ifdef CONFIG_AMIGAONEG3SEstatic voidoutput_data_short(int dev, ulong *sect_buf, int words){ ushort *dbuf; volatile ushort *pbuf; pbuf = (ushort *)(ATA_CURR_BASE(dev)+ATA_DATA_REG); dbuf = (ushort *)sect_buf; while (words--) { EIEIO; *pbuf = *dbuf++; EIEIO; } if (words&1) *pbuf = 0;}# endif /* CONFIG_AMIGAONEG3SE */#endif /* __PPC_ *//* We only need to swap data if we are running on a big endian cpu. *//* But Au1x00 cpu:s already swaps data in big endian mode! */#if defined(__LITTLE_ENDIAN) || defined(CONFIG_AU1X00)#define input_swap_data(x,y,z) input_data(x,y,z)#elsestatic voidinput_swap_data(int dev, ulong *sect_buf, int words){#ifndef CONFIG_HMI10 volatile ushort *pbuf = (ushort *)(ATA_CURR_BASE(dev)+ATA_DATA_REG); ushort *dbuf = (ushort *)sect_buf; PRINTF("in input swap data base for read is %lx\n", (unsigned long) pbuf); while (words--) { *dbuf++ = ld_le16(pbuf); *dbuf++ = ld_le16(pbuf); }#else /* CONFIG_HMI10 */ uchar i; volatile uchar *pbuf_even = (uchar *)(ATA_CURR_BASE(dev)+ATA_DATA_EVEN); volatile uchar *pbuf_odd = (uchar *)(ATA_CURR_BASE(dev)+ATA_DATA_ODD); ushort *dbuf = (ushort *)sect_buf; while (words--) { for (i=0; i<2; i++) { *(((uchar *)(dbuf)) + 1) = *pbuf_even; *(uchar *)dbuf = *pbuf_odd; dbuf+=1; } }#endif /* CONFIG_HMI10 */}#endif /* __LITTLE_ENDIAN || CONFIG_AU1X00 */#if defined(__PPC__) || defined(CONFIG_PXA_PCMCIA)static voidoutput_data(int dev, ulong *sect_buf, int words){#ifndef CONFIG_HMI10 ushort *dbuf; volatile ushort *pbuf; pbuf = (ushort *)(ATA_CURR_BASE(dev)+ATA_DATA_REG); dbuf = (ushort *)sect_buf; while (words--) { EIEIO; *pbuf = *dbuf++; EIEIO; *pbuf = *dbuf++; }#else /* CONFIG_HMI10 */ uchar *dbuf; volatile uchar *pbuf_even; volatile uchar *pbuf_odd; pbuf_even = (uchar *)(ATA_CURR_BASE(dev)+ATA_DATA_EVEN); pbuf_odd = (uchar *)(ATA_CURR_BASE(dev)+ATA_DATA_ODD); dbuf = (uchar *)sect_buf; while (words--) { EIEIO; *pbuf_even = *dbuf++; EIEIO; *pbuf_odd = *dbuf++; EIEIO; *pbuf_even = *dbuf++; EIEIO; *pbuf_odd = *dbuf++; }#endif /* CONFIG_HMI10 */}#else /* ! __PPC__ */static voidoutput_data(int dev, ulong *sect_buf, int words){ outsw(ATA_CURR_BASE(dev)+ATA_DATA_REG, sect_buf, words<<1);}#endif /* __PPC__ */#if defined(__PPC__) || defined(CONFIG_PXA_PCMCIA)static voidinput_data(int dev, ulong *sect_buf, int words){#ifndef CONFIG_HMI10 ushort *dbuf; volatile ushort *pbuf; pbuf = (ushort *)(ATA_CURR_BASE(dev)+ATA_DATA_REG); dbuf = (ushort *)sect_buf; PRINTF("in input data base for read is %lx\n", (unsigned long) pbuf); while (words--) { EIEIO; *dbuf++ = *pbuf; EIEIO; *dbuf++ = *pbuf; }#else /* CONFIG_HMI10 */ uchar *dbuf; volatile uchar *pbuf_even; volatile uchar *pbuf_odd; pbuf_even = (uchar *)(ATA_CURR_BASE(dev)+ATA_DATA_EVEN); pbuf_odd = (uchar *)(ATA_CURR_BASE(dev)+ATA_DATA_ODD); dbuf = (uchar *)sect_buf; while (words--) { EIEIO; *dbuf++ = *pbuf_even; EIEIO; *dbuf++ = *pbuf_odd; EIEIO; *dbuf++ = *pbuf_even; EIEIO; *dbuf++ = *pbuf_odd; }#endif /* CONFIG_HMI10 */}#else /* ! __PPC__ */static voidinput_data(int dev, ulong *sect_buf, int words){ insw(ATA_CURR_BASE(dev)+ATA_DATA_REG, sect_buf, words << 1);}#endif /* __PPC__ */#ifdef CONFIG_AMIGAONEG3SEstatic voidinput_data_short(int dev, ulong *sect_buf, int words){ ushort *dbuf; volatile ushort *pbuf; pbuf = (ushort *)(ATA_CURR_BASE(dev)+ATA_DATA_REG); dbuf = (ushort *)sect_buf; while (words--) { EIEIO; *dbuf++ = *pbuf; EIEIO; } if (words&1) { ushort dummy; dummy = *pbuf; }}#endif/* ------------------------------------------------------------------------- */static void ide_ident (block_dev_desc_t *dev_desc){ ulong iobuf[ATA_SECTORWORDS]; unsigned char c; hd_driveid_t *iop = (hd_driveid_t *)iobuf;#ifdef CONFIG_AMIGAONEG3SE int max_bus_scan; char *s;#endif#ifdef CONFIG_ATAPI int retries = 0; int do_retry = 0;#endif#if 0 int mode, cycle_time;#endif int device; device=dev_desc->dev; printf (" Device %d: ", device);#ifdef CONFIG_AMIGAONEG3SE s = getenv("ide_maxbus"); if (s) { max_bus_scan = simple_strtol(s, NULL, 10); } else { max_bus_scan = CFG_IDE_MAXBUS; } if (device >= max_bus_scan*2) { dev_desc->type=DEV_TYPE_UNKNOWN; return; }#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -