diff options
author | Daniel Stone <daniels@collabora.com> | 2022-03-29 13:59:57 +0100 |
---|---|---|
committer | Daniel Stone <daniels@collabora.com> | 2022-04-15 22:40:29 +0000 |
commit | 2b997bb4bb688be00620887c8646ff24ccb9396b (patch) | |
tree | 5376747120f851570f1254fcef2311d4a9114d14 /libkms | |
parent | 85393adb12ad6277b21b885f11a3b94ef2d531db (diff) | |
download | libdrm-2b997bb4bb688be00620887c8646ff24ccb9396b.tar.gz libdrm-2b997bb4bb688be00620887c8646ff24ccb9396b.tar.bz2 libdrm-2b997bb4bb688be00620887c8646ff24ccb9396b.zip |
libkms: Remove libkms completely
libkms was a very early attempt at a KMS management library, that only
got as far as handling requests to create buffers. It has since been
superseded by GBM in doing this, which everyone uses, unlike libkms
which no-one uses.
Remove it from the tree to avoid any confusion.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Diffstat (limited to 'libkms')
-rw-r--r-- | libkms/Android.mk | 51 | ||||
-rw-r--r-- | libkms/Makefile.sources | 23 | ||||
-rw-r--r-- | libkms/api.c | 139 | ||||
-rw-r--r-- | libkms/dumb.c | 216 | ||||
-rw-r--r-- | libkms/exynos.c | 220 | ||||
-rw-r--r-- | libkms/intel.c | 236 | ||||
-rw-r--r-- | libkms/internal.h | 80 | ||||
-rw-r--r-- | libkms/kms-symbols.txt | 8 | ||||
-rw-r--r-- | libkms/libkms.h | 82 | ||||
-rw-r--r-- | libkms/libkms.pc.in | 11 | ||||
-rw-r--r-- | libkms/linux.c | 147 | ||||
-rw-r--r-- | libkms/meson.build | 81 | ||||
-rw-r--r-- | libkms/nouveau.c | 218 | ||||
-rw-r--r-- | libkms/radeon.c | 239 | ||||
-rw-r--r-- | libkms/vmwgfx.c | 207 |
15 files changed, 0 insertions, 1958 deletions
diff --git a/libkms/Android.mk b/libkms/Android.mk deleted file mode 100644 index a8b9489f..00000000 --- a/libkms/Android.mk +++ /dev/null @@ -1,51 +0,0 @@ -DRM_GPU_DRIVERS := $(strip $(filter-out swrast, $(BOARD_GPU_DRIVERS))) - -intel_drivers := i915 i965 i915g iris -radeon_drivers := r300g r600g radeonsi -nouveau_drivers := nouveau -virgl_drivers := virgl -vmwgfx_drivers := vmwgfx - -valid_drivers := \ - $(intel_drivers) \ - $(radeon_drivers) \ - $(nouveau_drivers) \ - $(virgl_drivers) \ - $(vmwgfx_drivers) - -# warn about invalid drivers -invalid_drivers := $(filter-out $(valid_drivers), $(DRM_GPU_DRIVERS)) -ifneq ($(invalid_drivers),) -$(warning invalid GPU drivers: $(invalid_drivers)) -# tidy up -DRM_GPU_DRIVERS := $(filter-out $(invalid_drivers), $(DRM_GPU_DRIVERS)) -endif - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) -include $(LOCAL_PATH)/Makefile.sources - -LOCAL_SRC_FILES := $(LIBKMS_FILES) - -ifneq ($(filter $(vmwgfx_drivers), $(DRM_GPU_DRIVERS)),) -LOCAL_SRC_FILES += $(LIBKMS_VMWGFX_FILES) -endif - -ifneq ($(filter $(intel_drivers), $(DRM_GPU_DRIVERS)),) -LOCAL_SRC_FILES += $(LIBKMS_INTEL_FILES) -endif - -ifneq ($(filter $(nouveau_drivers), $(DRM_GPU_DRIVERS)),) -LOCAL_SRC_FILES += $(LIBKMS_NOUVEAU_FILES) -endif - -ifneq ($(filter $(radeon_drivers), $(DRM_GPU_DRIVERS)),) -LOCAL_SRC_FILES += $(LIBKMS_RADEON_FILES) -endif - -LOCAL_MODULE := libkms -LOCAL_SHARED_LIBRARIES := libdrm - -include $(LIBDRM_COMMON_MK) -include $(BUILD_SHARED_LIBRARY) diff --git a/libkms/Makefile.sources b/libkms/Makefile.sources deleted file mode 100644 index 3191f516..00000000 --- a/libkms/Makefile.sources +++ /dev/null @@ -1,23 +0,0 @@ -LIBKMS_FILES := \ - internal.h \ - linux.c \ - dumb.c \ - api.c - -LIBKMS_VMWGFX_FILES := \ - vmwgfx.c - -LIBKMS_INTEL_FILES := \ - intel.c - -LIBKMS_NOUVEAU_FILES := \ - nouveau.c - -LIBKMS_RADEON_FILES := \ - radeon.c - -LIBKMS_EXYNOS_FILES := \ - exynos.c - -LIBKMS_H_FILES := \ - libkms.h diff --git a/libkms/api.c b/libkms/api.c deleted file mode 100644 index caca1a87..00000000 --- a/libkms/api.c +++ /dev/null @@ -1,139 +0,0 @@ -/************************************************************************** - * - * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -#include <errno.h> -#include <stdlib.h> -#include <string.h> - -#include "libdrm_macros.h" -#include "internal.h" - -drm_public int kms_create(int fd, struct kms_driver **out) -{ - return linux_create(fd, out); -} - -drm_public int kms_get_prop(struct kms_driver *kms, unsigned key, unsigned *out) -{ - switch (key) { - case KMS_BO_TYPE: - break; - default: - return -EINVAL; - } - return kms->get_prop(kms, key, out); -} - -drm_public int kms_destroy(struct kms_driver **kms) -{ - if (!(*kms)) - return 0; - - free(*kms); - *kms = NULL; - return 0; -} - -drm_public int kms_bo_create(struct kms_driver *kms, const unsigned *attr, struct kms_bo **out) -{ - unsigned width = 0; - unsigned height = 0; - enum kms_bo_type type = KMS_BO_TYPE_SCANOUT_X8R8G8B8; - int i; - - for (i = 0; attr[i];) { - unsigned key = attr[i++]; - unsigned value = attr[i++]; - - switch (key) { - case KMS_WIDTH: - width = value; - break; - case KMS_HEIGHT: - height = value; - break; - case KMS_BO_TYPE: - type = value; - break; - default: - return -EINVAL; - } - } - - if (width == 0 || height == 0) - return -EINVAL; - - /* XXX sanity check type */ - - if (type == KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8 && - (width != 64 || height != 64)) - return -EINVAL; - - return kms->bo_create(kms, width, height, type, attr, out); -} - -drm_public int kms_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out) -{ - switch (key) { - case KMS_PITCH: - *out = bo->pitch; - break; - case KMS_HANDLE: - *out = bo->handle; - break; - default: - return -EINVAL; - } - - return 0; -} - -drm_public int kms_bo_map(struct kms_bo *bo, void **out) -{ - return bo->kms->bo_map(bo, out); -} - -drm_public int kms_bo_unmap(struct kms_bo *bo) -{ - return bo->kms->bo_unmap(bo); -} - -drm_public int kms_bo_destroy(struct kms_bo **bo) -{ - int ret; - - if (!(*bo)) - return 0; - - ret = (*bo)->kms->bo_destroy(*bo); - if (ret) - return ret; - - *bo = NULL; - return 0; -} diff --git a/libkms/dumb.c b/libkms/dumb.c deleted file mode 100644 index 17efc10a..00000000 --- a/libkms/dumb.c +++ /dev/null @@ -1,216 +0,0 @@ -/************************************************************************** - * - * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "internal.h" - -#include <sys/ioctl.h> -#include "xf86drm.h" -#include "libdrm_macros.h" - -struct dumb_bo -{ - struct kms_bo base; - unsigned map_count; -}; - -static int -dumb_get_prop(struct kms_driver *kms, unsigned key, unsigned *out) -{ - switch (key) { - case KMS_BO_TYPE: - *out = KMS_BO_TYPE_SCANOUT_X8R8G8B8 | KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8; - break; - default: - return -EINVAL; - } - return 0; -} - -static int -dumb_destroy(struct kms_driver *kms) -{ - free(kms); - return 0; -} - -static int -dumb_bo_create(struct kms_driver *kms, - const unsigned width, const unsigned height, - const enum kms_bo_type type, const unsigned *attr, - struct kms_bo **out) -{ - struct drm_mode_create_dumb arg; - struct dumb_bo *bo; - int i, ret; - - for (i = 0; attr[i]; i += 2) { - switch (attr[i]) { - case KMS_WIDTH: - case KMS_HEIGHT: - break; - case KMS_BO_TYPE: - break; - default: - return -EINVAL; - } - } - - bo = calloc(1, sizeof(*bo)); - if (!bo) - return -ENOMEM; - - memset(&arg, 0, sizeof(arg)); - - /* All BO_TYPE currently are 32bpp formats */ - arg.bpp = 32; - arg.width = width; - arg.height = height; - - ret = drmIoctl(kms->fd, DRM_IOCTL_MODE_CREATE_DUMB, &arg); - if (ret) - goto err_free; - - bo->base.kms = kms; - bo->base.handle = arg.handle; - bo->base.size = arg.size; - bo->base.pitch = arg.pitch; - - *out = &bo->base; - - return 0; - -err_free: - free(bo); - return ret; -} - -static int -dumb_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out) -{ - switch (key) { - default: - return -EINVAL; - } -} - -static int -dumb_bo_map(struct kms_bo *_bo, void **out) -{ - struct dumb_bo *bo = (struct dumb_bo *)_bo; - struct drm_mode_map_dumb arg; - void *map = NULL; - int ret; - - if (bo->base.ptr) { - bo->map_count++; - *out = bo->base.ptr; - return 0; - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = bo->base.handle; - - ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_MODE_MAP_DUMB, &arg); - if (ret) - return ret; - - map = drm_mmap(0, bo->base.size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->base.kms->fd, arg.offset); - if (map == MAP_FAILED) - return -errno; - - bo->base.ptr = map; - bo->map_count++; - *out = bo->base.ptr; - - return 0; -} - -static int -dumb_bo_unmap(struct kms_bo *_bo) -{ - struct dumb_bo *bo = (struct dumb_bo *)_bo; - bo->map_count--; - return 0; -} - -static int -dumb_bo_destroy(struct kms_bo *_bo) -{ - struct dumb_bo *bo = (struct dumb_bo *)_bo; - struct drm_mode_destroy_dumb arg; - int ret; - - if (bo->base.ptr) { - /* XXX Sanity check map_count */ - drm_munmap(bo->base.ptr, bo->base.size); - bo->base.ptr = NULL; - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = bo->base.handle; - - ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &arg); - if (ret) - return -errno; - - free(bo); - return 0; -} - -drm_private int -dumb_create(int fd, struct kms_driver **out) -{ - struct kms_driver *kms; - int ret; - uint64_t cap = 0; - - ret = drmGetCap(fd, DRM_CAP_DUMB_BUFFER, &cap); - if (ret || cap == 0) - return -EINVAL; - - kms = calloc(1, sizeof(*kms)); - if (!kms) - return -ENOMEM; - - kms->fd = fd; - - kms->bo_create = dumb_bo_create; - kms->bo_map = dumb_bo_map; - kms->bo_unmap = dumb_bo_unmap; - kms->bo_get_prop = dumb_bo_get_prop; - kms->bo_destroy = dumb_bo_destroy; - kms->get_prop = dumb_get_prop; - kms->destroy = dumb_destroy; - *out = kms; - - return 0; -} diff --git a/libkms/exynos.c b/libkms/exynos.c deleted file mode 100644 index ef64a668..00000000 --- a/libkms/exynos.c +++ /dev/null @@ -1,220 +0,0 @@ -/* exynos.c - * - * Copyright 2009 Samsung Electronics Co., Ltd. - * Authors: - * SooChan Lim <sc1.lim@samsung.com> - * Sangjin LEE <lsj119@samsung.com> - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "internal.h" - -#include <sys/mman.h> -#include <sys/ioctl.h> -#include "xf86drm.h" - -#include "libdrm_macros.h" -#include "exynos_drm.h" - -struct exynos_bo -{ - struct kms_bo base; - unsigned map_count; -}; - -static int -exynos_get_prop(struct kms_driver *kms, unsigned key, unsigned *out) -{ - switch (key) { - case KMS_BO_TYPE: - *out = KMS_BO_TYPE_SCANOUT_X8R8G8B8 | KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8; - break; - default: - return -EINVAL; - } - return 0; -} - -static int -exynos_destroy(struct kms_driver *kms) -{ - free(kms); - return 0; -} - -static int -exynos_bo_create(struct kms_driver *kms, - const unsigned width, const unsigned height, - const enum kms_bo_type type, const unsigned *attr, - struct kms_bo **out) -{ - struct drm_exynos_gem_create arg; - unsigned size, pitch; - struct exynos_bo *bo; - int i, ret; - - for (i = 0; attr[i]; i += 2) { - switch (attr[i]) { - case KMS_WIDTH: - case KMS_HEIGHT: - case KMS_BO_TYPE: - break; - default: - return -EINVAL; - } - } - - bo = calloc(1, sizeof(*bo)); - if (!bo) - return -ENOMEM; - - if (type == KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8) { - pitch = 64 * 4; - size = 64 * 64 * 4; - } else if (type == KMS_BO_TYPE_SCANOUT_X8R8G8B8) { - pitch = width * 4; - pitch = (pitch + 512 - 1) & ~(512 - 1); - size = pitch * ((height + 4 - 1) & ~(4 - 1)); - } else { - ret = -EINVAL; - goto err_free; - } - - memset(&arg, 0, sizeof(arg)); - arg.size = size; - - ret = drmCommandWriteRead(kms->fd, DRM_EXYNOS_GEM_CREATE, &arg, sizeof(arg)); - if (ret) - goto err_free; - - bo->base.kms = kms; - bo->base.handle = arg.handle; - bo->base.size = size; - bo->base.pitch = pitch; - - *out = &bo->base; - - return 0; - -err_free: - free(bo); - return ret; -} - -static int -exynos_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out) -{ - switch (key) { - default: - return -EINVAL; - } -} - -static int -exynos_bo_map(struct kms_bo *_bo, void **out) -{ - struct exynos_bo *bo = (struct exynos_bo *)_bo; - struct drm_mode_map_dumb arg; - void *map = NULL; - int ret; - - if (bo->base.ptr) { - bo->map_count++; - *out = bo->base.ptr; - return 0; - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = bo->base.handle; - - ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_MODE_MAP_DUMB, &arg); - if (ret) - return ret; - - map = drm_mmap(0, bo->base.size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->base.kms->fd, arg.offset); - if (map == MAP_FAILED) - return -errno; - - bo->base.ptr = map; - bo->map_count++; - *out = bo->base.ptr; - - return 0; -} - -static int -exynos_bo_unmap(struct kms_bo *_bo) -{ - struct exynos_bo *bo = (struct exynos_bo *)_bo; - bo->map_count--; - return 0; -} - -static int -exynos_bo_destroy(struct kms_bo *_bo) -{ - struct exynos_bo *bo = (struct exynos_bo *)_bo; - struct drm_gem_close arg; - int ret; - - if (bo->base.ptr) { - /* XXX Sanity check map_count */ - munmap(bo->base.ptr, bo->base.size); - bo->base.ptr = NULL; - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = bo->base.handle; - - ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_GEM_CLOSE, &arg); - if (ret) - return -errno; - - free(bo); - return 0; -} - -drm_private int -exynos_create(int fd, struct kms_driver **out) -{ - struct kms_driver *kms; - - kms = calloc(1, sizeof(*kms)); - if (!kms) - return -ENOMEM; - - kms->fd = fd; - - kms->bo_create = exynos_bo_create; - kms->bo_map = exynos_bo_map; - kms->bo_unmap = exynos_bo_unmap; - kms->bo_get_prop = exynos_bo_get_prop; - kms->bo_destroy = exynos_bo_destroy; - kms->get_prop = exynos_get_prop; - kms->destroy = exynos_destroy; - *out = kms; - - return 0; -} diff --git a/libkms/intel.c b/libkms/intel.c deleted file mode 100644 index 859e7a0f..00000000 --- a/libkms/intel.c +++ /dev/null @@ -1,236 +0,0 @@ -/************************************************************************** - * - * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "internal.h" - -#include <sys/ioctl.h> -#include "xf86drm.h" -#include "libdrm_macros.h" - -#include "i915_drm.h" - -struct intel_bo -{ - struct kms_bo base; - unsigned map_count; -}; - -static int -intel_get_prop(struct kms_driver *kms, unsigned key, unsigned *out) -{ - switch (key) { - case KMS_BO_TYPE: - *out = KMS_BO_TYPE_SCANOUT_X8R8G8B8 | KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8; - break; - default: - return -EINVAL; - } - return 0; -} - -static int -intel_destroy(struct kms_driver *kms) -{ - free(kms); - return 0; -} - -static int -intel_bo_create(struct kms_driver *kms, - const unsigned width, const unsigned height, - const enum kms_bo_type type, const unsigned *attr, - struct kms_bo **out) -{ - struct drm_i915_gem_create arg; - unsigned size, pitch; - struct intel_bo *bo; - int i, ret; - - for (i = 0; attr[i]; i += 2) { - switch (attr[i]) { - case KMS_WIDTH: - case KMS_HEIGHT: - case KMS_BO_TYPE: - break; - default: - return -EINVAL; - } - } - - bo = calloc(1, sizeof(*bo)); - if (!bo) - return -ENOMEM; - - if (type == KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8) { - pitch = 64 * 4; - size = 64 * 64 * 4; - } else if (type == KMS_BO_TYPE_SCANOUT_X8R8G8B8) { - pitch = width * 4; - pitch = (pitch + 512 - 1) & ~(512 - 1); - size = pitch * ((height + 4 - 1) & ~(4 - 1)); - } else { - free(bo); - return -EINVAL; - } - - memset(&arg, 0, sizeof(arg)); - arg.size = size; - - ret = drmCommandWriteRead(kms->fd, DRM_I915_GEM_CREATE, &arg, sizeof(arg)); - if (ret) - goto err_free; - - bo->base.kms = kms; - bo->base.handle = arg.handle; - bo->base.size = size; - bo->base.pitch = pitch; - - *out = &bo->base; - if (type == KMS_BO_TYPE_SCANOUT_X8R8G8B8 && pitch > 512) { - struct drm_i915_gem_set_tiling tile; - - memset(&tile, 0, sizeof(tile)); - tile.handle = bo->base.handle; - tile.tiling_mode = I915_TILING_X; - tile.stride = bo->base.pitch; - - ret = drmCommandWriteRead(kms->fd, DRM_I915_GEM_SET_TILING, &tile, sizeof(tile)); -#if 0 - if (ret) { - kms_bo_destroy(out); - return ret; - } -#endif - } - - return 0; - -err_free: - free(bo); - return ret; -} - -static int -intel_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out) -{ - switch (key) { - default: - return -EINVAL; - } -} - -static int -intel_bo_map(struct kms_bo *_bo, void **out) -{ - struct intel_bo *bo = (struct intel_bo *)_bo; - struct drm_i915_gem_mmap_gtt arg; - void *map = NULL; - int ret; - - if (bo->base.ptr) { - bo->map_count++; - *out = bo->base.ptr; - return 0; - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = bo->base.handle; - - ret = drmCommandWriteRead(bo->base.kms->fd, DRM_I915_GEM_MMAP_GTT, &arg, sizeof(arg)); - if (ret) - return ret; - - map = drm_mmap(0, bo->base.size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->base.kms->fd, arg.offset); - if (map == MAP_FAILED) - return -errno; - - bo->base.ptr = map; - bo->map_count++; - *out = bo->base.ptr; - - return 0; -} - -static int -intel_bo_unmap(struct kms_bo *_bo) -{ - struct intel_bo *bo = (struct intel_bo *)_bo; - bo->map_count--; - return 0; -} - -static int -intel_bo_destroy(struct kms_bo *_bo) -{ - struct intel_bo *bo = (struct intel_bo *)_bo; - struct drm_gem_close arg; - int ret; - - if (bo->base.ptr) { - /* XXX Sanity check map_count */ - drm_munmap(bo->base.ptr, bo->base.size); - bo->base.ptr = NULL; - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = bo->base.handle; - - ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_GEM_CLOSE, &arg); - if (ret) - return -errno; - - free(bo); - return 0; -} - -drm_private int -intel_create(int fd, struct kms_driver **out) -{ - struct kms_driver *kms; - - kms = calloc(1, sizeof(*kms)); - if (!kms) - return -ENOMEM; - - kms->fd = fd; - - kms->bo_create = intel_bo_create; - kms->bo_map = intel_bo_map; - kms->bo_unmap = intel_bo_unmap; - kms->bo_get_prop = intel_bo_get_prop; - kms->bo_destroy = intel_bo_destroy; - kms->get_prop = intel_get_prop; - kms->destroy = intel_destroy; - *out = kms; - - return 0; -} diff --git a/libkms/internal.h b/libkms/internal.h deleted file mode 100644 index 8b386db6..00000000 --- a/libkms/internal.h +++ /dev/null @@ -1,80 +0,0 @@ -/************************************************************************** - * - * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -#ifndef INTERNAL_H_ -#define INTERNAL_H_ - -#include "libdrm_macros.h" -#include "libkms.h" - -struct kms_driver -{ - int (*get_prop)(struct kms_driver *kms, const unsigned key, - unsigned *out); - int (*destroy)(struct kms_driver *kms); - - int (*bo_create)(struct kms_driver *kms, - unsigned width, - unsigned height, - enum kms_bo_type type, - const unsigned *attr, - struct kms_bo **out); - int (*bo_get_prop)(struct kms_bo *bo, const unsigned key, - unsigned *out); - int (*bo_map)(struct kms_bo *bo, void **out); - int (*bo_unmap)(struct kms_bo *bo); - int (*bo_destroy)(struct kms_bo *bo); - - int fd; -}; - -struct kms_bo -{ - struct kms_driver *kms; - void *ptr; - size_t size; - size_t offset; - size_t pitch; - unsigned handle; -}; - -drm_private int linux_create(int fd, struct kms_driver **out); - -drm_private int vmwgfx_create(int fd, struct kms_driver **out); - -drm_private int intel_create(int fd, struct kms_driver **out); - -drm_private int dumb_create(int fd, struct kms_driver **out); - -drm_private int nouveau_create(int fd, struct kms_driver **out); - -drm_private int radeon_create(int fd, struct kms_driver **out); - -drm_private int exynos_create(int fd, struct kms_driver **out); - -#endif diff --git a/libkms/kms-symbols.txt b/libkms/kms-symbols.txt deleted file mode 100644 index e0ba8c91..00000000 --- a/libkms/kms-symbols.txt +++ /dev/null @@ -1,8 +0,0 @@ -kms_bo_create -kms_bo_destroy -kms_bo_get_prop -kms_bo_map -kms_bo_unmap -kms_create -kms_destroy -kms_get_prop diff --git a/libkms/libkms.h b/libkms/libkms.h deleted file mode 100644 index 930a2bfc..00000000 --- a/libkms/libkms.h +++ /dev/null @@ -1,82 +0,0 @@ -/************************************************************************** - * - * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -#ifndef _LIBKMS_H_ -#define _LIBKMS_H_ - -#if defined(__cplusplus) -extern "C" { -#endif - -/** - * \file - * - */ - -struct kms_driver; -struct kms_bo; - -enum kms_attrib -{ - KMS_TERMINATE_PROP_LIST, -#define KMS_TERMINATE_PROP_LIST KMS_TERMINATE_PROP_LIST - KMS_BO_TYPE, -#define KMS_BO_TYPE KMS_BO_TYPE - KMS_WIDTH, -#define KMS_WIDTH KMS_WIDTH - KMS_HEIGHT, -#define KMS_HEIGHT KMS_HEIGHT - KMS_PITCH, -#define KMS_PITCH KMS_PITCH - KMS_HANDLE, -#define KMS_HANDLE KMS_HANDLE -}; - -enum kms_bo_type -{ - KMS_BO_TYPE_SCANOUT_X8R8G8B8 = (1 << 0), -#define KMS_BO_TYPE_SCANOUT_X8R8G8B8 KMS_BO_TYPE_SCANOUT_X8R8G8B8 - KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8 = (1 << 1), -#define KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8 KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8 -}; - -int kms_create(int fd, struct kms_driver **out); -int kms_get_prop(struct kms_driver *kms, unsigned key, unsigned *out); -int kms_destroy(struct kms_driver **kms); - -int kms_bo_create(struct kms_driver *kms, const unsigned *attr, struct kms_bo **out); -int kms_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out); -int kms_bo_map(struct kms_bo *bo, void **out); -int kms_bo_unmap(struct kms_bo *bo); -int kms_bo_destroy(struct kms_bo **bo); - -#if defined(__cplusplus) -}; -#endif - -#endif diff --git a/libkms/libkms.pc.in b/libkms/libkms.pc.in deleted file mode 100644 index 7c604294..00000000 --- a/libkms/libkms.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: libkms -Description: Library that abstracts away the different mm interface for kernel drivers -Version: 1.0.0 -Libs: -L${libdir} -lkms -Cflags: -I${includedir}/libkms -Requires.private: libdrm diff --git a/libkms/linux.c b/libkms/linux.c deleted file mode 100644 index 56205054..00000000 --- a/libkms/linux.c +++ /dev/null @@ -1,147 +0,0 @@ -/************************************************************************** - * - * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ -/* - * Thanks to krh and jcristau for the tips on - * going from fd to pci id via fstat and udev. - */ - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <xf86drm.h> -#include <string.h> -#include <unistd.h> -#include <sys/stat.h> -#include <sys/types.h> -#ifdef MAJOR_IN_MKDEV -#include <sys/mkdev.h> -#endif -#ifdef MAJOR_IN_SYSMACROS -#include <sys/sysmacros.h> -#endif - -#include "libdrm_macros.h" -#include "internal.h" - -#define PATH_SIZE 512 - -static int -linux_name_from_sysfs(int fd, char **out) -{ - char path[PATH_SIZE+1] = ""; /* initialize to please valgrind */ - char link[PATH_SIZE+1] = ""; - struct stat buffer; - unsigned maj, min; - char* slash_name; - int ret; - - /* - * Inside the sysfs directory for the device there is a symlink - * to the directory representing the driver module, that path - * happens to hold the name of the driver. - * - * So lets get the symlink for the drm device. Then read the link - * and filter out the last directory which happens to be the name - * of the driver, which we can use to load the correct interface. - * - * Thanks to Ray Strode of Plymouth for the code. - */ - - ret = fstat(fd, &buffer); - if (ret) - return -EINVAL; - - if (!S_ISCHR(buffer.st_mode)) - return -EINVAL; - - maj = major(buffer.st_rdev); - min = minor(buffer.st_rdev); - - snprintf(path, PATH_SIZE, "/sys/dev/char/%d:%d/device/driver", maj, min); - - if (readlink(path, link, PATH_SIZE) < 0) - return -EINVAL; - - /* link looks something like this: ../../../bus/pci/drivers/intel */ - slash_name = strrchr(link, '/'); - if (!slash_name) - return -EINVAL; - - /* copy name and at the same time remove the slash */ - *out = strdup(slash_name + 1); - return 0; -} - -static int -linux_from_sysfs(int fd, struct kms_driver **out) -{ - char *name; - int ret; - - ret = linux_name_from_sysfs(fd, &name); - if (ret) - return ret; - -#if HAVE_INTEL - if (!strcmp(name, "intel")) - ret = intel_create(fd, out); - else -#endif -#if HAVE_VMWGFX - if (!strcmp(name, "vmwgfx")) - ret = vmwgfx_create(fd, out); - else -#endif -#if HAVE_NOUVEAU - if (!strcmp(name, "nouveau")) - ret = nouveau_create(fd, out); - else -#endif -#if HAVE_RADEON - if (!strcmp(name, "radeon")) - ret = radeon_create(fd, out); - else -#endif -#if HAVE_EXYNOS - if (!strcmp(name, "exynos")) - ret = exynos_create(fd, out); - else -#endif - ret = -ENOSYS; - - free(name); - return ret; -} - -drm_private int -linux_create(int fd, struct kms_driver **out) -{ - if (!dumb_create(fd, out)) - return 0; - - return linux_from_sysfs(fd, out); -} diff --git a/libkms/meson.build b/libkms/meson.build deleted file mode 100644 index e2adaea3..00000000 --- a/libkms/meson.build +++ /dev/null @@ -1,81 +0,0 @@ -# Copyright © 2017-2018 Intel Corporation - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: - -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -libkms_include = [inc_root, inc_drm] -files_libkms = files( - 'linux.c', - 'dumb.c', - 'api.c', -) -if with_vmwgfx - files_libkms += files('vmwgfx.c') -endif -if with_intel - files_libkms += files('intel.c') -endif -if with_nouveau - files_libkms += files('nouveau.c') -endif -if with_radeon - files_libkms += files('radeon.c') -endif -if with_exynos - files_libkms += files('exynos.c') - libkms_include += include_directories('../exynos') -endif - -libkms = library( - 'kms', - [files_libkms, config_file], - c_args : libdrm_c_args, - include_directories : libkms_include, - link_with : libdrm, - version : '1.0.0', - install : true, -) - -ext_libkms = declare_dependency( - link_with : [libdrm, libkms], - include_directories : [libkms_include], -) - -if meson.version().version_compare('>= 0.54.0') - meson.override_dependency('kms', ext_libkms) -endif - -install_headers('libkms.h', subdir : 'libkms') - -pkg.generate( - libkms, - name : 'libkms', - subdirs : ['libkms'], - version : '1.0.0', - description : 'Library that abstracts away the different mm interfaces for kernel drivers', -) - -test( - 'kms-symbols-check', - symbols_check, - args : [ - '--lib', libkms, - '--symbols-file', files('kms-symbols.txt'), - '--nm', prog_nm.path(), - ], -) diff --git a/libkms/nouveau.c b/libkms/nouveau.c deleted file mode 100644 index 7fe23db3..00000000 --- a/libkms/nouveau.c +++ /dev/null @@ -1,218 +0,0 @@ -/************************************************************************** - * - * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "internal.h" - -#include <sys/ioctl.h> -#include "xf86drm.h" -#include "libdrm_macros.h" - -#include "nouveau_drm.h" - -struct nouveau_bo -{ - struct kms_bo base; - uint64_t map_handle; - unsigned map_count; -}; - -static int -nouveau_get_prop(struct kms_driver *kms, unsigned key, unsigned *out) -{ - switch (key) { - case KMS_BO_TYPE: - *out = KMS_BO_TYPE_SCANOUT_X8R8G8B8 | KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8; - break; - default: - return -EINVAL; - } - return 0; -} - -static int -nouveau_destroy(struct kms_driver *kms) -{ - free(kms); - return 0; -} - -static int -nouveau_bo_create(struct kms_driver *kms, - const unsigned width, const unsigned height, - const enum kms_bo_type type, const unsigned *attr, - struct kms_bo **out) -{ - struct drm_nouveau_gem_new arg; - unsigned size, pitch; - struct nouveau_bo *bo; - int i, ret; - - for (i = 0; attr[i]; i += 2) { - switch (attr[i]) { - case KMS_WIDTH: - case KMS_HEIGHT: - case KMS_BO_TYPE: - break; - default: - return -EINVAL; - } - } - - bo = calloc(1, sizeof(*bo)); - if (!bo) - return -ENOMEM; - - if (type == KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8) { - pitch = 64 * 4; - size = 64 * 64 * 4; - } else if (type == KMS_BO_TYPE_SCANOUT_X8R8G8B8) { - pitch = width * 4; - pitch = (pitch + 512 - 1) & ~(512 - 1); - size = pitch * height; - } else { - free(bo); - return -EINVAL; - } - - memset(&arg, 0, sizeof(arg)); - arg.info.size = size; - arg.info.domain = NOUVEAU_GEM_DOMAIN_MAPPABLE | NOUVEAU_GEM_DOMAIN_VRAM; - arg.info.tile_mode = 0; - arg.info.tile_flags = 0; - arg.align = 512; - arg.channel_hint = 0; - - ret = drmCommandWriteRead(kms->fd, DRM_NOUVEAU_GEM_NEW, &arg, sizeof(arg)); - if (ret) - goto err_free; - - bo->base.kms = kms; - bo->base.handle = arg.info.handle; - bo->base.size = size; - bo->base.pitch = pitch; - bo->map_handle = arg.info.map_handle; - - *out = &bo->base; - - return 0; - -err_free: - free(bo); - return ret; -} - -static int -nouveau_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out) -{ - switch (key) { - default: - return -EINVAL; - } -} - -static int -nouveau_bo_map(struct kms_bo *_bo, void **out) -{ - struct nouveau_bo *bo = (struct nouveau_bo *)_bo; - void *map = NULL; - - if (bo->base.ptr) { - bo->map_count++; - *out = bo->base.ptr; - return 0; - } - - map = drm_mmap(0, bo->base.size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->base.kms->fd, bo->map_handle); - if (map == MAP_FAILED) - return -errno; - - bo->base.ptr = map; - bo->map_count++; - *out = bo->base.ptr; - - return 0; -} - -static int -nouveau_bo_unmap(struct kms_bo *_bo) -{ - struct nouveau_bo *bo = (struct nouveau_bo *)_bo; - bo->map_count--; - return 0; -} - -static int -nouveau_bo_destroy(struct kms_bo *_bo) -{ - struct nouveau_bo *bo = (struct nouveau_bo *)_bo; - struct drm_gem_close arg; - int ret; - - if (bo->base.ptr) { - /* XXX Sanity check map_count */ - drm_munmap(bo->base.ptr, bo->base.size); - bo->base.ptr = NULL; - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = bo->base.handle; - - ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_GEM_CLOSE, &arg); - if (ret) - return -errno; - - free(bo); - return 0; -} - -drm_private int -nouveau_create(int fd, struct kms_driver **out) -{ - struct kms_driver *kms; - - kms = calloc(1, sizeof(*kms)); - if (!kms) - return -ENOMEM; - - kms->fd = fd; - - kms->bo_create = nouveau_bo_create; - kms->bo_map = nouveau_bo_map; - kms->bo_unmap = nouveau_bo_unmap; - kms->bo_get_prop = nouveau_bo_get_prop; - kms->bo_destroy = nouveau_bo_destroy; - kms->get_prop = nouveau_get_prop; - kms->destroy = nouveau_destroy; - *out = kms; - - return 0; -} diff --git a/libkms/radeon.c b/libkms/radeon.c deleted file mode 100644 index 2cb2b11f..00000000 --- a/libkms/radeon.c +++ /dev/null @@ -1,239 +0,0 @@ -/************************************************************************** - * - * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "internal.h" - -#include <sys/ioctl.h> -#include "xf86drm.h" -#include "libdrm_macros.h" - -#include "radeon_drm.h" - - -#define ALIGNMENT 512 - -struct radeon_bo -{ - struct kms_bo base; - unsigned map_count; -}; - -static int -radeon_get_prop(struct kms_driver *kms, unsigned key, unsigned *out) -{ - switch (key) { - case KMS_BO_TYPE: - *out = KMS_BO_TYPE_SCANOUT_X8R8G8B8 | KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8; - break; - default: - return -EINVAL; - } - return 0; -} - -static int -radeon_destroy(struct kms_driver *kms) -{ - free(kms); - return 0; -} - -static int -radeon_bo_create(struct kms_driver *kms, - const unsigned width, const unsigned height, - const enum kms_bo_type type, const unsigned *attr, - struct kms_bo **out) -{ - struct drm_radeon_gem_create arg; - unsigned size, pitch; - struct radeon_bo *bo; - int i, ret; - - for (i = 0; attr[i]; i += 2) { - switch (attr[i]) { - case KMS_WIDTH: - case KMS_HEIGHT: - case KMS_BO_TYPE: - break; - default: - return -EINVAL; - } - } - - switch (type) { - case KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8: - pitch = 4 * 64; - size = 4 * 64 * 64; - break; - case KMS_BO_TYPE_SCANOUT_X8R8G8B8: - pitch = width * 4; - pitch = (pitch + ALIGNMENT - 1) & ~(ALIGNMENT - 1); - size = pitch * height; - break; - default: - return -EINVAL; - } - - bo = calloc(1, sizeof(*bo)); - if (!bo) - return -ENOMEM; - - memset(&arg, 0, sizeof(arg)); - arg.size = size; - arg.alignment = ALIGNMENT; - arg.initial_domain = RADEON_GEM_DOMAIN_CPU; - arg.flags = 0; - arg.handle = 0; - - ret = drmCommandWriteRead(kms->fd, DRM_RADEON_GEM_CREATE, - &arg, sizeof(arg)); - if (ret) - goto err_free; - - bo->base.kms = kms; - bo->base.handle = arg.handle; - bo->base.size = size; - bo->base.pitch = pitch; - bo->base.offset = 0; - bo->map_count = 0; - - *out = &bo->base; - - return 0; - -err_free: - free(bo); - return ret; -} - -static int -radeon_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out) -{ - switch (key) { - default: - return -EINVAL; - } -} - -static int -radeon_bo_map(struct kms_bo *_bo, void **out) -{ - struct radeon_bo *bo = (struct radeon_bo *)_bo; - struct drm_radeon_gem_mmap arg; - void *map = NULL; - int ret; - - if (bo->base.ptr) { - bo->map_count++; - *out = bo->base.ptr; - return 0; - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = bo->base.handle; - arg.offset = bo->base.offset; - arg.size = (uint64_t)bo->base.size; - - ret = drmCommandWriteRead(bo->base.kms->fd, DRM_RADEON_GEM_MMAP, - &arg, sizeof(arg)); - if (ret) - return -errno; - - map = drm_mmap(0, arg.size, PROT_READ | PROT_WRITE, MAP_SHARED, - bo->base.kms->fd, arg.addr_ptr); - if (map == MAP_FAILED) - return -errno; - - bo->base.ptr = map; - bo->map_count++; - *out = bo->base.ptr; - - return 0; -} - -static int -radeon_bo_unmap(struct kms_bo *_bo) -{ - struct radeon_bo *bo = (struct radeon_bo *)_bo; - if (--bo->map_count == 0) { - drm_munmap(bo->base.ptr, bo->base.size); - bo->base.ptr = NULL; - } - return 0; -} - -static int -radeon_bo_destroy(struct kms_bo *_bo) -{ - struct radeon_bo *bo = (struct radeon_bo *)_bo; - struct drm_gem_close arg; - int ret; - - if (bo->base.ptr) { - /* XXX Sanity check map_count */ - drm_munmap(bo->base.ptr, bo->base.size); - bo->base.ptr = NULL; - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = bo->base.handle; - - ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_GEM_CLOSE, &arg); - if (ret) - return -errno; - - free(bo); - return 0; -} - -drm_private int -radeon_create(int fd, struct kms_driver **out) -{ - struct kms_driver *kms; - - kms = calloc(1, sizeof(*kms)); - if (!kms) - return -ENOMEM; - - kms->fd = fd; - - kms->bo_create = radeon_bo_create; - kms->bo_map = radeon_bo_map; - kms->bo_unmap = radeon_bo_unmap; - kms->bo_get_prop = radeon_bo_get_prop; - kms->bo_destroy = radeon_bo_destroy; - kms->get_prop = radeon_get_prop; - kms->destroy = radeon_destroy; - *out = kms; - - return 0; -} diff --git a/libkms/vmwgfx.c b/libkms/vmwgfx.c deleted file mode 100644 index 1984399c..00000000 --- a/libkms/vmwgfx.c +++ /dev/null @@ -1,207 +0,0 @@ -/************************************************************************** - * - * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifdef __FreeBSD__ -#define _WANT_KERNEL_ERRNO -#endif - -#include <errno.h> -#include <stdlib.h> -#include <string.h> -#include "internal.h" - -#include "xf86drm.h" -#include "libdrm_macros.h" -#include "vmwgfx_drm.h" - -struct vmwgfx_bo -{ - struct kms_bo base; - uint64_t map_handle; - unsigned map_count; -}; - -static int -vmwgfx_get_prop(struct kms_driver *kms, unsigned key, unsigned *out) -{ - switch (key) { - case KMS_BO_TYPE: - *out = KMS_BO_TYPE_SCANOUT_X8R8G8B8 | KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8; - break; - default: - return -EINVAL; - } - return 0; -} - -static int -vmwgfx_destroy(struct kms_driver *kms) -{ - free(kms); - return 0; -} - -static int -vmwgfx_bo_create(struct kms_driver *kms, - const unsigned width, const unsigned height, - const enum kms_bo_type type, const unsigned *attr, - struct kms_bo **out) -{ - struct vmwgfx_bo *bo; - int i, ret; - - for (i = 0; attr[i]; i += 2) { - switch (attr[i]) { - case KMS_WIDTH: - case KMS_HEIGHT: - case KMS_BO_TYPE: - break; - default: - return -EINVAL; - } - } - - bo = calloc(1, sizeof(*bo)); - if (!bo) - return -EINVAL; - - { - union drm_vmw_alloc_dmabuf_arg arg; - struct drm_vmw_alloc_dmabuf_req *req = &arg.req; - struct drm_vmw_dmabuf_rep *rep = &arg.rep; - - memset(&arg, 0, sizeof(arg)); - req->size = width * height * 4; - bo->base.size = req->size; - bo->base.pitch = width * 4; - bo->base.kms = kms; - - do { - ret = drmCommandWriteRead(bo->base.kms->fd, - DRM_VMW_ALLOC_DMABUF, - &arg, sizeof(arg)); - } while (ret == -ERESTART); - - if (ret) - goto err_free; - - bo->base.handle = rep->handle; - bo->map_handle = rep->map_handle; - bo->base.handle = rep->cur_gmr_id; - bo->base.offset = rep->cur_gmr_offset; - } - - *out = &bo->base; - - return 0; - -err_free: - free(bo); - return ret; -} - -static int -vmwgfx_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out) -{ - switch (key) { - default: - return -EINVAL; - } -} - -static int -vmwgfx_bo_map(struct kms_bo *_bo, void **out) -{ - struct vmwgfx_bo *bo = (struct vmwgfx_bo *)_bo; - void *map; - - if (bo->base.ptr) { - bo->map_count++; - *out = bo->base.ptr; - return 0; - } - - map = drm_mmap(NULL, bo->base.size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->base.kms->fd, bo->map_handle); - if (map == MAP_FAILED) - return -errno; - - bo->base.ptr = map; - bo->map_count++; - *out = bo->base.ptr; - - return 0; -} - -static int -vmwgfx_bo_unmap(struct kms_bo *_bo) -{ - struct vmwgfx_bo *bo = (struct vmwgfx_bo *)_bo; - bo->map_count--; - return 0; -} - -static int -vmwgfx_bo_destroy(struct kms_bo *_bo) -{ - struct vmwgfx_bo *bo = (struct vmwgfx_bo *)_bo; - struct drm_vmw_unref_dmabuf_arg arg; - - if (bo->base.ptr) { - /* XXX Sanity check map_count */ - drm_munmap(bo->base.ptr, bo->base.size); - bo->base.ptr = NULL; - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = bo->base.handle; - drmCommandWrite(bo->base.kms->fd, DRM_VMW_UNREF_DMABUF, &arg, sizeof(arg)); - - free(bo); - return 0; -} - -drm_private int -vmwgfx_create(int fd, struct kms_driver **out) -{ - struct kms_driver *kms; - - kms = calloc(1, sizeof(*kms)); - if (!kms) - return -ENOMEM; - - kms->fd = fd; - - kms->bo_create = vmwgfx_bo_create; - kms->bo_map = vmwgfx_bo_map; - kms->bo_unmap = vmwgfx_bo_unmap; - kms->bo_get_prop = vmwgfx_bo_get_prop; - kms->bo_destroy = vmwgfx_bo_destroy; - kms->get_prop = vmwgfx_get_prop; - kms->destroy = vmwgfx_destroy; - *out = kms; - return 0; -} |