]> xenbits.xensource.com Git - osstest/seabios.git/commitdiff
geometry: Add boot_lchs_find_*() utility functions
authorSam Eiderman <shmuel.eiderman@oracle.com>
Wed, 12 Jun 2019 09:37:02 +0000 (12:37 +0300)
committerGerd Hoffmann <kraxel@redhat.com>
Wed, 6 Nov 2019 09:56:00 +0000 (10:56 +0100)
Adding the following utility functions:

    * boot_lchs_find_pci_device
    * boot_lchs_find_scsi_device
    * boot_lchs_find_ata_device

These will be used to apply LCHS values received through fw_cfg.

Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com>
Reviewed-by: Arbel Moshe <arbel.moshe@oracle.com>
Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com>
Message-Id: <20190612093704.47175-4-shmuel.eiderman@oracle.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
src/boot.c
src/util.h

index b3d493049ae062bfc9ca62b0ab7d9956a0895085..9248fab95a465a4dc37e02d3dd5f9bbf1702148f 100644 (file)
@@ -157,6 +157,88 @@ loadBootDevices(void)
     }
 }
 
+// Search the bootdevices list for the given glob pattern.
+static BootDevice *
+bootdevice_find(const char *glob)
+{
+    dprintf(1, "Searching bootdevices for: %s\n", glob);
+    int i;
+    for (i = 0; i < BootDeviceCount; i++)
+        if (glob_prefix(glob, BootDevices[i].name))
+            return &BootDevices[i];
+    return NULL;
+}
+
+static BootDevice *
+bootdevice_find_pci_device(struct pci_device *pci)
+{
+    // Find pci device - for example: /pci@i0cf8/ethernet@5
+    char desc[256];
+    build_pci_path(desc, sizeof(desc), "*", pci);
+    return bootdevice_find(desc);
+}
+
+static BootDevice *
+bootdevice_find_scsi_device(struct pci_device *pci, int target, int lun)
+{
+    if (!pci)
+        // support only pci machine for now
+        return NULL;
+    // Find scsi drive - for example: /pci@i0cf8/scsi@5/channel@0/disk@1,0
+    char desc[256], *p;
+    p = build_pci_path(desc, sizeof(desc), "*", pci);
+    snprintf(p, desc+sizeof(desc)-p, "/*@0/*@%x,%x", target, lun);
+    return bootdevice_find(desc);
+}
+
+static BootDevice *
+bootdevice_find_ata_device(struct pci_device *pci, int chanid, int slave)
+{
+    if (!pci)
+        // support only pci machine for now
+        return NULL;
+    // Find ata drive - for example: /pci@i0cf8/ide@1,1/drive@1/disk@0
+    char desc[256], *p;
+    p = build_pci_path(desc, sizeof(desc), "*", pci);
+    snprintf(p, desc+sizeof(desc)-p, "/drive@%x/disk@%x", chanid, slave);
+    return bootdevice_find(desc);
+}
+
+int boot_lchs_find_pci_device(struct pci_device *pci, struct chs_s *chs)
+{
+    BootDevice *b = bootdevice_find_pci_device(pci);
+    if (!b)
+        return -1;
+    chs->cylinder = (u16)b->lcyls;
+    chs->head = (u16)b->lheads;
+    chs->sector = (u16)b->lsecs;
+    return 0;
+}
+
+int boot_lchs_find_scsi_device(struct pci_device *pci, int target, int lun,
+                               struct chs_s *chs)
+{
+    BootDevice *b = bootdevice_find_scsi_device(pci, target, lun);
+    if (!b)
+        return -1;
+    chs->cylinder = (u16)b->lcyls;
+    chs->head = (u16)b->lheads;
+    chs->sector = (u16)b->lsecs;
+    return 0;
+}
+
+int boot_lchs_find_ata_device(struct pci_device *pci, int chanid, int slave,
+                              struct chs_s *chs)
+{
+    BootDevice *b = bootdevice_find_ata_device(pci, chanid, slave);
+    if (!b)
+        return -1;
+    chs->cylinder = (u16)b->lcyls;
+    chs->head = (u16)b->lheads;
+    chs->sector = (u16)b->lsecs;
+    return 0;
+}
+
 
 /****************************************************************
  * Boot priority ordering
index e2afc80c425a55b2141df1e89aa82621ba90c03f..b173fa8898c719b9c558bd512921ed5b6a9a6ea2 100644 (file)
@@ -38,6 +38,12 @@ struct usbdevice_s;
 int bootprio_find_usb(struct usbdevice_s *usbdev, int lun);
 int get_keystroke_full(int msec);
 int get_keystroke(int msec);
+struct chs_s;
+int boot_lchs_find_pci_device(struct pci_device *pci, struct chs_s *chs);
+int boot_lchs_find_scsi_device(struct pci_device *pci, int target, int lun,
+                               struct chs_s *chs);
+int boot_lchs_find_ata_device(struct pci_device *pci, int chanid, int slave,
+                              struct chs_s *chs);
 
 // bootsplash.c
 void enable_vga_console(void);