]> mj.ucw.cz Git - pciutils.git/blob - lib/i386-io-haiku.h
libpci: windows: Define ERROR_NOT_FOUND
[pciutils.git] / lib / i386-io-haiku.h
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 void
72 intel_cleanup_io(struct pci_access *a UNUSED)
73 {
74   close(poke_driver_fd);
75 }
76
77 static inline u8
78 inb (u16 port)
79 {
80   port_io_args args = { POKE_SIGNATURE, port, sizeof(u8), 0 };
81   if (ioctl(poke_driver_fd, POKE_PORT_READ, &args, sizeof(args)) < 0)
82     return 0;
83   return (u8)args.value;
84 }
85
86 static inline u16
87 inw (u16 port)
88 {
89   port_io_args args = { POKE_SIGNATURE, port, sizeof(u16), 0 };
90   if (ioctl(poke_driver_fd, POKE_PORT_READ, &args, sizeof(args)) < 0)
91     return 0;
92   return (u16)args.value;
93 }
94
95 static inline u32
96 inl (u16 port)
97 {
98   port_io_args args = { POKE_SIGNATURE, port, sizeof(u32), 0 };
99   if (ioctl(poke_driver_fd, POKE_PORT_READ, &args, sizeof(args)) < 0)
100     return 0;
101   return (u32)args.value;
102 }
103
104 static inline void
105 outb (u8 value, u16 port)
106 {
107   port_io_args args = { POKE_SIGNATURE, port, sizeof(u8), value };
108   ioctl(poke_driver_fd, POKE_PORT_WRITE, &args, sizeof(args));
109 }
110
111 static inline void
112 outw (u16 value, u16 port)
113 {
114   port_io_args args = { POKE_SIGNATURE, port, sizeof(u16), value };
115   ioctl(poke_driver_fd, POKE_PORT_WRITE, &args, sizeof(args));
116 }
117
118 static inline void
119 outl (u32 value, u16 port)
120 {
121   port_io_args args = { POKE_SIGNATURE, port, sizeof(u32), value };
122   ioctl(poke_driver_fd, POKE_PORT_WRITE, &args, sizeof(args));
123 }
124
125 static inline void intel_io_lock(void)
126 {
127 }
128
129 static inline void intel_io_unlock(void)
130 {
131 }