summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary King <gking@nvidia.com>2009-12-16 13:24:12 -0800
committerGary King <gking@nvidia.com>2009-12-16 19:01:19 -0800
commite2d05b4f4cb28a6e66236bc814f01e74d2466121 (patch)
tree28690f6d7267d067a570f6748ed71abedd9a3cec
parentdd40c09c010cd04632825b76385c8a16cc67bcd5 (diff)
tegra RM: merge nvrm_module_common.c into nvrm_module.c
merge the relocation table parsing code out of nvrm_module_common.c and into nvrm_module.c
-rw-r--r--arch/arm/mach-tegra/nvrm/core/common/Makefile1
-rw-r--r--arch/arm/mach-tegra/nvrm/core/common/nvrm_module.c207
-rw-r--r--arch/arm/mach-tegra/nvrm/core/common/nvrm_module_common.c233
3 files changed, 207 insertions, 234 deletions
diff --git a/arch/arm/mach-tegra/nvrm/core/common/Makefile b/arch/arm/mach-tegra/nvrm/core/common/Makefile
index 50a5a62889c6..fcce9a5c566f 100644
--- a/arch/arm/mach-tegra/nvrm/core/common/Makefile
+++ b/arch/arm/mach-tegra/nvrm/core/common/Makefile
@@ -20,7 +20,6 @@ obj-y += nvrm_keylist.o
obj-y += nvrm_configuration.o
obj-y += nvrm_pmu.o
obj-y += nvrm_module.o
-obj-y += nvrm_module_common.o
obj-y += nvrm_hwintf.o
obj-y += nvrm_chiplib.o
obj-y += nvrm_clocks_limits.o
diff --git a/arch/arm/mach-tegra/nvrm/core/common/nvrm_module.c b/arch/arm/mach-tegra/nvrm/core/common/nvrm_module.c
index c56a8232a6b7..8af81759fa9e 100644
--- a/arch/arm/mach-tegra/nvrm/core/common/nvrm_module.c
+++ b/arch/arm/mach-tegra/nvrm/core/common/nvrm_module.c
@@ -277,3 +277,210 @@ NvError NvRmGetRandomBytes(
return NvSuccess;
}
+
+NvError
+NvRmPrivModuleInit( NvRmModuleTable *mod_table, NvU32 *reloc_table )
+{
+ NvError err;
+ NvU32 i;
+
+ /* invalidate the module table */
+ for( i = 0; i < NvRmPrivModuleID_Num; i++ )
+ {
+ mod_table->Modules[i].Index = NVRM_MODULE_INVALID;
+ }
+
+ /* clear the irq map */
+ NvOsMemset( &mod_table->IrqMap, 0, sizeof(mod_table->IrqMap) );
+
+ err = NvRmPrivRelocationTableParse( reloc_table,
+ &mod_table->ModInst, &mod_table->LastModInst,
+ mod_table->Modules, &mod_table->IrqMap );
+ if( err != NvSuccess )
+ {
+ NV_ASSERT( !"NvRmPrivModuleInit failed" );
+ return err;
+ }
+
+ NV_ASSERT( mod_table->LastModInst);
+ NV_ASSERT( mod_table->ModInst );
+
+ mod_table->NumModuleInstances = mod_table->LastModInst -
+ mod_table->ModInst;
+
+ return NvSuccess;
+}
+
+void
+NvRmPrivModuleDeinit( NvRmModuleTable *mod_table )
+{
+}
+
+NvError
+NvRmPrivGetModuleInstance( NvRmDeviceHandle hDevice, NvRmModuleID ModuleId,
+ NvRmModuleInstance **out )
+{
+ NvRmModuleTable *tbl;
+ NvRmModule *module; // Pointer to module table
+ NvRmModuleInstance *inst; // Pointer to device instance
+ NvU32 DeviceId; // Hardware device id
+ NvU32 Module;
+ NvU32 Instance;
+ NvU32 Bar;
+ NvU32 idx;
+
+ *out = NULL;
+
+ NV_ASSERT( hDevice );
+
+ tbl = NvRmPrivGetModuleTable( hDevice );
+
+ Module = NVRM_MODULE_ID_MODULE( ModuleId );
+ Instance = NVRM_MODULE_ID_INSTANCE( ModuleId );
+ Bar = NVRM_MODULE_ID_BAR( ModuleId );
+ NV_ASSERT( (NvU32)Module < (NvU32)NvRmPrivModuleID_Num );
+
+ // Get a pointer to the first instance of this module id type.
+ module = tbl->Modules;
+
+ // Check whether the index is valid or not.
+ if (module[Module].Index == NVRM_MODULE_INVALID)
+ {
+ return NvError_NotSupported;
+ }
+
+ inst = tbl->ModInst + module[Module].Index;
+
+ // Get its device id.
+ DeviceId = inst->DeviceId;
+
+ // find the right instance and bar
+ idx = 0;
+ while( inst->DeviceId == DeviceId )
+ {
+ if( idx == Instance && inst->Bar == Bar )
+ {
+ break;
+ }
+ if( inst->Bar == 0 )
+ {
+ idx++;
+ }
+
+ inst++;
+ }
+
+ // Is this a valid instance and is it of the same hardware type?
+ if( (inst >= tbl->LastModInst) || (DeviceId != inst->DeviceId) )
+ {
+ // Invalid instance.
+ return NvError_BadValue;
+ }
+
+ *out = inst;
+
+ // Check if instance is still valid and not bonded out.
+ // Still returning inst structure.
+ if ( (NvU8)-1 == inst->DevIdx )
+ return NvError_NotSupported;
+
+ return NvSuccess;
+}
+
+void
+NvRmModuleGetBaseAddress( NvRmDeviceHandle hDevice,
+ NvRmModuleID ModuleId, NvRmPhysAddr* pBaseAddress,
+ NvU32* pSize )
+{
+ NvRmModuleInstance *inst;
+
+ NV_ASSERT_SUCCESS(
+ NvRmPrivGetModuleInstance(hDevice, ModuleId, &inst)
+ );
+
+ if (pBaseAddress)
+ *pBaseAddress = inst->PhysAddr;
+ if (pSize)
+ *pSize = inst->Length;
+}
+
+NvU32
+NvRmModuleGetNumInstances(
+ NvRmDeviceHandle hDevice,
+ NvRmModuleID Module)
+{
+ NvError e;
+ NvRmModuleInstance *inst;
+ NvU32 n;
+ NvU32 id;
+
+ e = NvRmPrivGetModuleInstance( hDevice, NVRM_MODULE_ID(Module, 0), &inst);
+ if( e != NvSuccess )
+ {
+ return 0;
+ }
+
+ n = 0;
+ id = inst->DeviceId;
+ while( inst->DeviceId == id )
+ {
+ if( inst->Bar == 0 )
+ {
+ n++;
+ }
+
+ inst++;
+ }
+
+ return n;
+}
+
+NvError
+NvRmModuleGetModuleInfo(
+ NvRmDeviceHandle hDevice,
+ NvRmModuleID module,
+ NvU32 * pNum,
+ NvRmModuleInfo *pModuleInfo )
+{
+ NvU32 instance = 0;
+ NvU32 i = 0;
+
+ if ( NULL == pNum )
+ return NvError_BadParameter;
+
+ // if !pModuleInfo, returns total number of entries
+ while ( (NULL == pModuleInfo) || (i < *pNum) )
+ {
+ NvRmModuleInstance *inst;
+ NvError e = NvRmPrivGetModuleInstance(
+ hDevice, NVRM_MODULE_ID(module, instance), &inst);
+ if (e != NvSuccess)
+ {
+ if ( !(inst && ((NvU8)-1 == inst->DevIdx)) )
+ break;
+
+ /* else if a module instance not avail (bonded out), continue
+ * looking for next instance
+ */
+ }
+ else
+ {
+ if ( pModuleInfo )
+ {
+ pModuleInfo->Instance = instance;
+ pModuleInfo->Bar = inst->Bar;
+ pModuleInfo->BaseAddress = inst->PhysAddr;
+ pModuleInfo->Length = inst->Length;
+ pModuleInfo++;
+ }
+
+ i++;
+ }
+
+ instance++;
+ }
+
+ *pNum = i;
+
+ return NvSuccess;
+}
diff --git a/arch/arm/mach-tegra/nvrm/core/common/nvrm_module_common.c b/arch/arm/mach-tegra/nvrm/core/common/nvrm_module_common.c
deleted file mode 100644
index d5ae992f2a21..000000000000
--- a/arch/arm/mach-tegra/nvrm/core/common/nvrm_module_common.c
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
- * Copyright (c) 2009 NVIDIA Corporation.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * Neither the name of the NVIDIA Corporation nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#if NV_IS_AVP
-#define NV_DEF_RMC_TRACE 0 // NO TRACING FOR AVP
-#endif
-
-#include "nvcommon.h"
-#include "nvassert.h"
-#include "nvos.h"
-#include "nvrm_hwintf.h"
-#include "nvrm_module.h"
-#include "nvrm_module_private.h"
-#include "nvrm_moduleids.h"
-#include "ap15/ap15rm_private.h"
-
-#define NVRM_ENABLE_PRINTF 0 // Module debug: 0=disable, 1=enable
-
-#if (NV_DEBUG && NVRM_ENABLE_PRINTF)
-#define NVRM_MODULE_PRINTF(x) NvOsDebugPrintf x
-#else
-#define NVRM_MODULE_PRINTF(x)
-#endif
-
-NvError
-NvRmPrivModuleInit( NvRmModuleTable *mod_table, NvU32 *reloc_table )
-{
- NvError err;
- NvU32 i;
-
- /* invalidate the module table */
- for( i = 0; i < NvRmPrivModuleID_Num; i++ )
- {
- mod_table->Modules[i].Index = NVRM_MODULE_INVALID;
- }
-
- /* clear the irq map */
- NvOsMemset( &mod_table->IrqMap, 0, sizeof(mod_table->IrqMap) );
-
- err = NvRmPrivRelocationTableParse( reloc_table,
- &mod_table->ModInst, &mod_table->LastModInst,
- mod_table->Modules, &mod_table->IrqMap );
- if( err != NvSuccess )
- {
- NV_ASSERT( !"NvRmPrivModuleInit failed" );
- return err;
- }
-
- NV_ASSERT( mod_table->LastModInst);
- NV_ASSERT( mod_table->ModInst );
-
- mod_table->NumModuleInstances = mod_table->LastModInst -
- mod_table->ModInst;
-
- return NvSuccess;
-}
-
-void
-NvRmPrivModuleDeinit( NvRmModuleTable *mod_table )
-{
-}
-
-NvError
-NvRmPrivGetModuleInstance( NvRmDeviceHandle hDevice, NvRmModuleID ModuleId,
- NvRmModuleInstance **out )
-{
- NvRmModuleTable *tbl;
- NvRmModule *module; // Pointer to module table
- NvRmModuleInstance *inst; // Pointer to device instance
- NvU32 DeviceId; // Hardware device id
- NvU32 Module;
- NvU32 Instance;
-
- *out = NULL;
-
- NV_ASSERT( hDevice );
-
- tbl = NvRmPrivGetModuleTable( hDevice );
-
- Module = NVRM_MODULE_ID_MODULE( ModuleId );
- Instance = NVRM_MODULE_ID_INSTANCE( ModuleId );
- NV_ASSERT( (NvU32)Module < (NvU32)NvRmPrivModuleID_Num );
-
- // Get a pointer to the first instance of this module id type.
- module = tbl->Modules;
-
- // Check whether the index is valid or not.
- if (module[Module].Index == NVRM_MODULE_INVALID)
- {
- return NvError_NotSupported;
- }
-
- inst = tbl->ModInst + module[Module].Index;
-
- // Get its device id.
- DeviceId = inst->DeviceId;
-
- // Now point to the desired instance.
- inst += Instance;
-
- // Is this a valid instance and is it of the same hardware type?
- if ((inst >= tbl->LastModInst) || (DeviceId != inst->DeviceId))
- {
- // Invalid instance.
- return NvError_BadValue;
- }
-
- *out = inst;
-
- // Check if instance is still valid and not bonded out.
- // Still returning inst structure.
- if ( (NvU8)-1 == inst->DevIdx )
- return NvError_NotSupported;
-
- return NvSuccess;
-}
-
-void
-NvRmModuleGetBaseAddress( NvRmDeviceHandle hDevice,
- NvRmModuleID ModuleId, NvRmPhysAddr* pBaseAddress,
- NvU32* pSize )
-{
- NvRmModuleInstance *inst;
-
- NV_ASSERT_SUCCESS(
- NvRmPrivGetModuleInstance(hDevice, ModuleId, &inst)
- );
-
- if (pBaseAddress)
- *pBaseAddress = inst->PhysAddr;
- if (pSize)
- *pSize = inst->Length;
-}
-
-NvU32
-NvRmModuleGetNumInstances(
- NvRmDeviceHandle hDevice,
- NvRmModuleID Module)
-{
- NvU32 Instances = 0;
- NvU32 numInstances = 0;
- for (;;)
- {
- NvRmModuleInstance *inst;
- NvError e = NvRmPrivGetModuleInstance(
- hDevice, NVRM_MODULE_ID(Module, Instances), &inst);
- if (e != NvSuccess)
- {
- if ( !(inst && ((NvU8)-1 == inst->DevIdx)) )
- break;
- /* else if a module instance not avail (bonded out), continue
- looking for next instance. */
- }
- else
- numInstances++;
- Instances++;
- }
- return numInstances;
-}
-
-NvError
-NvRmModuleGetModuleInfo(
- NvRmDeviceHandle hDevice,
- NvRmModuleID module,
- NvU32 * pNum,
- NvRmModuleInfo *pModuleInfo
- )
-{
- NvU32 instance = 0;
- NvU32 numInstances = 0;
-
- if ( NULL == pNum )
- return NvError_BadParameter;
-
- // if !pModuleInfo, returns total numInstances
- while ( (NULL == pModuleInfo) || (numInstances < *pNum) )
- {
- NvRmModuleInstance *inst;
- NvError e = NvRmPrivGetModuleInstance(
- hDevice, NVRM_MODULE_ID(module, instance), &inst);
- if (e != NvSuccess)
- {
- if ( !(inst && ((NvU8)-1 == inst->DevIdx)) )
- break;
- /* else if a module instance not avail (bonded out), continue
- looking for next instance. */
- }
- else
- {
- if ( pModuleInfo )
- {
- pModuleInfo->Instance = instance;
- pModuleInfo->BaseAddress = inst->PhysAddr;
- pModuleInfo->Length = inst->Length;
- pModuleInfo++;
- }
- numInstances++;
- }
- instance++;
- }
- *pNum = numInstances; // update with correct number of instances
-
- return NvSuccess;
-}