1 /* 2 * Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 * DEALINGS IN THE SOFTWARE. 21 */ 22 23 #ifndef __NVIDIA_DRM_OS_INTERFACE_H__ 24 #define __NVIDIA_DRM_OS_INTERFACE_H__ 25 26 #include "nvidia-drm-conftest.h" /* NV_DRM_AVAILABLE */ 27 28 #include "nvtypes.h" 29 30 #if defined(NV_DRM_AVAILABLE) 31 32 #if defined(NV_DRM_FENCE_AVAILABLE) 33 #include "nvidia-dma-fence-helper.h" 34 #endif 35 36 #if defined(NV_LINUX) 37 #include "nv-kthread-q.h" 38 #include "linux/spinlock.h" 39 40 typedef struct nv_drm_workthread { 41 spinlock_t lock; 42 struct nv_kthread_q q; 43 bool shutting_down; 44 } nv_drm_workthread; 45 46 typedef nv_kthread_q_item_t nv_drm_work; 47 48 #else /* defined(NV_LINUX) */ 49 #error "Need to define deferred work primitives for this OS" 50 #endif /* else defined(NV_LINUX) */ 51 52 #if defined(NV_LINUX) 53 #include "nv-timer.h" 54 55 typedef struct nv_timer nv_drm_timer; 56 57 #else /* defined(NV_LINUX) */ 58 #error "Need to define kernel timer callback primitives for this OS" 59 #endif /* else defined(NV_LINUX) */ 60 61 #if defined(NV_DRM_FBDEV_GENERIC_SETUP_PRESENT) && defined(NV_DRM_APERTURE_REMOVE_CONFLICTING_PCI_FRAMEBUFFERS_PRESENT) 62 #define NV_DRM_FBDEV_GENERIC_AVAILABLE 63 #endif 64 65 struct page; 66 67 /* Set to true when the atomic modeset feature is enabled. */ 68 extern bool nv_drm_modeset_module_param; 69 #if defined(NV_DRM_FBDEV_GENERIC_AVAILABLE) 70 /* Set to true when the nvidia-drm driver should install a framebuffer device */ 71 extern bool nv_drm_fbdev_module_param; 72 #endif 73 74 void *nv_drm_calloc(size_t nmemb, size_t size); 75 76 void nv_drm_free(void *ptr); 77 78 char *nv_drm_asprintf(const char *fmt, ...); 79 80 void nv_drm_write_combine_flush(void); 81 82 int nv_drm_lock_user_pages(unsigned long address, 83 unsigned long pages_count, struct page ***pages); 84 85 void nv_drm_unlock_user_pages(unsigned long pages_count, struct page **pages); 86 87 void *nv_drm_vmap(struct page **pages, unsigned long pages_count); 88 89 void nv_drm_vunmap(void *address); 90 91 bool nv_drm_workthread_init(nv_drm_workthread *worker, const char *name); 92 93 /* Can be called concurrently with nv_drm_workthread_add_work() */ 94 void nv_drm_workthread_shutdown(nv_drm_workthread *worker); 95 96 void nv_drm_workthread_work_init(nv_drm_work *work, 97 void (*callback)(void *), 98 void *arg); 99 100 /* Can be called concurrently with nv_drm_workthread_shutdown() */ 101 int nv_drm_workthread_add_work(nv_drm_workthread *worker, nv_drm_work *work); 102 103 void nv_drm_timer_setup(nv_drm_timer *timer, 104 void (*callback)(nv_drm_timer *nv_drm_timer)); 105 106 void nv_drm_mod_timer(nv_drm_timer *timer, unsigned long relative_timeout_ms); 107 108 bool nv_drm_del_timer_sync(nv_drm_timer *timer); 109 110 unsigned long nv_drm_timer_now(void); 111 112 unsigned long nv_drm_timeout_from_ms(NvU64 relative_timeout_ms); 113 114 #if defined(NV_DRM_FENCE_AVAILABLE) 115 int nv_drm_create_sync_file(nv_dma_fence_t *fence); 116 117 nv_dma_fence_t *nv_drm_sync_file_get_fence(int fd); 118 #endif /* defined(NV_DRM_FENCE_AVAILABLE) */ 119 120 void nv_drm_yield(void); 121 122 #endif /* defined(NV_DRM_AVAILABLE) */ 123 124 #endif /* __NVIDIA_DRM_OS_INTERFACE_H__ */ 125