From fe925f4b2ca85e1ba31e9f4deb5c13f725621f25 Mon Sep 17 00:00:00 2001
From: Maksim Kuleshov mmcx@mail.ru Date: Sat, 30 Mar 2013 21:31:44 +0400 Subject: [PATCH 2/7] add lpt_io_direct to lpt_io module
Signed-off-by: Maksim Kuleshov mmcx@mail.ru --- lpt_io.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lpt_io.h | 1 + 2 files changed, 91 insertions(+)
diff --git a/lpt_io.c b/lpt_io.c index 638f6e9..e388cd5 100644 --- a/lpt_io.c +++ b/lpt_io.c @@ -15,7 +15,97 @@ struct lpt_io_driver { void *private; };
+#ifdef HAVE_DIRECT_IO +#if defined(__i386__) || defined(__x86_64__) +#include "hwaccess.h" +extern int rget_io_perms(void); +//FIXME 'int rget_io_perms(void)' declared in "programmer.h", not in "hwaccess.h" +#else +#error PCI port I/O access is not supported on this architecture yet. +#endif + +static struct lpt_io_private_direct { + uint16_t iobase; +} lpt_io_private_direct; + +static int lpt_io_direct_shutdown(void *data) +{ + (void)data; + return 0; +} + +static void lpt_io_direct_out_data(lpt_io_context_t context, uint8_t data) +{ + struct lpt_io_driver *driver = context; + struct lpt_io_private_direct *private = driver->private; + OUTB(data, private->iobase + 0); +} + +static void lpt_io_direct_out_control(lpt_io_context_t context, uint8_t data) +{ + struct lpt_io_driver *driver = context; + struct lpt_io_private_direct *private = driver->private; + OUTB(data, private->iobase + 2); +} + +static uint8_t lpt_io_direct_in_data(lpt_io_context_t context) +{ + struct lpt_io_driver *driver = context; + struct lpt_io_private_direct *private = driver->private; + return INB(private->iobase + 0); +} + +static uint8_t lpt_io_direct_in_status(lpt_io_context_t context) +{ + struct lpt_io_driver *driver = context; + struct lpt_io_private_direct *private = driver->private; + return INB(private->iobase + 1); +} + +static uint8_t lpt_io_direct_in_control(lpt_io_context_t context) +{ + struct lpt_io_driver *driver = context; + struct lpt_io_private_direct *private = driver->private; + return INB(private->iobase + 2); +} + +static int lpt_io_direct_init(lpt_io_context_t * p_context, void *data); + +static struct lpt_io_driver lpt_io_driver_direct = { + .method = "direct", + .init = lpt_io_direct_init, + .out_data = lpt_io_direct_out_data, + .out_control = lpt_io_direct_out_control, + .in_data = lpt_io_direct_in_data, + .in_status = lpt_io_direct_in_status, + .in_control = lpt_io_direct_in_control, + .shutdown = lpt_io_direct_shutdown, +}; + +static int lpt_io_direct_init(lpt_io_context_t * p_context, void *data) +{ + struct lpt_io_driver *driver = &lpt_io_driver_direct; + struct lpt_io_private_direct *private = &lpt_io_private_direct; + driver->private = (void *)private; + private->iobase = *(unsigned long *)data; + + if (rget_io_perms()) { + return 1; + } + + if (driver->shutdown) { + register_shutdown(driver->shutdown, driver); + } + + *p_context = (lpt_io_context_t) driver; + return 0; +} +#endif + static struct lpt_io_driver *lpt_io_drivers[] = { +#ifdef HAVE_DIRECT_IO + &lpt_io_driver_direct, +#endif NULL };
diff --git a/lpt_io.h b/lpt_io.h index a4912e8..5777654 100644 --- a/lpt_io.h +++ b/lpt_io.h @@ -1,3 +1,4 @@ +#define HAVE_DIRECT_IO //FIXME must be defined in Makefile #ifndef lpt_io_h_included_ #define lpt_io_h_included_