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-2010 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  
  30  namespace Genode {
  31  
  32     class Io_port_session
  33     {
  34        protected:
  35  
  36           enum Opcode { INB, INW, INL, OUTB, OUTW, OUTL };

  37  
  38        public:
  39  
  40           static const char *service_name() { return "IO_PORT"; }
  41  
  42           virtual ~Io_port_session() { }
  43  
  44           /******************************
  45            ** Read value from I/O port **
  46            ******************************/

  47  
  48           /**
  49            * Read byte (8 bit)
  50            *
  51            * \param address  physical I/O port address
  52            *
  53            * \return         value read from port
  54            */

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

  56  
  57           /**
  58            * Read word (16 bit)
  59            *
  60            * \param address  physical I/O port address
  61            *
  62            * \return         value read from port
  63            */

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

  65  
  66           /**
  67            * Read double word (32 bit)
  68            *
  69            * \param address  physical I/O port address
  70            *
  71            * \return         value read from port
  72            */

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

  74  
  75  
  76           /*****************************
  77            ** Write value to I/O port **
  78            *****************************/

  79  
  80           /**
  81            * Write byte (8 bit)
  82            *
  83            * \param address  physical I/O port address
  84            * \param value    value to write to port
  85            */

  86           virtual void outb(unsigned short addressunsigned char value) = 0;

  87  
  88           /**
  89            * Write word (16 bit)
  90            *
  91            * \param address  physical I/O port address
  92            * \param value    value to write to port
  93            */

  94           virtual void outw(unsigned short addressunsigned short value) = 0;

  95  
  96           /**
  97            * Write double word (32 bit)
  98            *
  99            * \param address  physical I/O port address
 100            * \param value    value to write to port
 101            */

 102           virtual void outl(unsigned short addressunsigned value) = 0;

 103     }
;

 104  }

 105  
 106  #endif /* _INCLUDE__IO_PORT_SESSION__IO_PORT_SESSION_H_ */