|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [RFC XEN PATCH v12 6/7] tools: Add new function to get gsi from dev
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_physdev_gsi_from_pcidev(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)
> +
> + 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.
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |