From 14a4f52b0d1b561ce52c4590bdd339497dfd5be5 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 25 Apr 2023 10:54:26 -0600 Subject: ide: Move ATA_CURR_BASE to C file This is not used outside one C file. Move it out of the header to reduce its visbility. Signed-off-by: Simon Glass --- include/ide.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'include') diff --git a/include/ide.h b/include/ide.h index 426cef4e39e..58f6640c61b 100644 --- a/include/ide.h +++ b/include/ide.h @@ -11,9 +11,6 @@ #define IDE_BUS(dev) (dev / (CONFIG_SYS_IDE_MAXDEVICE / CONFIG_SYS_IDE_MAXBUS)) -#define ATA_CURR_BASE(dev) (CONFIG_SYS_ATA_BASE_ADDR+ide_bus_offset[IDE_BUS(dev)]) -extern ulong ide_bus_offset[]; - /* * Function Prototypes */ -- cgit v1.3.1 From 091785110031efe1f417a727ac7db68f2beb3116 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 25 Apr 2023 10:54:28 -0600 Subject: ide: Drop CONFIG_START_IDE This is not used by any board. Drop it. Signed-off-by: Simon Glass --- common/board_r.c | 5 ----- include/ide.h | 7 ------- 2 files changed, 12 deletions(-) (limited to 'include') diff --git a/common/board_r.c b/common/board_r.c index 6b4180b3ecd..7076af64f5d 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -523,12 +523,7 @@ static int initr_post(void) static int initr_ide(void) { puts("IDE: "); -#if defined(CONFIG_START_IDE) - if (board_start_ide()) - ide_init(); -#else ide_init(); -#endif return 0; } #endif diff --git a/include/ide.h b/include/ide.h index 58f6640c61b..9c0d40364a8 100644 --- a/include/ide.h +++ b/include/ide.h @@ -47,11 +47,4 @@ void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts); void ide_led(uchar led, uchar status); -/** - * board_start_ide() - Start up the board IDE interfac - * - * Return: 0 if ok - */ -int board_start_ide(void); - #endif /* _IDE_H */ -- cgit v1.3.1 From 00a79f21c1c178d312635b96035da6aa48eb5321 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 25 Apr 2023 10:54:29 -0600 Subject: ide: Drop init for not using BLK ALl boards use CONFIG_BLK now so this code is not used. Drop it and the header-file #ifdef Signed-off-by: Simon Glass --- common/board_r.c | 12 ------------ include/ide.h | 7 ------- 2 files changed, 19 deletions(-) (limited to 'include') diff --git a/common/board_r.c b/common/board_r.c index 7076af64f5d..d798c00a80a 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -519,15 +519,6 @@ static int initr_post(void) } #endif -#if defined(CONFIG_IDE) && !defined(CONFIG_BLK) -static int initr_ide(void) -{ - puts("IDE: "); - ide_init(); - return 0; -} -#endif - #if defined(CFG_PRAM) /* * Export available size of memory for Linux, taking into account the @@ -778,9 +769,6 @@ static init_fnc_t init_sequence_r[] = { #ifdef CONFIG_POST initr_post, #endif -#if defined(CONFIG_IDE) && !defined(CONFIG_BLK) - initr_ide, -#endif #ifdef CONFIG_LAST_STAGE_INIT INIT_FUNC_WATCHDOG_RESET /* diff --git a/include/ide.h b/include/ide.h index 9c0d40364a8..457f275c61b 100644 --- a/include/ide.h +++ b/include/ide.h @@ -18,17 +18,10 @@ void ide_init(void); struct blk_desc; struct udevice; -#ifdef CONFIG_BLK ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, void *buffer); ulong ide_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, const void *buffer); -#else -ulong ide_read(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt, - void *buffer); -ulong ide_write(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt, - const void *buffer); -#endif #if defined(CONFIG_OF_IDE_FIXUP) int ide_device_present(int dev); -- cgit v1.3.1 From 80778f505c8c7ee18c24cfbcfe011f8a2abf7bcd Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 25 Apr 2023 10:54:30 -0600 Subject: ide: Move ide_init() into probing At present the code does ide_init() as a separate operation, then calls device_probe() to copy over the information. We can call ide_init() from probe just as easily. The only difference is that using 'ide init' twice will do nothing. However it already fails to copy over the new data in that case, so the effect is the same. For now, unbind the block devices and remove the IDE device, which causes the bus to be probed again. Later patches will fix this up fully, so that all blk_desc data is copied across. Since ide_reset() is only called from ide_init(), there is no need to init the ide_dev_desc[] array. This is already done at the end of ide_init() so drop this code. The call to uclass_first_device() is now within the probe() function of the same device, so does nothing. Drop it. Signed-off-by: Simon Glass --- cmd/ide.c | 22 +++++++++++++++++++++- drivers/block/ide.c | 13 ++++++------- include/ide.h | 1 - test/boot/bootdev.c | 2 -- 4 files changed, 27 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/cmd/ide.c b/cmd/ide.c index 6739f0b12d1..ddc87d3a0bb 100644 --- a/cmd/ide.c +++ b/cmd/ide.c @@ -10,12 +10,15 @@ #include #include +#include #include #include #include #include #include #include +#include +#include #include #include @@ -31,8 +34,25 @@ int do_ide(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { if (argc == 2) { if (strncmp(argv[1], "res", 3) == 0) { + struct udevice *dev; + int ret; + puts("\nReset IDE: "); - ide_init(); + ret = uclass_find_first_device(UCLASS_IDE, &dev); + ret = device_remove(dev, DM_REMOVE_NORMAL); + if (!ret) + ret = device_chld_unbind(dev, NULL); + if (ret) { + printf("Cannot remove IDE (err=%dE)\n", ret); + return CMD_RET_FAILURE; + } + + ret = uclass_first_device_err(UCLASS_IDE, &dev); + if (ret) { + printf("Init failed (err=%dE)\n", ret); + return CMD_RET_FAILURE; + } + return 0; } } diff --git a/drivers/block/ide.c b/drivers/block/ide.c index 6f601bcf864..13770484b36 100644 --- a/drivers/block/ide.c +++ b/drivers/block/ide.c @@ -58,8 +58,6 @@ static void ide_reset(void) for (i = 0; i < CONFIG_SYS_IDE_MAXBUS; ++i) ide_bus_ok[i] = 0; - for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i) - ide_dev_desc[i].type = DEV_TYPE_UNKNOWN; ide_set_reset(1); /* assert reset */ @@ -689,9 +687,8 @@ __weak unsigned char ide_inb(int dev, int port) return val; } -void ide_init(void) +static void ide_init(void) { - struct udevice *dev; unsigned char c; int i, bus; @@ -764,8 +761,6 @@ void ide_init(void) dev_print(&ide_dev_desc[i]); } schedule(); - - uclass_first_device(UCLASS_IDE, &dev); } __weak void ide_input_swap_data(int dev, ulong *sect_buf, int words) @@ -1067,7 +1062,9 @@ static int ide_bootdev_bind(struct udevice *dev) static int ide_bootdev_hunt(struct bootdev_hunter *info, bool show) { - ide_init(); + struct udevice *dev; + + uclass_first_device(UCLASS_IDE, &dev); return 0; } @@ -1104,6 +1101,8 @@ static int ide_probe(struct udevice *udev) int i; int ret; + ide_init(); + for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; i++) { if (ide_dev_desc[i].type != DEV_TYPE_UNKNOWN) { sprintf(name, "blk#%d", i); diff --git a/include/ide.h b/include/ide.h index 457f275c61b..3f36b4340d0 100644 --- a/include/ide.h +++ b/include/ide.h @@ -15,7 +15,6 @@ * Function Prototypes */ -void ide_init(void); struct blk_desc; struct udevice; ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index 0899c78c2c4..8cf3f30e0f7 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -376,7 +376,6 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts) ut_assert_nextline("Hunting with: simple_bus"); ut_assert_nextline("Found 2 extension board(s)."); ut_assert_nextline("Hunting with: ide"); - ut_assert_nextline("Bus 0: not available "); /* mmc hunter has already been used so should not run again */ @@ -487,7 +486,6 @@ static int bootdev_test_hunt_prio(struct unit_test_state *uts) /* now try a different priority, verbosely */ ut_assertok(bootdev_hunt_prio(BOOTDEVP_5_SCAN_SLOW, true)); ut_assert_nextline("Hunting with: ide"); - ut_assert_nextline("Bus 0: not available "); ut_assert_nextline("Hunting with: usb"); ut_assert_nextline( "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); -- cgit v1.3.1 From 62d13fa6349e66f839fa855ac3f7ec71a1adfe87 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 25 Apr 2023 10:54:31 -0600 Subject: ide: Drop ide_device_present() This function is not used anymore. Drop it. Signed-off-by: Simon Glass --- drivers/block/ide.c | 9 --------- include/ide.h | 4 ---- 2 files changed, 13 deletions(-) (limited to 'include') diff --git a/drivers/block/ide.c b/drivers/block/ide.c index 13770484b36..b5be022a067 100644 --- a/drivers/block/ide.c +++ b/drivers/block/ide.c @@ -1012,15 +1012,6 @@ WR_OUT: return n; } -#if defined(CONFIG_OF_IDE_FIXUP) -int ide_device_present(int dev) -{ - if (dev >= CONFIG_SYS_IDE_MAXBUS) - return 0; - return ide_dev_desc[dev].type == DEV_TYPE_UNKNOWN ? 0 : 1; -} -#endif - static int ide_blk_probe(struct udevice *udev) { struct blk_desc *desc = dev_get_uclass_plat(udev); diff --git a/include/ide.h b/include/ide.h index 3f36b4340d0..09b0117879f 100644 --- a/include/ide.h +++ b/include/ide.h @@ -22,10 +22,6 @@ ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, ulong ide_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, const void *buffer); -#if defined(CONFIG_OF_IDE_FIXUP) -int ide_device_present(int dev); -#endif - /* * I/O function overrides */ -- cgit v1.3.1 From f8e87e73e496d3f53307d5330c02185ee0b06131 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 25 Apr 2023 10:54:33 -0600 Subject: ide: Drop weak functions These are not used from outside this file anymore. Make them static and remove them from the header file. Signed-off-by: Simon Glass --- drivers/block/ide.c | 14 +++++++------- include/ide.h | 13 ------------- 2 files changed, 7 insertions(+), 20 deletions(-) (limited to 'include') diff --git a/drivers/block/ide.c b/drivers/block/ide.c index 58f1ef8f177..46e110fec5e 100644 --- a/drivers/block/ide.c +++ b/drivers/block/ide.c @@ -75,7 +75,7 @@ static void ide_reset(void) #define ide_reset() /* dummy */ #endif /* CONFIG_IDE_RESET */ -__weak void ide_outb(int dev, int port, unsigned char val) +static 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, ATA_CURR_BASE(dev) + port); @@ -83,7 +83,7 @@ __weak void ide_outb(int dev, int port, unsigned char val) outb(val, ATA_CURR_BASE(dev) + port); } -__weak unsigned char ide_inb(int dev, int port) +static unsigned char ide_inb(int dev, int port) { uchar val; @@ -94,7 +94,7 @@ __weak unsigned char ide_inb(int dev, int port) return val; } -__weak void ide_input_swap_data(int dev, ulong *sect_buf, int words) +static void ide_input_swap_data(int dev, ulong *sect_buf, int words) { uintptr_t paddr = (ATA_CURR_BASE(dev) + ATA_DATA_REG); ushort *dbuf = (ushort *)sect_buf; @@ -164,7 +164,7 @@ OUT: /* since ATAPI may use commands with not 4 bytes alligned length * we have our own transfer functions, 2 bytes alligned */ -__weak void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts) +static void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts) { uintptr_t paddr = (ATA_CURR_BASE(dev) + ATA_DATA_REG); ushort *dbuf; @@ -179,7 +179,7 @@ __weak void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts) } } -__weak void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts) +static void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts) { uintptr_t paddr = (ATA_CURR_BASE(dev) + ATA_DATA_REG); ushort *dbuf; @@ -778,7 +778,7 @@ static void ide_init(void) schedule(); } -__weak void ide_output_data(int dev, const ulong *sect_buf, int words) +static void ide_output_data(int dev, const ulong *sect_buf, int words) { uintptr_t paddr = (ATA_CURR_BASE(dev) + ATA_DATA_REG); ushort *dbuf; @@ -792,7 +792,7 @@ __weak void ide_output_data(int dev, const ulong *sect_buf, int words) } } -__weak void ide_input_data(int dev, ulong *sect_buf, int words) +static void ide_input_data(int dev, ulong *sect_buf, int words) { uintptr_t paddr = (ATA_CURR_BASE(dev) + ATA_DATA_REG); ushort *dbuf; diff --git a/include/ide.h b/include/ide.h index 09b0117879f..8c0eb2a022f 100644 --- a/include/ide.h +++ b/include/ide.h @@ -22,17 +22,4 @@ ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, ulong ide_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, const void *buffer); -/* - * I/O function overrides - */ -unsigned char ide_inb(int dev, int port); -void ide_outb(int dev, int port, unsigned char val); -void ide_input_swap_data(int dev, ulong *sect_buf, int words); -void ide_input_data(int dev, ulong *sect_buf, int words); -void ide_output_data(int dev, const ulong *sect_buf, int words); -void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts); -void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts); - -void ide_led(uchar led, uchar status); - #endif /* _IDE_H */ -- cgit v1.3.1 From 1486c906230ca61580a65421adb26a24f5128a4e Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 25 Apr 2023 10:54:34 -0600 Subject: ide: Create a prototype for ide_set_reset() This is used by a board so should be in the header file. Add it. Signed-off-by: Simon Glass --- drivers/block/ide.c | 2 -- include/ide.h | 10 ++++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/drivers/block/ide.c b/drivers/block/ide.c index 46e110fec5e..fa5f68ffeb0 100644 --- a/drivers/block/ide.c +++ b/drivers/block/ide.c @@ -50,8 +50,6 @@ struct blk_desc ide_dev_desc[CONFIG_SYS_IDE_MAXDEVICE]; #define IDE_SPIN_UP_TIME_OUT 5000 /* 5 sec spin-up timeout */ #ifdef CONFIG_IDE_RESET -extern void ide_set_reset(int idereset); - static void ide_reset(void) { int i; diff --git a/include/ide.h b/include/ide.h index 8c0eb2a022f..b586ba3df4b 100644 --- a/include/ide.h +++ b/include/ide.h @@ -22,4 +22,14 @@ ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, ulong ide_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, const void *buffer); +/** + * ide_set_reset() - Assert or de-assert reset for the IDE device + * + * This is provided by boards which need to reset the device through another + * means, e.g. a GPIO. + * + * @idereset: 1 to assert reset, 0 to de-assert it + */ +void ide_set_reset(int idereset); + #endif /* _IDE_H */ -- cgit v1.3.1 From 646deed40b8ffe9aa9c10b86f1addbb4a9788e91 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 25 Apr 2023 10:54:35 -0600 Subject: ide: Correct use of ATAPI The use of atapi_read() was incorrect dropped. Fix this so that it will be used when needed. Use a udevice for the first argument of atapi_read() so it is consistent with ide_read(). This requires much of the ATAPI code to be brought out from behind the existing #ifdef. It will still be removed by the compiler if it is not needed. Add an atapi flag to struct blk_desc so the information can be retained. Fixes: 145df842b44 ("dm: ide: Add support for driver-model block devices") Fixes: d0075059e4d ("ide: Drop non-DM code for BLK") Reviewed-by: Mattijs Korpershoek Signed-off-by: Simon Glass --- drivers/block/ide.c | 20 +++++++++++++++++--- include/blk.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/drivers/block/ide.c b/drivers/block/ide.c index fa5f68ffeb0..875192cba16 100644 --- a/drivers/block/ide.c +++ b/drivers/block/ide.c @@ -155,7 +155,6 @@ OUT: *last = '\0'; } -#ifdef CONFIG_ATAPI /**************************************************************************** * ATAPI Support */ @@ -422,9 +421,10 @@ error: #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(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt, +ulong atapi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, void *buffer) { + struct blk_desc *block_dev = dev_get_uclass_plat(dev); int device = block_dev->devnum; ulong n = 0; unsigned char ccb[12]; /* Command descriptor block */ @@ -466,6 +466,8 @@ ulong atapi_read(struct blk_desc *block_dev, lbaint_t blknr, lbaint_t blkcnt, return n; } +#ifdef CONFIG_ATAPI + static void atapi_inquiry(struct blk_desc *dev_desc) { unsigned char ccb[12]; /* Command descriptor block */ @@ -653,6 +655,7 @@ static void ide_ident(struct blk_desc *dev_desc) #ifdef CONFIG_ATAPI if (is_atapi) { + dev_desc->atapi = true; atapi_inquiry(dev_desc); return; } @@ -1010,6 +1013,17 @@ WR_OUT: return n; } +ulong ide_or_atapi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, + void *buffer) +{ + struct blk_desc *desc = dev_get_uclass_plat(dev); + + if (IS_ENABLED(CONFIG_ATAPI) && desc->atapi) + return atapi_read(dev, blknr, blkcnt, buffer); + + return ide_read(dev, blknr, blkcnt, buffer); +} + static int ide_blk_probe(struct udevice *udev) { struct blk_desc *desc = dev_get_uclass_plat(udev); @@ -1029,7 +1043,7 @@ static int ide_blk_probe(struct udevice *udev) } static const struct blk_ops ide_blk_ops = { - .read = ide_read, + .read = ide_or_atapi_read, .write = ide_write, }; diff --git a/include/blk.h b/include/blk.h index 1db203c1bab..871922dcde0 100644 --- a/include/blk.h +++ b/include/blk.h @@ -66,6 +66,7 @@ struct blk_desc { /* device can use 48bit addr (ATA/ATAPI v7) */ unsigned char lba48; #endif + unsigned char atapi; /* Use ATAPI protocol */ lbaint_t lba; /* number of blocks */ unsigned long blksz; /* block size */ int log2blksz; /* for convenience: log2(blksz) */ -- cgit v1.3.1 From 1b33fd83179c8f09b79930c9ffca6e8b9dfa37cf Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 25 Apr 2023 10:54:36 -0600 Subject: ide: Make function static Only one function is called from outside this file. Make all the others static. Signed-off-by: Simon Glass --- drivers/block/ide.c | 23 +++++++++++------------ include/ide.h | 11 ----------- 2 files changed, 11 insertions(+), 23 deletions(-) (limited to 'include') diff --git a/drivers/block/ide.c b/drivers/block/ide.c index 875192cba16..1d5e54d6eb9 100644 --- a/drivers/block/ide.c +++ b/drivers/block/ide.c @@ -219,8 +219,8 @@ static uchar atapi_wait_mask(int dev, ulong t, uchar mask, uchar res) /* * issue an atapi command */ -unsigned char atapi_issue(int device, unsigned char *ccb, int ccblen, - unsigned char *buffer, int buflen) +static unsigned char atapi_issue(int device, unsigned char *ccb, int ccblen, + unsigned char *buffer, int buflen) { unsigned char c, err, mask, res; int n; @@ -343,10 +343,9 @@ AI_OUT: #define ATAPI_DRIVE_NOT_READY 100 #define ATAPI_UNIT_ATTN 10 -unsigned char atapi_issue_autoreq(int device, - unsigned char *ccb, - int ccblen, - unsigned char *buffer, int buflen) +static unsigned char atapi_issue_autoreq(int device, unsigned char *ccb, + int ccblen, + unsigned char *buffer, int buflen) { unsigned char sense_data[18], sense_ccb[12]; unsigned char res, key, asc, ascq; @@ -421,8 +420,8 @@ error: #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(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, - void *buffer) +static ulong atapi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, + void *buffer) { struct blk_desc *block_dev = dev_get_uclass_plat(dev); int device = block_dev->devnum; @@ -810,8 +809,8 @@ static void ide_input_data(int dev, ulong *sect_buf, int words) } } -ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, - void *buffer) +static ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, + void *buffer) { struct blk_desc *block_dev = dev_get_uclass_plat(dev); int device = block_dev->devnum; @@ -930,8 +929,8 @@ IDE_READ_E: return n; } -ulong ide_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, - const void *buffer) +static ulong ide_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, + const void *buffer) { struct blk_desc *block_dev = dev_get_uclass_plat(dev); int device = block_dev->devnum; diff --git a/include/ide.h b/include/ide.h index b586ba3df4b..2c25e74ede0 100644 --- a/include/ide.h +++ b/include/ide.h @@ -11,17 +11,6 @@ #define IDE_BUS(dev) (dev / (CONFIG_SYS_IDE_MAXDEVICE / CONFIG_SYS_IDE_MAXBUS)) -/* - * Function Prototypes - */ - -struct blk_desc; -struct udevice; -ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, - void *buffer); -ulong ide_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, - const void *buffer); - /** * ide_set_reset() - Assert or de-assert reset for the IDE device * -- cgit v1.3.1 From 8b1b943a7aa3c2d071982b99220cdee49ed2c5fb Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 25 Apr 2023 10:54:41 -0600 Subject: ide: Avoid preprocessor for CONFIG_LBA48 Use IS_ENABLED() instead for all conditions. Add the 'lba48' flag into struct blk_desc always, since it uses very little space. Use a bool so the meaning is clearer. Signed-off-by: Simon Glass Reviewed-by: Mattijs Korpershoek --- drivers/block/ide.c | 57 +++++++++++++++++++---------------------------------- include/blk.h | 4 +--- 2 files changed, 21 insertions(+), 40 deletions(-) (limited to 'include') diff --git a/drivers/block/ide.c b/drivers/block/ide.c index 6c5227a5c0e..45201333c3c 100644 --- a/drivers/block/ide.c +++ b/drivers/block/ide.c @@ -540,11 +540,9 @@ static void atapi_inquiry(struct blk_desc *dev_desc) ((unsigned long) iobuf[5] << 16) + ((unsigned long) iobuf[6] << 8) + ((unsigned long) iobuf[7]); dev_desc->log2blksz = LOG2(dev_desc->blksz); -#ifdef CONFIG_LBA48 + /* ATAPI devices cannot use 48bit addressing (ATA/ATAPI v7) */ - dev_desc->lba48 = 0; -#endif - return; + dev_desc->lba48 = false; } static void ide_ident(struct blk_desc *dev_desc) @@ -645,9 +643,9 @@ static void ide_ident(struct blk_desc *dev_desc) ((unsigned long)iop.lba_capacity[0]) | ((unsigned long)iop.lba_capacity[1] << 16); -#ifdef CONFIG_LBA48 - if (iop.command_set_2 & 0x0400) { /* LBA 48 support */ - dev_desc->lba48 = 1; + if (IS_ENABLED(CONFIG_LBA48) && (iop.command_set_2 & 0x0400)) { + /* LBA 48 support */ + dev_desc->lba48 = true; for (int i = 0; i < 4; i++) iop.lba48_capacity[i] = be16_to_cpu(iop.lba48_capacity[i]); dev_desc->lba = @@ -656,9 +654,9 @@ static void ide_ident(struct blk_desc *dev_desc) ((unsigned long long)iop.lba48_capacity[2] << 32) | ((unsigned long long)iop.lba48_capacity[3] << 48)); } else { - dev_desc->lba48 = 0; + dev_desc->lba48 = false; } -#endif /* CONFIG_LBA48 */ + /* assuming HD */ dev_desc->type = DEV_TYPE_HARDDISK; dev_desc->blksz = ATA_BLOCKSIZE; @@ -795,15 +793,13 @@ static ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, ulong n = 0; unsigned char c; unsigned char pwrsave = 0; /* power save */ + bool lba48 = false; -#ifdef CONFIG_LBA48 - unsigned char lba48 = 0; - - if (blknr & 0x0000fffff0000000ULL) { + if (IS_ENABLED(CONFIG_LBA48) && (blknr & 0x0000fffff0000000ULL)) { /* more than 28 bits used, use 48bit mode */ - lba48 = 1; + lba48 = true; } -#endif + debug("ide_read dev %d start " LBAF ", blocks " LBAF " buffer at %lX\n", device, blknr, blkcnt, (ulong) buffer); @@ -845,8 +841,7 @@ static ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, printf("IDE read: device %d not ready\n", device); break; } -#ifdef CONFIG_LBA48 - if (lba48) { + if (IS_ENABLED(CONFIG_LBA48) && lba48) { /* write high bits */ ide_outb(device, ATA_SECT_CNT, 0); ide_outb(device, ATA_LBA_LOW, (blknr >> 24) & 0xFF); @@ -858,21 +853,17 @@ static ulong ide_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, ide_outb(device, ATA_LBA_HIGH, 0); #endif } -#endif ide_outb(device, ATA_SECT_CNT, 1); ide_outb(device, ATA_LBA_LOW, (blknr >> 0) & 0xFF); ide_outb(device, ATA_LBA_MID, (blknr >> 8) & 0xFF); ide_outb(device, ATA_LBA_HIGH, (blknr >> 16) & 0xFF); -#ifdef CONFIG_LBA48 - if (lba48) { + if (IS_ENABLED(CONFIG_LBA48) && lba48) { ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); ide_outb(device, ATA_COMMAND, ATA_CMD_PIO_READ_EXT); - } else -#endif - { + } else { ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device) | ((blknr >> 24) & 0xF)); ide_outb(device, ATA_COMMAND, ATA_CMD_PIO_READ); @@ -914,15 +905,12 @@ static ulong ide_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, int device = block_dev->devnum; ulong n = 0; unsigned char c; + bool lba48 = false; -#ifdef CONFIG_LBA48 - unsigned char lba48 = 0; - - if (blknr & 0x0000fffff0000000ULL) { + if (IS_ENABLED(CONFIG_LBA48) && (blknr & 0x0000fffff0000000ULL)) { /* more than 28 bits used, use 48bit mode */ - lba48 = 1; + lba48 = true; } -#endif /* Select device */ @@ -935,8 +923,7 @@ static ulong ide_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, printf("IDE read: device %d not ready\n", device); goto WR_OUT; } -#ifdef CONFIG_LBA48 - if (lba48) { + if (IS_ENABLED(CONFIG_LBA48) && lba48) { /* write high bits */ ide_outb(device, ATA_SECT_CNT, 0); ide_outb(device, ATA_LBA_LOW, (blknr >> 24) & 0xFF); @@ -948,21 +935,17 @@ static ulong ide_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, ide_outb(device, ATA_LBA_HIGH, 0); #endif } -#endif ide_outb(device, ATA_SECT_CNT, 1); ide_outb(device, ATA_LBA_LOW, (blknr >> 0) & 0xFF); ide_outb(device, ATA_LBA_MID, (blknr >> 8) & 0xFF); ide_outb(device, ATA_LBA_HIGH, (blknr >> 16) & 0xFF); -#ifdef CONFIG_LBA48 - if (lba48) { + if (IS_ENABLED(CONFIG_LBA48) && lba48) { ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); ide_outb(device, ATA_COMMAND, ATA_CMD_PIO_WRITE_EXT); - } else -#endif - { + } else { ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device) | ((blknr >> 24) & 0xF)); ide_outb(device, ATA_COMMAND, ATA_CMD_PIO_WRITE); diff --git a/include/blk.h b/include/blk.h index 871922dcde0..2c9c7985a88 100644 --- a/include/blk.h +++ b/include/blk.h @@ -62,10 +62,8 @@ struct blk_desc { unsigned char hwpart; /* HW partition, e.g. for eMMC */ unsigned char type; /* device type */ unsigned char removable; /* removable device */ -#ifdef CONFIG_LBA48 /* device can use 48bit addr (ATA/ATAPI v7) */ - unsigned char lba48; -#endif + bool lba48; unsigned char atapi; /* Use ATAPI protocol */ lbaint_t lba; /* number of blocks */ unsigned long blksz; /* block size */ -- cgit v1.3.1