diff options
author | Allen Martin <amartin@nvidia.com> | 2011-01-28 12:56:32 -0800 |
---|---|---|
committer | Varun Colbert <vcolbert@nvidia.com> | 2011-03-21 16:57:16 -0800 |
commit | f19b5db486e24a2a6520807126723073dd7028e5 (patch) | |
tree | 3b78273603de57941f5a0dbc4b73dffa9ae52c2c /arch | |
parent | 51e6f12b07d35e8787e8ad8ceb62638e15bc2505 (diff) |
ARM: tegra: Remove old nvrpc / nvfw drivers
These drivers are no longer needed with the switch to the new
AVP module loader driver
Signed-off-by: Allen Martin <amartin@nvidia.com>
(cherry picked from commit 9b78ac6fa04fe6dcf61b60863a5603b0eff00378)
Change-Id: I4aed0b4ccc8bb996513c5c8b1e057ee35f97d086
Reviewed-on: http://git-master/r/23627
Reviewed-by: Allen R Martin <amartin@nvidia.com>
Tested-by: Allen R Martin <amartin@nvidia.com>
Reviewed-by: Daniel Willemsen <dwillemsen@nvidia.com>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/arm/mach-tegra/nv/Makefile | 1 | ||||
-rw-r--r-- | arch/arm/mach-tegra/nv/nvrm/core/ap15/Makefile | 1 | ||||
-rw-r--r-- | arch/arm/mach-tegra/nv/nvrm/core/ap15/ap15rm_avp_service.c | 350 | ||||
-rw-r--r-- | arch/arm/mach-tegra/nv/nvrm/core/common/Makefile | 4 | ||||
-rw-r--r-- | arch/arm/mach-tegra/nv/nvrm/core/common/nvrm_avp_cpu_rpc.c | 357 | ||||
-rw-r--r-- | arch/arm/mach-tegra/nv/nvrm/core/common/nvrm_init_stub.c | 34 | ||||
-rw-r--r-- | arch/arm/mach-tegra/nv/nvrm/core/common/nvrm_moduleloader.c | 811 | ||||
-rw-r--r-- | arch/arm/mach-tegra/nv/nvrpc_user.c | 676 |
8 files changed, 0 insertions, 2234 deletions
diff --git a/arch/arm/mach-tegra/nv/Makefile b/arch/arm/mach-tegra/nv/Makefile index 7fb51c48192f..b7a0d7019f5d 100644 --- a/arch/arm/mach-tegra/nv/Makefile +++ b/arch/arm/mach-tegra/nv/Makefile @@ -11,7 +11,6 @@ ccflags-y += -Iarch/arm/mach-tegra/nv/include obj-$(CONFIG_TEGRA_NVRM) += nvrm_user.o -obj-$(CONFIG_TEGRA_NVRM) += nvrpc_user.o obj-$(CONFIG_TEGRA_NVRM) += nvrm/ obj-$(CONFIG_TEGRA_NVRM) += nvreftrack/ diff --git a/arch/arm/mach-tegra/nv/nvrm/core/ap15/Makefile b/arch/arm/mach-tegra/nv/nvrm/core/ap15/Makefile index b5e63bd493e1..5d94bc4ca846 100644 --- a/arch/arm/mach-tegra/nv/nvrm/core/ap15/Makefile +++ b/arch/arm/mach-tegra/nv/nvrm/core/ap15/Makefile @@ -11,6 +11,5 @@ ccflags-y += -Iarch/arm/mach-tegra/nv/nvrm/core/common ccflags-y += -Iarch/arm/mach-tegra/nv/nvrm/core #obj-y += ap15rm_init.o -obj-y += ap15rm_avp_service.o obj-y += ap15rm_xpc.o obj-y += ap15rm_xpc_hw_private.o diff --git a/arch/arm/mach-tegra/nv/nvrm/core/ap15/ap15rm_avp_service.c b/arch/arm/mach-tegra/nv/nvrm/core/ap15/ap15rm_avp_service.c deleted file mode 100644 index 64a220fb0a4d..000000000000 --- a/arch/arm/mach-tegra/nv/nvrm/core/ap15/ap15rm_avp_service.c +++ /dev/null @@ -1,350 +0,0 @@ -/* - * arch/arm/mach-tegra/nvrm/core/ap15/ap15rm_avp_service.c - * - * AVP service to handle AVP messages. - * - * Copyright (c) 2010, NVIDIA Corporation. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -/** @file - * @brief <b>NVIDIA Driver Development Kit: - * Testcases for the xpc </b> - * - * @b Description: This file implements the AVP service to handle AVP messages. - */ - -#include <linux/module.h> -#include <linux/kernel.h> -#include <linux/init.h> -#include <linux/device.h> -#include <linux/string.h> -#include <linux/miscdevice.h> -#include <linux/fs.h> -#include <linux/firmware.h> - -#include <linux/io.h> -#include <linux/delay.h> -#include <linux/dma-mapping.h> - -#include <mach/nvmap.h> - -#include "../../../../../../../drivers/video/tegra/nvmap/nvmap.h" -#include "nvcommon.h" -#include "nvassert.h" -#include "nvrm_drf.h" -#include "nvrm_init.h" -#include "nvrm_message.h" -#include "nvrm_rpc.h" -#include "nvrm_moduleloader_private.h" -#include "nvrm_graphics_private.h" -#include "ap15/arres_sema.h" -#include "ap15/arflow_ctlr.h" -#include "ap15/arapbpm.h" -#include "nvrm_avp_swi_registry.h" -#include "ap15/arevp.h" -#include "nvrm_hardware_access.h" -#include "mach/io.h" -#include "mach/iomap.h" - -extern struct nvmap_client *s_AvpClient; - -#define NV_USE_AOS 1 - -static void HandleCreateMessage(const NvRmMessage_HandleCreat *req, - NvRmMessage_HandleCreatResponse *resp) -{ - struct nvmap_handle_ref *ref; - - resp->msg = NvRmMsg_MemHandleCreate_Response; - ref = nvmap_create_handle(s_AvpClient, req->size); - if (IS_ERR(ref)) { - pr_err("[AVP] error creating handle %ld\n", PTR_ERR(ref)); - resp->error = NvError_InsufficientMemory; - } else { - resp->error = NvSuccess; - resp->hMem = (NvRmMemHandle)nvmap_ref_to_id(ref); - } -} - -static void HandleAllocMessage(const NvRmMessage_MemAlloc *req, NvRmMessage_Response *resp) -{ - struct nvmap_handle *handle; - unsigned int heap_mask = 0; - unsigned int i; - size_t align; - int err; - - resp->msg = NvRmMsg_MemAlloc_Response; - - if (!req->NumHeaps) - heap_mask = NVMAP_HEAP_CARVEOUT_GENERIC | NVMAP_HEAP_SYSMEM; - - for (i = 0; i < req->NumHeaps; i++) { - if (req->Heaps[i] == NvRmHeap_GART) - heap_mask |= NVMAP_HEAP_IOVMM; - else if (req->Heaps[i] == NvRmHeap_IRam) - heap_mask |= NVMAP_HEAP_CARVEOUT_IRAM; - else if (req->Heaps[i] == NvRmHeap_External) - heap_mask |= NVMAP_HEAP_SYSMEM; - else if (req->Heaps[i] == NvRmHeap_ExternalCarveOut) - heap_mask |= NVMAP_HEAP_CARVEOUT_GENERIC; - } - - handle = nvmap_get_handle_id(s_AvpClient, (unsigned long)req->hMem); - if (IS_ERR(handle)) { - resp->error = NvError_AccessDenied; - return; - } - - align = max_t(size_t, L1_CACHE_BYTES, req->Alignment); - err = nvmap_alloc_handle_id(s_AvpClient, (unsigned long)req->hMem, - heap_mask, align, 0); - nvmap_handle_put(handle); - - if (err) { - pr_err("[AVP] allocate handle error %d\n", err); - resp->error = NvError_InsufficientMemory; - } else { - resp->error = NvSuccess; - } -} -void NvRmPrivProcessMessage(NvRmRPCHandle hRPCHandle, char *pRecvMessage, int messageLength) -{ - switch (*(NvRmMsg *)pRecvMessage) { - - case NvRmMsg_MemHandleCreate: - { - NvRmMessage_HandleCreat *msgHandleCreate = NULL; - NvRmMessage_HandleCreatResponse msgRHandleCreate; - - msgHandleCreate = (NvRmMessage_HandleCreat*)pRecvMessage; - HandleCreateMessage(msgHandleCreate, &msgRHandleCreate); - NvRmPrivRPCSendMsg(hRPCHandle, &msgRHandleCreate, - sizeof(msgRHandleCreate)); - barrier(); - } - break; - case NvRmMsg_MemHandleOpen: - break; - case NvRmMsg_MemHandleFree: - { - NvRmMessage_HandleFree *msgHandleFree = NULL; - msgHandleFree = (NvRmMessage_HandleFree*)pRecvMessage; - nvmap_free_handle_id(s_AvpClient, (unsigned long)msgHandleFree->hMem); - barrier(); - } - break; - case NvRmMsg_MemAlloc: - { - NvRmMessage_MemAlloc *msgMemAlloc = NULL; - NvRmMessage_Response msgResponse; - msgMemAlloc = (NvRmMessage_MemAlloc*)pRecvMessage; - - HandleAllocMessage(msgMemAlloc, &msgResponse); - NvRmPrivRPCSendMsg(hRPCHandle, &msgResponse, sizeof(msgResponse)); - barrier(); - } - break; - case NvRmMsg_MemPin: - { - struct nvmap_handle_ref *ref; - NvRmMessage_Pin *msg; - NvRmMessage_PinResponse response; - unsigned long id; - int err; - - msg = (NvRmMessage_Pin *)pRecvMessage; - id = (unsigned long)msg->hMem; - response.msg = NvRmMsg_MemPin_Response; - - ref = nvmap_duplicate_handle_id(s_AvpClient, id); - if (IS_ERR(ref)) { - pr_err("[AVP] unable to duplicate handle for pin\n"); - err = PTR_ERR(ref); - } else { - err = nvmap_pin_ids(s_AvpClient, 1, &id); - } - if (!err) { - response.address = nvmap_handle_address(s_AvpClient, id); - } else { - pr_err("[AVP] pin error %d\n", err); - response.address = 0xffffffff; - } - - NvRmPrivRPCSendMsg(hRPCHandle, &response, sizeof(response)); - barrier(); - } - break; - case NvRmMsg_MemUnpin: - { - NvRmMessage_HandleFree *msg = NULL; - NvRmMessage_Response msgResponse; - unsigned long id; - - msg = (NvRmMessage_HandleFree*)pRecvMessage; - id = (unsigned long)msg->hMem; - nvmap_unpin_ids(s_AvpClient, 1, &id); - nvmap_free_handle_id(s_AvpClient, id); - - msgResponse.msg = NvRmMsg_MemUnpin_Response; - msgResponse.error = NvSuccess; - - NvRmPrivRPCSendMsg(hRPCHandle, &msgResponse, sizeof(msgResponse)); - barrier(); - } - break; - case NvRmMsg_MemGetAddress: - { - NvRmMessage_GetAddress *msg = NULL; - NvRmMessage_GetAddressResponse response; - unsigned long address; - - msg = (NvRmMessage_GetAddress*)pRecvMessage; - address = nvmap_handle_address(s_AvpClient, (unsigned long)msg->hMem); - response.address = address + msg->Offset; - response.msg = NvRmMsg_MemGetAddress_Response; - NvRmPrivRPCSendMsg(hRPCHandle, &response, sizeof(response)); - barrier(); - } - break; - case NvRmMsg_HandleFromId: - { - NvRmMessage_HandleFromId *msg = NULL; - struct nvmap_handle_ref *ref; - NvRmMessage_Response response; - - msg = (NvRmMessage_HandleFromId*)pRecvMessage; - ref = nvmap_duplicate_handle_id(s_AvpClient, msg->id); - - response.msg = NvRmMsg_HandleFromId_Response; - if (IS_ERR(ref)) { - response.error = NvError_InsufficientMemory; - pr_err("[AVP] duplicate handle error %ld\n", PTR_ERR(ref)); - } else { - response.error = NvSuccess; - } - NvRmPrivRPCSendMsg(hRPCHandle, &response, sizeof(response)); - } - break; - case NvRmMsg_PowerModuleClockControl: - { - NvRmMessage_Module *msgPMCC; - NvRmMessage_Response msgPMCCR; - msgPMCC = (NvRmMessage_Module*)pRecvMessage; - - msgPMCCR.msg = NvRmMsg_PowerModuleClockControl_Response; - msgPMCCR.error = NvRmPowerModuleClockControl(hRPCHandle->hRmDevice, - msgPMCC->ModuleId, - msgPMCC->ClientId, - msgPMCC->Enable); - - NvRmPrivRPCSendMsg(hRPCHandle, &msgPMCCR, sizeof(msgPMCCR)); - } - break; - case NvRmMsg_ModuleReset: - { - NvRmMessage_Module *msgPMCC; - NvRmMessage_Response msgPMCCR; - msgPMCC = (NvRmMessage_Module*)pRecvMessage; - - msgPMCCR.msg = NvRmMsg_ModuleReset_Response; - - NvRmModuleReset(hRPCHandle->hRmDevice, msgPMCC->ModuleId); - /// Send response since clients to this call needs to wait - /// for some time before they can start using the HW module - NvRmPrivRPCSendMsg(hRPCHandle, &msgPMCCR, sizeof(msgPMCCR)); - } - break; - - case NvRmMsg_PowerRegister: - { - NvRmMessage_PowerRegister *msgPower; - NvRmMessage_PowerRegister_Response msgResponse; - - msgPower = (NvRmMessage_PowerRegister*)pRecvMessage; - - msgResponse.msg = NvRmMsg_PowerResponse; - msgResponse.error = NvSuccess; - msgResponse.clientId = msgPower->clientId; - - NvRmPrivRPCSendMsg(hRPCHandle, &msgResponse, sizeof(msgResponse)); - - } - break; - - case NvRmMsg_PowerUnRegister: - break; - case NvRmMsg_PowerStarvationHint: - case NvRmMsg_PowerBusyHint: - { - NvRmMessage_Response msgResponse; - msgResponse.msg = NvRmMsg_PowerResponse; - msgResponse.error = NvSuccess; - NvRmPrivRPCSendMsg(hRPCHandle, &msgResponse, sizeof(msgResponse)); - } - break; - case NvRmMsg_PowerBusyMultiHint: - break; - case NvRmMsg_PowerDfsGetState: - { - NvRmMessage_PowerDfsGetState_Response msgResponse; - msgResponse.msg = NvRmMsg_PowerDfsGetState_Response; - msgResponse.state = NvRmDfsRunState_Stopped; - NvRmPrivRPCSendMsg(hRPCHandle, &msgResponse, sizeof(msgResponse)); - } - break; - case NvRmMsg_PowerModuleGetMaxFreq: - { - NvRmMessage_PowerModuleGetMaxFreq_Response msgResponse; - msgResponse.msg = NvRmMsg_PowerModuleGetMaxFreq; - msgResponse.freqKHz = 0; - NvRmPrivRPCSendMsg(hRPCHandle, &msgResponse, sizeof(msgResponse)); - } - break; - case NvRmMsg_PowerDfsGetClockUtilization: - { - NvRmMessage_PowerDfsGetClockUtilization_Response msgResponse; - NvRmDfsClockUsage ClockUsage = { 0, 0, 0, 0, 0, 0 }; - - msgResponse.msg = NvRmMsg_PowerDfsGetClockUtilization_Response; - msgResponse.error = NvSuccess; - NvOsMemcpy(&msgResponse.clockUsage, &ClockUsage, sizeof(ClockUsage)); - NvRmPrivRPCSendMsg(hRPCHandle, &msgResponse, sizeof(msgResponse)); - } - break; - case NvRmMsg_InitiateLP0: - { - //Just for testing purposes. - } - break; - case NvRmMsg_RemotePrintf: - { - NvRmMessage_RemotePrintf *msg; - - msg = (NvRmMessage_RemotePrintf*)pRecvMessage; - printk("AVP: %s", msg->string); - } - break; - case NvRmMsg_AVP_Reset: - NvOsDebugPrintf("AVP has been reset by WDT\n"); - break; - default: - panic("AVP Service::ProcessMessage: bad message"); - break; - } -} - diff --git a/arch/arm/mach-tegra/nv/nvrm/core/common/Makefile b/arch/arm/mach-tegra/nv/nvrm/core/common/Makefile index 4cec50329619..39de852aceea 100644 --- a/arch/arm/mach-tegra/nv/nvrm/core/common/Makefile +++ b/arch/arm/mach-tegra/nv/nvrm/core/common/Makefile @@ -11,11 +11,7 @@ ccflags-y += -Iarch/arm/mach-tegra/nv/nvrm/core/common ccflags-y += -Iarch/arm/mach-tegra/nv/nvrm/core obj-y += headavp.o -obj-y += nvrm_avp_cpu_rpc.o -obj-y += nvrm_moduleloader.o obj-y += nvrm_rmctrace.o obj-y += nvrm_transport.o obj-y += nvrm_module_stub.o obj-y += nvrm_power.o -obj-y += nvrm_init_stub.o - diff --git a/arch/arm/mach-tegra/nv/nvrm/core/common/nvrm_avp_cpu_rpc.c b/arch/arm/mach-tegra/nv/nvrm/core/common/nvrm_avp_cpu_rpc.c deleted file mode 100644 index 5a373b14b81e..000000000000 --- a/arch/arm/mach-tegra/nv/nvrm/core/common/nvrm_avp_cpu_rpc.c +++ /dev/null @@ -1,357 +0,0 @@ -/* - * arch/arm/mach-tegra/nvrm/core/common/nvrm_avp_cpu_rpc.c - * - * Transport API - * - * Copyright (c) 2010, NVIDIA Corporation. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -/** @file - * @brief <b>NVIDIA Driver Development Kit: - * Transport API</b> - * - * @b Description: This is the wrapper implementation of Transport API. - */ - -#include <linux/kernel.h> -#include <linux/string.h> - -#include "nvrm_transport.h" -#include "nvrm_xpc.h" -#include "nvrm_rpc.h" -#include "nvrm_interrupt.h" -#include "nvassert.h" -#include "nvrm_graphics_private.h" - -/* global variable passed from nvrpc_user.c */ -extern NvRmTransportHandle g_hTransportAvp; -extern NvRmTransportHandle g_hTransportCpu; -extern NvOsSemaphoreHandle g_hTransportAvpSem; -extern NvOsSemaphoreHandle g_hTransportCpuSem; -extern int g_hTransportAvpIsConnected; -extern int g_hTransportCpuIsConnected; - -/* local variables for handles */ -static NvOsThreadHandle s_RecvThreadId_Service; -static NvRmRPCHandle gs_hRPCHandle = NULL; -volatile static int s_ContinueProcessing = 1; - -#if !NV_IS_AVP -#define PORT_NAME "RPC_CPU_PORT" -#else -#define PORT_NAME "RPC_AVP_PORT" -#endif -/* Receive message port thread */ -static void ServiceThread( void *args ); -static void ServiceThread( void *args ) -{ - NvError Error = NvSuccess; - static NvU8 ReceiveMessage[MAX_MESSAGE_LENGTH]; - NvU32 MessageLength = 0; - - Error = NvRmPrivRPCWaitForConnect(gs_hRPCHandle); - if (Error) - { - goto exit_gracefully; - } - while (s_ContinueProcessing) - { - Error = NvRmPrivRPCRecvMsg(gs_hRPCHandle, ReceiveMessage, - &MessageLength); - if (Error == NvError_InvalidState) - { - break; - } - if (!Error) - { - ReceiveMessage[MessageLength] = '\0'; - } - NvRmPrivProcessMessage(gs_hRPCHandle, (char*)ReceiveMessage, - MessageLength); - } - -exit_gracefully: - return; -} - -NvError NvRmPrivRPCInit(NvRmDeviceHandle hDeviceHandle, char* portName, - NvRmRPCHandle *hRPCHandle ) -{ - NvError Error = NvSuccess; - - *hRPCHandle = NvOsAlloc(sizeof(NvRmRPC)); - if (!*hRPCHandle) - { - Error = NvError_InsufficientMemory; - return Error; - } - - Error = NvOsMutexCreate(&(*hRPCHandle)->RecvLock); - if( Error != NvSuccess) - { - goto clean_up; - } - - if (! portName) { - panic("%s: No port name.\n", __func__); - } - if (! strcmp(portName, "RPC_AVP_PORT")) { - if (g_hTransportAvp) panic("%s: g_hTransportAvp is already set.\n", __func__); - Error = NvOsSemaphoreCreate(&g_hTransportAvpSem, 0); - if (Error != NvSuccess) panic(__func__); - - Error = NvRmTransportOpen(hDeviceHandle, portName, g_hTransportAvpSem, - &g_hTransportAvp); - if (Error != NvSuccess) panic(__func__); - - (*hRPCHandle)->svcTransportHandle = g_hTransportAvp; - (*hRPCHandle)->TransportRecvSemId = g_hTransportAvpSem; - (*hRPCHandle)->isConnected = g_hTransportAvpIsConnected; - } - if (! strcmp(portName, "RPC_CPU_PORT")) { - if (g_hTransportCpu) panic("%s: g_hTransportCpu is already set.\n", __func__); - Error = NvOsSemaphoreCreate(&g_hTransportCpuSem, 0); - if (Error != NvSuccess) panic(__func__); - - Error = NvRmTransportOpen(hDeviceHandle, portName, g_hTransportCpuSem, - &g_hTransportCpu); - if (Error != NvSuccess) panic(__func__); - - (*hRPCHandle)->svcTransportHandle = g_hTransportCpu; - (*hRPCHandle)->TransportRecvSemId = g_hTransportCpuSem; - (*hRPCHandle)->isConnected = g_hTransportCpuIsConnected; - } - (*hRPCHandle)->hRmDevice = hDeviceHandle; - -clean_up: - return Error; -} - -void NvRmPrivRPCDeInit( NvRmRPCHandle hRPCHandle ) -{ - if(hRPCHandle != NULL) - { - if(hRPCHandle->svcTransportHandle != NULL) - { - NvOsSemaphoreDestroy(hRPCHandle->TransportRecvSemId); - NvOsMutexDestroy(hRPCHandle->RecvLock); - NvRmTransportClose(hRPCHandle->svcTransportHandle); - hRPCHandle->svcTransportHandle = NULL; - hRPCHandle->isConnected = NV_FALSE; - } - NvOsFree(hRPCHandle); - } -} - -void NvRmPrivRPCSendMsg(NvRmRPCHandle hRPCHandle, - void* pMessageBuffer, - NvU32 MessageSize) -{ - NvError Error = NvSuccess; - NV_ASSERT(hRPCHandle->svcTransportHandle != NULL); - - NvOsMutexLock(hRPCHandle->RecvLock); - Error = NvRmTransportSendMsg(hRPCHandle->svcTransportHandle, - pMessageBuffer, MessageSize, NV_WAIT_INFINITE); - NvOsMutexUnlock(hRPCHandle->RecvLock); - if(Error) - NV_ASSERT(Error == NvSuccess); -} - -void NvRmPrivRPCSendMsgWithResponse( NvRmRPCHandle hRPCHandle, - void* pRecvMessageBuffer, - NvU32 MaxSize, - NvU32 * pMessageSize, - void* pSendMessageBuffer, - NvU32 MessageSize) -{ - NvError Error = NvSuccess; - NV_ASSERT(hRPCHandle->svcTransportHandle != NULL); - - NvOsMutexLock(hRPCHandle->RecvLock); - Error = NvRmTransportSendMsg(hRPCHandle->svcTransportHandle, - pSendMessageBuffer, MessageSize, NV_WAIT_INFINITE); - if (Error) - { - // TODO: Determine cause of error and pass appropriate error to caller. - NvOsDebugPrintf("%s: error in NvRmTransportSendMsg\n", __func__); - goto clean_up; - } - NvOsSemaphoreWait(hRPCHandle->TransportRecvSemId); - - Error = NvRmTransportRecvMsg(hRPCHandle->svcTransportHandle, - pRecvMessageBuffer, MaxSize, pMessageSize); - if (Error) - { - NvOsDebugPrintf("%s: error in NvRmTransportRecvMsg\n", __func__); - goto clean_up; - } - -clean_up: - NV_ASSERT(Error == NvSuccess); - NvOsMutexUnlock(hRPCHandle->RecvLock); -} - -NvError NvRmPrivRPCWaitForConnect( NvRmRPCHandle hRPCHandle ) -{ - NvError Error = NvSuccess; - - NV_ASSERT(hRPCHandle != NULL); - NV_ASSERT(hRPCHandle->svcTransportHandle != NULL); - - if (hRPCHandle->isConnected) panic("%s: line=%d\n", __func__, __LINE__); - if(hRPCHandle->isConnected == NV_FALSE) - { - Error = NvRmTransportSetQueueDepth(hRPCHandle->svcTransportHandle, - MAX_QUEUE_DEPTH, MAX_MESSAGE_LENGTH); - if (Error) - { - goto clean_up; - } - Error = NvError_InvalidState; - // Connect to the other end - while (s_ContinueProcessing) - { - Error = NvRmTransportWaitForConnect( - hRPCHandle->svcTransportHandle, 100 ); - if (Error == NvSuccess) - { - hRPCHandle->isConnected = NV_TRUE; - break; - } - // if there is some other issue than a timeout, then bail out. - if (Error != NvError_Timeout) - { - goto clean_up; - } - } - } - -clean_up: - return Error; -} - -NvError NvRmPrivRPCConnect( NvRmRPCHandle hRPCHandle ) -{ - NvError Error = NvSuccess; - - NV_ASSERT(hRPCHandle != NULL); - NV_ASSERT(hRPCHandle->svcTransportHandle != NULL); - - /* if (hRPCHandle->isConnected) panic("%s: line=%d\n", __func__, __LINE__); */ - NvOsMutexLock(hRPCHandle->RecvLock); - if(hRPCHandle->isConnected == NV_TRUE) - { - goto clean_up; - } - Error = NvRmTransportSetQueueDepth(hRPCHandle->svcTransportHandle, - MAX_QUEUE_DEPTH, MAX_MESSAGE_LENGTH); - if (Error) - { - goto clean_up; - } - Error = NvError_InvalidState; - -#define CONNECTION_TIMEOUT (20 * 1000) - - // Connect to the other end with a large timeout - // Timeout value has been increased to suit slow enviornments like - // emulation FPGAs - Error = NvRmTransportConnect(hRPCHandle->svcTransportHandle, - CONNECTION_TIMEOUT ); - if(Error == NvSuccess) - { - hRPCHandle->isConnected = NV_TRUE; - } - else - { - NvOsDebugPrintf("%s: Not connected.\n", __func__); - } - -#undef CONNECTION_TIMEOUT - -clean_up: - NvOsMutexUnlock(hRPCHandle->RecvLock); - return Error; -} - -NvError NvRmPrivRPCRecvMsg( NvRmRPCHandle hRPCHandle, void* pMessageBuffer, - NvU32 * pMessageSize ) -{ - NvError Error = NvSuccess; - NV_ASSERT(hRPCHandle->svcTransportHandle != NULL); - - if (s_ContinueProcessing == 0) - { - Error = NvError_InvalidState; - goto clean_up; - } - - NvOsSemaphoreWait(hRPCHandle->TransportRecvSemId); - if(s_ContinueProcessing != 0) - { - - Error = NvRmTransportRecvMsg(hRPCHandle->svcTransportHandle, - pMessageBuffer, MAX_MESSAGE_LENGTH, pMessageSize); - } - else - { - Error = NvError_InvalidState; - } -clean_up: - return Error; -} - -void NvRmPrivRPCClose( NvRmRPCHandle hRPCHandle ) -{ - // signal the thread to exit - s_ContinueProcessing = 0; - if(hRPCHandle && hRPCHandle->svcTransportHandle != NULL) - { - if (hRPCHandle->TransportRecvSemId) - NvOsSemaphoreSignal(hRPCHandle->TransportRecvSemId); - } -} - -NvError NvRmPrivInitService(NvRmDeviceHandle hDeviceHandle) -{ - NvError Error = NvSuccess; - - Error = NvRmPrivRPCInit(hDeviceHandle, PORT_NAME, &gs_hRPCHandle); - if( Error != NvSuccess) - { - goto exit_gracefully; - } - NV_ASSERT(gs_hRPCHandle != NULL); - -#if !NV_IS_AVP - Error = NvOsInterruptPriorityThreadCreate(ServiceThread, NULL, - &s_RecvThreadId_Service); -#else - Error = NvOsThreadCreate(ServiceThread, NULL, &s_RecvThreadId_Service); -#endif - -exit_gracefully: - return Error; -} - -void NvRmPrivServiceDeInit() -{ - NvRmPrivRPCClose(gs_hRPCHandle); - NvOsThreadJoin(s_RecvThreadId_Service); - NvRmPrivRPCDeInit(gs_hRPCHandle); -} diff --git a/arch/arm/mach-tegra/nv/nvrm/core/common/nvrm_init_stub.c b/arch/arm/mach-tegra/nv/nvrm/core/common/nvrm_init_stub.c deleted file mode 100644 index 481ebd43260f..000000000000 --- a/arch/arm/mach-tegra/nv/nvrm/core/common/nvrm_init_stub.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2009 NVIDIA Corporation. All rights reserved. - * - * NVIDIA Corporation and its licensors retain all intellectual property - * and proprietary rights in and to this software, related documentation - * and any modifications thereto. Any use, reproduction, disclosure or - * distribution of this software and related documentation without an express - * license agreement from NVIDIA Corporation is strictly prohibited. - */ - -#include "nvcommon.h" -#include "nvos.h" -#include "nvassert.h" -#include "nvidlcmd.h" -#include "nvrm_init.h" - -void NvRmClose(NvRmDeviceHandle hDevice) -{ -} - -NvError NvRmOpenNew(NvRmDeviceHandle *pHandle) -{ - *pHandle = (void *)1; - return NvSuccess; -} - -void NvRmInit(NvRmDeviceHandle *pHandle) -{ -} - -NvError NvRmOpen(NvRmDeviceHandle *pHandle, NvU32 DeviceId) -{ - return NvRmOpenNew(pHandle); -} diff --git a/arch/arm/mach-tegra/nv/nvrm/core/common/nvrm_moduleloader.c b/arch/arm/mach-tegra/nv/nvrm/core/common/nvrm_moduleloader.c deleted file mode 100644 index a4d47cd1748b..000000000000 --- a/arch/arm/mach-tegra/nv/nvrm/core/common/nvrm_moduleloader.c +++ /dev/null @@ -1,811 +0,0 @@ -/* - * arch/arm/mach-tegra/nvrm/core/common/nvrm_moduleloader.c - * - * AVP firmware module loader - * - * Copyright (c) 2010, NVIDIA Corporation. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#define NV_ENABLE_DEBUG_PRINTS 0 - -#include <linux/module.h> -#include <linux/kernel.h> -#include <linux/init.h> -#include <linux/delay.h> -#include <linux/dma-mapping.h> -#include <linux/device.h> -#include <linux/string.h> -#include <linux/miscdevice.h> -#include <linux/fs.h> -#include <linux/firmware.h> -#include <linux/uaccess.h> -#include <linux/platform_device.h> -#include <asm/cacheflush.h> -#include <asm/io.h> -#include <mach/nvmap.h> - -#include "nvcommon.h" -#include "nvassert.h" -#include "nvos.h" -#include "nvutil.h" -#include "nvrm_hardware_access.h" -#include "nvrm_message.h" -#include "nvrm_rpc.h" -#include "nvrm_moduleloader.h" -#include "nvrm_moduleloader_private.h" -#include "nvrm_graphics_private.h" -#include "nvrm_structure.h" -#include "nvfw.h" -#include "ap15/arflow_ctlr.h" -#include "ap15/arevp.h" -#include "mach/io.h" -#include "mach/iomap.h" -#include "headavp.h" - -#define DEVICE_NAME "nvfw" - -#define _TEGRA_AVP_RESET_VECTOR_ADDR \ - (IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE) + EVP_COP_RESET_VECTOR_0) - -static const struct firmware *s_FwEntry; -static NvRmRPCHandle s_RPCHandle = NULL; - -static struct nvmap_handle_ref *s_KernelImage = NULL; -struct nvmap_client *s_AvpClient = NULL; - -static NvError SendMsgDetachModule(NvRmLibraryHandle hLibHandle); -static NvError SendMsgAttachModule( - NvRmLibraryHandle hLibHandle, - void* pArgs, - NvU32 loadAddress, - NvU32 fileSize, - NvBool greedy, - NvU32 sizeOfArgs); -NvU32 NvRmModuleGetChipId(NvRmDeviceHandle hDevice); -NvError NvRmPrivInitModuleLoaderRPC(NvRmDeviceHandle hDevice); -void NvRmPrivDeInitModuleLoaderRPC(void); -static NvError NvRmPrivInitAvp(NvRmDeviceHandle hDevice); - -#define AVP_KERNEL_SIZE_MAX SZ_1M - -#define ADD_MASK 0x00000001 -#define SUB_MASK 0xFFFFFFFD - -static int nvfw_open(struct inode *inode, struct file *file); -static int nvfw_close(struct inode *inode, struct file *file); -static long nvfw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); -static ssize_t nvfw_write(struct file *, const char __user *, size_t, loff_t *); - -static NvError NvRmPrivInitAvp(NvRmDeviceHandle hRm); - -static const struct file_operations nvfw_fops = -{ - .owner = THIS_MODULE, - .open = nvfw_open, - .release = nvfw_close, - .write = nvfw_write, - .unlocked_ioctl = nvfw_ioctl, -}; - -static struct miscdevice nvfw_dev = -{ - .name = DEVICE_NAME, - .fops = &nvfw_fops, - .minor = MISC_DYNAMIC_MINOR, -}; - -// FIXME: This function is just for debugging. -ssize_t nvfw_write(struct file *file, const char __user *buff, size_t count, loff_t *offp) -{ - NvRmDeviceHandle hRmDevice; - NvRmLibraryHandle hRmLibHandle; - char filename[100]; - int error; - - error = copy_from_user(filename, buff, count); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - filename[count] = 0; - error = NvRmOpen( &hRmDevice, 0 ); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - error = NvRmLoadLibrary(hRmDevice, filename, NULL, 0, &hRmLibHandle); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - return count; -} - -int nvfw_open(struct inode *inode, struct file *file) -{ - return 0; -} - -int nvfw_close(struct inode *inode, struct file *file) -{ - return 0; -} - -static int nvfw_ioctl_load_library(struct file *filp, void __user *arg) -{ - struct nvfw_load_handle op; - NvRmDeviceHandle hRmDevice; - NvRmLibraryHandle hRmLibHandle; - char *filename = NULL; - void *args = NULL; - int error; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - filename = NvOsAlloc(op.length + 1); - error = copy_from_user(filename, op.filename, op.length + 1); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - args = NvOsAlloc(op.argssize); - error = copy_from_user(args, op.args, op.argssize); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - error = NvRmOpen( &hRmDevice, 0 ); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - error = NvRmLoadLibrary(hRmDevice, filename, args, op.argssize, &hRmLibHandle); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - op.handle = hRmLibHandle; - error = copy_to_user(arg, &op, sizeof(op)); - - NvOsFree(filename); - NvOsFree(args); - return error; -} - -static int nvfw_ioctl_load_library_ex(struct file *filp, void __user *arg) -{ - struct nvfw_load_handle op; - NvRmDeviceHandle hRmDevice; - NvRmLibraryHandle hRmLibHandle; - char *filename = NULL; - void *args = NULL; - int error; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - filename = NvOsAlloc(op.length + 1); - error = copy_from_user(filename, op.filename, op.length + 1); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - args = NvOsAlloc(op.argssize); - error = copy_from_user(args, op.args, op.argssize); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - error = NvRmOpen( &hRmDevice, 0 ); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - error = NvRmLoadLibraryEx(hRmDevice, filename, args, op.argssize, op.greedy, &hRmLibHandle); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - op.handle = hRmLibHandle; - error = copy_to_user(arg, &op, sizeof(op)); - - NvOsFree(filename); - NvOsFree(args); - return error; -} - -static int nvfw_ioctl_free_library(struct file *filp, void __user *arg) -{ - struct nvfw_load_handle op; - NvRmDeviceHandle hRmDevice; - int error; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - error = NvRmOpen( &hRmDevice, 0 ); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - error = NvRmFreeLibrary(op.handle); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - return error; -} - -static int nvfw_ioctl_get_proc_address(struct file *filp, void __user *arg) -{ - struct nvfw_get_proc_address_handle op; - NvRmDeviceHandle hRmDevice; - char *symbolname; - int error; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - symbolname = NvOsAlloc(op.length + 1); - error = copy_from_user(symbolname, op.symbolname, op.length + 1); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - error = NvRmOpen( &hRmDevice, 0 ); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - error = NvRmGetProcAddress(op.handle, symbolname, &op.address); - if (error) panic("%s: line=%d\n", __func__, __LINE__); - - error = copy_to_user(arg, &op, sizeof(op)); - - NvOsFree(symbolname); - return error; -} - -static long nvfw_ioctl(struct file *filp, - unsigned int cmd, unsigned long arg) -{ - int err = 0; - void __user *uarg = (void __user *)arg; - - switch (cmd) { - case NVFW_IOC_LOAD_LIBRARY: - err = nvfw_ioctl_load_library(filp, uarg); - break; - case NVFW_IOC_LOAD_LIBRARY_EX: - err = nvfw_ioctl_load_library_ex(filp, uarg); - break; - case NVFW_IOC_FREE_LIBRARY: - err = nvfw_ioctl_free_library(filp, uarg); - break; - case NVFW_IOC_GET_PROC_ADDRESS: - err = nvfw_ioctl_get_proc_address(filp, uarg); - break; - default: - return -ENOTTY; - } - return err; -} - -static NvError PrivateOsFopen( - const char *filename, - NvU32 flags, - PrivateOsFileHandle *file) -{ - PrivateOsFileHandle hFile; - - hFile = NvOsAlloc(sizeof(PrivateOsFile)); - if (hFile == NULL) - return NvError_InsufficientMemory; - - pr_debug("%s <kernel impl>: file=%s\n", __func__, filename); - if (request_firmware(&s_FwEntry, filename, nvfw_dev.this_device) != 0) - { - pr_err("%s: Cannot read firmware '%s'\n", __func__, filename); - return NvError_FileReadFailed; - } - hFile->pstart = s_FwEntry->data; - hFile->pread = s_FwEntry->data; - hFile->pend = s_FwEntry->data + s_FwEntry->size; - - *file = hFile; - - return NvError_Success; -} - -static void PrivateOsFclose(PrivateOsFileHandle hFile) -{ - release_firmware(s_FwEntry); - NV_ASSERT(hFile); - NvOsFree(hFile); -} - -NvError NvRmLoadLibrary( - NvRmDeviceHandle hDevice, - const char *pLibName, - void* pArgs, - NvU32 sizeOfArgs, - NvRmLibraryHandle *hLibHandle) -{ - NvError Error = NvSuccess; - NV_ASSERT(sizeOfArgs <= MAX_ARGS_SIZE); - - Error = NvRmLoadLibraryEx(hDevice, pLibName, pArgs, sizeOfArgs, NV_FALSE, - hLibHandle); - return Error; -} - -NvError NvRmLoadLibraryEx( - NvRmDeviceHandle hDevice, - const char *pLibName, - void* pArgs, - NvU32 sizeOfArgs, - NvBool IsApproachGreedy, - NvRmLibraryHandle *hLibHandle) -{ - NvRmLibraryHandle library = NULL; - NvError e = NvSuccess; - PrivateOsFileHandle hFile = NULL; - struct nvmap_handle_ref *staging = NULL; - void *loadAddr = NULL; - NvU32 len = 0; - NvU32 physAddr; - - NV_ASSERT(sizeOfArgs <= MAX_ARGS_SIZE); - - NV_CHECK_ERROR_CLEANUP(NvRmPrivInitAvp(hDevice)); - - e = NvRmPrivRPCConnect(s_RPCHandle); - if (e != NvSuccess) - { - NvOsDebugPrintf("RPCConnect timed out during NvRmLoadLibrary\n"); - goto fail; - } - - library = NvOsAlloc(sizeof(*library)); - if (!library) - { - e = NvError_InsufficientMemory; - goto fail; - } - - NV_CHECK_ERROR_CLEANUP(PrivateOsFopen(pLibName, NVOS_OPEN_READ, &hFile)); - len = (NvU32)hFile->pend - (NvU32)hFile->pstart; - - staging = nvmap_alloc(s_AvpClient, len, L1_CACHE_BYTES, - NVMAP_HANDLE_WRITE_COMBINE); - if (IS_ERR(staging)) { - e = NvError_InsufficientMemory; - goto fail; - } - loadAddr = nvmap_mmap(staging); - if (!loadAddr) { - e = NvError_InsufficientMemory; - goto fail; - } - physAddr = nvmap_pin(s_AvpClient, staging); - if (IS_ERR((void*)physAddr)) { - e = NvError_InsufficientMemory; - goto fail; - } - - NvOsMemcpy(loadAddr, hFile->pstart, len); - - memcpy(loadAddr, hFile->pstart, len); - wmb(); - - NV_CHECK_ERROR_CLEANUP(SendMsgAttachModule(library, pArgs, physAddr, len, - IsApproachGreedy, sizeOfArgs)); - -fail: - if (loadAddr) - { - if (!IS_ERR((void*)physAddr)) - nvmap_unpin(s_AvpClient, staging); - - nvmap_munmap(staging, loadAddr); - } - - if (!IS_ERR_OR_NULL(staging)) - nvmap_free(s_AvpClient, staging); - - if (hFile) - PrivateOsFclose(hFile); - - if (e != NvSuccess) - { - NvOsFree(library); - library = NULL; - } - - *hLibHandle = library; - return e; -} - -NvError NvRmGetProcAddress( - NvRmLibraryHandle Handle, - const char *pSymbol, - void **pSymAddress) -{ - NvError Error = NvSuccess; - NV_ASSERT(Handle); - Error = NvRmPrivGetProcAddress(Handle, pSymbol, pSymAddress); - return Error; -} - -NvError NvRmFreeLibrary(NvRmLibraryHandle hLibHandle) -{ - NvError e = NvSuccess; - NV_ASSERT(hLibHandle); - - e = NvRmPrivRPCConnect(s_RPCHandle); - if (e != NvSuccess) - return e; - - e = SendMsgDetachModule(hLibHandle); - if (e != NvSuccess) - return e; - - NvOsFree(hLibHandle); - return NvSuccess; -} - -//before unloading loading send message to avp with args and entry point via transport -static NvError SendMsgDetachModule(NvRmLibraryHandle hLibHandle) -{ - NvU32 RecvMsgSize; - NvRmMessage_DetachModule Msg; - NvRmMessage_DetachModuleResponse MsgR; - - Msg.msg = NvRmMsg_DetachModule; - - Msg.msg = NvRmMsg_DetachModule; - Msg.reason = NvRmModuleLoaderReason_Detach; - Msg.libraryId = hLibHandle->libraryId; - RecvMsgSize = sizeof(NvRmMessage_DetachModuleResponse); - NvRmPrivRPCSendMsgWithResponse(s_RPCHandle, &MsgR, RecvMsgSize, - &RecvMsgSize, &Msg, sizeof(Msg)); - - return MsgR.error; -} - -//after successful loading send message to avp with args and entry point via transport -static NvError SendMsgAttachModule( - NvRmLibraryHandle hLibHandle, - void* pArgs, - NvU32 loadAddress, - NvU32 fileSize, - NvBool greedy, - NvU32 sizeOfArgs) -{ - NvU32 RecvMsgSize; - NvRmMessage_AttachModule Msg; - NvRmMessage_AttachModuleResponse MsgR; - - NvOsMemset(&Msg, 0, sizeof(Msg)); - Msg.msg = NvRmMsg_AttachModule; - - if(pArgs) - NvOsMemcpy(Msg.args, pArgs, sizeOfArgs); - - Msg.size = sizeOfArgs; - Msg.address = loadAddress; - Msg.filesize = fileSize; - if (greedy) - Msg.reason = NvRmModuleLoaderReason_AttachGreedy; - else - Msg.reason = NvRmModuleLoaderReason_Attach; - - RecvMsgSize = sizeof(NvRmMessage_AttachModuleResponse); - - NvRmPrivRPCSendMsgWithResponse(s_RPCHandle, &MsgR, RecvMsgSize, - &RecvMsgSize, &Msg, sizeof(Msg)); - - hLibHandle->libraryId = MsgR.libraryId; - return MsgR.error; -} - - -NvError NvRmPrivInitModuleLoaderRPC(NvRmDeviceHandle hDevice) -{ - NvError err = NvSuccess; - - if (s_RPCHandle) - return NvError_Success; - - NvOsDebugPrintf("%s <kernel impl>: NvRmPrivRPCInit(RPC_AVP_PORT)\n", __func__); - err = NvRmPrivRPCInit(hDevice, "RPC_AVP_PORT", &s_RPCHandle); - if (err) panic("%s: NvRmPrivRPCInit FAILED\n", __func__); - - return err; -} - -void NvRmPrivDeInitModuleLoaderRPC() -{ - NvRmPrivRPCDeInit(s_RPCHandle); -} - -NvError NvRmPrivGetProcAddress( - NvRmLibraryHandle Handle, - const char *pSymbol, - void **pSymAddress) -{ - NvRmLibHandle *hHandle = Handle; - - if (hHandle->libraryId == 0) - return NvError_SymbolNotFound; - - *pSymAddress = (void *)hHandle->libraryId; - return NvSuccess; -} - -static void NvRmPrivResetAvp(NvRmDeviceHandle hRm, unsigned long reset_va) -{ - u32 *stub_va = &_tegra_avp_launcher_stub_data[AVP_LAUNCHER_START_VA]; - unsigned long stub_addr = virt_to_phys(_tegra_avp_launcher_stub); - unsigned int tmp; - unsigned long timeout; - - *stub_va = reset_va; - __cpuc_flush_dcache_area(stub_va, sizeof(*stub_va)); - outer_clean_range(__pa(stub_va), __pa(stub_va+1)); - - tmp = readl(_TEGRA_AVP_RESET_VECTOR_ADDR); - writel(stub_addr, _TEGRA_AVP_RESET_VECTOR_ADDR); - barrier(); - NvRmModuleReset(hRm, NvRmModuleID_Avp); - writel(0, IO_ADDRESS(TEGRA_FLOW_CTRL_BASE) + FLOW_CTRL_HALT_COP); - - barrier(); - timeout = jiffies + HZ; - /* the AVP firmware will reprogram its reset vector as the kernel - * starts, so a dead kernel can be detected by polling this value */ - while (time_before(jiffies, timeout)) { - if (readl(_TEGRA_AVP_RESET_VECTOR_ADDR) != stub_addr) - break; - cpu_relax(); - } - - WARN_ON(readl(_TEGRA_AVP_RESET_VECTOR_ADDR) == stub_addr); -} - -void NvRmPrivXpcSendMsgAddress(void); - -static NvError NvRmPrivInitAvp(NvRmDeviceHandle hRm) -{ - u32 *stub_phys = &_tegra_avp_launcher_stub_data[AVP_LAUNCHER_MMU_PHYSICAL]; - PrivateOsFileHandle kernel; - void *map = NULL; - NvError e; - NvU32 len; - NvU32 phys; - - if (s_KernelImage) - return NvSuccess; - - s_AvpClient = nvmap_create_client(nvmap_dev, "nvrm"); - if (IS_ERR(s_AvpClient)) { - e = NvError_InsufficientMemory; - goto fail; - } - - s_KernelImage = nvmap_alloc(s_AvpClient, SZ_1M, SZ_1M, - NVMAP_HANDLE_WRITE_COMBINE); - if (IS_ERR(s_KernelImage)) { - e = NvError_InsufficientMemory; - goto fail; - } - - map = nvmap_mmap(s_KernelImage); - if (map == NULL) { - e = NvError_InsufficientMemory; - goto fail; - } - - phys = nvmap_pin(s_AvpClient, s_KernelImage); - if (IS_ERR((void *)phys)) { - e = NvError_InsufficientMemory; - goto fail; - } - - NV_CHECK_ERROR_CLEANUP(PrivateOsFopen("nvrm_avp.bin", - NVOS_OPEN_READ, &kernel)); - - memset(map, 0, SZ_1M); - len = (NvU32)kernel->pend - (NvU32)kernel->pstart; - memcpy(map, kernel->pstart, len); - wmb(); - - PrivateOsFclose(kernel); - - *stub_phys = phys; - __cpuc_flush_dcache_area(stub_phys, sizeof(*stub_phys)); - outer_clean_range(__pa(stub_phys), __pa(stub_phys+1)); - - NvRmPrivResetAvp(hRm, 0x00100000ul); - - NV_CHECK_ERROR_CLEANUP(NvRmPrivInitService(hRm)); - - NvRmPrivXpcSendMsgAddress(); - - e = NvRmPrivInitModuleLoaderRPC(hRm); - if (e != NvSuccess) - { - NvRmPrivServiceDeInit(); - goto fail; - } - - nvmap_munmap(s_KernelImage, map); - - return NvSuccess; - -fail: - writel(2 << 29, IO_ADDRESS(TEGRA_FLOW_CTRL_BASE) + FLOW_CTRL_HALT_COP); - if (map) - { - if (!IS_ERR_OR_NULL((void *)phys)) - nvmap_unpin(s_AvpClient, s_KernelImage); - } - if (!IS_ERR_OR_NULL(s_KernelImage)) - nvmap_free(s_AvpClient, s_KernelImage); - if (!IS_ERR_OR_NULL(s_AvpClient)) - nvmap_client_put(s_AvpClient); - s_KernelImage = NULL; - s_AvpClient = NULL; - return e; -} - -static void __iomem *iram_base = IO_ADDRESS(TEGRA_IRAM_BASE); -static void __iomem *iram_backup; -static dma_addr_t iram_backup_addr; -static u32 iram_size = TEGRA_IRAM_SIZE; -static u32 iram_backup_size = TEGRA_IRAM_SIZE + 4; -static u32 avp_resume_addr; - -static NvError NvRmPrivSuspendAvp(NvRmRPCHandle hRPCHandle) -{ - NvError err = NvSuccess; - NvRmMessage_InitiateLP0 lp0_msg; - void *avp_suspend_done = iram_backup + iram_size; - unsigned long timeout; - - pr_info("%s()+\n", __func__); - - if (!s_KernelImage) - goto done; - else if (!iram_backup_addr) { - /* XXX: should we return error? */ - pr_warning("%s: iram backup ram missing, not suspending avp\n", - __func__); - goto done; - } - - NV_ASSERT(hRPCHandle->svcTransportHandle != NULL); - - lp0_msg.msg = NvRmMsg_InitiateLP0; - lp0_msg.sourceAddr = (u32)TEGRA_IRAM_BASE; - lp0_msg.bufferAddr = (u32)iram_backup_addr; - lp0_msg.bufferSize = (u32)iram_size; - - writel(0, avp_suspend_done); - - NvOsMutexLock(hRPCHandle->RecvLock); - err = NvRmTransportSendMsg(hRPCHandle->svcTransportHandle, &lp0_msg, - sizeof(lp0_msg), 1000); - NvOsMutexUnlock(hRPCHandle->RecvLock); - - if (err != NvSuccess) { - pr_err("%s: cannot send AVP LP0 message\n", __func__); - goto done; - } - - timeout = jiffies + msecs_to_jiffies(1000); - while (!readl(avp_suspend_done) && time_before(jiffies, timeout)) { - udelay(10); - cpu_relax(); - } - - if (!readl(avp_suspend_done)) { - pr_err("%s: AVP failed to suspend\n", __func__); - err = NvError_Timeout; - goto done; - } - - avp_resume_addr = readl(iram_base); - if (!avp_resume_addr) { - pr_err("%s: AVP failed to set it's resume address\n", __func__); - err = NvError_InvalidState; - goto done; - } - - pr_info("avp_suspend: resume_addr=%x\n", avp_resume_addr); - avp_resume_addr &= 0xFFFFFFFE; - - pr_info("%s()-\n", __func__); - -done: - return err; -} - -static NvError NvRmPrivResumeAvp(NvRmRPCHandle hRPCHandle) -{ - NvError ret = NvSuccess; - - pr_info("%s()+\n", __func__); - if (!s_KernelImage || !avp_resume_addr) - goto done; - - NvRmPrivResetAvp(hRPCHandle->hRmDevice, avp_resume_addr); - avp_resume_addr = 0; - - pr_info("%s()-\n", __func__); - -done: - return ret; -} - -int __init _avp_suspend_resume_init(void) -{ - /* allocate an iram sized chunk of ram to give to the AVP */ - iram_backup = dma_alloc_coherent(NULL, iram_backup_size, - &iram_backup_addr, GFP_KERNEL); - if (!iram_backup) - { - pr_err("%s: Unable to allocate iram backup mem\n", __func__); - return -ENOMEM; - } - - return 0; -} - -static int avp_suspend(struct platform_device *pdev, pm_message_t state) -{ - NvError err; - - err = NvRmPrivSuspendAvp(s_RPCHandle); - if (err != NvSuccess) - return -EIO; - return 0; -} - -static int avp_resume(struct platform_device *pdev) -{ - NvError err; - - err = NvRmPrivResumeAvp(s_RPCHandle); - if (err != NvSuccess) - return -EIO; - return 0; -} - -static struct platform_driver avp_nvfw_driver = { - .suspend = avp_suspend, - .resume = avp_resume, - .driver = { - .name = "nvfw-avp-device", - .owner = THIS_MODULE, - }, -}; - -int __init _avp_suspend_resume_init(void); - -static int __init nvfw_init(void) -{ - int ret = 0; - struct platform_device *pdev; - - ret = misc_register(&nvfw_dev); - s_KernelImage = NULL; - if (ret) panic("%s: misc_register FAILED\n", __func__); - - ret = _avp_suspend_resume_init(); - if (ret) - goto err; - pdev = platform_create_bundle(&avp_nvfw_driver, NULL, NULL, 0, NULL, 0); - if (!pdev) { - pr_err("%s: Can't reg platform driver\n", __func__); - ret = -EINVAL; - goto err; - } - - return 0; - -err: - return ret; -} - -static void __exit nvfw_deinit(void) -{ - misc_deregister(&nvfw_dev); -} - -module_init(nvfw_init); -module_exit(nvfw_deinit); diff --git a/arch/arm/mach-tegra/nv/nvrpc_user.c b/arch/arm/mach-tegra/nv/nvrpc_user.c deleted file mode 100644 index 526c9fffb2a2..000000000000 --- a/arch/arm/mach-tegra/nv/nvrpc_user.c +++ /dev/null @@ -1,676 +0,0 @@ -/* - * arch/arm/mach-tegra/nvrpc_user.c - * - * User-land access to NvRm transport APIs - * - * Copyright (c) 2008-2010, NVIDIA Corporation. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#define NV_DEBUG 0 - -#include <linux/module.h> -#include <linux/proc_fs.h> -#include <linux/miscdevice.h> -#include <linux/uaccess.h> -#include <mach/nvrm_linux.h> -#include <mach/nvrpc.h> -#include "nvcommon.h" -#include "nvassert.h" -#include "nvos.h" -#include "nvrm_transport.h" -#include "nvrm_xpc.h" - -#define DEVICE_NAME "nvrpc" -#define NVRPC_MAX_LOCAL_STACK 256 -#define nvrpc_stack_kzalloc(stackbuf, size, gfp) \ - ((size) > sizeof((stackbuf)) ? kzalloc((size),(gfp)) : (stackbuf)) -#define nvrpc_stack_kfree(stackbuf, buf) \ - do { \ - if ((buf) && (buf)!=(void *)(stackbuf)) \ - kfree(buf); \ - } while (0); - -static int nvrpc_open(struct inode *inode, struct file *file); -static int nvrpc_close(struct inode *inode, struct file *file); -static long nvrpc_unlocked_ioctl(struct file *file, - unsigned int cmd, unsigned long arg); - -//Ioctl functions -static int nvrpc_ioctl_open(struct file *filp, - unsigned int cmd, void __user *arg); -static int nvrpc_ioctl_get_port_name(struct file *filp, - unsigned int cmd, void __user *arg); -static int nvrpc_ioctl_close(struct file *filp, - unsigned int cmd, void __user *arg); -static int nvrpc_ioctl_wait_for_connect(struct file *filp, - unsigned int cmd, void __user *arg); -static int nvrpc_ioctl_connect(struct file *filp, - unsigned int cmd, void __user *arg); -static int nvrpc_ioctl_set_queue_depth(struct file *filp, - unsigned int cmd, void __user *arg); -static int nvrpc_ioctl_send_msg(struct file *filp, - unsigned int cmd, void __user *arg); -static int nvrpc_ioctl_send_msg_lp0(struct file *filp, - unsigned int cmd, void __user *arg); -static int nvrpc_ioctl_recv_msg(struct file *filp, - unsigned int cmd, void __user *arg); -static int nvrpc_ioctl_xpc_init(struct file *filp, - unsigned int cmd, void __user *arg); -static int nvrpc_ioctl_xpc_acquire(struct file *filp, - unsigned int cmd, void __user *arg); -static int nvrpc_ioctl_xpc_release(struct file *filp, - unsigned int cmd, void __user *arg); -static int nvrpc_ioctl_xpc_get_msg(struct file *filp, - unsigned int cmd, void __user *arg); -static int nvrpc_ioctl_xpc_send_msg(struct file *filp, - unsigned int cmd, void __user *arg); -static int nvrpc_ioctl_xpc_destroy(struct file *filp, - unsigned int cmd, void __user *arg); -static int nvrpc_ioctl_xpc_create(struct file *filp, - unsigned int cmd, void __user *arg); -// local function -static int nvrpc_make_error_code(NvError e); - -static const struct file_operations nvrpc_fops = -{ - .owner = THIS_MODULE, - .open = nvrpc_open, - .release = nvrpc_close, - .unlocked_ioctl = nvrpc_unlocked_ioctl, -}; - -static struct miscdevice nvrpc_dev = -{ - .name = DEVICE_NAME, - .fops = &nvrpc_fops, - .minor = MISC_DYNAMIC_MINOR, -}; - -static DEFINE_MUTEX(nvrpc_device_lock); - -static NvBool s_init_done = NV_FALSE; -NvRmDeviceHandle s_hRmGlobal = NULL; - -int nvrpc_open(struct inode *inode, struct file *file) -{ - NvError e = NvSuccess; - - mutex_lock(&nvrpc_device_lock); - if (s_init_done == NV_FALSE) { - e = NvRmTransportInit(s_hRmGlobal); - s_init_done = NV_TRUE; - } - mutex_unlock(&nvrpc_device_lock); - - if (e == NvSuccess) - return 0; - else - return -ENODEV; -} - -int nvrpc_close(struct inode *inode, struct file *file) -{ - return 0; -} - -static int nvrpc_make_error_code(NvError e) -{ - int error = 0; - if (error != NvSuccess) { - if (e == NvError_InvalidAddress) - error = -EFAULT; - else if (e == NvError_BadParameter) - error = -EINVAL; - else - error = -EIO; - } - return error; -} - -NvRmTransportHandle g_hTransportAvp = NULL; -NvRmTransportHandle g_hTransportCpu = NULL; -NvOsSemaphoreHandle g_hTransportAvpSem = NULL; -NvOsSemaphoreHandle g_hTransportCpuSem = NULL; -int g_hTransportAvpIsConnected = 0; -int g_hTransportCpuIsConnected = 0; - -static int nvrpc_ioctl_open(struct file *filp, - unsigned int cmd, void __user *arg) -{ - NvError e = NvSuccess; - int error; - struct nvrpc_open_params op; - char *p_name = NULL; - NvOsSemaphoreHandle recv_sem = NULL; - NvU32 port_name[NVRPC_MAX_LOCAL_STACK/sizeof(NvU32)]; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) - goto fail; - - if (op.port_name_size) { - p_name = nvrpc_stack_kzalloc(port_name, - op.port_name_size, GFP_KERNEL); - if (!p_name) { - error = -ENOMEM; - goto fail; - } - error = copy_from_user(p_name, (const void*)op.port_name, - op.port_name_size); - if (error) - goto fail; - if (p_name[op.port_name_size - 1] != 0) { - error = -EINVAL; - goto fail; - } - } - if (op.sem) { - NvOsSemaphoreHandle sem = (NvOsSemaphoreHandle) op.sem; - e = NvOsSemaphoreUnmarshal(sem, &recv_sem); - if (e != NvSuccess) - goto fail; - } - op.ret_val = NvRmTransportOpen(s_hRmGlobal, p_name, recv_sem, - (void *)&op.transport_handle); - error = copy_to_user(arg, &op, sizeof(op)); - if (p_name && ! strcmp(p_name, "RPC_CPU_PORT")) { - if (g_hTransportCpu) { - panic("%s: g_hTransportCpu=%p is already assigned.\n", __func__, g_hTransportCpu); - } - g_hTransportCpu = (NvRmTransportHandle)op.transport_handle; - g_hTransportCpuSem = (NvOsSemaphoreHandle) op.sem; - } - if (p_name && ! strcmp(p_name, "RPC_AVP_PORT")) { - if (g_hTransportAvp) { - panic("%s: g_hTransportAvp=%p is already assigned.\n", __func__, g_hTransportAvp); - } - g_hTransportAvp = (NvRmTransportHandle)op.transport_handle; - g_hTransportAvpSem = (NvOsSemaphoreHandle) op.sem; - } - -fail: - nvrpc_stack_kfree((char*)port_name, p_name); - if (recv_sem) - NvOsSemaphoreDestroy(recv_sem); - if (e != NvSuccess) - error = nvrpc_make_error_code(e); - return error; -} - -static int nvrpc_ioctl_get_port_name(struct file *filp, - unsigned int cmd, void __user *arg) -{ - int error; - - struct nvrpc_open_params op; - NvS8 *p_name = NULL; - NvU32 port_name[NVRPC_MAX_LOCAL_STACK/sizeof(NvU32)]; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) - goto fail; - if (op.port_name_size && op.port_name) { - p_name = nvrpc_stack_kzalloc(port_name, - op.port_name_size, GFP_KERNEL); - if (!p_name) { - error = -ENOMEM; - goto fail; - } - } - NvRmTransportGetPortName((NvRmTransportHandle)op.transport_handle, - p_name, op.port_name_size); - - if (op.port_name_size && p_name) { - error = copy_to_user((void*)op.port_name, - p_name, op.port_name_size * sizeof(NvU8)); - } - -fail: - nvrpc_stack_kfree((NvS8*)port_name, p_name); - return error; -} - -static int nvrpc_ioctl_close(struct file *filp, - unsigned int cmd, void __user *arg) -{ - int error; - struct nvrpc_handle_param op; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) - goto fail; - NvRmTransportClose((void*)op.handle); - -fail: - return error; -} - -static int nvrpc_ioctl_wait_for_connect(struct file *filp, - unsigned int cmd, void __user *arg) -{ - NvError e = NvSuccess; - int error; - struct nvrpc_handle_param op; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) - goto fail; - op.ret_val = NvRmTransportWaitForConnect( - (void *)op.handle, op.param); - error = copy_to_user(arg, &op, sizeof(op)); - -fail: - if (e != NvSuccess) - error = nvrpc_make_error_code(e); - return error; -} - -static int nvrpc_ioctl_connect(struct file *filp, - unsigned int cmd, void __user *arg) -{ - NvError e = NvSuccess; - int error; - struct nvrpc_handle_param op; - NvU8 port_name[NVRPC_MAX_LOCAL_STACK]; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) - goto fail; - - NvRmTransportGetPortName((void *)op.handle, - port_name, sizeof(port_name)); - - - op.ret_val = NvRmTransportConnect( - (void *)op.handle, op.param); - error = copy_to_user(arg, &op, sizeof(op)); - - if (! strcmp(port_name, "RPC_AVP_PORT")) { - g_hTransportAvpIsConnected = 1; - } - if (! strcmp(port_name, "RPC_CPU_PORT")) { - g_hTransportCpuIsConnected = 1; - } - -fail: - if (e != NvSuccess) - error = nvrpc_make_error_code(e); - return error; -} - -static int nvrpc_ioctl_set_queue_depth(struct file *filp, - unsigned int cmd, void __user *arg) -{ - NvError e = NvSuccess; - int error; - struct nvrpc_set_queue_depth_params op; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) - goto fail; - op.ret_val = NvRmTransportSetQueueDepth( - (NvRmTransportHandle)op.transport_handle, - op.max_queue_depth, - op.max_message_size); - error = copy_to_user(arg, &op, sizeof(op)); - -fail: - if (e != NvSuccess) - error = nvrpc_make_error_code(e); - return error; -} - -static int nvrpc_ioctl_send_msg(struct file *filp, - unsigned int cmd, void __user *arg) -{ - int error; - struct nvrpc_msg_params op; - void* msg_buffer = NULL; - NvU32 buffer[NVRPC_MAX_LOCAL_STACK/sizeof(NvU32)]; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) - goto fail; - if (op.msg_buffer && op.max_message_size) { - msg_buffer = nvrpc_stack_kzalloc(buffer, - op.max_message_size, - GFP_KERNEL); - if (!msg_buffer) { - error = -ENOMEM; - goto fail; - } - error = copy_from_user(msg_buffer, - (void*)op.msg_buffer, - op.max_message_size); - if (error) - goto fail; - } - - op.ret_val = NvRmTransportSendMsg( - (NvRmTransportHandle)op.transport_handle, - msg_buffer, op.max_message_size, op.params); - error = copy_to_user(arg, &op, sizeof(op)); - -fail: - nvrpc_stack_kfree(buffer, msg_buffer); - return error; -} - -static int nvrpc_ioctl_send_msg_lp0(struct file *filp, - unsigned int cmd, void __user *arg) -{ - int error; - struct nvrpc_msg_params op; - void* msg_buffer = NULL; - NvU32 buffer[NVRPC_MAX_LOCAL_STACK/sizeof(NvU32)]; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) - goto fail; - if (op.msg_buffer && op.max_message_size) { - msg_buffer = nvrpc_stack_kzalloc(buffer, - op.max_message_size, GFP_KERNEL); - if (!msg_buffer) { - error = -ENOMEM; - goto fail; - } - error = copy_from_user(msg_buffer, (void*)op.msg_buffer, - op.max_message_size); - if (error) - goto fail; - } - op.ret_val = NvRmTransportSendMsgInLP0( - (NvRmTransportHandle)op.transport_handle, - msg_buffer, op.max_message_size); - error = copy_to_user(arg, &op, sizeof(op)); - -fail: - nvrpc_stack_kfree(buffer, msg_buffer); - return error; -} - -static int nvrpc_ioctl_recv_msg(struct file *filp, - unsigned int cmd, void __user *arg) -{ - int error; - struct nvrpc_msg_params op; - void* msg_buffer = NULL; - NvU32 buffer[NVRPC_MAX_LOCAL_STACK/sizeof(NvU32)]; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) - goto fail; - if (op.msg_buffer && op.max_message_size) { - msg_buffer = nvrpc_stack_kzalloc(buffer, - op.max_message_size, GFP_KERNEL); - if (!msg_buffer) { - error = -ENOMEM; - goto fail; - } - } else { - error = -EINVAL; - goto fail; - } - op.ret_val = NvRmTransportRecvMsg( - (NvRmTransportHandle)op.transport_handle, - msg_buffer, op.max_message_size, &op.params); - error = copy_to_user(arg, &op, sizeof(op)); - if (op.msg_buffer && msg_buffer) { - error = copy_to_user((void*)op.msg_buffer, - msg_buffer, op.max_message_size); - if (error) - goto fail; - } - -fail: - nvrpc_stack_kfree(buffer, msg_buffer); - return error; -} - -static int nvrpc_ioctl_xpc_init(struct file *filp, - unsigned int cmd, void __user *arg) -{ - int error; - struct nvrpc_handle_param op; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) - goto fail; - op.ret_val = NvRmXpcInitArbSemaSystem((void *)op.handle); - error = copy_to_user(arg, &op, sizeof(op)); - -fail: - return error; -} - -static int nvrpc_ioctl_xpc_acquire(struct file *filp, - unsigned int cmd, void __user *arg) -{ - int error; - struct nvrpc_handle_param op; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) - goto fail; - NvRmXpcModuleAcquire(op.param); - -fail: - return error; -} - -static int nvrpc_ioctl_xpc_release(struct file *filp, - unsigned int cmd, void __user *arg) -{ - int error; - struct nvrpc_handle_param op; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) - goto fail; - NvRmXpcModuleRelease(op.param); - -fail: - return error; -} - -static int nvrpc_ioctl_xpc_get_msg(struct file *filp, - unsigned int cmd, void __user *arg) -{ - int error; - struct nvrpc_handle_param op; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) - goto fail; - op.ret_val = NvRmPrivXpcGetMessage( - (NvRmPrivXpcMessageHandle)op.handle); - error = copy_to_user(arg, &op, sizeof(op)); - -fail: - return error; -} - -static int nvrpc_ioctl_xpc_send_msg(struct file *filp, - unsigned int cmd, void __user *arg) -{ - int error; - struct nvrpc_handle_param op; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) - goto fail; - op.ret_val = NvRmPrivXpcSendMessage( - (NvRmPrivXpcMessageHandle)op.handle, op.param); - error = copy_to_user(arg, &op, sizeof(op)); - -fail: - return error; -} - -static int nvrpc_ioctl_xpc_destroy(struct file *filp, - unsigned int cmd, void __user *arg) -{ - int error; - struct nvrpc_handle_param op; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) - goto fail; - NvRmPrivXpcDestroy((NvRmPrivXpcMessageHandle)op.handle); - -fail: - return error; -} - -static int nvrpc_ioctl_xpc_create(struct file *filp, - unsigned int cmd, void __user *arg) -{ - int error; - struct nvrpc_handle_param op; - - error = copy_from_user(&op, arg, sizeof(op)); - if (error) - goto fail; - op.ret_val = NvRmPrivXpcCreate((NvRmDeviceHandle)op.handle, - (void*)&op.param); - error = copy_to_user(&op, arg, sizeof(op)); - -fail: - return error; -} - - -static long nvrpc_unlocked_ioctl(struct file *file, - unsigned int cmd, unsigned long arg) -{ - int err = 0; - void __user *uarg = (void __user *)arg; - - if (_IOC_TYPE(cmd) != NVRPC_IOC_MAGIC) - return -ENOTTY; - if (_IOC_DIR(cmd) & _IOC_READ) - err = !access_ok(VERIFY_WRITE, uarg, _IOC_SIZE(cmd)); - if (_IOC_DIR(cmd) & _IOC_WRITE) - err = !access_ok(VERIFY_READ, uarg, _IOC_SIZE(cmd)); - - if (err) - return -EFAULT; - - switch (cmd) { - case NVRPC_IOCTL_OPEN: - err = nvrpc_ioctl_open(file, cmd, uarg); - break; - - case NVRPC_IOCTL_GET_PORTNAME: - err = nvrpc_ioctl_get_port_name(file, cmd, uarg); - break; - - case NVRPC_IOCTL_CLOSE: - err = nvrpc_ioctl_close(file, cmd, uarg); - break; - - case NVRPC_IOCTL_INIT: - case NVRPC_IOCTL_DEINIT: - break; - - case NVRPC_IOCTL_WAIT_FOR_CONNECT: - err = nvrpc_ioctl_wait_for_connect(file, cmd, uarg); - break; - - case NVRPC_IOCTL_CONNECT: - err = nvrpc_ioctl_connect(file, cmd, uarg); - break; - - case NVRPC_IOCTL_SET_QUEUE_DEPTH: - err = nvrpc_ioctl_set_queue_depth(file, cmd, uarg); - break; - - case NVRPC_IOCTL_SEND_MSG: - err = nvrpc_ioctl_send_msg(file, cmd, uarg); - break; - - case NVRPC_IOCTL_SEND_MSG_LP0: - err = nvrpc_ioctl_send_msg_lp0(file, cmd, uarg); - break; - - case NVRPC_IOCTL_RECV_MSG: - err = nvrpc_ioctl_recv_msg(file, cmd, uarg); - break; - - case NVRPC_IOCTL_XPC_INIT: - err = nvrpc_ioctl_xpc_init(file, cmd, uarg); - break; - - case NVRPC_IOCTL_XPC_ACQUIRE: - err = nvrpc_ioctl_xpc_acquire(file, cmd, uarg); - break; - - case NVRPC_IOCTL_XPC_RELEASE: - err = nvrpc_ioctl_xpc_release(file, cmd, uarg); - break; - - case NVRPC_IOCTL_XPC_GET_MSG: - err = nvrpc_ioctl_xpc_get_msg(file, cmd, uarg); - break; - - case NVRPC_IOCTL_XPC_SEND_MSG: - err = nvrpc_ioctl_xpc_send_msg(file, cmd, uarg); - break; - - case NVRPC_IOCTL_XPC_DESTROY: - err = nvrpc_ioctl_xpc_destroy(file, cmd, uarg); - break; - - case NVRPC_IOCTL_XPC_CREATE: - err = nvrpc_ioctl_xpc_create(file, cmd, uarg); - break; - - default: - return -ENOTTY; - } - return err; -} - -static int __init nvrpc_init(void) -{ - int ret = 0; - - NvRmDeviceHandle handle; - NvRmInit(&handle); - - if (s_init_done == NV_FALSE) { - NvError e; - - e = NvRmOpen(&s_hRmGlobal, 0); - e = NvRmTransportInit(s_hRmGlobal); - s_init_done = NV_TRUE; - } - - ret = misc_register(&nvrpc_dev); - if (ret) { - pr_err("%s misc register FAILED\n", __func__); - } - return ret; -} - -static void __exit nvrpc_deinit(void) -{ - misc_deregister(&nvrpc_dev); -} - -module_init(nvrpc_init); -module_exit(nvrpc_deinit); |