summaryrefslogtreecommitdiff
path: root/util/x86emu/yabel/io.c
diff options
context:
space:
mode:
authorMyles Watson <mylesgw@gmail.com>2010-03-05 18:27:19 +0000
committerMyles Watson <mylesgw@gmail.com>2010-03-05 18:27:19 +0000
commitb0259117f214a80d1ca945bd1fe05b6b3d9858a9 (patch)
tree50f607aa8d8ac00d7b10fe970cea756d7e2470c3 /util/x86emu/yabel/io.c
parentf98ad3ace0852159c6e716a5563a9c3df8cf76f3 (diff)
downloadcoreboot-b0259117f214a80d1ca945bd1fe05b6b3d9858a9.tar.xz
1. Move run_bios prototype to device.h
2. Use time.h for get_time() and move tb_freq into functions.c 3. Move read_io and write_io to io.c and make them static 4. Make a couple of functions static in interrupt.c 5. Refactor a cast from char[] to u64 to get rid of potential alignment problems and a warning Signed-off-by: Myles Watson <mylesgw@gmail.com> Acked-by: Stefan Reinauer <stepan@coresystems.de> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@5191 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/x86emu/yabel/io.c')
-rw-r--r--util/x86emu/yabel/io.c49
1 files changed, 44 insertions, 5 deletions
diff --git a/util/x86emu/yabel/io.c b/util/x86emu/yabel/io.c
index 6d36e8078f..38a5d32c7c 100644
--- a/util/x86emu/yabel/io.c
+++ b/util/x86emu/yabel/io.c
@@ -24,12 +24,51 @@
#include <device/pci_ops.h>
#endif
-// those are defined in net-snk/oflib/pci.c
-extern unsigned int read_io(void *, size_t);
-extern int write_io(void *, unsigned int, size_t);
+static unsigned int
+read_io(void *addr, size_t sz)
+{
+ unsigned int ret;
+ /* since we are using inb instructions, we need the port number as 16bit value */
+ u16 port = (u16)(u32) addr;
+
+ switch (sz) {
+ case 1:
+ asm volatile ("inb %1, %b0" : "=a"(ret) : "d" (port));
+ break;
+ case 2:
+ asm volatile ("inw %1, %w0" : "=a"(ret) : "d" (port));
+ break;
+ case 4:
+ asm volatile ("inl %1, %0" : "=a"(ret) : "d" (port));
+ break;
+ default:
+ ret = 0;
+ }
+
+ return ret;
+}
-//defined in net-snk/kernel/timer.c
-extern u64 get_time(void);
+static int
+write_io(void *addr, unsigned int value, size_t sz)
+{
+ u16 port = (u16)(u32) addr;
+ switch (sz) {
+ /* since we are using inb instructions, we need the port number as 16bit value */
+ case 1:
+ asm volatile ("outb %b0, %1" : : "a"(value), "d" (port));
+ break;
+ case 2:
+ asm volatile ("outw %w0, %1" : : "a"(value), "d" (port));
+ break;
+ case 4:
+ asm volatile ("outl %0, %1" : : "a"(value), "d" (port));
+ break;
+ default:
+ return -1;
+ }
+
+ return 0;
+}
#ifdef CONFIG_ARCH_X86
#include <arch/io.h>