Skip to content

Commit f118319

Browse files
committed
Skip virtio-GPU device owned by LIC
virtio-GPU on PCI bus with * vendor id 0x1af4 * device id 0x1110 * subvendor id 0x8086 * subdevice id 0x201 is reserved for usage in Linux in Container (LIC). Skip this device when creating drm devices. Tracked-On: OAM-131266 Signed-off-by: Weifeng Liu <weifeng.liu@intel.com>
1 parent bf884fc commit f118319

File tree

1 file changed

+50
-17
lines changed

1 file changed

+50
-17
lines changed

drm/ResourceManager.cpp

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,55 @@ ResourceManager::~ResourceManager() {
4747
uevent_listener_.Exit();
4848
}
4949

50-
static int FindVirtioGpuCard(ResourceManager *res_man, char* path_pattern,
51-
int start, int end) {
52-
bool find = false;
53-
int i = 0;
54-
for (i = start; i <= end; i++) {
50+
static bool IsVirtioGpuOwnedByLic(int fd) {
51+
drmDevicePtr drm_device = NULL;
52+
bool result = false;
53+
54+
if(drmGetDevice(fd, &drm_device) < 0) {
55+
ALOGE("Failed to get drm device info: %s\n", strerror(errno));
56+
return false;
57+
}
58+
59+
// virtio-GPU with subdevice id 0x201 should be owned by LIC, don't touch it.
60+
if (drm_device->bustype == DRM_BUS_PCI &&
61+
drm_device->deviceinfo.pci->vendor_id == 0x1af4 &&
62+
drm_device->deviceinfo.pci->device_id == 0x1110 &&
63+
drm_device->deviceinfo.pci->subvendor_id == 0x8086 &&
64+
drm_device->deviceinfo.pci->subdevice_id == 0x201) {
65+
result = true;
66+
}
67+
drmFreeDevice(&drm_device);
68+
return result;
69+
}
70+
71+
static int FindVirtioGpuCard(char* path_pattern, int start, int end) {
72+
for (int i = start; i <= end; i++) {
5573
std::ostringstream path;
5674
path << path_pattern << i;
57-
auto dev = DrmDevice::CreateInstance(path.str(), res_man);
58-
if (dev != nullptr) {
59-
if (dev->GetName() == "virtio_gpu") {
60-
find = true;
61-
break;
62-
}
75+
auto fd = UniqueFd(open(path.str().c_str(), O_RDWR | O_CLOEXEC));
76+
if (!fd) {
77+
continue;
6378
}
79+
80+
if (IsVirtioGpuOwnedByLic(fd.Get())) {
81+
ALOGI("Skip drm device %s for LIC\n", path.str().c_str());
82+
continue;
83+
}
84+
85+
drmVersionPtr version = drmGetVersion(fd.Get());
86+
if (version == NULL) {
87+
ALOGE("Failed to get version for drm device %s\n", path.str().c_str());
88+
continue;
89+
}
90+
if (strncmp(version->name, "virtio_gpu", version->name_len) == 0) {
91+
drmFreeVersion(version);
92+
return i;
93+
}
94+
drmFreeVersion(version);
6495
}
65-
if (find) {
66-
return i;
67-
} else {
68-
return -1;
69-
}
96+
97+
ALOGD("No virtio-GPU device found\n");
98+
return -1;
7099
}
71100

72101
void ResourceManager::ReloadNode() {
@@ -84,6 +113,10 @@ void ResourceManager::ReloadNode() {
84113

85114
auto dev = DrmDevice::CreateInstance(path.str(), this);
86115
if (dev && DrmDevice::IsIvshmDev(dev->GetFd())) {
116+
if (IsVirtioGpuOwnedByLic(dev->GetFd())) {
117+
ALOGD("Skip drm device owned by LIC: %s\n", path.str().c_str());
118+
break;
119+
}
87120
ALOGD("create ivshmem node card%d, the fd of dev is %x\n", idx, dev->GetFd());
88121
drms_.emplace_back(std::move(dev));
89122
reloaded_ = true;
@@ -134,7 +167,7 @@ void ResourceManager::Init() {
134167
drms_.emplace_back(std::move(dev));
135168
}
136169
} else if (node_num <= 3) {
137-
int card_id = FindVirtioGpuCard(this, path_pattern, 0, node_num - 1);
170+
int card_id = FindVirtioGpuCard(path_pattern, 0, node_num - 1);
138171
if (card_id < 0) {
139172
card_id = 0;
140173
}

0 commit comments

Comments
 (0)