pc-bios/s390-ccw: Move the inner logic of find_subch() to a separate function

Move the code to a separate function to be able to re-use it from a
different spot later.

Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Message-Id: <20200806105349.632-5-thuth@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
Thomas Huth 2020-07-28 15:50:31 +02:00
parent f3180b0266
commit d2cf4af1f4

View file

@ -51,29 +51,19 @@ unsigned int get_loadparm_index(void)
return atoui(loadparm_str); return atoui(loadparm_str);
} }
/* static int is_dev_possibly_bootable(int dev_no, int sch_no)
* Find the subchannel connected to the given device (dev_no) and fill in the
* subchannel information block (schib) with the connected subchannel's info.
* NOTE: The global variable blk_schid is updated to contain the subchannel
* information.
*
* If the caller gives dev_no=-1 then the user did not specify a boot device.
* In this case we'll just use the first potentially bootable device we find.
*/
static bool find_subch(int dev_no)
{ {
Schib schib;
int i, r;
bool is_virtio; bool is_virtio;
Schib schib;
int r;
for (i = 0; i < 0x10000; i++) { blk_schid.sch_no = sch_no;
blk_schid.sch_no = i;
r = stsch_err(blk_schid, &schib); r = stsch_err(blk_schid, &schib);
if ((r == 3) || (r == -EIO)) { if (r == 3 || r == -EIO) {
break; return -ENODEV;
} }
if (!schib.pmcw.dnv) { if (!schib.pmcw.dnv) {
continue; return false;
} }
enable_subchannel(blk_schid); enable_subchannel(blk_schid);
@ -85,7 +75,7 @@ static bool find_subch(int dev_no)
*/ */
is_virtio = virtio_is_supported(blk_schid); is_virtio = virtio_is_supported(blk_schid);
/* No specific devno given, just return 1st possibly bootable device */ /* No specific devno given, just return whether the device is possibly bootable */
if (dev_no < 0) { if (dev_no < 0) {
switch (cutype) { switch (cutype) {
case CU_TYPE_VIRTIO: case CU_TYPE_VIRTIO:
@ -98,12 +88,12 @@ static bool find_subch(int dev_no)
return true; return true;
} }
} }
continue; return false;
case CU_TYPE_DASD_3990: case CU_TYPE_DASD_3990:
case CU_TYPE_DASD_2107: case CU_TYPE_DASD_2107:
return true; return true;
default: default:
continue; return false;
} }
} }
@ -111,6 +101,31 @@ static bool find_subch(int dev_no)
if (schib.pmcw.dev == dev_no) { if (schib.pmcw.dev == dev_no) {
return true; return true;
} }
return false;
}
/*
* Find the subchannel connected to the given device (dev_no) and fill in the
* subchannel information block (schib) with the connected subchannel's info.
* NOTE: The global variable blk_schid is updated to contain the subchannel
* information.
*
* If the caller gives dev_no=-1 then the user did not specify a boot device.
* In this case we'll just use the first potentially bootable device we find.
*/
static bool find_subch(int dev_no)
{
int i, r;
for (i = 0; i < 0x10000; i++) {
r = is_dev_possibly_bootable(dev_no, i);
if (r < 0) {
break;
}
if (r == true) {
return true;
}
} }
return false; return false;