1 /*
2
3 This file is provided under a dual BSD/GPLv2 license. When using or
4 redistributing this file, you may do so under either license.
5
6 GPL LICENSE SUMMARY
7
8 Copyright(c) 2005-2008 Intel Corporation. All rights reserved.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of version 2 of the GNU General Public License as
12 published by the Free Software Foundation.
13
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
22 The full GNU General Public License is included in this distribution
23 in the file called LICENSE.GPL.
24
25 Contact Information:
26 Intel Corporation
27 2200 Mission College Blvd.
28 Santa Clara, CA 97052
29
30 BSD LICENSE
31
32 Copyright(c) 2005-2008 Intel Corporation. All rights reserved.
33
34 Redistribution and use in source and binary forms, with or without
35 modification, are permitted provided that the following conditions
36 are met:
37
38 * Redistributions of source code must retain the above copyright
39 notice, this list of conditions and the following disclaimer.
40 * Redistributions in binary form must reproduce the above copyright
41 notice, this list of conditions and the following disclaimer in
42 the documentation and/or other materials provided with the
43 distribution.
44 * Neither the name of Intel Corporation nor the names of its
45 contributors may be used to endorse or promote products derived
46 from this software without specific prior written permission.
47
48 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
49 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
50 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
51 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
52 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
53 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
54 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
55 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
56 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
58 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59
60 */
61
62 #ifndef SVEN_FW_H
63 #include "sven_fw.h"
64 #endif
65
66 #define _OSAL_IO_MEMMAP_H /* to prevent errors when including sven_devh.h */
67 #define _OSAL_ASSERT_H /* to prevent errors when including sven_devh.h */
68 #include "sven_devh.h"
69
70 #include "fw_pvt.h"
71
72 static os_devhandle_t g_svenh;
73
74 #define FW_SVEN_DEVH_DISABLE_SVEN_REGISTER_IO
75 //#define SVEN_DEVH_DISABLE_SVEN
76
77 extern int sven_fw_is_tx_enabled(
78 struct SVENHandle *svenh );
79
80 #ifndef SVEN_DEVH_DISABLE_SVEN
sven_write_event(struct SVENHandle * svenh,struct SVENEvent * ev)81 static void sven_write_event(
82 struct SVENHandle *svenh,
83 struct SVENEvent *ev )
84 {
85 if ( NULL == svenh )
86 svenh = &g_svenh.devh_svenh;
87
88 if ( NULL != svenh->phot )
89 sven_fw_write_event(svenh,ev);
90 }
91
sven_fw_initialize_event_top(struct SVENEvent * ev,int module,int unit,int event_type,int event_subtype)92 static void sven_fw_initialize_event_top(
93 struct SVENEvent *ev,
94 int module,
95 int unit,
96 int event_type,
97 int event_subtype )
98 {
99 ev->se_et.et_gencount = 0;
100 ev->se_et.et_module = module;
101 ev->se_et.et_unit = unit;
102 ev->se_et.et_type = event_type;
103 ev->se_et.et_subtype = event_subtype;
104 }
105 #endif
106
sven_get_timestamp()107 uint32_t sven_get_timestamp()
108 {
109 uint32_t value = 0;
110
111 if ( NULL != g_svenh.devh_svenh.ptime )
112 {
113 value = sven_fw_read_external_register( &g_svenh.devh_svenh, g_svenh.devh_svenh.ptime );
114 }
115
116 return(value);
117 }
118
119 /* ---------------------------------------------------------------------- */
120 /* ---------------------------------------------------------------------- */
121
devh_SVEN_SetModuleUnit(os_devhandle_t * devh,int sven_module,int sven_unit)122 void devh_SVEN_SetModuleUnit(
123 os_devhandle_t *devh,
124 int sven_module,
125 int sven_unit )
126 {
127 #ifndef SVEN_DEVH_DISABLE_SVEN
128 if ( NULL == devh )
129 devh = &g_svenh;
130 devh->devh_sven_module = sven_module;
131 devh->devh_sven_unit = sven_unit;
132 #endif
133 }
134
devhandle_factory(const char * desc)135 os_devhandle_t *devhandle_factory( const char *desc )
136 {
137 /* pointer to global vsparc local registers */
138 g_svenh.devh_regs_ptr = (void *) 0x10000000; /* firmware address to Local (GV) registers */
139
140 return( &g_svenh );
141 }
142
devhandle_connect_name(os_devhandle_t * devh,const char * devname)143 int devhandle_connect_name(
144 os_devhandle_t *devh,
145 const char *devname )
146 {
147 return(1);
148 }
149
150 /* ---------------------------------------------------------------------- */
151 /* ---------------------------------------------------------------------- */
152
devh_SVEN_WriteModuleEvent(os_devhandle_t * devh,int module_event_subtype,unsigned int payload0,unsigned int payload1,unsigned int payload2,unsigned int payload3,unsigned int payload4,unsigned int payload5)153 void devh_SVEN_WriteModuleEvent(
154 os_devhandle_t *devh,
155 int module_event_subtype,
156 unsigned int payload0,
157 unsigned int payload1,
158 unsigned int payload2,
159 unsigned int payload3,
160 unsigned int payload4,
161 unsigned int payload5 )
162 {
163 #ifndef SVEN_DEVH_DISABLE_SVEN
164 struct SVENEvent ev __attribute__ ((aligned(8)));
165
166 devh = (NULL != devh) ? devh : &g_svenh;
167
168 if ( ! sven_fw_is_tx_enabled( &devh->devh_svenh ) )
169 return;
170
171 sven_fw_initialize_event_top( &ev,
172 devh->devh_sven_module,
173 1 /* devh->devh_sven_unit */,
174 SVEN_event_type_module_specific,
175 module_event_subtype );
176
177 ev.u.se_uint[0] = payload0;
178 ev.u.se_uint[1] = payload1;
179 ev.u.se_uint[2] = payload2;
180 ev.u.se_uint[3] = payload3;
181 ev.u.se_uint[4] = payload4;
182 ev.u.se_uint[5] = payload5;
183
184 sven_write_event( &devh->devh_svenh, &ev );
185 #endif
186 }
187
188 /* ---------------------------------------------------------------------- */
189 /* SVEN FW TX: Required custom routines to enable FW TX */
190 /* ---------------------------------------------------------------------- */
sven_fw_set_globals(struct SVEN_FW_Globals * fw_globals)191 int sven_fw_set_globals(
192 struct SVEN_FW_Globals *fw_globals )
193 {
194 sven_fw_attach( &g_svenh.devh_svenh, fw_globals );
195 devh_SVEN_SetModuleUnit( &g_svenh, SVEN_module_GEN4_GV, 1 );
196 return(0);
197 }
198
199 uint32_t cp_using_dma_phys(uint32_t ddr_addr, uint32_t local_addr, uint32_t size, char to_ddr, char swap);
200
sven_fw_read_external_register(struct SVENHandle * svenh,volatile unsigned int * preg)201 unsigned int sven_fw_read_external_register(
202 struct SVENHandle *svenh,
203 volatile unsigned int *preg )
204 {
205 unsigned int reg __attribute__ ((aligned(8)));
206
207 (void)svenh; // argument unused
208
209 cp_using_dma_phys( (uint32_t) preg, (uint32_t) ®, 4, 0, 0 );
210
211 return( reg );
212 }
213
sven_fw_copy_event_to_host_mem(struct SVENHandle * svenh,volatile struct SVENEvent * to,const struct SVENEvent * from)214 void sven_fw_copy_event_to_host_mem(
215 struct SVENHandle *svenh,
216 volatile struct SVENEvent *to,
217 const struct SVENEvent *from )
218 {
219 (void)svenh; // argument unused
220
221 cp_using_dma_phys( (uint32_t) to, (uint32_t) from, sizeof(*to), 1, 0 );
222 }
223 /* ---------------------------------------------------------------------- */
224 /* ---------------------------------------------------------------------- */
225