[SeaBIOS] [PATCH] USB boot priority

Gleb Natapov gleb at redhat.com
Fri Dec 31 07:48:34 CET 2010


On Thu, Dec 30, 2010 at 08:56:07PM -0500, Kevin O'Connor wrote:
> This adds tracking of USB port paths, and enables searching the
> bootorder file based on it.  It's on top of the other patches I've
> sent.
> 
> Gleb - I tried adding:
> 
>   -usb -drive file=dos-drivec,if=none,id=d1 -device usb-storage,drive=d1,bootindex=1
> 
> But qemu didn't add anything to the bootorder file.  (It does register
> the usb drive.)
> 
Hm, I forgot to add bootindex treatment in usb-storage code. Will fix in
qemu.

> -Kevin
> 
> 
> diff --git a/src/boot.c b/src/boot.c
> index 2f9b315..4185102 100644
> --- a/src/boot.c
> +++ b/src/boot.c
> @@ -162,6 +162,21 @@ int bootprio_find_named_rom(const char *name, int instance)
>      return find_prio(desc);
>  }
>  
> +int bootprio_find_usb(int bdf, u64 path)
> +{
> +    // Find usb - for example: /pci at i0cf8/usb at 1,2/hub at 1/network at 0/ethernet at 0
> +    int i;
> +    char desc[256], *p;
> +    p = build_pci_path(desc, sizeof(desc), "usb", bdf);
> +    for (i=56; i>0; i-=8) {
> +        int port = (path >> i) & 0xff;
> +        if (port != 0xff)
> +            p += snprintf(p, desc+sizeof(desc)-p, "/hub@%x", port);
> +    }
> +    snprintf(p, desc+sizeof(desc)-p, "/*@%x", (u32)(path & 0xff));
> +    return find_prio(desc);
> +}
> +
>  
>  /****************************************************************
>   * Boot setup
> diff --git a/src/boot.h b/src/boot.h
> index 8f56ccf..62f4b2b 100644
> --- a/src/boot.h
> +++ b/src/boot.h
> @@ -15,8 +15,9 @@ void boot_add_cbfs(void *data, const char *desc, int prio);
>  void boot_prep(void);
>  int bootprio_find_pci_device(int bdf);
>  int bootprio_find_ata_device(int bdf, int chanid, int slave);
> -int bootprio_find_fdc_device(int bfd, int port, int fdid);
> +int bootprio_find_fdc_device(int bdf, int port, int fdid);
>  int bootprio_find_pci_rom(int bdf, int instance);
>  int bootprio_find_named_rom(const char *name, int instance);
> +int bootprio_find_usb(int bdf, u64 path);
>  
>  #endif // __BOOT_H
> diff --git a/src/usb-ehci.c b/src/usb-ehci.c
> index 4e228bd..f11924a 100644
> --- a/src/usb-ehci.c
> +++ b/src/usb-ehci.c
> @@ -265,6 +265,7 @@ ehci_init(u16 bdf, int busid, int compbdf)
>      struct usb_ehci_s *cntl = malloc_tmphigh(sizeof(*cntl));
>      memset(cntl, 0, sizeof(*cntl));
>      cntl->usb.busid = busid;
> +    cntl->usb.bdf = bdf;
>      cntl->usb.type = USB_TYPE_EHCI;
>      cntl->caps = caps;
>      cntl->regs = (void*)caps + readb(&caps->caplength);
> diff --git a/src/usb-msc.c b/src/usb-msc.c
> index d5fe7ba..58a5d14 100644
> --- a/src/usb-msc.c
> +++ b/src/usb-msc.c
> @@ -143,7 +143,10 @@ setup_drive_cdrom(struct disk_op_s *op, char *desc)
>  {
>      op->drive_g->blksize = CDROM_SECTOR_SIZE;
>      op->drive_g->sectors = (u64)-1;
> -    boot_add_cd(op->drive_g, desc, -1);
> +    struct usb_pipe *pipe = container_of(
> +        op->drive_g, struct usbdrive_s, drive)->bulkout;
> +    int prio = bootprio_find_usb(pipe->cntl->bdf, pipe->path);
> +    boot_add_cd(op->drive_g, desc, prio);
>      return 0;
>  }
>  
> @@ -168,7 +171,10 @@ setup_drive_hd(struct disk_op_s *op, char *desc)
>      dprintf(1, "USB MSC blksize=%d sectors=%d\n", blksize, sectors);
>  
>      // Register with bcv system.
> -    boot_add_hd(op->drive_g, desc, -1);
> +    struct usb_pipe *pipe = container_of(
> +        op->drive_g, struct usbdrive_s, drive)->bulkout;
> +    int prio = bootprio_find_usb(pipe->cntl->bdf, pipe->path);
> +    boot_add_hd(op->drive_g, desc, prio);
>  
>      return 0;
>  }
> diff --git a/src/usb-ohci.c b/src/usb-ohci.c
> index 7e91b9f..86eba0d 100644
> --- a/src/usb-ohci.c
> +++ b/src/usb-ohci.c
> @@ -211,6 +211,7 @@ ohci_init(u16 bdf, int busid)
>      struct usb_ohci_s *cntl = malloc_tmphigh(sizeof(*cntl));
>      memset(cntl, 0, sizeof(*cntl));
>      cntl->usb.busid = busid;
> +    cntl->usb.bdf = bdf;
>      cntl->usb.type = USB_TYPE_OHCI;
>  
>      u32 baseaddr = pci_config_readl(bdf, PCI_BASE_ADDRESS_0);
> diff --git a/src/usb-uhci.c b/src/usb-uhci.c
> index 6549808..40f83bb 100644
> --- a/src/usb-uhci.c
> +++ b/src/usb-uhci.c
> @@ -186,6 +186,7 @@ uhci_init(u16 bdf, int busid)
>      struct usb_uhci_s *cntl = malloc_tmphigh(sizeof(*cntl));
>      memset(cntl, 0, sizeof(*cntl));
>      cntl->usb.busid = busid;
> +    cntl->usb.bdf = bdf;
>      cntl->usb.type = USB_TYPE_UHCI;
>      cntl->iobase = (pci_config_readl(bdf, PCI_BASE_ADDRESS_4)
>                      & PCI_BASE_ADDRESS_IO_MASK);
> diff --git a/src/usb.c b/src/usb.c
> index aa8d72c..a07bc1f 100644
> --- a/src/usb.c
> +++ b/src/usb.c
> @@ -259,6 +259,7 @@ usb_set_address(struct usbhub_s *hub, int port, int speed)
>          dummy.cntl = cntl;
>          dummy.type = cntl->type;
>          dummy.maxpacket = 8;
> +        dummy.path = (u64)-1;
>          cntl->defaultpipe = defpipe = alloc_default_control_pipe(&dummy);
>          if (!defpipe)
>              return NULL;
> @@ -294,6 +295,9 @@ usb_set_address(struct usbhub_s *hub, int port, int speed)
>      defpipe->devaddr = cntl->maxaddr;
>      struct usb_pipe *pipe = alloc_default_control_pipe(defpipe);
>      defpipe->devaddr = 0;
> +    if (hub->pipe)
> +        pipe->path = hub->pipe->path;
> +    pipe->path = (pipe->path << 8) | port;
>      return pipe;
>  }
>  
> diff --git a/src/usb.h b/src/usb.h
> index f28a3a7..966e94b 100644
> --- a/src/usb.h
> +++ b/src/usb.h
> @@ -7,6 +7,7 @@
>  // Information on a USB end point.
>  struct usb_pipe {
>      struct usb_s *cntl;
> +    u64 path;
>      u8 type;
>      u8 ep;
>      u8 devaddr;
> @@ -21,6 +22,7 @@ struct usb_s {
>      struct usb_pipe *defaultpipe;
>      struct mutex_s resetlock;
>      int busid;
> +    u16 bdf;
>      u8 type;
>      u8 maxaddr;
>  };
> 
> _______________________________________________
> SeaBIOS mailing list
> SeaBIOS at seabios.org
> http://www.seabios.org/mailman/listinfo/seabios

--
			Gleb.



More information about the SeaBIOS mailing list