[PATCH 0/2] ide: remove global channels list

Here are another couple of patches which convert the IDE channel and drive pointers into instance variables, allowing the global IDE channels list to be removed. Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> Mark Cave-Ayland (2): ide: use instance values to hold C drive and channel structures ide: locate drives by iterating over the device tree during ob_ide_quiesce() drivers/ide.c | 71 +++++++++++++++++---------------------------------- drivers/ide.h | 1 - 2 files changed, 23 insertions(+), 49 deletions(-) -- 2.20.1

Rather than iterate over the global IDE channels list, use instance variables to hold the relevant pointers. This allows us to remove ide_seek_channel() since it is no longer necessary for each IDE device to iterate over the global list in order to locate the drive/channel information. Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> --- drivers/ide.c | 41 +++++++++++++++-------------------------- drivers/ide.h | 1 - 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/drivers/ide.c b/drivers/ide.c index e56cb4c..62c20b9 100644 --- a/drivers/ide.c +++ b/drivers/ide.c @@ -73,19 +73,6 @@ static inline void ide_add_channel(struct ide_channel *chan) channels = chan; } -static struct ide_channel *ide_seek_channel(phandle_t ph) -{ - struct ide_channel *current; - - current = channels; - while (current) { - if (current->ph == ph) - return current; - current = current->next; - } - return NULL; -} - /* * don't be pedantic */ @@ -1230,18 +1217,10 @@ ob_ide_open(int *idx) int ret=1; phandle_t ph; struct ide_drive *drive; - struct ide_channel *chan; - int unit; - fword("my-unit"); - unit = POP(); - - fword("my-parent"); - fword("ihandle>phandle"); - ph=(phandle_t)POP(); - - chan = ide_seek_channel(ph); - drive = &chan->drives[unit]; + PUSH(find_ih_method("drive", my_self())); + fword("execute"); + drive = cell2pointer(POP()); *(struct ide_drive **)idx = drive; IDE_DPRINTF("opening channel %d unit %d\n", idx[1], idx[0]); @@ -1437,7 +1416,9 @@ int ob_ide_init(const char *path, uint32_t io_port0, uint32_t ctl_port0, fword("new-device"); dnode = get_cur_dev(); - chan->ph = dnode; + + PUSH(pointer2cell(chan)); + feval("value chan"); BIND_NODE_METHODS(get_cur_dev(), ob_ide_ctrl); @@ -1500,6 +1481,9 @@ int ob_ide_init(const char *path, uint32_t io_port0, uint32_t ctl_port0, push_str("block"); fword("device-type"); + PUSH(pointer2cell(drive)); + feval("value drive"); + BIND_NODE_METHODS(dnode, ob_ide); fword("is-deblocker"); @@ -1626,7 +1610,9 @@ int macio_ide_init(const char *path, uint32_t addr, int nb_channels) fword("new-device"); dnode = get_cur_dev(); - chan->ph = dnode; + + PUSH(pointer2cell(chan)); + feval("value chan"); snprintf(nodebuff, sizeof(nodebuff), DEV_NAME "-%d", current_channel); push_str(nodebuff); @@ -1741,6 +1727,9 @@ int macio_ide_init(const char *path, uint32_t addr, int nb_channels) push_str("block"); fword("device-type"); + PUSH(pointer2cell(drive)); + feval("value drive"); + BIND_NODE_METHODS(dnode, ob_ide); fword("is-deblocker"); diff --git a/drivers/ide.h b/drivers/ide.h index 8983c8e..f6abb7b 100644 --- a/drivers/ide.h +++ b/drivers/ide.h @@ -167,7 +167,6 @@ struct ide_drive { struct ide_channel { - phandle_t ph; struct ide_channel *next; /* -- 2.20.1

It is now possible to locate IDE drives by searching the device tree for "block" type devices containing a C drive instance variable. Rewrite ob_ide_quiesce() to locate and quiesce IDE drives using this method which finally enables us to remove the global IDE channels list and its remaining ide_add_channel() function. Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> --- drivers/ide.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/drivers/ide.c b/drivers/ide.c index 62c20b9..4cc572c 100644 --- a/drivers/ide.c +++ b/drivers/ide.c @@ -65,14 +65,6 @@ DECLARE_UNNAMED_NODE( ob_ide_ctrl, 0, sizeof(int)); static int current_channel = FIRST_UNIT; -static struct ide_channel *channels = NULL; - -static inline void ide_add_channel(struct ide_channel *chan) -{ - chan->next = channels; - channels = chan; -} - /* * don't be pedantic */ @@ -1405,8 +1397,6 @@ int ob_ide_init(const char *path, uint32_t io_port0, uint32_t ctl_port0, chan->drives[j].nr = i * 2 + j; } - ide_add_channel(chan); - ob_ide_probe(chan); if (!chan->present) @@ -1507,23 +1497,21 @@ int ob_ide_init(const char *path, uint32_t io_port0, uint32_t ctl_port0, void ob_ide_quiesce(void) { - struct ide_channel *channel; - int i; + phandle_t ph = 0, xt; + struct ide_drive *drive; - channel = channels; - while (channel) { - for (i = 0; i < 2; i++) { - struct ide_drive *drive = &channel->drives[i]; + while ((ph = dt_iterate_type(ph, "block"))) { + xt = find_package_method("drive", ph); - if (!drive->present) - continue; + if (xt) { + PUSH(xt); + fword("execute"); + drive = cell2pointer(POP()); ob_ide_select_drive(drive); ob_ide_software_reset(drive); ob_ide_device_type_check(drive); } - - channel = channel->next; } } @@ -1604,8 +1592,6 @@ int macio_ide_init(const char *path, uint32_t addr, int nb_channels) continue; } - ide_add_channel(chan); - ob_ide_identify_drives(chan); fword("new-device"); -- 2.20.1

On 22/10/2019 19:05, Mark Cave-Ayland wrote:
Here are another couple of patches which convert the IDE channel and drive pointers into instance variables, allowing the global IDE channels list to be removed.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Mark Cave-Ayland (2): ide: use instance values to hold C drive and channel structures ide: locate drives by iterating over the device tree during ob_ide_quiesce()
drivers/ide.c | 71 +++++++++++++++++---------------------------------- drivers/ide.h | 1 - 2 files changed, 23 insertions(+), 49 deletions(-)
Applied to master. ATB, Mark.
participants (1)
-
Mark Cave-Ayland