2 * Copyright 2005, Oscar Lesta. All rights reserved.
3 * Distributed under the terms of the MIT License.
8 #include <KernelExport.h>
15 ////////////////////////////////////////////////////////////////////////////////
17 static status_t
poke_open(const char*, uint32
, void**);
18 static status_t
poke_close(void*);
19 static status_t
poke_free(void*);
20 static status_t
poke_control(void*, uint32
, void*, size_t);
21 static status_t
poke_read(void*, off_t
, void*, size_t*);
22 static status_t
poke_write(void*, off_t
, const void*, size_t*);
24 ////////////////////////////////////////////////////////////////////////////////
26 static const char* poke_name
[] = {
27 "misc/"POKE_DEVICE_NAME
,
32 device_hooks poke_hooks
= {
41 int32 api_version
= B_CUR_DRIVER_API_VERSION
;
46 static int32 open_count
;
48 ////////////////////////////////////////////////////////////////////////////////
63 if (get_module(B_ISA_MODULE_NAME
, (module_info
**)&isa
) < B_OK
)
66 if (get_module(B_PCI_MODULE_NAME
, (module_info
**)&pci
) < B_OK
) {
67 put_module(B_ISA_MODULE_NAME
);
78 put_module(B_ISA_MODULE_NAME
);
79 put_module(B_PCI_MODULE_NAME
);
91 find_device(const char* name
)
97 ////////////////////////////////////////////////////////////////////////////////
102 poke_open(const char* name
, uint32 flags
, void** cookie
)
106 if (atomic_add(&open_count
, 1) != 0) {
107 atomic_add(&open_count
, -1);
116 poke_close(void* cookie
)
123 poke_free(void* cookie
)
125 atomic_add(&open_count
, -1);
131 poke_control(void* cookie
, uint32 op
, void* arg
, size_t length
)
137 port_io_args
* ioctl
= (port_io_args
*)arg
;
138 if (ioctl
->signature
!= POKE_SIGNATURE
)
142 switch (ioctl
->size
) {
144 ioctl
->value
= isa
->read_io_8(ioctl
->port
);
147 ioctl
->value
= isa
->read_io_16(ioctl
->port
);
150 ioctl
->value
= isa
->read_io_32(ioctl
->port
);
153 result
= B_BAD_VALUE
;
159 case POKE_PORT_WRITE
:
162 port_io_args
* ioctl
= (port_io_args
*)arg
;
163 if (ioctl
->signature
!= POKE_SIGNATURE
)
167 switch (ioctl
->size
) {
169 isa
->write_io_8(ioctl
->port
, ioctl
->value
);
172 isa
->write_io_16(ioctl
->port
, ioctl
->value
);
175 isa
->write_io_32(ioctl
->port
, ioctl
->value
);
178 result
= B_BAD_VALUE
;
184 case POKE_PORT_INDEXED_READ
:
186 port_io_args
* ioctl
= (port_io_args
*)arg
;
187 if (ioctl
->signature
!= POKE_SIGNATURE
)
190 isa
->write_io_8(ioctl
->port
, ioctl
->size
);
191 ioctl
->value
= isa
->read_io_8(ioctl
->port
+ 1);
195 case POKE_PORT_INDEXED_WRITE
:
197 port_io_args
* ioctl
= (port_io_args
*)arg
;
198 if (ioctl
->signature
!= POKE_SIGNATURE
)
201 isa
->write_io_8(ioctl
->port
, ioctl
->size
);
202 isa
->write_io_8(ioctl
->port
+ 1, ioctl
->value
);
206 case POKE_PCI_READ_CONFIG
:
208 pci_io_args
* ioctl
= (pci_io_args
*)arg
;
209 if (ioctl
->signature
!= POKE_SIGNATURE
)
212 ioctl
->value
= pci
->read_pci_config(ioctl
->bus
, ioctl
->device
,
213 ioctl
->function
, ioctl
->offset
, ioctl
->size
);
217 case POKE_PCI_WRITE_CONFIG
:
219 pci_io_args
* ioctl
= (pci_io_args
*)arg
;
220 if (ioctl
->signature
!= POKE_SIGNATURE
)
223 pci
->write_pci_config(ioctl
->bus
, ioctl
->device
, ioctl
->function
,
224 ioctl
->offset
, ioctl
->size
, ioctl
->value
);
228 case POKE_GET_NTH_PCI_INFO
:
230 pci_info_args
* ioctl
= (pci_info_args
*)arg
;
231 if (ioctl
->signature
!= POKE_SIGNATURE
)
234 ioctl
->status
= pci
->get_nth_pci_info(ioctl
->index
, ioctl
->info
);
238 case POKE_GET_PHYSICAL_ADDRESS
:
240 mem_map_args
* ioctl
= (mem_map_args
*)arg
;
241 physical_entry table
;
244 if (ioctl
->signature
!= POKE_SIGNATURE
)
247 result
= get_memory_map(ioctl
->address
, ioctl
->size
, &table
, 1);
248 ioctl
->physical_address
= (void*)(addr_t
)table
.address
;
249 // TODO: mem_map_args::physical_address should be phys_addr_t!
250 ioctl
->size
= table
.size
;
254 case POKE_MAP_MEMORY
:
256 mem_map_args
* ioctl
= (mem_map_args
*)arg
;
257 if (ioctl
->signature
!= POKE_SIGNATURE
)
260 ioctl
->area
= map_physical_memory(ioctl
->name
,
261 (addr_t
)ioctl
->physical_address
, ioctl
->size
, ioctl
->flags
,
262 ioctl
->protection
, (void**)&ioctl
->address
);
266 case POKE_UNMAP_MEMORY
:
268 mem_map_args
* ioctl
= (mem_map_args
*)arg
;
269 if (ioctl
->signature
!= POKE_SIGNATURE
)
272 return delete_area(ioctl
->area
);
281 poke_read(void* cookie
, off_t position
, void* buffer
, size_t* numBytes
)
284 return B_NOT_ALLOWED
;
289 poke_write(void* cookie
, off_t position
, const void* buffer
, size_t* numBytes
)
292 return B_NOT_ALLOWED
;