blob: 2392adffdff2284af45f6ffb0f54139f083febe8 [file] [log] [blame]
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05001// Definitions for X86 IO port access.
2//
3// Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4//
5// This file may be distributed under the terms of the GNU GPLv3 license.
6#ifndef __IOPORT_H
7#define __IOPORT_H
8
9#include "types.h" // u8
10
11#define PORT_DMA_ADDR_2 0x0004
12#define PORT_DMA_CNT_2 0x0005
13#define PORT_DMA1_MASK_REG 0x000a
14#define PORT_DMA1_MODE_REG 0x000b
15#define PORT_DMA1_CLEAR_FF_REG 0x000c
16#define PORT_DMA1_MASTER_CLEAR 0x000d
17#define PORT_PIC1 0x0020
18#define PORT_PIC1_DATA 0x0021
19#define PORT_PIT_COUNTER0 0x0040
20#define PORT_PIT_COUNTER1 0x0041
21#define PORT_PIT_COUNTER2 0x0042
22#define PORT_PIT_MODE 0x0043
Kevin O'Connoree2fd7a2008-03-02 08:42:16 -050023#define PORT_PS2_DATA 0x0060
24#define PORT_PS2_CTRLB 0x0061
25#define PORT_PS2_STATUS 0x0064
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050026#define PORT_CMOS_INDEX 0x0070
27#define PORT_CMOS_DATA 0x0071
Kevin O'Connor4b60c002008-02-25 22:29:55 -050028#define PORT_DIAG 0x0080
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050029#define PORT_DMA_PAGE_2 0x0081
30#define PORT_A20 0x0092
31#define PORT_PIC2 0x00a0
32#define PORT_PIC2_DATA 0x00a1
33#define PORT_DMA2_MASK_REG 0x00d4
34#define PORT_DMA2_MODE_REG 0x00d6
35#define PORT_DMA2_MASTER_CLEAR 0x00da
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050036#define PORT_MATH_CLEAR 0x00f0
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050037#define PORT_FD_DOR 0x03f2
38#define PORT_FD_STATUS 0x03f4
39#define PORT_FD_DATA 0x03f5
Kevin O'Connor438f6352008-03-30 21:46:53 -040040#define PORT_HD_DATA 0x03f6
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050041
42// PORT_PIC1 bitdefs
43#define PIC1_IRQ5 (1<<5)
44// PORT_PIC2 bitdefs
45#define PIC2_IRQ8 (1<<0)
46#define PIC2_IRQ13 (1<<5)
47
48// PORT_KBD_CTRLB bitdefs
49#define KBD_REFRESH (1<<4)
50
51
52static inline void outb(u8 value, u16 port) {
53 __asm__ __volatile__("outb %b0, %w1" : : "a"(value), "Nd"(port));
54}
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050055static inline void outw(u16 value, u16 port) {
56 __asm__ __volatile__("outw %w0, %w1" : : "a"(value), "Nd"(port));
57}
58static inline void outl(u32 value, u16 port) {
59 __asm__ __volatile__("outl %0, %w1" : : "a"(value), "Nd"(port));
60}
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050061static inline u8 inb(u16 port) {
62 u8 value;
63 __asm__ __volatile__("inb %w1, %b0" : "=a"(value) : "Nd"(port));
64 return value;
65}
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050066static inline u16 inw(u16 port) {
67 u16 value;
68 __asm__ __volatile__("inw %w1, %w0" : "=a"(value) : "Nd"(port));
69 return value;
70}
71static inline u32 inl(u16 port) {
72 u32 value;
73 __asm__ __volatile__("inl %w1, %0" : "=a"(value) : "Nd"(port));
74 return value;
75}
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050076
Kevin O'Connor843a62c2008-03-09 00:59:58 -050077static inline void insb(u16 port, u8 *data, u32 count) {
78 asm volatile("rep insb (%%dx), %%es:(%%di)"
79 : "+c"(count), "+D"(data) : "d"(port) : "memory");
80}
81static inline void insw(u16 port, u16 *data, u32 count) {
82 asm volatile("rep insw (%%dx), %%es:(%%di)"
83 : "+c"(count), "+D"(data) : "d"(port) : "memory");
84}
85static inline void insl(u16 port, u32 *data, u32 count) {
86 asm volatile("rep insl (%%dx), %%es:(%%di)"
87 : "+c"(count), "+D"(data) : "d"(port) : "memory");
88}
89// XXX - outs not limited to es segment
90static inline void outsb(u16 port, u8 *data, u32 count) {
91 asm volatile("rep outsb %%es:(%%si), (%%dx)"
92 : "+c"(count), "+S"(data) : "d"(port) : "memory");
93}
94static inline void outsw(u16 port, u16 *data, u32 count) {
95 asm volatile("rep outsw %%es:(%%si), (%%dx)"
96 : "+c"(count), "+S"(data) : "d"(port) : "memory");
97}
98static inline void outsl(u16 port, u32 *data, u32 count) {
99 asm volatile("rep outsl %%es:(%%si), (%%dx)"
100 : "+c"(count), "+S"(data) : "d"(port) : "memory");
101}
102
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500103#endif // ioport.h