Annotation of embedaddon/pciutils/lib/i386-io-haiku.h, revision 1.1
1.1 ! misho 1: /*
! 2: * The PCI Library -- Access to i386 I/O ports on Haiku
! 3: *
! 4: * Copyright (c) 2009 Francois Revol <revol@free.fr>
! 5: *
! 6: * Can be freely distributed and used under the terms of the GNU GPL.
! 7: */
! 8:
! 9: #include <Drivers.h>
! 10: #include <ISA.h>
! 11: #include <PCI.h>
! 12:
! 13: /* from haiku/trunk/headers/private/drivers/poke.h */
! 14:
! 15: #define POKE_DEVICE_NAME "poke"
! 16: #define POKE_DEVICE_FULLNAME "/dev/misc/poke"
! 17: #define POKE_SIGNATURE 'wltp' // "We Like To Poke"
! 18:
! 19: enum {
! 20: POKE_PORT_READ = B_DEVICE_OP_CODES_END + 1,
! 21: POKE_PORT_WRITE,
! 22: POKE_PORT_INDEXED_READ,
! 23: POKE_PORT_INDEXED_WRITE,
! 24: POKE_PCI_READ_CONFIG,
! 25: POKE_PCI_WRITE_CONFIG,
! 26: POKE_GET_NTH_PCI_INFO,
! 27: POKE_GET_PHYSICAL_ADDRESS,
! 28: POKE_MAP_MEMORY,
! 29: POKE_UNMAP_MEMORY
! 30: };
! 31:
! 32:
! 33: typedef struct {
! 34: uint32 signature;
! 35: uint8 index;
! 36: pci_info* info;
! 37: status_t status;
! 38: } pci_info_args;
! 39:
! 40:
! 41: typedef struct {
! 42: uint32 signature;
! 43: uint16 port;
! 44: uint8 size; // == index for POKE_PORT_INDEXED_*
! 45: uint32 value;
! 46: } port_io_args;
! 47:
! 48:
! 49: typedef struct {
! 50: uint32 signature;
! 51: uint8 bus;
! 52: uint8 device;
! 53: uint8 function;
! 54: uint8 size;
! 55: uint8 offset;
! 56: uint32 value;
! 57: } pci_io_args;
! 58:
! 59:
! 60: /* en poke.h*/
! 61:
! 62: static int poke_driver_fd;
! 63:
! 64: static int
! 65: intel_setup_io(struct pci_access *a UNUSED)
! 66: {
! 67: poke_driver_fd = open(POKE_DEVICE_FULLNAME, O_RDWR);
! 68: return (poke_driver_fd < 0) ? 0 : 1;
! 69: }
! 70:
! 71: static inline int
! 72: intel_cleanup_io(struct pci_access *a UNUSED)
! 73: {
! 74: close(poke_driver_fd);
! 75: return 1;
! 76: }
! 77:
! 78: static inline u8
! 79: inb (u16 port)
! 80: {
! 81: port_io_args args = { POKE_SIGNATURE, port, sizeof(u8), 0 };
! 82: if (ioctl(poke_driver_fd, POKE_PORT_READ, &args, sizeof(args)) < 0)
! 83: return 0;
! 84: return (u8)args.value;
! 85: }
! 86:
! 87: static inline u16
! 88: inw (u16 port)
! 89: {
! 90: port_io_args args = { POKE_SIGNATURE, port, sizeof(u16), 0 };
! 91: if (ioctl(poke_driver_fd, POKE_PORT_READ, &args, sizeof(args)) < 0)
! 92: return 0;
! 93: return (u16)args.value;
! 94: }
! 95:
! 96: static inline u32
! 97: inl (u16 port)
! 98: {
! 99: port_io_args args = { POKE_SIGNATURE, port, sizeof(u32), 0 };
! 100: if (ioctl(poke_driver_fd, POKE_PORT_READ, &args, sizeof(args)) < 0)
! 101: return 0;
! 102: return (u32)args.value;
! 103: }
! 104:
! 105: static inline void
! 106: outb (u8 value, u16 port)
! 107: {
! 108: port_io_args args = { POKE_SIGNATURE, port, sizeof(u8), value };
! 109: ioctl(poke_driver_fd, POKE_PORT_WRITE, &args, sizeof(args));
! 110: }
! 111:
! 112: static inline void
! 113: outw (u16 value, u16 port)
! 114: {
! 115: port_io_args args = { POKE_SIGNATURE, port, sizeof(u16), value };
! 116: ioctl(poke_driver_fd, POKE_PORT_WRITE, &args, sizeof(args));
! 117: }
! 118:
! 119: static inline void
! 120: outl (u32 value, u16 port)
! 121: {
! 122: port_io_args args = { POKE_SIGNATURE, port, sizeof(u32), value };
! 123: ioctl(poke_driver_fd, POKE_PORT_WRITE, &args, sizeof(args));
! 124: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>