sysfs implementation in i915
Gilbert Adikankwu
Posted on October 30, 2023
In this article, I explain my understanding of the sysfs implementation of i915. I will attempt to analyze an entry to aid the explanation.
What is sysfs?
Sysfs is a virtual file system that provides a way to export kernel data structures and attributes (think functionality) to the userspace. The data structures are created with objects and are represented as directories and subdirectories in /sys
while the attributes are files inside these directories. The files contain
kernel-generated information that provides functionality to users.
What is i915?
i915 driver is an open-source graphics driver for Intel integrated graphics chipset. It supports the Intel i915 family of chipsets, including the Intel HD Graphics 2000/3000/4000/5000 series graphics processors.
sysfs interface of i915
The sysfs interface of the i915 driver provides a way to access and modify various parameters of the driver and the hardware it controls.
The sysfs interface of the i915 driver is organized into a hierarchy of directories and files. The top-level directory is /sys/class/drm
. This directory contains one subdirectory for each graphics device driver that it manages. sys/class/drm/card0
is the subdirectory for the i915 device driver. Each subdirectory is named after the device’s unique identifier, which is typically a combination of the bus type and address.
The focus of this article is to analyze structs that created this entry /sys/class/drm/card0/gt
drm
is a framework that manages device drivers. i915
is a device driver and gt
is a device.
The gt
device entry shows up as a subdirectory in the i915 sysfs implementation. Things to know about how sysfs entry is created:
- Sysfs entries for kobjects are always directories. A call to kobject_add results in the creation of a directory in sysfs. Usually, that directory contains one or more attributes.
- The name assigned to the kobject is the name used for the sysfs directory.
- The sysfs entry is located in the directory corresponding to the kobject's parent pointer. If parent is NULL when kobject_add is called, it is set to the kobject embedded in the new kobject's kset.
gt
is a kobject. A kobject can be either a device which shows up as a subdirectory in sysfs or a device attribute with shows up as a file inside a device subdirectory in sysfs. The major struct behind every device in sysfs is struct device
. This struct contains information that determines the hierarchy position of the device in the sysfs interface. For the DRM framework, struct device
is embedded inside struct drm_minor
. struct drm_minor
represents a DRM minor number for the device node in /dev. The kernel uses the minor to know the device a device driver is referring to.
struct drm_minor
and struct device
are embedded inside struct drm_device
. Then struct drm_device
is embedded inside struct drm_i915_private
.
It is struct drm_i915_private
that is used to create the gt
subdirectory with the function below.
void i915_setup_sysfs(struct drm_i915_private *dev_priv);
Posted on October 30, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.