blob: 3282fb49546af3acdc1daace77ad37785af8c904 [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//
Kevin O'Connorb1b7c2a2009-01-15 20:52:58 -05005// This file may be distributed under the terms of the GNU LGPLv3 license.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05006#ifndef __IOPORT_H
7#define __IOPORT_H
8
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05009#define PORT_DMA_ADDR_2 0x0004
10#define PORT_DMA_CNT_2 0x0005
11#define PORT_DMA1_MASK_REG 0x000a
12#define PORT_DMA1_MODE_REG 0x000b
13#define PORT_DMA1_CLEAR_FF_REG 0x000c
14#define PORT_DMA1_MASTER_CLEAR 0x000d
Kevin O'Connorf54c1502008-06-14 15:56:16 -040015#define PORT_PIC1_CMD 0x0020
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050016#define PORT_PIC1_DATA 0x0021
17#define PORT_PIT_COUNTER0 0x0040
18#define PORT_PIT_COUNTER1 0x0041
19#define PORT_PIT_COUNTER2 0x0042
20#define PORT_PIT_MODE 0x0043
Kevin O'Connoree2fd7a2008-03-02 08:42:16 -050021#define PORT_PS2_DATA 0x0060
22#define PORT_PS2_CTRLB 0x0061
23#define PORT_PS2_STATUS 0x0064
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050024#define PORT_CMOS_INDEX 0x0070
25#define PORT_CMOS_DATA 0x0071
Kevin O'Connor4b60c002008-02-25 22:29:55 -050026#define PORT_DIAG 0x0080
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050027#define PORT_DMA_PAGE_2 0x0081
28#define PORT_A20 0x0092
Kevin O'Connorf54c1502008-06-14 15:56:16 -040029#define PORT_PIC2_CMD 0x00a0
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050030#define PORT_PIC2_DATA 0x00a1
Kevin O'Connore682cbc2008-12-06 23:11:56 -050031#define PORT_SMI_CMD 0x00b2
32#define PORT_SMI_STATUS 0x00b3
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050033#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'Connor4ccb2312009-12-05 11:25:09 -050037#define PORT_ATA2_CMD_BASE 0x0170
38#define PORT_ATA1_CMD_BASE 0x01f0
Kevin O'Connor0c5893d2009-07-13 20:29:07 -040039#define PORT_LPT2 0x0278
Kevin O'Connorc151b3b2009-05-12 22:59:41 -040040#define PORT_SERIAL4 0x02e8
41#define PORT_SERIAL2 0x02f8
Kevin O'Connor525219b2009-12-05 13:36:18 -050042#define PORT_ATA2_CTRL_BASE 0x0374
Kevin O'Connor0c5893d2009-07-13 20:29:07 -040043#define PORT_LPT1 0x0378
Kevin O'Connorc151b3b2009-05-12 22:59:41 -040044#define PORT_SERIAL3 0x03e8
Kevin O'Connor525219b2009-12-05 13:36:18 -050045#define PORT_ATA1_CTRL_BASE 0x03f4
Kevin O'Connor031ef552010-12-27 19:26:57 -050046#define PORT_FD_BASE 0x03f0
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050047#define PORT_FD_DOR 0x03f2
48#define PORT_FD_STATUS 0x03f4
49#define PORT_FD_DATA 0x03f5
Kevin O'Connor438f6352008-03-30 21:46:53 -040050#define PORT_HD_DATA 0x03f6
Kevin O'Connor2ad37442008-05-06 19:49:01 -040051#define PORT_FD_DIR 0x03f7
Kevin O'Connorc151b3b2009-05-12 22:59:41 -040052#define PORT_SERIAL1 0x03f8
Kevin O'Connor0f803e42008-05-24 23:07:16 -040053#define PORT_PCI_CMD 0x0cf8
Kevin O'Connoradaf3732010-09-13 20:22:07 -040054#define PORT_PCI_REBOOT 0x0cf9
Kevin O'Connor0f803e42008-05-24 23:07:16 -040055#define PORT_PCI_DATA 0x0cfc
Kevin O'Connorf13b0082008-08-17 11:26:42 -040056#define PORT_BIOS_DEBUG 0x0402
Kevin O'Connor20543002008-10-25 15:43:46 -040057#define PORT_QEMU_CFG_CTL 0x0510
58#define PORT_QEMU_CFG_DATA 0x0511
Kevin O'Connore682cbc2008-12-06 23:11:56 -050059#define PORT_ACPI_PM_BASE 0xb000
60#define PORT_SMB_BASE 0xb100
Kevin O'Connor2ad37442008-05-06 19:49:01 -040061#define PORT_BIOS_APM 0x8900
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050062
Kevin O'Connorc151b3b2009-05-12 22:59:41 -040063// Serial port offsets
64#define SEROFF_DATA 0
65#define SEROFF_DLL 0
66#define SEROFF_IER 1
67#define SEROFF_DLH 1
68#define SEROFF_IIR 2
69#define SEROFF_LCR 3
70#define SEROFF_LSR 5
71#define SEROFF_MSR 6
72
Kevin O'Connord9a8b2d2008-11-16 09:17:02 -050073// PORT_A20 bitdefs
74#define A20_ENABLE_BIT 0x02
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050075
Kevin O'Connor75f49b32009-03-07 00:07:24 -050076// PORT_CMOS_INDEX nmi disable bit
77#define NMI_DISABLE_BIT 0x80
78
Kevin O'Connord9a8b2d2008-11-16 09:17:02 -050079#ifndef __ASSEMBLY__
80
81#include "types.h" // u8
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050082
83static inline void outb(u8 value, u16 port) {
84 __asm__ __volatile__("outb %b0, %w1" : : "a"(value), "Nd"(port));
85}
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050086static inline void outw(u16 value, u16 port) {
87 __asm__ __volatile__("outw %w0, %w1" : : "a"(value), "Nd"(port));
88}
89static inline void outl(u32 value, u16 port) {
90 __asm__ __volatile__("outl %0, %w1" : : "a"(value), "Nd"(port));
91}
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050092static inline u8 inb(u16 port) {
93 u8 value;
94 __asm__ __volatile__("inb %w1, %b0" : "=a"(value) : "Nd"(port));
95 return value;
96}
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050097static inline u16 inw(u16 port) {
98 u16 value;
99 __asm__ __volatile__("inw %w1, %w0" : "=a"(value) : "Nd"(port));
100 return value;
101}
102static inline u32 inl(u16 port) {
103 u32 value;
104 __asm__ __volatile__("inl %w1, %0" : "=a"(value) : "Nd"(port));
105 return value;
106}
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500107
Kevin O'Connor843a62c2008-03-09 00:59:58 -0500108static inline void insb(u16 port, u8 *data, u32 count) {
Kevin O'Connor7edaa652009-10-24 17:54:06 -0400109 asm volatile("rep insb (%%dx), %%es:(%%edi)"
Kevin O'Connor843a62c2008-03-09 00:59:58 -0500110 : "+c"(count), "+D"(data) : "d"(port) : "memory");
111}
112static inline void insw(u16 port, u16 *data, u32 count) {
Kevin O'Connor7edaa652009-10-24 17:54:06 -0400113 asm volatile("rep insw (%%dx), %%es:(%%edi)"
Kevin O'Connor843a62c2008-03-09 00:59:58 -0500114 : "+c"(count), "+D"(data) : "d"(port) : "memory");
115}
116static inline void insl(u16 port, u32 *data, u32 count) {
Kevin O'Connor7edaa652009-10-24 17:54:06 -0400117 asm volatile("rep insl (%%dx), %%es:(%%edi)"
Kevin O'Connor843a62c2008-03-09 00:59:58 -0500118 : "+c"(count), "+D"(data) : "d"(port) : "memory");
119}
120// XXX - outs not limited to es segment
121static inline void outsb(u16 port, u8 *data, u32 count) {
Kevin O'Connor7edaa652009-10-24 17:54:06 -0400122 asm volatile("rep outsb %%es:(%%esi), (%%dx)"
Kevin O'Connor843a62c2008-03-09 00:59:58 -0500123 : "+c"(count), "+S"(data) : "d"(port) : "memory");
124}
125static inline void outsw(u16 port, u16 *data, u32 count) {
Kevin O'Connor7edaa652009-10-24 17:54:06 -0400126 asm volatile("rep outsw %%es:(%%esi), (%%dx)"
Kevin O'Connor843a62c2008-03-09 00:59:58 -0500127 : "+c"(count), "+S"(data) : "d"(port) : "memory");
128}
129static inline void outsl(u16 port, u32 *data, u32 count) {
Kevin O'Connor7edaa652009-10-24 17:54:06 -0400130 asm volatile("rep outsl %%es:(%%esi), (%%dx)"
Kevin O'Connor843a62c2008-03-09 00:59:58 -0500131 : "+c"(count), "+S"(data) : "d"(port) : "memory");
132}
133
Kevin O'Connord9a8b2d2008-11-16 09:17:02 -0500134#endif // !__ASSEMBLY__
135
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500136#endif // ioport.h