Commit 64a08a9ffc0ff8c9e56b204842a5650c19b48db4

Authored by Benoît Thébaudeau
Committed by Wolfgang Denk
1 parent 67cbbf25c5
Exists in master and in 55 other branches 8qm-imx_v2020.04_5.4.70_2.3.0, emb_lf_v2022.04, emb_lf_v2023.04, imx_v2015.04_4.1.15_1.0.0_ga, pitx_8mp_lf_v2020.04, smarc-8m-android-10.0.0_2.6.0, smarc-8m-android-11.0.0_2.0.0, smarc-8mp-android-11.0.0_2.0.0, smarc-emmc-imx_v2014.04_3.10.53_1.1.0_ga, smarc-emmc-imx_v2014.04_3.14.28_1.0.0_ga, smarc-imx-l5.0.0_1.0.0-ga, smarc-imx6_v2018.03_4.14.98_2.0.0_ga, smarc-imx7_v2017.03_4.9.11_1.0.0_ga, smarc-imx7_v2018.03_4.14.98_2.0.0_ga, smarc-imx_v2014.04_3.14.28_1.0.0_ga, smarc-imx_v2015.04_4.1.15_1.0.0_ga, smarc-imx_v2017.03_4.9.11_1.0.0_ga, smarc-imx_v2017.03_4.9.88_2.0.0_ga, smarc-imx_v2017.03_o8.1.0_1.3.0_8m, smarc-imx_v2018.03_4.14.78_1.0.0_ga, smarc-m6.0.1_2.1.0-ga, smarc-n7.1.2_2.0.0-ga, smarc-rel_imx_4.1.15_2.0.0_ga, smarc_8m-imx_v2018.03_4.14.98_2.0.0_ga, smarc_8m-imx_v2019.04_4.19.35_1.1.0, smarc_8m_00d0-imx_v2018.03_4.14.98_2.0.0_ga, smarc_8mm-imx_v2018.03_4.14.98_2.0.0_ga, smarc_8mm-imx_v2019.04_4.19.35_1.1.0, smarc_8mm-imx_v2020.04_5.4.24_2.1.0, smarc_8mp_lf_v2020.04, smarc_8mq-imx_v2020.04_5.4.24_2.1.0, smarc_8mq_lf_v2020.04, ti-u-boot-2015.07, u-boot-2013.01.y, v2013.10, v2013.10-smarct33, v2013.10-smartmen, v2014.01, v2014.04, v2014.04-smarct33, v2014.04-smarct33-emmc, v2014.04-smartmen, v2014.07, v2014.07-smarct33, v2014.07-smartmen, v2015.07-smarct33, v2015.07-smarct33-emmc, v2015.07-smarct4x, v2016.05-dlt, v2016.05-smarct3x, v2016.05-smarct3x-emmc, v2016.05-smarct4x, v2017.01-smarct3x, v2017.01-smarct3x-emmc, v2017.01-smarct4x

part_mac: dcache: allocate cacheline-aligned buffers

This patch forces the correct alignment for DMA operations of buffers used by
part_mac.c.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
Cc: Wolfgang Denk <wd@denx.de>

Showing 1 changed file with 34 additions and 34 deletions Inline Diff

1 /* 1 /*
2 * (C) Copyright 2000 2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 * 4 *
5 * See file CREDITS for list of people who contributed to this 5 * See file CREDITS for list of people who contributed to this
6 * project. 6 * project.
7 * 7 *
8 * This program is free software; you can redistribute it and/or 8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as 9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of 10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version. 11 * the License, or (at your option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA 21 * MA 02111-1307 USA
22 */ 22 */
23 23
24 /* 24 /*
25 * Support for harddisk partitions. 25 * Support for harddisk partitions.
26 * 26 *
27 * To be compatible with LinuxPPC and Apple we use the standard Apple 27 * To be compatible with LinuxPPC and Apple we use the standard Apple
28 * SCSI disk partitioning scheme. For more information see: 28 * SCSI disk partitioning scheme. For more information see:
29 * http://developer.apple.com/techpubs/mac/Devices/Devices-126.html#MARKER-14-92 29 * http://developer.apple.com/techpubs/mac/Devices/Devices-126.html#MARKER-14-92
30 */ 30 */
31 31
32 #include <common.h> 32 #include <common.h>
33 #include <command.h> 33 #include <command.h>
34 #include <ide.h> 34 #include <ide.h>
35 #include "part_mac.h" 35 #include "part_mac.h"
36 36
37 #if defined(CONFIG_CMD_IDE) || \ 37 #if defined(CONFIG_CMD_IDE) || \
38 defined(CONFIG_CMD_SCSI) || \ 38 defined(CONFIG_CMD_SCSI) || \
39 defined(CONFIG_CMD_SATA) || \ 39 defined(CONFIG_CMD_SATA) || \
40 defined(CONFIG_CMD_USB) || \ 40 defined(CONFIG_CMD_USB) || \
41 defined(CONFIG_MMC) || \ 41 defined(CONFIG_MMC) || \
42 defined(CONFIG_SYSTEMACE) 42 defined(CONFIG_SYSTEMACE)
43 43
44 /* stdlib.h causes some compatibility problems; should fixe these! -- wd */ 44 /* stdlib.h causes some compatibility problems; should fixe these! -- wd */
45 #ifndef __ldiv_t_defined 45 #ifndef __ldiv_t_defined
46 typedef struct { 46 typedef struct {
47 long int quot; /* Quotient */ 47 long int quot; /* Quotient */
48 long int rem; /* Remainder */ 48 long int rem; /* Remainder */
49 } ldiv_t; 49 } ldiv_t;
50 extern ldiv_t ldiv (long int __numer, long int __denom); 50 extern ldiv_t ldiv (long int __numer, long int __denom);
51 # define __ldiv_t_defined 1 51 # define __ldiv_t_defined 1
52 #endif 52 #endif
53 53
54 54
55 static int part_mac_read_ddb (block_dev_desc_t *dev_desc, mac_driver_desc_t *ddb_p); 55 static int part_mac_read_ddb (block_dev_desc_t *dev_desc, mac_driver_desc_t *ddb_p);
56 static int part_mac_read_pdb (block_dev_desc_t *dev_desc, int part, mac_partition_t *pdb_p); 56 static int part_mac_read_pdb (block_dev_desc_t *dev_desc, int part, mac_partition_t *pdb_p);
57 57
58 /* 58 /*
59 * Test for a valid MAC partition 59 * Test for a valid MAC partition
60 */ 60 */
61 int test_part_mac (block_dev_desc_t *dev_desc) 61 int test_part_mac (block_dev_desc_t *dev_desc)
62 { 62 {
63 mac_driver_desc_t ddesc; 63 ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1);
64 mac_partition_t mpart; 64 ALLOC_CACHE_ALIGN_BUFFER(mac_partition_t, mpart, 1);
65 ulong i, n; 65 ulong i, n;
66 66
67 if (part_mac_read_ddb (dev_desc, &ddesc)) { 67 if (part_mac_read_ddb (dev_desc, ddesc)) {
68 /* error reading Driver Desriptor Block, or no valid Signature */ 68 /* error reading Driver Desriptor Block, or no valid Signature */
69 return (-1); 69 return (-1);
70 } 70 }
71 71
72 n = 1; /* assuming at least one partition */ 72 n = 1; /* assuming at least one partition */
73 for (i=1; i<=n; ++i) { 73 for (i=1; i<=n; ++i) {
74 if ((dev_desc->block_read(dev_desc->dev, i, 1, (ulong *)&mpart) != 1) || 74 if ((dev_desc->block_read(dev_desc->dev, i, 1, (ulong *)mpart) != 1) ||
75 (mpart.signature != MAC_PARTITION_MAGIC) ) { 75 (mpart->signature != MAC_PARTITION_MAGIC) ) {
76 return (-1); 76 return (-1);
77 } 77 }
78 /* update partition count */ 78 /* update partition count */
79 n = mpart.map_count; 79 n = mpart->map_count;
80 } 80 }
81 return (0); 81 return (0);
82 } 82 }
83 83
84 84
85 void print_part_mac (block_dev_desc_t *dev_desc) 85 void print_part_mac (block_dev_desc_t *dev_desc)
86 { 86 {
87 ulong i, n; 87 ulong i, n;
88 mac_driver_desc_t ddesc; 88 ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1);
89 mac_partition_t mpart; 89 ALLOC_CACHE_ALIGN_BUFFER(mac_partition_t, mpart, 1);
90 ldiv_t mb, gb; 90 ldiv_t mb, gb;
91 91
92 if (part_mac_read_ddb (dev_desc, &ddesc)) { 92 if (part_mac_read_ddb (dev_desc, ddesc)) {
93 /* error reading Driver Desriptor Block, or no valid Signature */ 93 /* error reading Driver Desriptor Block, or no valid Signature */
94 return; 94 return;
95 } 95 }
96 96
97 n = ddesc.blk_count; 97 n = ddesc->blk_count;
98 98
99 mb = ldiv(n, ((1024 * 1024) / ddesc.blk_size)); /* MB */ 99 mb = ldiv(n, ((1024 * 1024) / ddesc->blk_size)); /* MB */
100 /* round to 1 digit */ 100 /* round to 1 digit */
101 mb.rem *= 10 * ddesc.blk_size; 101 mb.rem *= 10 * ddesc->blk_size;
102 mb.rem += 512 * 1024; 102 mb.rem += 512 * 1024;
103 mb.rem /= 1024 * 1024; 103 mb.rem /= 1024 * 1024;
104 104
105 gb = ldiv(10 * mb.quot + mb.rem, 10240); 105 gb = ldiv(10 * mb.quot + mb.rem, 10240);
106 gb.rem += 512; 106 gb.rem += 512;
107 gb.rem /= 1024; 107 gb.rem /= 1024;
108 108
109 109
110 printf ("Block Size=%d, Number of Blocks=%d, " 110 printf ("Block Size=%d, Number of Blocks=%d, "
111 "Total Capacity: %ld.%ld MB = %ld.%ld GB\n" 111 "Total Capacity: %ld.%ld MB = %ld.%ld GB\n"
112 "DeviceType=0x%x, DeviceId=0x%x\n\n" 112 "DeviceType=0x%x, DeviceId=0x%x\n\n"
113 " #: type name" 113 " #: type name"
114 " length base (size)\n", 114 " length base (size)\n",
115 ddesc.blk_size, 115 ddesc->blk_size,
116 ddesc.blk_count, 116 ddesc->blk_count,
117 mb.quot, mb.rem, gb.quot, gb.rem, 117 mb.quot, mb.rem, gb.quot, gb.rem,
118 ddesc.dev_type, ddesc.dev_id 118 ddesc->dev_type, ddesc->dev_id
119 ); 119 );
120 120
121 n = 1; /* assuming at least one partition */ 121 n = 1; /* assuming at least one partition */
122 for (i=1; i<=n; ++i) { 122 for (i=1; i<=n; ++i) {
123 ulong bytes; 123 ulong bytes;
124 char c; 124 char c;
125 125
126 printf ("%4ld: ", i); 126 printf ("%4ld: ", i);
127 if (dev_desc->block_read (dev_desc->dev, i, 1, (ulong *)&mpart) != 1) { 127 if (dev_desc->block_read (dev_desc->dev, i, 1, (ulong *)mpart) != 1) {
128 printf ("** Can't read Partition Map on %d:%ld **\n", 128 printf ("** Can't read Partition Map on %d:%ld **\n",
129 dev_desc->dev, i); 129 dev_desc->dev, i);
130 return; 130 return;
131 } 131 }
132 132
133 if (mpart.signature != MAC_PARTITION_MAGIC) { 133 if (mpart->signature != MAC_PARTITION_MAGIC) {
134 printf ("** Bad Signature on %d:%ld - " 134 printf ("** Bad Signature on %d:%ld - "
135 "expected 0x%04x, got 0x%04x\n", 135 "expected 0x%04x, got 0x%04x\n",
136 dev_desc->dev, i, MAC_PARTITION_MAGIC, mpart.signature); 136 dev_desc->dev, i, MAC_PARTITION_MAGIC, mpart->signature);
137 return; 137 return;
138 } 138 }
139 139
140 /* update partition count */ 140 /* update partition count */
141 n = mpart.map_count; 141 n = mpart->map_count;
142 142
143 c = 'k'; 143 c = 'k';
144 bytes = mpart.block_count; 144 bytes = mpart->block_count;
145 bytes /= (1024 / ddesc.blk_size); /* kB; assumes blk_size == 512 */ 145 bytes /= (1024 / ddesc->blk_size); /* kB; assumes blk_size == 512 */
146 if (bytes >= 1024) { 146 if (bytes >= 1024) {
147 bytes >>= 10; 147 bytes >>= 10;
148 c = 'M'; 148 c = 'M';
149 } 149 }
150 if (bytes >= 1024) { 150 if (bytes >= 1024) {
151 bytes >>= 10; 151 bytes >>= 10;
152 c = 'G'; 152 c = 'G';
153 } 153 }
154 154
155 printf ("%20.32s %-18.32s %10u @ %-10u (%3ld%c)\n", 155 printf ("%20.32s %-18.32s %10u @ %-10u (%3ld%c)\n",
156 mpart.type, 156 mpart->type,
157 mpart.name, 157 mpart->name,
158 mpart.block_count, 158 mpart->block_count,
159 mpart.start_block, 159 mpart->start_block,
160 bytes, c 160 bytes, c
161 ); 161 );
162 } 162 }
163 163
164 return; 164 return;
165 } 165 }
166 166
167 167
168 /* 168 /*
169 * Read Device Descriptor Block 169 * Read Device Descriptor Block
170 */ 170 */
171 static int part_mac_read_ddb (block_dev_desc_t *dev_desc, mac_driver_desc_t *ddb_p) 171 static int part_mac_read_ddb (block_dev_desc_t *dev_desc, mac_driver_desc_t *ddb_p)
172 { 172 {
173 if (dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *)ddb_p) != 1) { 173 if (dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *)ddb_p) != 1) {
174 printf ("** Can't read Driver Desriptor Block **\n"); 174 printf ("** Can't read Driver Desriptor Block **\n");
175 return (-1); 175 return (-1);
176 } 176 }
177 177
178 if (ddb_p->signature != MAC_DRIVER_MAGIC) { 178 if (ddb_p->signature != MAC_DRIVER_MAGIC) {
179 #if 0 179 #if 0
180 printf ("** Bad Signature: expected 0x%04x, got 0x%04x\n", 180 printf ("** Bad Signature: expected 0x%04x, got 0x%04x\n",
181 MAC_DRIVER_MAGIC, ddb_p->signature); 181 MAC_DRIVER_MAGIC, ddb_p->signature);
182 #endif 182 #endif
183 return (-1); 183 return (-1);
184 } 184 }
185 return (0); 185 return (0);
186 } 186 }
187 187
188 /* 188 /*
189 * Read Partition Descriptor Block 189 * Read Partition Descriptor Block
190 */ 190 */
191 static int part_mac_read_pdb (block_dev_desc_t *dev_desc, int part, mac_partition_t *pdb_p) 191 static int part_mac_read_pdb (block_dev_desc_t *dev_desc, int part, mac_partition_t *pdb_p)
192 { 192 {
193 int n = 1; 193 int n = 1;
194 194
195 for (;;) { 195 for (;;) {
196 /* 196 /*
197 * We must always read the descritpor block for 197 * We must always read the descritpor block for
198 * partition 1 first since this is the only way to 198 * partition 1 first since this is the only way to
199 * know how many partitions we have. 199 * know how many partitions we have.
200 */ 200 */
201 if (dev_desc->block_read (dev_desc->dev, n, 1, (ulong *)pdb_p) != 1) { 201 if (dev_desc->block_read (dev_desc->dev, n, 1, (ulong *)pdb_p) != 1) {
202 printf ("** Can't read Partition Map on %d:%d **\n", 202 printf ("** Can't read Partition Map on %d:%d **\n",
203 dev_desc->dev, n); 203 dev_desc->dev, n);
204 return (-1); 204 return (-1);
205 } 205 }
206 206
207 if (pdb_p->signature != MAC_PARTITION_MAGIC) { 207 if (pdb_p->signature != MAC_PARTITION_MAGIC) {
208 printf ("** Bad Signature on %d:%d: " 208 printf ("** Bad Signature on %d:%d: "
209 "expected 0x%04x, got 0x%04x\n", 209 "expected 0x%04x, got 0x%04x\n",
210 dev_desc->dev, n, MAC_PARTITION_MAGIC, pdb_p->signature); 210 dev_desc->dev, n, MAC_PARTITION_MAGIC, pdb_p->signature);
211 return (-1); 211 return (-1);
212 } 212 }
213 213
214 if (n == part) 214 if (n == part)
215 return (0); 215 return (0);
216 216
217 if ((part < 1) || (part > pdb_p->map_count)) { 217 if ((part < 1) || (part > pdb_p->map_count)) {
218 printf ("** Invalid partition %d:%d [%d:1...%d:%d only]\n", 218 printf ("** Invalid partition %d:%d [%d:1...%d:%d only]\n",
219 dev_desc->dev, part, 219 dev_desc->dev, part,
220 dev_desc->dev, 220 dev_desc->dev,
221 dev_desc->dev, pdb_p->map_count); 221 dev_desc->dev, pdb_p->map_count);
222 return (-1); 222 return (-1);
223 } 223 }
224 224
225 /* update partition count */ 225 /* update partition count */
226 n = part; 226 n = part;
227 } 227 }
228 228
229 /* NOTREACHED */ 229 /* NOTREACHED */
230 } 230 }
231 231
232 int get_partition_info_mac (block_dev_desc_t *dev_desc, int part, disk_partition_t *info) 232 int get_partition_info_mac (block_dev_desc_t *dev_desc, int part, disk_partition_t *info)
233 { 233 {
234 mac_driver_desc_t ddesc; 234 ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1);
235 mac_partition_t mpart; 235 ALLOC_CACHE_ALIGN_BUFFER(mac_partition_t, mpart, 1);
236 236
237 if (part_mac_read_ddb (dev_desc, &ddesc)) { 237 if (part_mac_read_ddb (dev_desc, ddesc)) {
238 return (-1); 238 return (-1);
239 } 239 }
240 240
241 info->blksz = ddesc.blk_size; 241 info->blksz = ddesc->blk_size;
242 242
243 if (part_mac_read_pdb (dev_desc, part, &mpart)) { 243 if (part_mac_read_pdb (dev_desc, part, mpart)) {
244 return (-1); 244 return (-1);
245 } 245 }
246 246
247 info->start = mpart.start_block; 247 info->start = mpart->start_block;
248 info->size = mpart.block_count; 248 info->size = mpart->block_count;
249 memcpy (info->type, mpart.type, sizeof(info->type)); 249 memcpy (info->type, mpart->type, sizeof(info->type));
250 memcpy (info->name, mpart.name, sizeof(info->name)); 250 memcpy (info->name, mpart->name, sizeof(info->name));
251 251
252 return (0); 252 return (0);
253 } 253 }
254 254
255 #endif 255 #endif
256 256