2 * The PCI Library -- Access to i386 I/O ports on Haiku
4 * Copyright (c) 2009 Francois Revol <revol@free.fr>
6 * Can be freely distributed and used under the terms of the GNU GPL v2+
8 * SPDX-License-Identifier: GPL-2.0-or-later
15 /* from haiku/trunk/headers/private/drivers/poke.h */
17 #define POKE_DEVICE_NAME "poke"
18 #define POKE_DEVICE_FULLNAME "/dev/misc/poke"
19 #define POKE_SIGNATURE 'wltp' // "We Like To Poke"
22 POKE_PORT_READ = B_DEVICE_OP_CODES_END + 1,
24 POKE_PORT_INDEXED_READ,
25 POKE_PORT_INDEXED_WRITE,
27 POKE_PCI_WRITE_CONFIG,
28 POKE_GET_NTH_PCI_INFO,
29 POKE_GET_PHYSICAL_ADDRESS,
46 uint8 size; // == index for POKE_PORT_INDEXED_*
64 static int poke_driver_fd;
67 intel_setup_io(struct pci_access *a UNUSED)
70 * Opening poke device on systems with the linked change below
71 * automatically changes process IOPL to 3 and closing its file
72 * descriptor changes process IOPL back to 0, which give access
73 * to all x86 IO ports via x86 in/out instructions for this
74 * userspace process. To support also older systems without this
75 * change, access IO ports via ioctl() instead of x86 in/out.
76 * https://review.haiku-os.org/c/haiku/+/1077
78 poke_driver_fd = open(POKE_DEVICE_FULLNAME, O_RDWR);
79 return (poke_driver_fd < 0) ? 0 : 1;
83 intel_cleanup_io(struct pci_access *a UNUSED)
85 close(poke_driver_fd);
91 port_io_args args = { POKE_SIGNATURE, port, sizeof(u8), 0 };
92 if (ioctl(poke_driver_fd, POKE_PORT_READ, &args, sizeof(args)) < 0)
94 return (u8)args.value;
100 port_io_args args = { POKE_SIGNATURE, port, sizeof(u16), 0 };
101 if (ioctl(poke_driver_fd, POKE_PORT_READ, &args, sizeof(args)) < 0)
103 return (u16)args.value;
109 port_io_args args = { POKE_SIGNATURE, port, sizeof(u32), 0 };
110 if (ioctl(poke_driver_fd, POKE_PORT_READ, &args, sizeof(args)) < 0)
112 return (u32)args.value;
116 intel_outb (u8 value, u16 port)
118 port_io_args args = { POKE_SIGNATURE, port, sizeof(u8), value };
119 ioctl(poke_driver_fd, POKE_PORT_WRITE, &args, sizeof(args));
123 intel_outw (u16 value, u16 port)
125 port_io_args args = { POKE_SIGNATURE, port, sizeof(u16), value };
126 ioctl(poke_driver_fd, POKE_PORT_WRITE, &args, sizeof(args));
130 intel_outl (u32 value, u16 port)
132 port_io_args args = { POKE_SIGNATURE, port, sizeof(u32), value };
133 ioctl(poke_driver_fd, POKE_PORT_WRITE, &args, sizeof(args));
136 static inline void intel_io_lock(void)
140 static inline void intel_io_unlock(void)