]> git.ipfire.org Git - people/ms/u-boot.git/blame - lib/display_options.c
x86: Move link to use driver model for SCSI
[people/ms/u-boot.git] / lib / display_options.c
CommitLineData
20e0e233
WD
1/*
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
1a459660 5 * SPDX-License-Identifier: GPL-2.0+
20e0e233
WD
6 */
7
8#include <common.h>
24b852a7 9#include <console.h>
33eac2dc 10#include <div64.h>
c6da9ae8 11#include <inttypes.h>
09c2e90c 12#include <version.h>
c95c4280
GL
13#include <linux/ctype.h>
14#include <asm/io.h>
20e0e233
WD
15
16int display_options (void)
17{
20e0e233
WD
18#if defined(BUILD_TAG)
19 printf ("\n\n%s, Build: %s\n\n", version_string, BUILD_TAG);
20#else
21 printf ("\n\n%s\n\n", version_string);
22#endif
23 return 0;
24}
25
33eac2dc
SG
26void print_freq(uint64_t freq, const char *s)
27{
80402f34 28 unsigned long m = 0;
33eac2dc
SG
29 uint32_t f;
30 static const char names[] = {'G', 'M', 'K'};
31 unsigned long d = 1e9;
32 char c = 0;
33 unsigned int i;
34
35 for (i = 0; i < ARRAY_SIZE(names); i++, d /= 1000) {
36 if (freq >= d) {
37 c = names[i];
38 break;
39 }
40 }
41
42 if (!c) {
43 printf("%" PRIu64 " Hz%s", freq, s);
44 return;
45 }
46
47 f = do_div(freq, d);
33eac2dc
SG
48
49 /* If there's a remainder, show the first few digits */
50 if (f) {
51 m = f;
52 while (m > 1000)
53 m /= 10;
54 while (m && !(m % 10))
55 m /= 10;
56 if (m >= 100)
57 m = (m / 10) + (m % 100 >= 50);
58 }
59
e9015b30 60 printf("%lu", (unsigned long) freq);
33eac2dc
SG
61 if (m)
62 printf(".%ld", m);
63 printf(" %cHz%s", c, s);
64}
65
c6da9ae8 66void print_size(uint64_t size, const char *s)
20e0e233 67{
52dbac69 68 unsigned long m = 0, n;
c6da9ae8 69 uint64_t f;
4b42c905 70 static const char names[] = {'E', 'P', 'T', 'G', 'M', 'K'};
f2d76ae4 71 unsigned long d = 10 * ARRAY_SIZE(names);
4b42c905
TT
72 char c = 0;
73 unsigned int i;
20e0e233 74
f2d76ae4
NT
75 for (i = 0; i < ARRAY_SIZE(names); i++, d -= 10) {
76 if (size >> d) {
4b42c905
TT
77 c = names[i];
78 break;
417faf28 79 }
20e0e233
WD
80 }
81
4b42c905 82 if (!c) {
c6da9ae8 83 printf("%" PRIu64 " Bytes%s", size, s);
4b42c905
TT
84 return;
85 }
86
f2d76ae4
NT
87 n = size >> d;
88 f = size & ((1ULL << d) - 1);
20e0e233 89
417faf28 90 /* If there's a remainder, deal with it */
f2d76ae4
NT
91 if (f) {
92 m = (10ULL * f + (1ULL << (d - 1))) >> d;
20e0e233 93
417faf28
BB
94 if (m >= 10) {
95 m -= 10;
96 n += 1;
97 }
0d498393
WD
98 }
99
4b42c905 100 printf ("%lu", n);
20e0e233
WD
101 if (m) {
102 printf (".%ld", m);
103 }
4b42c905 104 printf (" %ciB%s", c, s);
20e0e233 105}
c95c4280 106
c95c4280
GL
107#define MAX_LINE_LENGTH_BYTES (64)
108#define DEFAULT_LINE_LENGTH_BYTES (16)
bda32ffc
SG
109int print_buffer(ulong addr, const void *data, uint width, uint count,
110 uint linelen)
c95c4280 111{
150f7236
RM
112 /* linebuf as a union causes proper alignment */
113 union linebuf {
4d1fd7f1
YS
114#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
115 uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1];
116#endif
150f7236
RM
117 uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1];
118 uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1];
119 uint8_t uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1];
120 } lb;
c95c4280 121 int i;
4d1fd7f1 122#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
80402f34 123 uint64_t __maybe_unused x;
4d1fd7f1 124#else
80402f34 125 uint32_t __maybe_unused x;
4d1fd7f1 126#endif
c95c4280
GL
127
128 if (linelen*width > MAX_LINE_LENGTH_BYTES)
129 linelen = MAX_LINE_LENGTH_BYTES / width;
130 if (linelen < 1)
131 linelen = DEFAULT_LINE_LENGTH_BYTES / width;
132
133 while (count) {
efd7c114 134 uint thislinelen = linelen;
c95c4280
GL
135 printf("%08lx:", addr);
136
137 /* check for overflow condition */
efd7c114
AB
138 if (count < thislinelen)
139 thislinelen = count;
c95c4280
GL
140
141 /* Copy from memory into linebuf and print hex values */
efd7c114 142 for (i = 0; i < thislinelen; i++) {
64419e47 143 if (width == 4)
150f7236 144 x = lb.ui[i] = *(volatile uint32_t *)data;
4d1fd7f1
YS
145#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
146 else if (width == 8)
147 x = lb.uq[i] = *(volatile uint64_t *)data;
148#endif
64419e47 149 else if (width == 2)
150f7236 150 x = lb.us[i] = *(volatile uint16_t *)data;
64419e47 151 else
150f7236 152 x = lb.uc[i] = *(volatile uint8_t *)data;
4d1fd7f1 153#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
66da9beb 154 printf(" %0*llx", width * 2, (long long)x);
4d1fd7f1 155#else
64419e47 156 printf(" %0*x", width * 2, x);
4d1fd7f1 157#endif
c95c4280
GL
158 data += width;
159 }
160
efd7c114
AB
161 while (thislinelen < linelen) {
162 /* fill line with whitespace for nice ASCII print */
163 for (i=0; i<width*2+1; i++)
164 puts(" ");
165 linelen--;
166 }
167
c95c4280 168 /* Print data in ASCII characters */
efd7c114 169 for (i = 0; i < thislinelen * width; i++) {
150f7236
RM
170 if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80)
171 lb.uc[i] = '.';
172 }
173 lb.uc[i] = '\0';
174 printf(" %s\n", lb.uc);
c95c4280
GL
175
176 /* update references */
efd7c114
AB
177 addr += thislinelen * width;
178 count -= thislinelen;
c95c4280
GL
179
180 if (ctrlc())
181 return -1;
182 }
183
184 return 0;
185}