ioport: consolidate duplicated logic in register_ioport_{read, write}().

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Isaku Yamahata 2009-07-02 19:32:08 +09:00 committed by Anthony Liguori
parent d56dd6cf03
commit 23e0affdd2

View File

@ -121,19 +121,27 @@ static void default_ioport_writel(void *opaque, uint32_t address, uint32_t data)
#endif #endif
} }
static int ioport_bsize(int size, int *bsize)
{
if (size == 1) {
*bsize = 0;
} else if (size == 2) {
*bsize = 1;
} else if (size == 4) {
*bsize = 2;
} else {
return -1;
}
return 0;
}
/* size is the word size in byte */ /* size is the word size in byte */
int register_ioport_read(int start, int length, int size, int register_ioport_read(int start, int length, int size,
IOPortReadFunc *func, void *opaque) IOPortReadFunc *func, void *opaque)
{ {
int i, bsize; int i, bsize;
if (size == 1) { if (ioport_bsize(size, &bsize)) {
bsize = 0;
} else if (size == 2) {
bsize = 1;
} else if (size == 4) {
bsize = 2;
} else {
hw_error("register_ioport_read: invalid size"); hw_error("register_ioport_read: invalid size");
return -1; return -1;
} }
@ -152,13 +160,7 @@ int register_ioport_write(int start, int length, int size,
{ {
int i, bsize; int i, bsize;
if (size == 1) { if (ioport_bsize(size, &bsize)) {
bsize = 0;
} else if (size == 2) {
bsize = 1;
} else if (size == 4) {
bsize = 2;
} else {
hw_error("register_ioport_write: invalid size"); hw_error("register_ioport_write: invalid size");
return -1; return -1;
} }