kernel-device, generic: add subsystem vendor ID support

Add subsystem vendor ID support, that can be used in pci devices
instead of vendor ID customization.
This commit is contained in:
Daniele Palmas
2022-05-04 11:04:34 +02:00
parent 4140758fdf
commit ff5840c3c7
4 changed files with 56 additions and 17 deletions

View File

@@ -68,6 +68,7 @@ struct _MMKernelDeviceGenericPrivate {
gchar *physdev_sysfs_path;
guint16 physdev_vid;
guint16 physdev_pid;
guint16 physdev_subsystem_vid;
guint16 physdev_revision;
gchar *physdev_manufacturer;
gchar *physdev_product;
@@ -401,6 +402,7 @@ preload_contents_pci (MMKernelDeviceGeneric *self)
self->priv->physdev_sysfs_path = g_strdup (iter);
self->priv->physdev_vid = read_sysfs_attribute_as_hex (self->priv->physdev_sysfs_path, "vendor");
self->priv->physdev_pid = read_sysfs_attribute_as_hex (self->priv->physdev_sysfs_path, "device");
self->priv->physdev_subsystem_vid = read_sysfs_attribute_as_hex (self->priv->physdev_sysfs_path, "subsystem_vendor");
self->priv->physdev_revision = read_sysfs_attribute_as_hex (self->priv->physdev_sysfs_path, "revision");
/* stop traversing as soon as the physical device is found */
break;
@@ -582,6 +584,8 @@ preload_contents (MMKernelDeviceGeneric *self)
mm_obj_dbg (self, " vendor: %04x", self->priv->physdev_vid);
if (self->priv->physdev_pid)
mm_obj_dbg (self, " product: %04x", self->priv->physdev_pid);
if (self->priv->physdev_subsystem_vid)
mm_obj_dbg (self, " subsystem vendor: %04x", self->priv->physdev_subsystem_vid);
if (self->priv->physdev_revision)
mm_obj_dbg (self, " revision: %04x", self->priv->physdev_revision);
if (self->priv->physdev_manufacturer)
@@ -695,6 +699,12 @@ kernel_device_get_physdev_pid (MMKernelDevice *self)
return MM_KERNEL_DEVICE_GENERIC (self)->priv->physdev_pid;
}
static guint16
kernel_device_get_physdev_subsystem_vid (MMKernelDevice *self)
{
return MM_KERNEL_DEVICE_GENERIC (self)->priv->physdev_subsystem_vid;
}
static guint16
kernel_device_get_physdev_revision (MMKernelDevice *self)
{
@@ -808,13 +818,16 @@ check_condition (MMKernelDeviceGeneric *self,
g_strdelimit (attribute, "{}", ' ');
g_strstrip (attribute);
/* VID/PID directly from our API */
/* VID/PID/SUBSYSTEM VID directly from our API */
if (g_str_equal (attribute, "idVendor") || g_str_equal (attribute, "vendor"))
result = ((mm_get_uint_from_hex_str (match->value, &val)) &&
((mm_kernel_device_get_physdev_vid (MM_KERNEL_DEVICE (self)) == val) == condition_equal));
else if (g_str_equal (attribute, "idProduct") || g_str_equal (attribute, "device"))
result = ((mm_get_uint_from_hex_str (match->value, &val)) &&
((mm_kernel_device_get_physdev_pid (MM_KERNEL_DEVICE (self)) == val) == condition_equal));
else if (g_str_equal (attribute, "subsystem_vendor"))
result = ((mm_get_uint_from_hex_str (match->value, &val)) &&
((mm_kernel_device_get_physdev_subsystem_vid (MM_KERNEL_DEVICE (self)) == val) == condition_equal));
/* manufacturer in the physdev */
else if (g_str_equal (attribute, "manufacturer"))
result = ((self->priv->physdev_manufacturer && g_str_equal (self->priv->physdev_manufacturer, match->value)) == condition_equal);
@@ -1201,6 +1214,7 @@ mm_kernel_device_generic_class_init (MMKernelDeviceGenericClass *klass)
kernel_device_class->get_physdev_uid = kernel_device_get_physdev_uid;
kernel_device_class->get_physdev_vid = kernel_device_get_physdev_vid;
kernel_device_class->get_physdev_pid = kernel_device_get_physdev_pid;
kernel_device_class->get_physdev_subsystem_vid = kernel_device_get_physdev_subsystem_vid;
kernel_device_class->get_physdev_revision = kernel_device_get_physdev_revision;
kernel_device_class->get_physdev_sysfs_path = kernel_device_get_physdev_sysfs_path;
kernel_device_class->get_physdev_subsystem = kernel_device_get_physdev_subsystem;

View File

@@ -48,6 +48,7 @@ struct _MMKernelDeviceUdevPrivate {
GUdevDevice *physdev;
guint16 vendor;
guint16 product;
guint16 subsystem_vendor;
guint16 revision;
gchar *driver;
@@ -186,6 +187,7 @@ preload_contents_pci (MMKernelDeviceUdev *self)
if (!self->priv->physdev && (g_strcmp0 (g_udev_device_get_subsystem (iter), "pci") == 0)) {
self->priv->vendor = udev_device_get_sysfs_attr_as_hex (iter, "vendor");
self->priv->product = udev_device_get_sysfs_attr_as_hex (iter, "device");
self->priv->subsystem_vendor = udev_device_get_sysfs_attr_as_hex (iter, "subsystem_vendor");
self->priv->revision = udev_device_get_sysfs_attr_as_hex (iter, "revision");
self->priv->physdev = g_object_ref (iter);
/* stop traversing as soon as the physical device is found */
@@ -296,6 +298,8 @@ preload_contents (MMKernelDeviceUdev *self)
mm_obj_dbg (self, " vendor: %04x", self->priv->vendor);
if (self->priv->product)
mm_obj_dbg (self, " product: %04x", self->priv->product);
if (self->priv->subsystem_vendor)
mm_obj_dbg (self, " subsystem vendor: %04x", self->priv->subsystem_vendor);
if (self->priv->revision)
mm_obj_dbg (self, " revision: %04x", self->priv->revision);
}
@@ -407,6 +411,12 @@ kernel_device_get_physdev_pid (MMKernelDevice *self)
return MM_KERNEL_DEVICE_UDEV (self)->priv->product;
}
static guint16
kernel_device_get_physdev_subsystem_vid (MMKernelDevice *self)
{
return MM_KERNEL_DEVICE_UDEV (self)->priv->subsystem_vendor;
}
static guint16
kernel_device_get_physdev_revision (MMKernelDevice *self)
{
@@ -805,6 +815,7 @@ mm_kernel_device_udev_class_init (MMKernelDeviceUdevClass *klass)
kernel_device_class->get_physdev_uid = kernel_device_get_physdev_uid;
kernel_device_class->get_physdev_vid = kernel_device_get_physdev_vid;
kernel_device_class->get_physdev_pid = kernel_device_get_physdev_pid;
kernel_device_class->get_physdev_subsystem_vid = kernel_device_get_physdev_subsystem_vid;
kernel_device_class->get_physdev_revision = kernel_device_get_physdev_revision;
kernel_device_class->get_physdev_sysfs_path = kernel_device_get_physdev_sysfs_path;
kernel_device_class->get_physdev_subsystem = kernel_device_get_physdev_subsystem;

View File

@@ -105,6 +105,18 @@ mm_kernel_device_get_physdev_vid (MMKernelDevice *self)
0);
}
guint16
mm_kernel_device_get_physdev_subsystem_vid (MMKernelDevice *self)
{
/* when a lower device is available, physdev info taken from it */
if (self->priv->lower_device)
return mm_kernel_device_get_physdev_subsystem_vid (self->priv->lower_device);
return (MM_KERNEL_DEVICE_GET_CLASS (self)->get_physdev_subsystem_vid ?
MM_KERNEL_DEVICE_GET_CLASS (self)->get_physdev_subsystem_vid (self) :
0);
}
guint16
mm_kernel_device_get_physdev_pid (MMKernelDevice *self)
{

View File

@@ -52,14 +52,15 @@ struct _MMKernelDeviceClass {
const gchar * (* get_interface_sysfs_path) (MMKernelDevice *self);
const gchar * (* get_interface_description) (MMKernelDevice *self);
const gchar * (* get_physdev_uid) (MMKernelDevice *self);
guint16 (* get_physdev_vid) (MMKernelDevice *self);
guint16 (* get_physdev_pid) (MMKernelDevice *self);
guint16 (* get_physdev_revision) (MMKernelDevice *self);
const gchar * (* get_physdev_sysfs_path) (MMKernelDevice *self);
const gchar * (* get_physdev_subsystem) (MMKernelDevice *self);
const gchar * (* get_physdev_manufacturer) (MMKernelDevice *self);
const gchar * (* get_physdev_product) (MMKernelDevice *self);
const gchar * (* get_physdev_uid) (MMKernelDevice *self);
guint16 (* get_physdev_vid) (MMKernelDevice *self);
guint16 (* get_physdev_pid) (MMKernelDevice *self);
guint16 (* get_physdev_subsystem_vid) (MMKernelDevice *self);
guint16 (* get_physdev_revision) (MMKernelDevice *self);
const gchar * (* get_physdev_sysfs_path) (MMKernelDevice *self);
const gchar * (* get_physdev_subsystem) (MMKernelDevice *self);
const gchar * (* get_physdev_manufacturer) (MMKernelDevice *self);
const gchar * (* get_physdev_product) (MMKernelDevice *self);
gboolean (* cmp) (MMKernelDevice *a, MMKernelDevice *b);
@@ -88,14 +89,15 @@ gint mm_kernel_device_get_interface_protocol (MMKernelDevice *self);
const gchar *mm_kernel_device_get_interface_sysfs_path (MMKernelDevice *self);
const gchar *mm_kernel_device_get_interface_description (MMKernelDevice *self);
const gchar *mm_kernel_device_get_physdev_uid (MMKernelDevice *self);
guint16 mm_kernel_device_get_physdev_vid (MMKernelDevice *self);
guint16 mm_kernel_device_get_physdev_pid (MMKernelDevice *self);
guint16 mm_kernel_device_get_physdev_revision (MMKernelDevice *self);
const gchar *mm_kernel_device_get_physdev_sysfs_path (MMKernelDevice *self);
const gchar *mm_kernel_device_get_physdev_subsystem (MMKernelDevice *self);
const gchar *mm_kernel_device_get_physdev_manufacturer (MMKernelDevice *self);
const gchar *mm_kernel_device_get_physdev_product (MMKernelDevice *self);
const gchar *mm_kernel_device_get_physdev_uid (MMKernelDevice *self);
guint16 mm_kernel_device_get_physdev_vid (MMKernelDevice *self);
guint16 mm_kernel_device_get_physdev_pid (MMKernelDevice *self);
guint16 mm_kernel_device_get_physdev_subsystem_vid (MMKernelDevice *self);
guint16 mm_kernel_device_get_physdev_revision (MMKernelDevice *self);
const gchar *mm_kernel_device_get_physdev_sysfs_path (MMKernelDevice *self);
const gchar *mm_kernel_device_get_physdev_subsystem (MMKernelDevice *self);
const gchar *mm_kernel_device_get_physdev_manufacturer (MMKernelDevice *self);
const gchar *mm_kernel_device_get_physdev_product (MMKernelDevice *self);
MMKernelDevice *mm_kernel_device_peek_lower_device (MMKernelDevice *self);