[U-Boot-Users] Patch for port I/O commands, 'in' and 'out'.

Marc Singer elf at buici.com
Thu May 29 08:17:39 CEST 2003


This patch provides port I/O commands for architectures that support
them.  AFAIK, the only current architecture using a separate IO space
is IA32 (aka x86).

-------------- next part --------------
Index: sf/u-boot/CHANGELOG
diff -u sf/u-boot/CHANGELOG:1.1.1.1 sf/u-boot/CHANGELOG:1.2
--- sf/u-boot/CHANGELOG:1.1.1.1	Thu May 22 17:20:42 2003
+++ sf/u-boot/CHANGELOG	Wed May 28 23:11:51 2003
@@ -2,6 +2,9 @@
 Changes since U-Boot 0.3.1:
 ======================================================================
 
+* Patch by Marc Singer, 28 May 2003:
+  Added port I/O commands.
+
 * Patch by Dave Ellis, 22 May 2003:
   Fix problem with only partially cleared .bss segment
 
Index: sf/u-boot/common/Makefile
diff -u sf/u-boot/common/Makefile:1.1.1.1 sf/u-boot/common/Makefile:1.2
--- sf/u-boot/common/Makefile:1.1.1.1	Thu May 22 17:20:43 2003
+++ sf/u-boot/common/Makefile	Wed May 28 23:04:53 2003
@@ -36,7 +36,7 @@
 	  cmd_jffs2.o cmd_log.o cmd_mem.o cmd_mii.o cmd_misc.o \
 	  cmd_net.o cmd_nvedit.o env_common.o \
 	  env_flash.o env_eeprom.o env_nvram.o env_nowhere.o \
-	  cmd_pci.o cmd_pcmcia.o \
+	  cmd_pci.o cmd_pcmcia.o cmd_portio.o \
 	  cmd_reginfo.o cmd_scsi.o cmd_vfd.o cmd_usb.o \
 	  command.o console.o devices.o dlmalloc.o \
 	  docecc.o environment.o flash.o fpga.o \
Index: sf/u-boot/common/cmd_mem.c
diff -u sf/u-boot/common/cmd_mem.c:1.1.1.1 sf/u-boot/common/cmd_mem.c:1.2
--- sf/u-boot/common/cmd_mem.c:1.1.1.1	Thu May 22 17:20:43 2003
+++ sf/u-boot/common/cmd_mem.c	Wed May 28 23:04:53 2003
@@ -31,7 +31,8 @@
 #include <command.h>
 #include <cmd_mem.h>
 
-#if (CONFIG_COMMANDS & (CFG_CMD_MEMORY | CFG_CMD_PCI | CFG_CMD_I2C))
+#if (CONFIG_COMMANDS & (CFG_CMD_MEMORY | CFG_CMD_PCI | CFG_CMD_I2C\
+			| CMD_CMD_PORTIO))
 int cmd_get_data_size(char* arg, int default_size)
 {
 	/* Check for a size specification .b, .w or .l.
Index: sf/u-boot/common/cmd_portio.c
diff -u /dev/null sf/u-boot/common/cmd_portio.c:1.2
--- /dev/null	Wed May 28 23:12:00 2003
+++ sf/u-boot/common/cmd_portio.c	Wed May 28 23:09:57 2003
@@ -0,0 +1,155 @@
+/*
+ * (C) Copyright 2003
+ * Marc Singer, elf at buici.com
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+/*
+ * Port I/O Functions
+ *
+ * Copied from FADS ROM, Dan Malek (dmalek at jlc.net)
+ */
+
+#include <common.h>
+#include <command.h>
+#include <cmd_portio.h>
+
+extern int cmd_get_data_size(char* arg, int default_size);
+
+/* Display values from last command.
+ * Memory modify remembered values are different from display memory.
+ */
+static uint in_last_addr, in_last_size;
+static uint out_last_addr, out_last_size, out_last_value;
+
+
+#if (CONFIG_COMMANDS & (CFG_CMD_PORTIO))
+
+int do_portio_out (cmd_tbl_t* cmdtp, int flag, int argc, char* argv[])
+{
+  uint addr = out_last_addr;
+  uint size = out_last_size;
+  uint value = out_last_value;
+
+  if (argc != 3) {
+    printf ("Usage:\n%s\n", cmdtp->usage);
+    return 1;
+  }
+
+  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], 1);
+    addr = simple_strtoul(argv[1], NULL, 16);
+    value = simple_strtoul (argv[2], NULL, 16);
+  }
+
+#if defined (CONFIG_X86)
+
+ {
+   unsigned short port = addr;
+
+   switch (size) {
+   default:
+   case 1:
+     {
+       unsigned char ch = value;
+       __asm__ volatile ("out %0, %%dx" : : "a" (ch), "d" (port));
+     }
+     break;
+   case 2:
+     {
+       unsigned short w = value;
+       __asm__ volatile ("out %0, %%dx" : : "a" (w), "d" (port));
+     }
+     break;
+   case 4:
+     __asm__ volatile ("out %0, %%dx" : : "a" (value), "d" (port));
+     break;
+   }
+ }
+
+#endif /* CONFIG_X86 */
+
+  out_last_addr = addr;
+  out_last_size = size;
+  out_last_value = value;
+
+  return 0;
+}
+
+int do_portio_in (cmd_tbl_t* cmdtp, int flag, int argc, char* argv[])
+{
+  uint addr = in_last_addr;
+  uint size = in_last_size;
+
+  if (argc != 2) {
+    printf ("Usage:\n%s\n", cmdtp->usage);
+    return 1;
+  }
+
+  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], 1);
+    addr = simple_strtoul(argv[1], NULL, 16);
+  }
+
+#if defined (CONFIG_X86)
+
+  {
+    unsigned short port = addr;
+    
+    switch (size) {
+    default:
+    case 1:
+      {
+	unsigned char ch;
+	__asm__ volatile ("in %%dx, %0" : "=a" (ch) : "d" (port));
+	printf (" %02x\n", ch);
+      }
+      break;
+    case 2:
+      {
+	unsigned short w;
+	__asm__ volatile ("in %%dx, %0" : "=a" (w) : "d" (port));
+	printf (" %04x\n", w);
+      }
+      break;
+    case 4:
+      {
+	unsigned long l;
+	__asm__ volatile ("in %%dx, %0" : "=a" (l) : "d" (port));
+	printf (" %08lx\n", l);
+      }      
+      break;
+    }
+  }
+#endif /* CONFIG_X86 */
+
+  in_last_addr = addr;
+  in_last_size = size;
+
+  return 0;
+}
+
+#endif	/* CFG_CMD_PORTIO */
Index: sf/u-boot/common/command.c
diff -u sf/u-boot/common/command.c:1.1.1.1 sf/u-boot/common/command.c:1.2
--- sf/u-boot/common/command.c:1.1.1.1	Thu May 22 17:20:43 2003
+++ sf/u-boot/common/command.c	Wed May 28 23:04:53 2003
@@ -79,6 +79,8 @@
 #include <cmd_boota.h>
 #endif
 
+#include <cmd_portio.h>
+
 /*
  * HELP command
  */
@@ -284,6 +286,7 @@
 	CMD_TBL_IMM
 	CMD_TBL_INM
 	CMD_TBL_IMW
+	CMD_TBL_IN
 	CMD_TBL_ICRC
 	CMD_TBL_IPROBE
 	CMD_TBL_ILOOP
@@ -314,6 +317,7 @@
 	CMD_TBL_NANDBOOT
 	CMD_TBL_NEXT
 	CMD_TBL_NM
+	CMD_TBL_OUT
 	CMD_TBL_PCI
 	CMD_TBL_PRINTENV
 	CMD_TBL_PROTECT
Index: sf/u-boot/include/cmd_confdefs.h
diff -u sf/u-boot/include/cmd_confdefs.h:1.1.1.1 sf/u-boot/include/cmd_confdefs.h:1.2
--- sf/u-boot/include/cmd_confdefs.h:1.1.1.1	Thu May 22 17:20:44 2003
+++ sf/u-boot/include/cmd_confdefs.h	Wed May 28 23:04:53 2003
@@ -80,6 +80,7 @@
 #define CFG_CMD_VFD	0x0000400000000000	/* VFD support (TRAB)		*/
 #define CFG_CMD_NAND	0x0000800000000000	/* NAND support        		*/
 #define CFG_CMD_BMP	0x0001000000000000	/* BMP support			*/
+#define CFG_CMD_PORTIO	0x0002000000000000	/* Port I/O		        */
 
 #define CFG_CMD_ALL	0xFFFFFFFFFFFFFFFF	/* ALL commands			*/
 
Index: sf/u-boot/include/cmd_portio.h
diff -u /dev/null sf/u-boot/include/cmd_portio.h:1.1
--- /dev/null	Wed May 28 23:12:00 2003
+++ sf/u-boot/include/cmd_portio.h	Wed May 28 23:04:53 2003
@@ -0,0 +1,51 @@
+/*
+ * (C) Copyright 2003
+ * Marc Singer, elf at buici.com
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+/*
+ * Memory Functions
+ */
+#ifndef	_CMD_PORTIO_H
+#define _CMD_PORTIO_H
+
+#if (CONFIG_COMMANDS & CFG_CMD_PORTIO)
+#define CMD_TBL_OUT	MK_CMD_TBL_ENTRY(				      \
+	"out",		3,	3,	1,	do_portio_out,		      \
+	"out     - write datum to IO port\n",				      \
+	"[.b, .w, .l] port value\n    - output to IO port\n"	      	      \
+),
+#define CMD_TBL_IN	MK_CMD_TBL_ENTRY(				      \
+ 	"in",		2,	2,	1,	do_portio_in,		      \
+	"in      - read data from an IO port\n",			      \
+	"[.b, .w, .l] port\n"						      \
+	"    - read datum from IO port\n"				      \
+),
+
+int do_portio_out (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
+int do_portio_in  (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
+
+#else
+#define CMD_TBL_PORTIO_OUT
+#define CMD_TBL_PORTIO_IN
+#endif	/* CFG_CMD_PORTIO */
+
+#endif	/* _CMD_PORTIO_H */


More information about the U-Boot mailing list