Blame view

cmd/io.c 2.41 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  // SPDX-License-Identifier: GPL-2.0+
9ad557be2   Vadim Bendebury   Add console comma...
2
3
  /*
   * Copyright (c) 2012 The Chromium OS Authors.
9ad557be2   Vadim Bendebury   Add console comma...
4
5
6
7
8
9
10
11
12
   */
  
  /*
   * IO space access commands.
   */
  
  #include <common.h>
  #include <command.h>
  #include <asm/io.h>
9da3776bf   Simon Glass   iod: Enhance to s...
13
14
15
16
17
18
  /* Display values from last command */
  static ulong last_addr, last_size;
  static ulong last_length = 0x40;
  static ulong base_address;
  
  #define DISP_LINE_LEN	16
9ad557be2   Vadim Bendebury   Add console comma...
19
20
21
22
23
24
25
26
  /*
   * IO Display
   *
   * Syntax:
   *	iod{.b, .w, .l} {addr}
   */
  int do_io_iod(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  {
9da3776bf   Simon Glass   iod: Enhance to s...
27
28
29
30
31
32
33
34
35
36
37
38
39
  	ulong addr, length, bytes;
  	u8 buf[DISP_LINE_LEN];
  	int size, todo;
  
  	/*
  	 * We use the last specified parameters, unless new ones are
  	 * entered.
  	 */
  	addr = last_addr;
  	size = last_size;
  	length = last_length;
  
  	if (argc < 2)
9ad557be2   Vadim Bendebury   Add console comma...
40
  		return CMD_RET_USAGE;
9da3776bf   Simon Glass   iod: Enhance to s...
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  	if ((flag & CMD_FLAG_REPEAT) == 0) {
  		/*
  		 * New command specified.  Check for a size specification.
  		 * Defaults to long if no or incorrect specification.
  		 */
  		size = cmd_get_data_size(argv[0], 4);
  		if (size < 0)
  			return 1;
  
  		/* Address is specified since argc > 1 */
  		addr = simple_strtoul(argv[1], NULL, 16);
  		addr += base_address;
  
  		/*
  		 * If another parameter, it is the length to display.
  		 * Length is the number of objects, not number of bytes.
  		 */
  		if (argc > 2)
  			length = simple_strtoul(argv[2], NULL, 16);
  	}
  
  	bytes = size * length;
  
  	/* Print the lines */
  	for (; bytes > 0; addr += todo) {
  		u8 *ptr = buf;
  		int i;
  
  		todo = min(bytes, (ulong)DISP_LINE_LEN);
  		for (i = 0; i < todo; i += size, ptr += size) {
  			if (size == 4)
  				*(u32 *)ptr = inl(addr + i);
  			else if (size == 2)
  				*(u16 *)ptr = inw(addr + i);
  			else
  				*ptr = inb(addr + i);
  		}
  		print_buffer(addr, buf, size, todo / size,
  			     DISP_LINE_LEN / size);
  		bytes -= todo;
  	}
  
  	last_addr = addr;
  	last_length = length;
  	last_size = size;
9ad557be2   Vadim Bendebury   Add console comma...
86
87
88
89
90
91
  
  	return 0;
  }
  
  int do_io_iow(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  {
9398b8ce5   Tom Rini   cmd/io.c: Fix com...
92
93
  	ulong addr, val;
  	int size;
9ad557be2   Vadim Bendebury   Add console comma...
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
  
  	if (argc != 3)
  		return CMD_RET_USAGE;
  
  	size = cmd_get_data_size(argv[0], 4);
  	if (size < 0)
  		return 1;
  
  	addr = simple_strtoul(argv[1], NULL, 16);
  	val = simple_strtoul(argv[2], NULL, 16);
  
  	if (size == 4)
  		outl((u32) val, addr);
  	else if (size == 2)
  		outw((u16) val, addr);
  	else
  		outb((u8) val, addr);
  
  	return 0;
  }
  
  /**************************************************/
9da3776bf   Simon Glass   iod: Enhance to s...
116
  U_BOOT_CMD(iod, 3, 1, do_io_iod,
d641819cf   Bin Meng   common/cmd_io.c: ...
117
  	   "IO space display", "[.b, .w, .l] address");
9ad557be2   Vadim Bendebury   Add console comma...
118
119
  
  U_BOOT_CMD(iow, 3, 0, do_io_iow,
d641819cf   Bin Meng   common/cmd_io.c: ...
120
121
  	   "IO space modify",
  	   "[.b, .w, .l] address value");