On 2024/7/8 21:27, Anthony PERARD wrote:
> On Mon, Jul 08, 2024 at 07:41:23PM +0800, Jiqian Chen wrote:
>> diff --git a/tools/libs/ctrl/xc_physdev.c b/tools/libs/ctrl/xc_physdev.c
>> index e9fcd755fa62..54edb0f3c0dc 100644
>> --- a/tools/libs/ctrl/xc_physdev.c
>> +++ b/tools/libs/ctrl/xc_physdev.c
>> @@ -111,3 +111,38 @@ int xc_physdev_unmap_pirq(xc_interface *xch,
>>      return rc;
>>  }
>>  
>> +int -(xc_interface *xch, uint32_t sbdf)
>> +{
>> +    int rc = -1;
>> +
>> +#if defined(__linux__)
>> +    int fd;
>> +    privcmd_gsi_from_pcidev_t dev_gsi = {
>> +        .sbdf = sbdf,
>> +        .gsi = 0,
>> +    };
>> +
>> +    fd = open("/dev/xen/privcmd", O_RDWR);
> 
> 
> You could reuse the already opened fd from libxencall:
>     xencall_fd(xch->xcall)
Do I need to check it this fd<0?

> 
>> +
>> +    if (fd < 0 && (errno == ENOENT || errno == ENXIO || errno == ENODEV)) {
>> +        /* Fallback to /proc/xen/privcmd */
>> +        fd = open("/proc/xen/privcmd", O_RDWR);
>> +    }
>> +
>> +    if (fd < 0) {
>> +        PERROR("Could not obtain handle on privileged command interface");
>> +        return rc;
>> +    }
>> +
>> +    rc = ioctl(fd, IOCTL_PRIVCMD_GSI_FROM_PCIDEV, &dev_gsi);
> 
> I think this would be better implemented in Linux only C file instead of
> using #define. There's already "xc_linux.c" which is probably good
> enough to be used here.
> 
> Implementation for other OS would just set errno to ENOSYS and
> return -1.
Thanks, will change in next version.

> 
> 

-- 
Best regards,
Jiqian Chen.

Reply via email to