1  /*
   2   * \brief  I/O-port session interface
   3   * \author Christian Helmuth
   4   * \date   2007-04-17
   5   *
   6   * An I/O port session permits access to a range of ports. Inside this range
   7   * variable-sized accesses (i.e., 8, 16, 32 bit) at arbitrary addresses are
   8   * allowed - currently, alignment is not enforced. Core enforces that access is
   9   * limited to the session-defined range while the user provides physical I/O port
  10   * addresses as function parameters.
  11   *
  12   * The design is founded on experiences while programming PCI configuration
  13   * space which needs two 32-bit port registers. Each byte, word and dword in
  14   * the data register must be explicitly accessible for read and write. The old
  15   * design needs six capabilities only for the data register.
  16   */

  17  
  18  /*
  19   * Copyright (C) 2007-2013 Genode Labs GmbH
  20   *
  21   * This file is part of the Genode OS framework, which is distributed
  22   * under the terms of the GNU General Public License version 2.
  23   */

  24  
  25  #ifndef _INCLUDE__IO_PORT_SESSION__IO_PORT_SESSION_H_
  26  #define _INCLUDE__IO_PORT_SESSION__IO_PORT_SESSION_H_
  27  
  28  #include <base/capability.h>
  29  #include <session/session.h>
  30  
  31  namespace Genode {
  32  
  33     struct Io_port_session : Session
  34     {
  35        static const char *service_name() { return "IO_PORT"; }
  36  
  37        virtual ~Io_port_session() { }
  38  
  39        /******************************
  40         ** Read value from I/O port **
  41         ******************************/

  42  
  43        /**
  44         * Read byte (8 bit)
  45         *
  46         * \param address  physical I/O port address
  47         *
  48         * \return         value read from port
  49         */

  50        virtual unsigned char inb(unsigned short address) = 0;

  51  
  52        /**
  53         * Read word (16 bit)
  54         *
  55         * \param address  physical I/O port address
  56         *
  57         * \return         value read from port
  58         */

  59        virtual unsigned short inw(unsigned short address) = 0;

  60  
  61        /**
  62         * Read double word (32 bit)
  63         *
  64         * \param address  physical I/O port address
  65         *
  66         * \return         value read from port
  67         */

  68        virtual unsigned inl(unsigned short address) = 0;

  69  
  70  
  71        /*****************************
  72         ** Write value to I/O port **
  73         *****************************/

  74  
  75        /**
  76         * Write byte (8 bit)
  77         *
  78         * \param address  physical I/O port address
  79         * \param value    value to write to port
  80         */

  81        virtual void outb(unsigned short address, unsigned char value) = 0;

  82  
  83        /**
  84         * Write word (16 bit)
  85         *
  86         * \param address  physical I/O port address
  87         * \param value    value to write to port
  88         */

  89        virtual void outw(unsigned short address, unsigned short value) = 0;

  90  
  91        /**
  92         * Write double word (32 bit)
  93         *
  94         * \param address  physical I/O port address
  95         * \param value    value to write to port
  96         */

  97        virtual void outl(unsigned short address, unsigned value) = 0;

  98  
  99  
 100        /*********************
 101         ** RPC declaration **
 102         *********************/

 103  
 104        GENODE_RPC(Rpc_inb, unsigned char,  inb, unsigned short);
 105        GENODE_RPC(Rpc_inw, unsigned short, inw, unsigned short);
 106        GENODE_RPC(Rpc_inl, unsigned,       inl, unsigned short);
 107  
 108        GENODE_RPC(Rpc_outb, void, outb, unsigned short, unsigned char);
 109        GENODE_RPC(Rpc_outw, void, outw, unsigned short, unsigned short);
 110        GENODE_RPC(Rpc_outl, void, outl, unsigned short, unsigned);
 111  
 112        GENODE_RPC_INTERFACE(Rpc_inb, Rpc_inw, Rpc_inl, Rpc_outb, Rpc_outw, Rpc_outl);
 113     }
;

 114  }

 115  
 116  #endif /* _INCLUDE__IO_PORT_SESSION__IO_PORT_SESSION_H_ */