]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - src/ti/ipc/remoteproc/Resource.c
ipc-bios.bld: Add "-cr" lnkOpt in for C66 target for remoteproc loaded images.
[ipc/ipcdev.git] / src / ti / ipc / remoteproc / Resource.c
1 /*
2  * Copyright (c) 2011-2012, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * *  Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * *  Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * *  Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
33 /*
34  *  ======== Resource.c ========
35  *
36  */
38 #include <xdc/runtime/System.h>
39 #include <xdc/runtime/Startup.h>
41 #include "rsc_types.h"
42 #include "package/internal/Resource.xdc.h"
45 /*
46  *  ======== Resource_getTraceBufPtr ========
47  */
48 Ptr Resource_getTraceBufPtr()
49 {
50     UInt32 i;
51     UInt32 offset;
52     UInt32 type;
53     struct fw_rsc_trace *entry = NULL;
54     Resource_RscTable *table = (Resource_RscTable *)
55                                             (Resource_module->pTable);
57     for (i = 0; i < module->pTable->num; i++) {
58         offset = (UInt32)((Char *)table + table->offset[i]);
59         type = *(UInt32 *)offset;
60         if (type == TYPE_TRACE) {
61             entry = (struct fw_rsc_trace *)offset;
62             return ((Ptr)entry->da);
63         }
64     }
66     return (NULL);
67 }
69 /*
70  *  ======== Resource_getEntry ========
71  */
72 Resource_MemEntry *Resource_getEntry(UInt index)
73 {
74     UInt32 offset;
75     UInt32 *type;
76     Resource_MemEntry *entry = NULL;
77     Resource_RscTable *table = (Resource_RscTable *)
78                                             (Resource_module->pTable);
80     if (index >= table->num) {
81         return (NULL);
82     }
84     offset = (UInt32)((Char *)table + table->offset[index]);
85     type = (UInt32 *)offset;
86     if (*type == TYPE_CARVEOUT || *type == TYPE_DEVMEM) {
87         entry = (Resource_MemEntry *) ((Char *)offset);
88     }
90     return (entry);
91 }
93 /*
94  *************************************************************************
95  *                      Module wide functions
96  *************************************************************************
97  */
99 /*
100  *  ======== Resource_Module_startup ========
101  */
102 Int Resource_Module_startup(Int phase)
104     Resource_init();
105     return (Startup_DONE);
108 /*
109  *  ======== Resource_virtToPhys ========
110  */
111 Int Resource_virtToPhys(UInt32 va, UInt32 *pa)
113     UInt32 i;
114     UInt32 offset;
115     Resource_MemEntry *entry;
117     *pa = NULL;
119     for (i = 0; i < module->pTable->num; i++) {
120         entry = Resource_getEntry(i);
121         if (entry && va >= entry->da && va < (entry->da + entry->len)) {
122                 offset = va - entry->da;
123                 *pa = entry->pa + offset;
124                 return (Resource_S_SUCCESS);
125         }
126     }
128     return (Resource_E_NOTFOUND);
131 /*
132  *  ======== Resource_physToVirt ========
133  */
134 Int Resource_physToVirt(UInt32 pa, UInt32 *va)
136     UInt32 i;
137     UInt32 offset;
138     Resource_MemEntry *entry;
140     *va = NULL;
142     for (i = 0; i < module->pTable->num; i++) {
143         entry = Resource_getEntry(i);
144         if (entry && pa >= entry->pa && pa < (entry->pa + entry->len)) {
145                 offset = pa - entry->pa;
146                 *va = entry->da + offset;
147                 return (Resource_S_SUCCESS);
148         }
149     }
151     return (Resource_E_NOTFOUND);