On 2016-12-05 13:20, Henning Schild wrote:
> Match the device class and "protocol" while probing and skip unknow
> devices.
> 
> Signed-off-by: Henning Schild <[email protected]>
> 
> diff --git a/inmates/demos/x86/ivshmem-demo.c 
> b/inmates/demos/x86/ivshmem-demo.c
> --- a/inmates/demos/x86/ivshmem-demo.c
> +++ b/inmates/demos/x86/ivshmem-demo.c
> @@ -1,7 +1,7 @@
>  /*
>   * Jailhouse, a Linux-based partitioning hypervisor
>   *
> - * Copyright (c) Siemens AG, 2014
> + * Copyright (c) Siemens AG, 2016

"2014-2016"

>   *
>   * Authors:
>   *  Henning Schild <[email protected]>
> @@ -17,6 +17,8 @@
>  #define IVSHMEM_CFG_SHMEM_PTR        0x40
>  #define IVSHMEM_CFG_SHMEM_SZ 0x48
>  
> +#define JAILHOUSE_SHMEM_PROTO_UNDEFINED      0x0000
> +
>  #define IRQ_VECTOR   32
>  
>  #define MAX_NDEV     4
> @@ -110,23 +112,36 @@
>       printk("IVSHMEM: got interrupt ... %d\n", irq_counter++);
>  }
>  
> +static int match_class_rev(unsigned int class_rev)
> +{
> +     return (class_rev & 0xffffff00) ==
> +             ((PCI_DEV_CLASS_OTHER << 24 |
> +               JAILHOUSE_SHMEM_PROTO_UNDEFINED << 8) & 0xffffff00);

The masking of constants is a bit overkill, so is moving this simple
condition into single-user function IMHO.

> +}
> +
>  void inmate_main(void)
>  {
>       int i;
>       int bdf = 0;
> +     unsigned int class_rev;
>       struct ivshmem_dev_data *d;
>       volatile char *shmem;
>  
>       int_init();
>  
> -again:
> -     bdf = pci_find_device(VENDORID, DEVICEID, bdf);
> -     if (bdf != -1) {
> +     while ((ndevices < MAX_NDEV) &&
> +            (-1 != (bdf = pci_find_device(VENDORID, DEVICEID, bdf)))) {
>               printk("IVSHMEM: Found %04x:%04x at %02x:%02x.%x\n",
>                      pci_read_config(bdf, PCI_CFG_VENDOR_ID, 2),
>                      pci_read_config(bdf, PCI_CFG_DEVICE_ID, 2),
>                      bdf >> 8, (bdf >> 3) & 0x1f, bdf & 0x3);
> -
> +             class_rev = pci_read_config(bdf, 0x8, 4);
> +             if (!match_class_rev(class_rev)) {
> +                     printk("IVSHMEM: class/revision %08x, not supported "
> +                            "skipping device\n", class_rev);

Missed in round #1: This will generate a warning when running in QEMU
e.g. (or any other system config that also has a VETH device). Rather
report about the picked device, I would say.

> +                     bdf++;
> +                     continue;
> +             }
>               ndevices++;
>               d = devs + ndevices - 1;
>               d->bdf = bdf;
> @@ -139,8 +154,6 @@
>               int_set_handler(IRQ_VECTOR + ndevices - 1, irq_handler);
>               pci_msix_set_vector(bdf, IRQ_VECTOR + ndevices - 1, 0);
>               bdf++;
> -             if (ndevices < MAX_NDEV)
> -                     goto again;
>       }
>  
>       if (!ndevices) {
> diff --git a/inmates/lib/x86/inmate.h b/inmates/lib/x86/inmate.h
> --- a/inmates/lib/x86/inmate.h
> +++ b/inmates/lib/x86/inmate.h
> @@ -53,6 +53,8 @@
>  
>  #define PCI_ID_ANY           0xffff
>  
> +#define PCI_DEV_CLASS_OTHER  0xff
> +
>  #define PCI_CAP_MSI          0x05
>  #define PCI_CAP_MSIX         0x11
>  
> 

Jan

-- 
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to