Perl interface to direct port I/O functions (inb(), outb() and friends)

From: Andrew Ho (andrew.ho_at_gmail.com)
Date: 02/20/05

  • Next message: kramer27182_at_yahoo.com: "POP3Client problem with SSL"
    Date: 19 Feb 2005 20:00:01 -0800
    
    

    Hello,

    On Linux or BSD systems, you can do direct port I/O from C/C++ using
    the inb() and outb() functions. In addition, on Linux and glibc based
    systems you may have to use ioperm() to get access to a port, and the
    BSDs have equivalents (I've been using /dev/io on FreeBSD and sysarch()
    and iopl on OpenBSD).

    Typically, you want to do this to do some sort of ad hoc hardware
    interfacing: for example, using your joystick port or parallel port for
    random hackery.

    I've written some XS glue--it's pretty simple--to provide Perl access
    to these functions; it's four simple exported functions:

        port_open($portnum);
        write_byte($portnum, $value);
        $value = read_byte($portnum);
        port_close($portnum);

    I have a few questions. First, is there already a module that does this
    for me? I note at least one port-specific module, Device::ParallelPort,
    but no general interface to inb() and outb() and equivalents (it could
    almost be, though, the API is pretty much the same, so perhaps it just
    bears renaming!).

    If there is not such a module, I'd like to contribute one. I'm thinking
    the Sys:: namespace is the right place for it, so I'd suggest something
    like Sys::PortIO. I'm quite open to alternate suggestions.

    I'm already registered with PAUSE, so if I don't hear back from anybody
    in a week or so, I'll probably just go ahead with packaging up and
    submitting the code I've got working. Thanks!

    Humbly,

    Andrew

    -----------------------------------------------------------------------
    'Twas brillig, and the slithy toves Andrew Ho
     Did gyre and gimble in the wabe. andrew@zeuscat.com
     All mimsy were the borogoves,
     And the mome raths outgrabe. http://www.zeuscat.com/andrew/
    -----------------------------------------------------------------------


  • Next message: kramer27182_at_yahoo.com: "POP3Client problem with SSL"

    Relevant Pages

    • serial IO port from User space with functions such as inb and outb?
      ... I'd like to know is it able to access to the serial IO port from User ... space with functions such as inb and outb? ... if it is not work,, can I export these ports to userspace so that I can ...
      (comp.os.linux.development.apps)
    • Re: RFC: outb 0x80 in inb_p, outb_p harmful on some modern AMD64 with MCP51 laptops
      ... any intelligent way to force PCI posting? ... the outb and the following port 0x80 cycle, which locks the bus, are tiny. ... inb 0x80 ...
      (Linux-Kernel)
    • Re: [PATCH] x86: provide a DMI based port 0x80 I/O delay override
      ... It's not a regression as far as I can see (ie we've always done that port 80 access for slow-down), and quite frankly, I think the code is horribly ugly. ... a udelayis going to satisfy the delay property though -- but doesn't do anything for the other things the outb() does. ... With an arch that purports to support just about anything though there's some fairly justified fear, uncertainty, doubt that the ones to break aren't going to be found and reported quickly/easily. ... With the various races in drivers additionally an early suggestion by Andi Kleen to leave the outb in place for a DMI year X might in fact be justified. ...
      (Linux-Kernel)
    • Re: [PATCH] x86: provide a DMI based port 0x80 I/O delay override.
      ... H. Peter Anvin wrote: ... an inb takes 1/2 the elapsed time compared to a read to "known" unused ... ticks for port 0xed and other unused ports. ... port 0xed: cycles: out 2541, ...
      (Linux-Kernel)
    • Re: [PATCH] x86: provide a DMI based port 0x80 I/O delay override.
      ... inb takes 1/2 the elapsed time compared to a read to "known" unused port ... port 0xed and other unused ports (tsc at 800 MHz). ...
      (Linux-Kernel)