mirror of
https://github.com/NVIDIA/open-gpu-kernel-modules.git
synced 2026-02-22 07:53:58 +00:00
515.43.04
This commit is contained in:
181
src/nvidia-modeset/kapi/include/nvkms-kapi-internal.h
Normal file
181
src/nvidia-modeset/kapi/include/nvkms-kapi-internal.h
Normal file
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2014 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __NVKMS_KAPI_INTERNAL_H__
|
||||
|
||||
#define __NVKMS_KAPI_INTERNAL_H__
|
||||
|
||||
#include "unix_rm_handle.h"
|
||||
|
||||
#include "nvkms-utils.h"
|
||||
#include "nvkms-kapi-private.h"
|
||||
|
||||
//XXX Decouple functions like nvEvoLog used for logging from NVKMS
|
||||
|
||||
#define nvKmsKapiLogDebug(__format...) \
|
||||
nvEvoLogDebug(EVO_LOG_INFO, "[kapi] "__format)
|
||||
|
||||
#define nvKmsKapiLogDeviceDebug(__device, __format, ...) \
|
||||
nvEvoLogDebug(EVO_LOG_INFO, "[kapi][GPU Id 0x%08x] "__format, \
|
||||
device->gpuId, ##__VA_ARGS__)
|
||||
|
||||
struct NvKmsKapiDevice {
|
||||
|
||||
NvU32 gpuId;
|
||||
|
||||
nvkms_sema_handle_t *pSema;
|
||||
|
||||
/* RM handles */
|
||||
|
||||
NvU32 hRmClient;
|
||||
NvU32 hRmDevice, hRmSubDevice;
|
||||
NvU32 deviceInstance;
|
||||
|
||||
NVUnixRmHandleAllocatorRec handleAllocator;
|
||||
|
||||
/* NVKMS handles */
|
||||
|
||||
struct nvkms_per_open *pKmsOpen;
|
||||
|
||||
NvKmsDeviceHandle hKmsDevice;
|
||||
NvKmsDispHandle hKmsDisp;
|
||||
NvU32 dispIdx;
|
||||
|
||||
NvU32 subDeviceMask;
|
||||
|
||||
NvBool isSOC;
|
||||
NvKmsDispIOCoherencyModes isoIOCoherencyModes;
|
||||
NvKmsDispIOCoherencyModes nisoIOCoherencyModes;
|
||||
NvBool supportsSyncpts;
|
||||
|
||||
/* Device capabilities */
|
||||
|
||||
struct {
|
||||
struct NvKmsCompositionCapabilities cursorCompositionCaps;
|
||||
struct NvKmsCompositionCapabilities overlayCompositionCaps;
|
||||
|
||||
NvU16 validLayerRRTransforms;
|
||||
|
||||
NvU32 maxWidthInPixels;
|
||||
NvU32 maxHeightInPixels;
|
||||
NvU32 maxCursorSizeInPixels;
|
||||
|
||||
NvU8 genericPageKind;
|
||||
} caps;
|
||||
|
||||
NvU64 supportedSurfaceMemoryFormats[NVKMS_KAPI_LAYER_MAX];
|
||||
|
||||
NvU32 numHeads;
|
||||
NvU32 numLayers[NVKMS_KAPI_MAX_HEADS];
|
||||
|
||||
struct {
|
||||
NvU32 hRmHandle;
|
||||
NvKmsSurfaceHandle hKmsHandle;
|
||||
|
||||
NvBool mapped;
|
||||
void *pLinearAddress;
|
||||
|
||||
enum NvKmsNIsoFormat format;
|
||||
} notifier;
|
||||
|
||||
struct {
|
||||
NvU32 currFlipNotifierIndex;
|
||||
} layerState[NVKMS_KAPI_MAX_HEADS][NVKMS_MAX_LAYERS_PER_HEAD];
|
||||
|
||||
void *privateData;
|
||||
|
||||
void (*eventCallback)(const struct NvKmsKapiEvent *event);
|
||||
};
|
||||
|
||||
struct NvKmsKapiMemory {
|
||||
NvU32 hRmHandle;
|
||||
NvU64 size;
|
||||
|
||||
struct NvKmsKapiPrivSurfaceParams surfaceParams;
|
||||
};
|
||||
|
||||
struct NvKmsKapiSurface {
|
||||
NvKmsSurfaceHandle hKmsHandle;
|
||||
};
|
||||
|
||||
|
||||
enum NvKmsKapiAllocationType {
|
||||
NVKMS_KAPI_ALLOCATION_TYPE_SCANOUT = 0,
|
||||
NVKMS_KAPI_ALLOCATION_TYPE_NOTIFIER = 1,
|
||||
};
|
||||
|
||||
static inline void *nvKmsKapiCalloc(size_t nmem, size_t size)
|
||||
{
|
||||
return nvInternalAlloc(nmem * size, NV_TRUE);
|
||||
}
|
||||
|
||||
static inline void nvKmsKapiFree(void *ptr)
|
||||
{
|
||||
return nvInternalFree(ptr);
|
||||
}
|
||||
|
||||
static inline NvU32 nvKmsKapiGenerateRmHandle(struct NvKmsKapiDevice *device)
|
||||
{
|
||||
NvU32 handle;
|
||||
|
||||
nvkms_sema_down(device->pSema);
|
||||
handle = nvGenerateUnixRmHandle(&device->handleAllocator);
|
||||
nvkms_sema_up(device->pSema);
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
static inline void nvKmsKapiFreeRmHandle(struct NvKmsKapiDevice *device,
|
||||
NvU32 handle)
|
||||
{
|
||||
nvkms_sema_down(device->pSema);
|
||||
nvFreeUnixRmHandle(&device->handleAllocator, handle);
|
||||
nvkms_sema_up(device->pSema);
|
||||
}
|
||||
|
||||
NvBool nvKmsKapiAllocateVideoMemory(struct NvKmsKapiDevice *device,
|
||||
NvU32 hRmHandle,
|
||||
enum NvKmsSurfaceMemoryLayout layout,
|
||||
NvU64 size,
|
||||
enum NvKmsKapiAllocationType type,
|
||||
NvU8 *compressible);
|
||||
|
||||
NvBool nvKmsKapiAllocateSystemMemory(struct NvKmsKapiDevice *device,
|
||||
NvU32 hRmHandle,
|
||||
enum NvKmsSurfaceMemoryLayout layout,
|
||||
NvU64 size,
|
||||
enum NvKmsKapiAllocationType type,
|
||||
NvU8 *compressible);
|
||||
|
||||
struct NvKmsKapiChannelEvent*
|
||||
nvKmsKapiAllocateChannelEvent(struct NvKmsKapiDevice *device,
|
||||
NvKmsChannelEventProc *proc,
|
||||
void *data,
|
||||
NvU64 nvKmsParamsUser,
|
||||
NvU64 nvKmsParamsSize);
|
||||
|
||||
void
|
||||
nvKmsKapiFreeChannelEvent(struct NvKmsKapiDevice *device,
|
||||
struct NvKmsKapiChannelEvent *cb);
|
||||
|
||||
#endif /* __NVKMS_KAPI_INTERNAL_H__ */
|
||||
85
src/nvidia-modeset/kapi/include/nvkms-kapi-notifiers.h
Normal file
85
src/nvidia-modeset/kapi/include/nvkms-kapi-notifiers.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2016 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __NVKMS_KAPI_NOTIFIERS_H__
|
||||
|
||||
#define __NVKMS_KAPI_NOTIFIERS_H__
|
||||
|
||||
#include "nvkms-kapi-internal.h"
|
||||
|
||||
#define NVKMS_KAPI_MAX_NOTIFERS_PER_LAYER 0x2
|
||||
#define NVKMS_KAPI_NOTIFIER_SIZE 0x10
|
||||
|
||||
static inline NvU32 NVKMS_KAPI_INC_NOTIFIER_INDEX(const NvU32 index)
|
||||
{
|
||||
return (index + 1) % NVKMS_KAPI_MAX_NOTIFERS_PER_LAYER;
|
||||
}
|
||||
|
||||
static inline NvU32 NVKMS_KAPI_DEC_NOTIFIER_INDEX(const NvU32 index)
|
||||
{
|
||||
if (index == 0) {
|
||||
/*
|
||||
* Wrap "backwards" to the largest allowed notifier index.
|
||||
*/
|
||||
return NVKMS_KAPI_MAX_NOTIFERS_PER_LAYER - 1;
|
||||
}
|
||||
|
||||
return index - 1;
|
||||
}
|
||||
|
||||
static inline NvU32 NVKMS_KAPI_NOTIFIER_INDEX(NvU32 head, NvU32 layer,
|
||||
NvU32 index)
|
||||
{
|
||||
NvU64 notifierIndex = 0;
|
||||
|
||||
notifierIndex = head *
|
||||
NVKMS_MAX_LAYERS_PER_HEAD *
|
||||
NVKMS_KAPI_MAX_NOTIFERS_PER_LAYER;
|
||||
|
||||
notifierIndex += layer *
|
||||
NVKMS_KAPI_MAX_NOTIFERS_PER_LAYER;
|
||||
|
||||
notifierIndex += index;
|
||||
|
||||
return notifierIndex;
|
||||
}
|
||||
|
||||
static inline NvU32 NVKMS_KAPI_NOTIFIER_OFFSET(NvU32 head,
|
||||
NvU32 layer, NvU32 index)
|
||||
{
|
||||
return NVKMS_KAPI_NOTIFIER_INDEX(head, layer, index) *
|
||||
NVKMS_KAPI_NOTIFIER_SIZE;
|
||||
}
|
||||
|
||||
NvBool nvKmsKapiAllocateNotifiers(struct NvKmsKapiDevice *device, NvBool inVideoMemory);
|
||||
|
||||
void nvKmsKapiFreeNotifiers(struct NvKmsKapiDevice *device);
|
||||
|
||||
NvBool nvKmsKapiIsNotifierFinish(const struct NvKmsKapiDevice *device,
|
||||
const NvU32 head, const NvU32 layer,
|
||||
const NvU32 index);
|
||||
|
||||
void nvKmsKapiNotifierSetNotBegun(struct NvKmsKapiDevice *device,
|
||||
NvU32 head, NvU32 layer, NvU32 index);
|
||||
|
||||
#endif /* __NVKMS_KAPI_NOTIFIERS_H__ */
|
||||
59
src/nvidia-modeset/kapi/interface/nvkms-kapi-private.h
Normal file
59
src/nvidia-modeset/kapi/interface/nvkms-kapi-private.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2017 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if !defined(__NVKMS_KAPI_PRIVATE_H__)
|
||||
#define __NVKMS_KAPI_PRIVATE_H__
|
||||
|
||||
#include "nvtypes.h"
|
||||
#include "nvkms-api.h"
|
||||
|
||||
struct NvKmsKapiPrivAllocateChannelEventParams {
|
||||
NvU32 hClient;
|
||||
NvU32 hChannel;
|
||||
};
|
||||
|
||||
struct NvKmsKapiPrivSurfaceParams {
|
||||
enum NvKmsSurfaceMemoryLayout layout;
|
||||
|
||||
struct {
|
||||
struct {
|
||||
NvU32 x;
|
||||
NvU32 y;
|
||||
NvU32 z;
|
||||
} log2GobsPerBlock;
|
||||
|
||||
NvU32 pitchInBlocks;
|
||||
NvBool genericMemory;
|
||||
} blockLinear;
|
||||
};
|
||||
|
||||
struct NvKmsKapiPrivImportMemoryParams {
|
||||
int memFd;
|
||||
struct NvKmsKapiPrivSurfaceParams surfaceParams;
|
||||
};
|
||||
|
||||
struct NvKmsKapiPrivExportMemoryParams {
|
||||
int memFd;
|
||||
};
|
||||
|
||||
#endif /* !defined(__NVKMS_KAPI_PRIVATE_H__) */
|
||||
1061
src/nvidia-modeset/kapi/interface/nvkms-kapi.h
Normal file
1061
src/nvidia-modeset/kapi/interface/nvkms-kapi.h
Normal file
File diff suppressed because it is too large
Load Diff
150
src/nvidia-modeset/kapi/src/nvkms-kapi-channelevent.c
Normal file
150
src/nvidia-modeset/kapi/src/nvkms-kapi-channelevent.c
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2016 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "nvidia-modeset-os-interface.h"
|
||||
|
||||
#include "nvkms-rmapi.h"
|
||||
|
||||
#include "nvkms-kapi.h"
|
||||
#include "nvkms-kapi-private.h"
|
||||
#include "nvkms-kapi-internal.h"
|
||||
|
||||
#include "class/cl0005.h"
|
||||
|
||||
struct NvKmsKapiChannelEvent {
|
||||
struct NvKmsKapiDevice *device;
|
||||
|
||||
NvKmsChannelEventProc *proc;
|
||||
void *data;
|
||||
|
||||
struct NvKmsKapiPrivAllocateChannelEventParams nvKmsParams;
|
||||
|
||||
NvHandle hCallback;
|
||||
NVOS10_EVENT_KERNEL_CALLBACK_EX rmCallback;
|
||||
};
|
||||
|
||||
static void ChannelEventHandler(void *arg1, void *arg2, NvHandle hEvent,
|
||||
NvU32 data, NvU32 status)
|
||||
{
|
||||
struct NvKmsKapiChannelEvent *cb = arg1;
|
||||
cb->proc(cb->data, 0);
|
||||
}
|
||||
|
||||
struct NvKmsKapiChannelEvent* nvKmsKapiAllocateChannelEvent
|
||||
(
|
||||
struct NvKmsKapiDevice *device,
|
||||
NvKmsChannelEventProc *proc,
|
||||
void *data,
|
||||
NvU64 nvKmsParamsUser,
|
||||
NvU64 nvKmsParamsSize
|
||||
)
|
||||
{
|
||||
int status;
|
||||
NvU32 ret;
|
||||
|
||||
struct NvKmsKapiChannelEvent *cb = NULL;
|
||||
NV0005_ALLOC_PARAMETERS eventParams = { };
|
||||
|
||||
if (device == NULL || proc == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
cb = nvKmsKapiCalloc(1, sizeof(*cb));
|
||||
if (cb == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Verify the driver-private params size and copy it in from userspace */
|
||||
|
||||
if (nvKmsParamsSize != sizeof(cb->nvKmsParams)) {
|
||||
nvKmsKapiLogDebug(
|
||||
"NVKMS private memory import parameter size mismatch - "
|
||||
"expected: 0x%llx, caller specified: 0x%llx",
|
||||
(NvU64)sizeof(cb->nvKmsParams), nvKmsParamsSize);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
status = nvkms_copyin(&cb->nvKmsParams,
|
||||
nvKmsParamsUser, sizeof(cb->nvKmsParams));
|
||||
if (status != 0) {
|
||||
nvKmsKapiLogDebug(
|
||||
"NVKMS private memory import parameters could not be read from "
|
||||
"userspace");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
cb->device = device;
|
||||
|
||||
cb->proc = proc;
|
||||
cb->data = data;
|
||||
|
||||
cb->rmCallback.func = ChannelEventHandler;
|
||||
cb->rmCallback.arg = cb;
|
||||
|
||||
cb->hCallback = nvGenerateUnixRmHandle(&device->handleAllocator);
|
||||
if (cb->hCallback == 0x0) {
|
||||
nvKmsKapiLogDeviceDebug(device,
|
||||
"Failed to allocate event callback handle");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
eventParams.hParentClient = cb->nvKmsParams.hClient;
|
||||
eventParams.hClass = NV01_EVENT_KERNEL_CALLBACK_EX;
|
||||
eventParams.notifyIndex = 0;
|
||||
eventParams.data = NV_PTR_TO_NvP64(&cb->rmCallback);
|
||||
|
||||
ret = nvRmApiAlloc(device->hRmClient,
|
||||
cb->nvKmsParams.hChannel,
|
||||
cb->hCallback,
|
||||
NV01_EVENT_KERNEL_CALLBACK_EX,
|
||||
&eventParams);
|
||||
if (ret != NVOS_STATUS_SUCCESS) {
|
||||
nvKmsKapiLogDeviceDebug(device, "Failed to allocate event callback");
|
||||
nvFreeUnixRmHandle(&device->handleAllocator, cb->hCallback);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return cb;
|
||||
fail:
|
||||
nvKmsKapiFree(cb);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void nvKmsKapiFreeChannelEvent
|
||||
(
|
||||
struct NvKmsKapiDevice *device,
|
||||
struct NvKmsKapiChannelEvent *cb
|
||||
)
|
||||
{
|
||||
if (device == NULL || cb == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
nvRmApiFree(device->hRmClient,
|
||||
device->hRmClient,
|
||||
cb->hCallback);
|
||||
|
||||
nvFreeUnixRmHandle(&device->handleAllocator, cb->hCallback);
|
||||
|
||||
nvKmsKapiFree(cb);
|
||||
}
|
||||
227
src/nvidia-modeset/kapi/src/nvkms-kapi-notifiers.c
Normal file
227
src/nvidia-modeset/kapi/src/nvkms-kapi-notifiers.c
Normal file
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2016 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "nvidia-modeset-os-interface.h"
|
||||
|
||||
#include "nvkms-api.h"
|
||||
#include "nvkms-sync.h"
|
||||
#include "nvkms-rmapi.h"
|
||||
#include "nvkms-kapi-notifiers.h"
|
||||
|
||||
#define NVKMS_KAPI_MAX_NOTIFIERS \
|
||||
(NVKMS_KAPI_MAX_HEADS * \
|
||||
NVKMS_MAX_LAYERS_PER_HEAD * \
|
||||
NVKMS_KAPI_MAX_NOTIFERS_PER_LAYER)
|
||||
|
||||
void nvKmsKapiFreeNotifiers(struct NvKmsKapiDevice *device)
|
||||
{
|
||||
if (device->notifier.hKmsHandle != 0) {
|
||||
struct NvKmsUnregisterSurfaceParams paramsUnreg = { };
|
||||
NvBool status;
|
||||
|
||||
paramsUnreg.request.deviceHandle = device->hKmsDevice;
|
||||
paramsUnreg.request.surfaceHandle = device->notifier.hKmsHandle;
|
||||
|
||||
status = nvkms_ioctl_from_kapi(device->pKmsOpen,
|
||||
NVKMS_IOCTL_UNREGISTER_SURFACE,
|
||||
¶msUnreg, sizeof(paramsUnreg));
|
||||
|
||||
if (!status) {
|
||||
nvKmsKapiLogDeviceDebug(
|
||||
device,
|
||||
"NVKMS_IOCTL_UNREGISTER_SURFACE failed");
|
||||
}
|
||||
|
||||
device->notifier.hKmsHandle = 0;
|
||||
}
|
||||
|
||||
if (device->notifier.mapped) {
|
||||
NV_STATUS status;
|
||||
|
||||
status = nvRmApiUnmapMemory(device->hRmClient,
|
||||
device->hRmSubDevice,
|
||||
device->notifier.hRmHandle,
|
||||
device->notifier.pLinearAddress,
|
||||
0);
|
||||
|
||||
if (status != NV_OK) {
|
||||
nvKmsKapiLogDeviceDebug(
|
||||
device,
|
||||
"UnmapMemory failed with error code 0x%08x",
|
||||
status);
|
||||
}
|
||||
|
||||
device->notifier.mapped = NV_FALSE;
|
||||
}
|
||||
|
||||
if (device->notifier.hRmHandle != 0) {
|
||||
NvU32 status;
|
||||
|
||||
status = nvRmApiFree(device->hRmClient,
|
||||
device->hRmDevice,
|
||||
device->notifier.hRmHandle);
|
||||
|
||||
if (status != NVOS_STATUS_SUCCESS) {
|
||||
nvKmsKapiLogDeviceDebug(
|
||||
device,
|
||||
"RmFree failed with error code 0x%08x",
|
||||
status);
|
||||
}
|
||||
|
||||
nvFreeUnixRmHandle(&device->handleAllocator, device->notifier.hRmHandle);
|
||||
device->notifier.hRmHandle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void InitNotifier(struct NvKmsKapiDevice *device,
|
||||
NvU32 head, NvU32 layer, NvU32 index)
|
||||
{
|
||||
nvKmsResetNotifier(device->notifier.format,
|
||||
(layer == NVKMS_OVERLAY_LAYER),
|
||||
NVKMS_KAPI_NOTIFIER_INDEX(head, layer, index),
|
||||
device->notifier.pLinearAddress);
|
||||
}
|
||||
|
||||
#define NVKMS_KAPI_NOTIFIERS_SURFACE_SIZE 0x1000
|
||||
|
||||
NvBool nvKmsKapiAllocateNotifiers(struct NvKmsKapiDevice *device,
|
||||
NvBool inVideoMemory)
|
||||
{
|
||||
struct NvKmsRegisterSurfaceParams surfParams = {};
|
||||
NV_STATUS status = 0;
|
||||
NvU8 compressible = 0;
|
||||
NvBool ret;
|
||||
|
||||
ct_assert((NVKMS_KAPI_MAX_NOTIFIERS * NVKMS_KAPI_NOTIFIER_SIZE) <=
|
||||
(NVKMS_KAPI_NOTIFIERS_SURFACE_SIZE));
|
||||
|
||||
ct_assert(NVKMS_KAPI_NOTIFIER_SIZE >= sizeof(NvNotification));
|
||||
nvAssert(NVKMS_KAPI_NOTIFIER_SIZE >=
|
||||
nvKmsSizeOfNotifier(device->notifier.format, TRUE /* overlay */));
|
||||
nvAssert(NVKMS_KAPI_NOTIFIER_SIZE >=
|
||||
nvKmsSizeOfNotifier(device->notifier.format, FALSE /* overlay */));
|
||||
|
||||
device->notifier.hRmHandle =
|
||||
nvGenerateUnixRmHandle(&device->handleAllocator);
|
||||
|
||||
if (device->notifier.hRmHandle == 0x0) {
|
||||
nvKmsKapiLogDeviceDebug(
|
||||
device,
|
||||
"nvGenerateUnixRmHandle() failed");
|
||||
return NV_FALSE;
|
||||
}
|
||||
|
||||
if (inVideoMemory) {
|
||||
ret = nvKmsKapiAllocateVideoMemory(device,
|
||||
device->notifier.hRmHandle,
|
||||
NvKmsSurfaceMemoryLayoutPitch,
|
||||
NVKMS_KAPI_NOTIFIERS_SURFACE_SIZE,
|
||||
NVKMS_KAPI_ALLOCATION_TYPE_NOTIFIER,
|
||||
&compressible);
|
||||
} else {
|
||||
ret = nvKmsKapiAllocateSystemMemory(device,
|
||||
device->notifier.hRmHandle,
|
||||
NvKmsSurfaceMemoryLayoutPitch,
|
||||
NVKMS_KAPI_NOTIFIERS_SURFACE_SIZE,
|
||||
NVKMS_KAPI_ALLOCATION_TYPE_NOTIFIER,
|
||||
&compressible);
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
nvFreeUnixRmHandle(&device->handleAllocator, device->notifier.hRmHandle);
|
||||
device->notifier.hRmHandle = 0x0;
|
||||
goto failed;
|
||||
}
|
||||
|
||||
status = nvRmApiMapMemory(device->hRmClient,
|
||||
device->hRmSubDevice,
|
||||
device->notifier.hRmHandle,
|
||||
0,
|
||||
NVKMS_KAPI_NOTIFIERS_SURFACE_SIZE,
|
||||
&device->notifier.pLinearAddress,
|
||||
0);
|
||||
|
||||
if (status != NV_OK) {
|
||||
nvKmsKapiLogDeviceDebug(
|
||||
device,
|
||||
"MapMemory failed with error code 0x%08x",
|
||||
status);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
device->notifier.mapped = NV_TRUE;
|
||||
|
||||
surfParams.request.deviceHandle = device->hKmsDevice;
|
||||
surfParams.request.useFd = FALSE;
|
||||
surfParams.request.rmClient = device->hRmClient;
|
||||
|
||||
surfParams.request.widthInPixels = NVKMS_KAPI_NOTIFIERS_SURFACE_SIZE;
|
||||
surfParams.request.heightInPixels = 1;
|
||||
surfParams.request.layout = NvKmsSurfaceMemoryLayoutPitch;
|
||||
surfParams.request.format = NvKmsSurfaceMemoryFormatI8;
|
||||
surfParams.request.log2GobsPerBlockY = 0;
|
||||
surfParams.request.isoType = NVKMS_MEMORY_NISO;
|
||||
|
||||
surfParams.request.planes[0].u.rmObject = device->notifier.hRmHandle;
|
||||
surfParams.request.planes[0].pitch = NVKMS_KAPI_NOTIFIERS_SURFACE_SIZE;
|
||||
surfParams.request.planes[0].rmObjectSizeInBytes =
|
||||
NVKMS_KAPI_NOTIFIERS_SURFACE_SIZE;
|
||||
|
||||
if (!nvkms_ioctl_from_kapi(device->pKmsOpen,
|
||||
NVKMS_IOCTL_REGISTER_SURFACE,
|
||||
&surfParams, sizeof(surfParams))) {
|
||||
nvKmsKapiLogDeviceDebug(
|
||||
device,
|
||||
"NVKMS_IOCTL_REGISTER_SURFACE failed");
|
||||
goto failed;
|
||||
}
|
||||
|
||||
device->notifier.hKmsHandle = surfParams.reply.surfaceHandle;
|
||||
|
||||
/* Init Notifiers */
|
||||
|
||||
{
|
||||
NvU32 head;
|
||||
|
||||
for (head = 0; head < device->numHeads; head++) {
|
||||
NvU32 layer;
|
||||
|
||||
for (layer = 0; layer < NVKMS_MAX_LAYERS_PER_HEAD; layer++) {
|
||||
NvU32 index;
|
||||
|
||||
for (index = 0;
|
||||
index < NVKMS_KAPI_MAX_NOTIFERS_PER_LAYER; index++) {
|
||||
InitNotifier(device, head, layer, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NV_TRUE;
|
||||
|
||||
failed:
|
||||
|
||||
nvKmsKapiFreeNotifiers(device);
|
||||
|
||||
return NV_FALSE;
|
||||
}
|
||||
3092
src/nvidia-modeset/kapi/src/nvkms-kapi.c
Normal file
3092
src/nvidia-modeset/kapi/src/nvkms-kapi.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user