cros_ec_python.ioports.baseportio

This file includes the base class for Port I/O backends.

It doesn't do anything on its own, but it is used as a base for all port I/O backends to inherit from.

See cros_ec_python.ioports for a few examples of a class that inherits from this class.

 1"""
 2This file includes the base class for Port I/O backends.
 3
 4It doesn't do anything on its own, but it is used as a base for all port I/O backends to inherit from.
 5
 6See `cros_ec_python.ioports` for a few examples of a class that inherits from this class.
 7"""
 8
 9import abc
10
11
12class PortIOClass(metaclass=abc.ABCMeta):
13    """
14    Base class for port I/O backends to inherit from.
15    """
16
17    @abc.abstractmethod
18    def outb(self, data: int, port: int) -> None:
19        """
20        Write a byte (8 bit) to the specified port.
21        :param data: Byte to write.
22        :param port: Port to write to.
23        """
24        pass
25
26    @abc.abstractmethod
27    def outw(self, data: int, port: int) -> None:
28        """
29        Write a word (16 bit) to the specified port.
30        :param data: Word to write.
31        :param port: Port to write to.
32        """
33        pass
34
35    @abc.abstractmethod
36    def outl(self, data: int, port: int) -> None:
37        """
38        Write a long (32 bit) to the specified port.
39        :param data: Long to write.
40        :param port: Port to write to.
41        """
42        pass
43
44    @abc.abstractmethod
45    def inb(self, port: int) -> int:
46        """
47        Read a byte (8 bit) from the specified port.
48        :param port: Port to read from.
49        :return: Byte read.
50        """
51        pass
52
53    @abc.abstractmethod
54    def inw(self, port: int) -> int:
55        """
56        Read a word (16 bit) from the specified port.
57        :param port: Port to read from.
58        :return: Word read.
59        """
60        pass
61
62    @abc.abstractmethod
63    def inl(self, port: int) -> int:
64        """
65        Read a long (32 bit) from the specified port.
66        :param port: Port to read from.
67        :return: Long read.
68        """
69        pass
70
71    @abc.abstractmethod
72    def ioperm(self, port: int, num: int, turn_on: bool) -> None:
73        """
74        Set I/O permissions for a range of ports.
75        :param port: Start of port range.
76        :param num: Number of ports to set permissions for.
77        :param turn_on: Whether to turn on or off permissions.
78        """
79        pass
80
81    @abc.abstractmethod
82    def iopl(self, level: int) -> None:
83        """
84        Set I/O permissions level.
85        :param level: Permissions level.
86        """
87        pass
class PortIOClass:
13class PortIOClass(metaclass=abc.ABCMeta):
14    """
15    Base class for port I/O backends to inherit from.
16    """
17
18    @abc.abstractmethod
19    def outb(self, data: int, port: int) -> None:
20        """
21        Write a byte (8 bit) to the specified port.
22        :param data: Byte to write.
23        :param port: Port to write to.
24        """
25        pass
26
27    @abc.abstractmethod
28    def outw(self, data: int, port: int) -> None:
29        """
30        Write a word (16 bit) to the specified port.
31        :param data: Word to write.
32        :param port: Port to write to.
33        """
34        pass
35
36    @abc.abstractmethod
37    def outl(self, data: int, port: int) -> None:
38        """
39        Write a long (32 bit) to the specified port.
40        :param data: Long to write.
41        :param port: Port to write to.
42        """
43        pass
44
45    @abc.abstractmethod
46    def inb(self, port: int) -> int:
47        """
48        Read a byte (8 bit) from the specified port.
49        :param port: Port to read from.
50        :return: Byte read.
51        """
52        pass
53
54    @abc.abstractmethod
55    def inw(self, port: int) -> int:
56        """
57        Read a word (16 bit) from the specified port.
58        :param port: Port to read from.
59        :return: Word read.
60        """
61        pass
62
63    @abc.abstractmethod
64    def inl(self, port: int) -> int:
65        """
66        Read a long (32 bit) from the specified port.
67        :param port: Port to read from.
68        :return: Long read.
69        """
70        pass
71
72    @abc.abstractmethod
73    def ioperm(self, port: int, num: int, turn_on: bool) -> None:
74        """
75        Set I/O permissions for a range of ports.
76        :param port: Start of port range.
77        :param num: Number of ports to set permissions for.
78        :param turn_on: Whether to turn on or off permissions.
79        """
80        pass
81
82    @abc.abstractmethod
83    def iopl(self, level: int) -> None:
84        """
85        Set I/O permissions level.
86        :param level: Permissions level.
87        """
88        pass

Base class for port I/O backends to inherit from.

@abc.abstractmethod
def outb(self, data: int, port: int) -> None:
18    @abc.abstractmethod
19    def outb(self, data: int, port: int) -> None:
20        """
21        Write a byte (8 bit) to the specified port.
22        :param data: Byte to write.
23        :param port: Port to write to.
24        """
25        pass

Write a byte (8 bit) to the specified port.

Parameters
  • data: Byte to write.
  • port: Port to write to.
@abc.abstractmethod
def outw(self, data: int, port: int) -> None:
27    @abc.abstractmethod
28    def outw(self, data: int, port: int) -> None:
29        """
30        Write a word (16 bit) to the specified port.
31        :param data: Word to write.
32        :param port: Port to write to.
33        """
34        pass

Write a word (16 bit) to the specified port.

Parameters
  • data: Word to write.
  • port: Port to write to.
@abc.abstractmethod
def outl(self, data: int, port: int) -> None:
36    @abc.abstractmethod
37    def outl(self, data: int, port: int) -> None:
38        """
39        Write a long (32 bit) to the specified port.
40        :param data: Long to write.
41        :param port: Port to write to.
42        """
43        pass

Write a long (32 bit) to the specified port.

Parameters
  • data: Long to write.
  • port: Port to write to.
@abc.abstractmethod
def inb(self, port: int) -> int:
45    @abc.abstractmethod
46    def inb(self, port: int) -> int:
47        """
48        Read a byte (8 bit) from the specified port.
49        :param port: Port to read from.
50        :return: Byte read.
51        """
52        pass

Read a byte (8 bit) from the specified port.

Parameters
  • port: Port to read from.
Returns

Byte read.

@abc.abstractmethod
def inw(self, port: int) -> int:
54    @abc.abstractmethod
55    def inw(self, port: int) -> int:
56        """
57        Read a word (16 bit) from the specified port.
58        :param port: Port to read from.
59        :return: Word read.
60        """
61        pass

Read a word (16 bit) from the specified port.

Parameters
  • port: Port to read from.
Returns

Word read.

@abc.abstractmethod
def inl(self, port: int) -> int:
63    @abc.abstractmethod
64    def inl(self, port: int) -> int:
65        """
66        Read a long (32 bit) from the specified port.
67        :param port: Port to read from.
68        :return: Long read.
69        """
70        pass

Read a long (32 bit) from the specified port.

Parameters
  • port: Port to read from.
Returns

Long read.

@abc.abstractmethod
def ioperm(self, port: int, num: int, turn_on: bool) -> None:
72    @abc.abstractmethod
73    def ioperm(self, port: int, num: int, turn_on: bool) -> None:
74        """
75        Set I/O permissions for a range of ports.
76        :param port: Start of port range.
77        :param num: Number of ports to set permissions for.
78        :param turn_on: Whether to turn on or off permissions.
79        """
80        pass

Set I/O permissions for a range of ports.

Parameters
  • port: Start of port range.
  • num: Number of ports to set permissions for.
  • turn_on: Whether to turn on or off permissions.
@abc.abstractmethod
def iopl(self, level: int) -> None:
82    @abc.abstractmethod
83    def iopl(self, level: int) -> None:
84        """
85        Set I/O permissions level.
86        :param level: Permissions level.
87        """
88        pass

Set I/O permissions level.

Parameters
  • level: Permissions level.