1 /*
2 *
3 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
38 /**********************************************************************************************************
39 * FILE PURPOSE: Support functions specific to gem
40 **********************************************************************************************************
41 * FILE NAME: gem.c
42 *
43 * DESCRIPTION: Contains functions common to all gem devices.
44 *
45 **********************************************************************************************************/
46 #include "types.h"
47 #include "btblwrap.h"
49 extern volatile cregister unsigned int CSR;
50 #define C64X_REG_CSR_BIT_EN (1 << 8)
52 /************************************************************************************
53 * FUNCTION PURPOSE: Copy data from the boot table to the destination locations
54 ************************************************************************************
55 * DESCRIPTION: Copy data from the boot table to the destination.
56 *
57 * The input data is interpreted as 32 bit values, made up of two 16
58 * bit values in big endian format. This is done to acheive endian
59 * independence on the c64x.
60 *
61 * If the size is not evenly divisible by 4 then the final write does a
62 * read first, and writes the most significant bytes back.
63 ************************************************************************************/
64 UINT16 coreCopyData (UINT32 dest_addr, UINT16 *p_data, UINT32 sizeBytes, UINT16 start_vector)
65 {
66 UINT32 value;
67 UINT32 insert;
68 UINT32 i;
69 UINT32 j;
70 UINT32 n32;
71 UINT32 rb;
73 UINT32 *restrict rdest;
74 UINT16 *restrict rsrc;
76 chipDummy ((void *)start_vector);
78 n32 = sizeBytes >> 2;
81 /* If the destination address is 32 bit aligned an unaligned copy is not requird */
82 if ((dest_addr & 0x3) == 0) {
84 rdest = (UINT32 *)dest_addr;
85 rsrc = p_data;
87 for (i = j = 0; i < n32; i++, j += 2) {
89 value = (((UINT32)rsrc[j]) << 16) | (rsrc[j+1]);
90 rdest[i] = value;
92 }
94 dest_addr += (n32 << 2);
97 } else {
99 /* Do whole 32 bit writes first */
100 for (i = j = 0; i < n32; i++, j += 2) {
102 value = (((UINT32)p_data[j]) << 16) | (p_data[j+1]);
103 chipStoreWord ((UINT32 *)dest_addr, value);
104 dest_addr += 4;
106 }
108 }
110 /* Handle any remaining values based on the endian of the device */
111 rb = sizeBytes - (n32 << 2);
113 if (rb != 0) {
115 value = chipReadWord ((UINT32 *)dest_addr);
117 if ((CSR & C64X_REG_CSR_BIT_EN) != 0) {
119 /* Little endian. Put remaining bytes in the least significant value */
120 if (rb >= 1) {
121 insert = (p_data[j] >> 8) & 0x00ff;
122 value = (value & 0xffffff00) | insert;
124 }
126 if (rb >= 2) {
127 insert = p_data[j] & 0x00ff;
128 value = (value & 0xffff00ff) | (insert << 8);
130 }
132 if (rb >= 3) {
133 insert = (p_data[j+1] >> 8) & 0x00ff;
134 value = (value & 0xff00ffff) | (insert << 16);
135 }
137 } else {
139 /* Bit endian. Put remaining bytes in the most significant value */
140 if (rb == 1) {
141 insert = (p_data[j] >> 8) & 0xff;
142 value = (value & 0x00ffffff) | (insert << 24);
144 } else if (rb == 2) {
145 insert = p_data[j] & 0xffff;
146 value = (value & 0x0000ffff) | (insert << 16);
148 } else if (rb == 3) {
149 insert = ((p_data[j] << 8) | (p_data[j+1] >> 8)) & 0x00ffffff;
150 value = (value & 0x000000ff) | (insert << 8);
151 }
153 }
155 chipStoreWord ((UINT32 *)dest_addr, value);
157 }
160 return (CORE_NOERR);
162 } /* coreCopyData */