Merge branch 'master' of git://git.denx.de/u-boot-x86
[oweals/u-boot.git] / common / cmd_ide.c
index f3c0425d9892e73d185fdaec0c0a5f04f9c47cdb..f19a7ce42a728895ecb3582bd35d7487c2ef559e 100644 (file)
@@ -79,8 +79,8 @@ static void ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len
 
 #ifdef CONFIG_ATAPI
 static void    atapi_inquiry(block_dev_desc_t *dev_desc);
-static ulong atapi_read(int device, ulong blknr, lbaint_t blkcnt,
-                       void *buffer);
+static ulong atapi_read(block_dev_desc_t *block_dev, lbaint_t blknr,
+                       lbaint_t blkcnt, void *buffer);
 #endif
 
 
@@ -187,6 +187,7 @@ int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
                if (strcmp(argv[1], "read") == 0) {
                        ulong addr = simple_strtoul(argv[2], NULL, 16);
                        ulong cnt = simple_strtoul(argv[4], NULL, 16);
+                       block_dev_desc_t *dev_desc;
                        ulong n;
 
 #ifdef CONFIG_SYS_64BIT_LBA
@@ -201,9 +202,9 @@ int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
                                curr_device, blk, cnt);
 #endif
 
-                       n = ide_dev_desc[curr_device].block_read(curr_device,
-                                                                blk, cnt,
-                                                                (ulong *)addr);
+                       dev_desc = &ide_dev_desc[curr_device];
+                       n = dev_desc->block_read(dev_desc, blk, cnt,
+                                                (ulong *)addr);
                        /* flush cache after read */
                        flush_cache(addr,
                                    cnt * ide_dev_desc[curr_device].blksz);
@@ -230,7 +231,8 @@ int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
                        printf("\nIDE write: device %d block # %ld, count %ld ... ",
                                curr_device, blk, cnt);
 #endif
-                       n = ide_write(curr_device, blk, cnt, (ulong *) addr);
+                       n = ide_write(&ide_dev_desc[curr_device], blk, cnt,
+                                     (ulong *)addr);
 
                        printf("%ld blocks written: %s\n",
                                n, (n == cnt) ? "OK" : "ERROR");
@@ -253,7 +255,7 @@ int do_diskboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 
 /* ------------------------------------------------------------------------- */
 
-void __ide_led(uchar led, uchar status)
+__weak void ide_led(uchar led, uchar status)
 {
 #if defined(CONFIG_IDE_LED) && defined(PER8_BASE) /* required by LED_PORT */
        static uchar led_buffer;        /* Buffer for current LED status */
@@ -269,9 +271,6 @@ void __ide_led(uchar led, uchar status)
 #endif
 }
 
-void ide_led(uchar led, uchar status)
-       __attribute__ ((weak, alias("__ide_led")));
-
 #ifndef CONFIG_IDE_LED /* define LED macros, they are not used anyways */
 # define DEVICE_LED(x) 0
 # define LED_IDE1 1
@@ -280,7 +279,7 @@ void ide_led(uchar led, uchar status)
 
 /* ------------------------------------------------------------------------- */
 
-inline void __ide_outb(int dev, int port, unsigned char val)
+__weak void ide_outb(int dev, int port, unsigned char val)
 {
        debug("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n",
              dev, port, val,
@@ -299,10 +298,7 @@ inline void __ide_outb(int dev, int port, unsigned char val)
 #endif
 }
 
-void ide_outb(int dev, int port, unsigned char val)
-       __attribute__ ((weak, alias("__ide_outb")));
-
-inline unsigned char __ide_inb(int dev, int port)
+__weak unsigned char ide_inb(int dev, int port)
 {
        uchar val;
 
@@ -318,9 +314,6 @@ inline unsigned char __ide_inb(int dev, int port)
        return val;
 }
 
-unsigned char ide_inb(int dev, int port)
-       __attribute__ ((weak, alias("__ide_inb")));
-
 void ide_init(void)
 {
        unsigned char c;
@@ -461,23 +454,14 @@ block_dev_desc_t *ide_get_dev(int dev)
 
 /* ------------------------------------------------------------------------- */
 
-void ide_input_swap_data(int dev, ulong *sect_buf, int words)
-       __attribute__ ((weak, alias("__ide_input_swap_data")));
-
-void ide_input_data(int dev, ulong *sect_buf, int words)
-       __attribute__ ((weak, alias("__ide_input_data")));
-
-void ide_output_data(int dev, const ulong *sect_buf, int words)
-       __attribute__ ((weak, alias("__ide_output_data")));
-
 /* We only need to swap data if we are running on a big endian cpu. */
 #if defined(__LITTLE_ENDIAN)
-void __ide_input_swap_data(int dev, ulong *sect_buf, int words)
+__weak void ide_input_swap_data(int dev, ulong *sect_buf, int words)
 {
        ide_input_data(dev, sect_buf, words);
 }
 #else
-void __ide_input_swap_data(int dev, ulong *sect_buf, int words)
+__weak void ide_input_swap_data(int dev, ulong *sect_buf, int words)
 {
        volatile ushort *pbuf =
                (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
@@ -500,7 +484,7 @@ void __ide_input_swap_data(int dev, ulong *sect_buf, int words)
 
 
 #if defined(CONFIG_IDE_SWAP_IO)
-void __ide_output_data(int dev, const ulong *sect_buf, int words)
+__weak void ide_output_data(int dev, const ulong *sect_buf, int words)
 {
        ushort *dbuf;
        volatile ushort *pbuf;
@@ -515,7 +499,7 @@ void __ide_output_data(int dev, const ulong *sect_buf, int words)
        }
 }
 #else  /* ! CONFIG_IDE_SWAP_IO */
-void __ide_output_data(int dev, const ulong *sect_buf, int words)
+__weak void ide_output_data(int dev, const ulong *sect_buf, int words)
 {
 #if defined(CONFIG_IDE_AHB)
        ide_write_data(dev, sect_buf, words);
@@ -526,7 +510,7 @@ void __ide_output_data(int dev, const ulong *sect_buf, int words)
 #endif /* CONFIG_IDE_SWAP_IO */
 
 #if defined(CONFIG_IDE_SWAP_IO)
-void __ide_input_data(int dev, ulong *sect_buf, int words)
+__weak void ide_input_data(int dev, ulong *sect_buf, int words)
 {
        ushort *dbuf;
        volatile ushort *pbuf;
@@ -544,7 +528,7 @@ void __ide_input_data(int dev, ulong *sect_buf, int words)
        }
 }
 #else  /* ! CONFIG_IDE_SWAP_IO */
-void __ide_input_data(int dev, ulong *sect_buf, int words)
+__weak void ide_input_data(int dev, ulong *sect_buf, int words)
 {
 #if defined(CONFIG_IDE_AHB)
        ide_read_data(dev, sect_buf, words);
@@ -729,8 +713,10 @@ static void ide_ident(block_dev_desc_t *dev_desc)
 
 /* ------------------------------------------------------------------------- */
 
-ulong ide_read(int device, lbaint_t blknr, lbaint_t blkcnt, void *buffer)
+ulong ide_read(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
+              void *buffer)
 {
+       int device = block_dev->dev;
        ulong n = 0;
        unsigned char c;
        unsigned char pwrsave = 0;      /* power save */
@@ -853,8 +839,10 @@ IDE_READ_E:
 /* ------------------------------------------------------------------------- */
 
 
-ulong ide_write(int device, lbaint_t blknr, lbaint_t blkcnt, const void *buffer)
+ulong ide_write(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
+               const void *buffer)
 {
+       int device = block_dev->dev;
        ulong n = 0;
        unsigned char c;
 
@@ -1038,17 +1026,10 @@ int ide_device_present(int dev)
  * ATAPI Support
  */
 
-void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
-       __attribute__ ((weak, alias("__ide_input_data_shorts")));
-
-void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
-       __attribute__ ((weak, alias("__ide_output_data_shorts")));
-
-
 #if defined(CONFIG_IDE_SWAP_IO)
 /* since ATAPI may use commands with not 4 bytes alligned length
  * we have our own transfer functions, 2 bytes alligned */
-void __ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
+__weak void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
        ushort *dbuf;
        volatile ushort *pbuf;
@@ -1065,7 +1046,7 @@ void __ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
        }
 }
 
-void __ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
+__weak void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
        ushort *dbuf;
        volatile ushort *pbuf;
@@ -1083,12 +1064,12 @@ void __ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
 }
 
 #else  /* ! CONFIG_IDE_SWAP_IO */
-void __ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
+__weak void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
        outsw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, shorts);
 }
 
-void __ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
+__weak void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
        insw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, shorts);
 }
@@ -1413,13 +1394,15 @@ static void atapi_inquiry(block_dev_desc_t *dev_desc)
 #define ATAPI_READ_BLOCK_SIZE  2048    /* assuming CD part */
 #define ATAPI_READ_MAX_BLOCK   (ATAPI_READ_MAX_BYTES/ATAPI_READ_BLOCK_SIZE)
 
-ulong atapi_read(int device, ulong blknr, lbaint_t blkcnt, void *buffer)
+ulong atapi_read(block_dev_desc_t *block_dev, lbaint_t blknr, lbaint_t blkcnt,
+                void *buffer)
 {
+       int device = block_dev->dev;
        ulong n = 0;
        unsigned char ccb[12];  /* Command descriptor block */
        ulong cnt;
 
-       debug("atapi_read dev %d start %lX, blocks " LBAF " buffer at %lX\n",
+       debug("atapi_read dev %d start " LBAF " blocks " LBAF " buffer at %lX\n",
              device, blknr, blkcnt, (ulong) buffer);
 
        do {