Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 1 | // Definitions for X86 IO port access. |
| 2 | // |
| 3 | // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net> |
| 4 | // |
Kevin O'Connor | b1b7c2a | 2009-01-15 20:52:58 -0500 | [diff] [blame] | 5 | // This file may be distributed under the terms of the GNU LGPLv3 license. |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 6 | #ifndef __IOPORT_H |
| 7 | #define __IOPORT_H |
| 8 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 9 | #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'Connor | f54c150 | 2008-06-14 15:56:16 -0400 | [diff] [blame] | 15 | #define PORT_PIC1_CMD 0x0020 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 16 | #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'Connor | ee2fd7a | 2008-03-02 08:42:16 -0500 | [diff] [blame] | 21 | #define PORT_PS2_DATA 0x0060 |
| 22 | #define PORT_PS2_CTRLB 0x0061 |
| 23 | #define PORT_PS2_STATUS 0x0064 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 24 | #define PORT_CMOS_INDEX 0x0070 |
| 25 | #define PORT_CMOS_DATA 0x0071 |
Kevin O'Connor | 4b60c00 | 2008-02-25 22:29:55 -0500 | [diff] [blame] | 26 | #define PORT_DIAG 0x0080 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 27 | #define PORT_DMA_PAGE_2 0x0081 |
| 28 | #define PORT_A20 0x0092 |
Kevin O'Connor | f54c150 | 2008-06-14 15:56:16 -0400 | [diff] [blame] | 29 | #define PORT_PIC2_CMD 0x00a0 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 30 | #define PORT_PIC2_DATA 0x00a1 |
Kevin O'Connor | e682cbc | 2008-12-06 23:11:56 -0500 | [diff] [blame] | 31 | #define PORT_SMI_CMD 0x00b2 |
| 32 | #define PORT_SMI_STATUS 0x00b3 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 33 | #define PORT_DMA2_MASK_REG 0x00d4 |
| 34 | #define PORT_DMA2_MODE_REG 0x00d6 |
| 35 | #define PORT_DMA2_MASTER_CLEAR 0x00da |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 36 | #define PORT_MATH_CLEAR 0x00f0 |
Kevin O'Connor | 0c5893d | 2009-07-13 20:29:07 -0400 | [diff] [blame] | 37 | #define PORT_LPT2 0x0278 |
Kevin O'Connor | c151b3b | 2009-05-12 22:59:41 -0400 | [diff] [blame] | 38 | #define PORT_SERIAL4 0x02e8 |
| 39 | #define PORT_SERIAL2 0x02f8 |
Kevin O'Connor | 0c5893d | 2009-07-13 20:29:07 -0400 | [diff] [blame] | 40 | #define PORT_LPT1 0x0378 |
Kevin O'Connor | c151b3b | 2009-05-12 22:59:41 -0400 | [diff] [blame] | 41 | #define PORT_SERIAL3 0x03e8 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 42 | #define PORT_FD_DOR 0x03f2 |
| 43 | #define PORT_FD_STATUS 0x03f4 |
| 44 | #define PORT_FD_DATA 0x03f5 |
Kevin O'Connor | 438f635 | 2008-03-30 21:46:53 -0400 | [diff] [blame] | 45 | #define PORT_HD_DATA 0x03f6 |
Kevin O'Connor | 2ad3744 | 2008-05-06 19:49:01 -0400 | [diff] [blame] | 46 | #define PORT_FD_DIR 0x03f7 |
Kevin O'Connor | c151b3b | 2009-05-12 22:59:41 -0400 | [diff] [blame] | 47 | #define PORT_SERIAL1 0x03f8 |
Kevin O'Connor | 0f803e4 | 2008-05-24 23:07:16 -0400 | [diff] [blame] | 48 | #define PORT_PCI_CMD 0x0cf8 |
| 49 | #define PORT_PCI_DATA 0x0cfc |
Kevin O'Connor | f13b008 | 2008-08-17 11:26:42 -0400 | [diff] [blame] | 50 | #define PORT_BIOS_DEBUG 0x0402 |
Kevin O'Connor | 2054300 | 2008-10-25 15:43:46 -0400 | [diff] [blame] | 51 | #define PORT_QEMU_CFG_CTL 0x0510 |
| 52 | #define PORT_QEMU_CFG_DATA 0x0511 |
Kevin O'Connor | e682cbc | 2008-12-06 23:11:56 -0500 | [diff] [blame] | 53 | #define PORT_ACPI_PM_BASE 0xb000 |
| 54 | #define PORT_SMB_BASE 0xb100 |
Kevin O'Connor | 2ad3744 | 2008-05-06 19:49:01 -0400 | [diff] [blame] | 55 | #define PORT_BIOS_APM 0x8900 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 56 | |
Kevin O'Connor | c151b3b | 2009-05-12 22:59:41 -0400 | [diff] [blame] | 57 | // Serial port offsets |
| 58 | #define SEROFF_DATA 0 |
| 59 | #define SEROFF_DLL 0 |
| 60 | #define SEROFF_IER 1 |
| 61 | #define SEROFF_DLH 1 |
| 62 | #define SEROFF_IIR 2 |
| 63 | #define SEROFF_LCR 3 |
| 64 | #define SEROFF_LSR 5 |
| 65 | #define SEROFF_MSR 6 |
| 66 | |
Kevin O'Connor | d9a8b2d | 2008-11-16 09:17:02 -0500 | [diff] [blame] | 67 | // PORT_A20 bitdefs |
| 68 | #define A20_ENABLE_BIT 0x02 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 69 | |
Kevin O'Connor | 75f49b3 | 2009-03-07 00:07:24 -0500 | [diff] [blame] | 70 | // PORT_CMOS_INDEX nmi disable bit |
| 71 | #define NMI_DISABLE_BIT 0x80 |
| 72 | |
Kevin O'Connor | d9a8b2d | 2008-11-16 09:17:02 -0500 | [diff] [blame] | 73 | #ifndef __ASSEMBLY__ |
| 74 | |
| 75 | #include "types.h" // u8 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 76 | |
| 77 | static inline void outb(u8 value, u16 port) { |
| 78 | __asm__ __volatile__("outb %b0, %w1" : : "a"(value), "Nd"(port)); |
| 79 | } |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 80 | static inline void outw(u16 value, u16 port) { |
| 81 | __asm__ __volatile__("outw %w0, %w1" : : "a"(value), "Nd"(port)); |
| 82 | } |
| 83 | static inline void outl(u32 value, u16 port) { |
| 84 | __asm__ __volatile__("outl %0, %w1" : : "a"(value), "Nd"(port)); |
| 85 | } |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 86 | static inline u8 inb(u16 port) { |
| 87 | u8 value; |
| 88 | __asm__ __volatile__("inb %w1, %b0" : "=a"(value) : "Nd"(port)); |
| 89 | return value; |
| 90 | } |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 91 | static inline u16 inw(u16 port) { |
| 92 | u16 value; |
| 93 | __asm__ __volatile__("inw %w1, %w0" : "=a"(value) : "Nd"(port)); |
| 94 | return value; |
| 95 | } |
| 96 | static inline u32 inl(u16 port) { |
| 97 | u32 value; |
| 98 | __asm__ __volatile__("inl %w1, %0" : "=a"(value) : "Nd"(port)); |
| 99 | return value; |
| 100 | } |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 101 | |
Kevin O'Connor | 843a62c | 2008-03-09 00:59:58 -0500 | [diff] [blame] | 102 | static inline void insb(u16 port, u8 *data, u32 count) { |
Kevin O'Connor | 7edaa65 | 2009-10-24 17:54:06 -0400 | [diff] [blame] | 103 | asm volatile("rep insb (%%dx), %%es:(%%edi)" |
Kevin O'Connor | 843a62c | 2008-03-09 00:59:58 -0500 | [diff] [blame] | 104 | : "+c"(count), "+D"(data) : "d"(port) : "memory"); |
| 105 | } |
| 106 | static inline void insw(u16 port, u16 *data, u32 count) { |
Kevin O'Connor | 7edaa65 | 2009-10-24 17:54:06 -0400 | [diff] [blame] | 107 | asm volatile("rep insw (%%dx), %%es:(%%edi)" |
Kevin O'Connor | 843a62c | 2008-03-09 00:59:58 -0500 | [diff] [blame] | 108 | : "+c"(count), "+D"(data) : "d"(port) : "memory"); |
| 109 | } |
| 110 | static inline void insl(u16 port, u32 *data, u32 count) { |
Kevin O'Connor | 7edaa65 | 2009-10-24 17:54:06 -0400 | [diff] [blame] | 111 | asm volatile("rep insl (%%dx), %%es:(%%edi)" |
Kevin O'Connor | 843a62c | 2008-03-09 00:59:58 -0500 | [diff] [blame] | 112 | : "+c"(count), "+D"(data) : "d"(port) : "memory"); |
| 113 | } |
| 114 | // XXX - outs not limited to es segment |
| 115 | static inline void outsb(u16 port, u8 *data, u32 count) { |
Kevin O'Connor | 7edaa65 | 2009-10-24 17:54:06 -0400 | [diff] [blame] | 116 | asm volatile("rep outsb %%es:(%%esi), (%%dx)" |
Kevin O'Connor | 843a62c | 2008-03-09 00:59:58 -0500 | [diff] [blame] | 117 | : "+c"(count), "+S"(data) : "d"(port) : "memory"); |
| 118 | } |
| 119 | static inline void outsw(u16 port, u16 *data, u32 count) { |
Kevin O'Connor | 7edaa65 | 2009-10-24 17:54:06 -0400 | [diff] [blame] | 120 | asm volatile("rep outsw %%es:(%%esi), (%%dx)" |
Kevin O'Connor | 843a62c | 2008-03-09 00:59:58 -0500 | [diff] [blame] | 121 | : "+c"(count), "+S"(data) : "d"(port) : "memory"); |
| 122 | } |
| 123 | static inline void outsl(u16 port, u32 *data, u32 count) { |
Kevin O'Connor | 7edaa65 | 2009-10-24 17:54:06 -0400 | [diff] [blame] | 124 | asm volatile("rep outsl %%es:(%%esi), (%%dx)" |
Kevin O'Connor | 843a62c | 2008-03-09 00:59:58 -0500 | [diff] [blame] | 125 | : "+c"(count), "+S"(data) : "d"(port) : "memory"); |
| 126 | } |
| 127 | |
Kevin O'Connor | d9a8b2d | 2008-11-16 09:17:02 -0500 | [diff] [blame] | 128 | #endif // !__ASSEMBLY__ |
| 129 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 130 | #endif // ioport.h |