Patrick Georgi (patrick@georgi-clan.de) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/1062
-gerrit
commit 5acd7482a14eb7e92b0207491f7c1fb4e7aec35d Author: Patrick Georgi patrick@georgi-clan.de Date: Wed May 30 00:15:18 2012 +0200
Create single function for I/O access
All SerialICE I/O accesses are sent through a single function with read size as argument.
Change-Id: Ic21c589d9a6161fb6c59f5ed59bd1a1455ae606b Signed-off-by: Kyösti Mälkki kyosti.malkki@gmail.com [pg: Reorganized Kyösti's patch set] Signed-off-by: Patrick Georgi patrick@georgi-clan.de --- qemu-0.15.x/serialice.c | 69 ++++++++++++++++++++++++++++++++++------------ 1 files changed, 51 insertions(+), 18 deletions(-)
diff --git a/qemu-0.15.x/serialice.c b/qemu-0.15.x/serialice.c index 1fb2e5f..5f58e5d 100644 --- a/qemu-0.15.x/serialice.c +++ b/qemu-0.15.x/serialice.c @@ -707,6 +707,51 @@ static void serialice_get_mainboard(void) printf("%s\n", serialice_mainboard); }
+static uint32_t serialice_io_read_wrapper(uint16_t port, unsigned int size) +{ + switch (size) { + case 1: + sprintf(s->command, "*ri%04x.b", port); + // command read back: "\n00" (3 characters) + serialice_command(s->command, 3); + return (uint8_t) strtoul(s->buffer + 1, (char **)NULL, 16); + case 2: + sprintf(s->command, "*ri%04x.w", port); + // command read back: "\n0000" (5 characters) + serialice_command(s->command, 5); + return (uint16_t) strtoul(s->buffer + 1, (char **)NULL, 16); + case 4: + sprintf(s->command, "*ri%04x.l", port); + // command read back: "\n00000000" (9 characters) + serialice_command(s->command, 9); + return strtoul(s->buffer + 1, (char **)NULL, 16); + default: + printf("WARNING: unknown read access size %d @%08x\n", size, port); + return -1; + } +} + +static void serialice_io_write_wrapper(uint16_t port, unsigned int size, uint32_t data) +{ + switch (size) { + case 1: + sprintf(s->command, "*wi%04x.b=%02x", port, (uint8_t) data); + serialice_command(s->command, 0); + return; + case 2: + sprintf(s->command, "*wi%04x.w=%04x", port, (uint16_t) data); + serialice_command(s->command, 0); + return; + case 4: + sprintf(s->command, "*wi%04x.l=%08x", port, data); + serialice_command(s->command, 0); + return; + default: + printf("WARNING: unknown write access size %d @%08x\n", size, port); + } + return; +} + uint8_t serialice_inb(uint16_t port) { uint8_t ret; @@ -718,10 +763,7 @@ uint8_t serialice_inb(uint16_t port) if (filtered) { ret = data & 0xff; } else { - sprintf(s->command, "*ri%04x.b", port); - // command read back: "\n00" (3 characters) - serialice_command(s->command, 3); - ret = (uint8_t) strtoul(s->buffer + 1, (char **)NULL, 16); + return serialice_io_read_wrapper(port, 1); }
serialice_log(LOG_READ | LOG_IO, ret, port, 1); @@ -740,10 +782,7 @@ uint16_t serialice_inw(uint16_t port) if (filtered) { ret = data & 0xffff; } else { - sprintf(s->command, "*ri%04x.w", port); - // command read back: "\n0000" (5 characters) - serialice_command(s->command, 5); - ret = (uint16_t) strtoul(s->buffer + 1, (char **)NULL, 16); + return serialice_io_read_wrapper(port, 2); }
serialice_log(LOG_READ | LOG_IO, ret, port, 2); @@ -762,10 +801,7 @@ uint32_t serialice_inl(uint16_t port) if (filtered) { ret = data; } else { - sprintf(s->command, "*ri%04x.l", port); - // command read back: "\n00000000" (9 characters) - serialice_command(s->command, 9); - ret = (uint32_t) strtoul(s->buffer + 1, (char **)NULL, 16); + return serialice_io_read_wrapper(port, 4); }
serialice_log(LOG_READ | LOG_IO, ret, port, 4); @@ -784,8 +820,7 @@ void serialice_outb(uint8_t data, uint16_t port) data = (uint8_t) filtered_data; } else { data = (uint8_t) filtered_data; - sprintf(s->command, "*wi%04x.b=%02x", port, data); - serialice_command(s->command, 0); + serialice_io_write_wrapper(port, 1, data); }
serialice_log(LOG_WRITE | LOG_IO, data, port, 1); @@ -802,8 +837,7 @@ void serialice_outw(uint16_t data, uint16_t port) data = (uint16_t) filtered_data; } else { data = (uint16_t) filtered_data; - sprintf(s->command, "*wi%04x.w=%04x", port, data); - serialice_command(s->command, 0); + serialice_io_write_wrapper(port, 2, data); }
serialice_log(LOG_WRITE | LOG_IO, data, port, 2); @@ -820,8 +854,7 @@ void serialice_outl(uint32_t data, uint16_t port) data = filtered_data; } else { data = filtered_data; - sprintf(s->command, "*wi%04x.l=%08x", port, data); - serialice_command(s->command, 0); + serialice_io_write_wrapper(port, 4, data); }
serialice_log(LOG_WRITE | LOG_IO, data, port, 4);