summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@openbsd.org>2011-12-29 21:14:44 +0100
committerMark Kettenis <kettenis@openbsd.org>2012-01-03 20:02:52 +0100
commitb56f9a84f3dff995a6901ffec6bcc161ec0245ad (patch)
tree498c57dbeaee3f08f40412003eb92461e56859d6
parenta798395a1bfd9d06d40e2d8d14377a156c94429a (diff)
OpenBSD: Implement map_legacy and legacy_io
Signed-off-by: Mark Kettenis <kettenis@openbsd.org> Reviewed-by: Matthieu Herrb <matthieu.herrb@laas.fr> Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com> Tested-by: Matthieu Herrb <matthieu.herrb@laas.fr>
-rw-r--r--src/openbsd_pci.c153
-rw-r--r--src/pciaccess_private.h1
2 files changed, 152 insertions, 2 deletions
diff --git a/src/openbsd_pci.c b/src/openbsd_pci.c
index 219aba7..14e976d 100644
--- a/src/openbsd_pci.c
+++ b/src/openbsd_pci.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2008 Mark Kettenis 2 * Copyright (c) 2008, 2011 Mark Kettenis
3 * 3 *
4 * Permission to use, copy, modify, and distribute this software for any 4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above 5 * purpose with or without fee is hereby granted, provided that the above
@@ -394,6 +394,141 @@ pci_device_openbsd_probe(struct pci_device *device)
394 return 0; 394 return 0;
395} 395}
396 396
397#if defined(__i386__) || defined(__amd64__)
398#include <machine/sysarch.h>
399#include <machine/pio.h>
400#endif
401
402static struct pci_io_handle *
403pci_device_openbsd_open_legacy_io(struct pci_io_handle *ret,
404 struct pci_device *dev, pciaddr_t base, pciaddr_t size)
405{
406#if defined(__i386__)
407 struct i386_iopl_args ia;
408
409 ia.iopl = 1;
410 if (sysarch(I386_IOPL, &ia))
411 return NULL;
412
413 ret->base = base;
414 ret->size = size;
415 return ret;
416#elif defined(__amd64__)
417 struct amd64_iopl_args ia;
418
419 ia.iopl = 1;
420 if (sysarch(AMD64_IOPL, &ia))
421 return NULL;
422
423 ret->base = base;
424 ret->size = size;
425 return ret;
426#elif defined(PCI_MAGIC_IO_RANGE)
427 ret->memory = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
428 aperturefd, PCI_MAGIC_IO_RANGE + base);
429 if (ret->memory == MAP_FAILED)
430 return NULL;
431
432 ret->base = base;
433 ret->size = size;
434 return ret;
435#else
436 return NULL;
437#endif
438}
439
440static uint32_t
441pci_device_openbsd_read32(struct pci_io_handle *handle, uint32_t reg)
442{
443#if defined(__i386__) || defined(__amd64__)
444 return inl(handle->base + reg);
445#else
446 return *(uint32_t *)((uintptr_t)handle->memory + reg);
447#endif
448}
449
450static uint16_t
451pci_device_openbsd_read16(struct pci_io_handle *handle, uint32_t reg)
452{
453#if defined(__i386__) || defined(__amd64__)
454 return inw(handle->base + reg);
455#else
456 return *(uint16_t *)((uintptr_t)handle->memory + reg);
457#endif
458}
459
460static uint8_t
461pci_device_openbsd_read8(struct pci_io_handle *handle, uint32_t reg)
462{
463#if defined(__i386__) || defined(__amd64__)
464 return inb(handle->base + reg);
465#else
466 return *(uint8_t *)((uintptr_t)handle->memory + reg);
467#endif
468}
469
470static void
471pci_device_openbsd_write32(struct pci_io_handle *handle, uint32_t reg,
472 uint32_t data)
473{
474#if defined(__i386__) || defined(__amd64__)
475 outl(handle->base + reg, data);
476#else
477 *(uint16_t *)((uintptr_t)handle->memory + reg) = data;
478#endif
479}
480
481static void
482pci_device_openbsd_write16(struct pci_io_handle *handle, uint32_t reg,
483 uint16_t data)
484{
485#if defined(__i386__) || defined(__amd64__)
486 outw(handle->base + reg, data);
487#else
488 *(uint8_t *)((uintptr_t)handle->memory + reg) = data;
489#endif
490}
491
492static void
493pci_device_openbsd_write8(struct pci_io_handle *handle, uint32_t reg,
494 uint8_t data)
495{
496#if defined(__i386__) || defined(__amd64__)
497 outb(handle->base + reg, data);
498#else
499 *(uint32_t *)((uintptr_t)handle->memory + reg) = data;
500#endif
501}
502
503static int
504pci_device_openbsd_map_legacy(struct pci_device *dev, pciaddr_t base,
505 pciaddr_t size, unsigned map_flags, void **addr)
506{
507 struct pci_device_mapping map;
508 int err;
509
510 map.base = base;
511 map.size = size;
512 map.flags = map_flags;
513 map.memory = NULL;
514 err = pci_device_openbsd_map_range(dev, &map);
515 *addr = map.memory;
516
517 return err;
518}
519
520static int
521pci_device_openbsd_unmap_legacy(struct pci_device *dev, void *addr,
522 pciaddr_t size)
523{
524 struct pci_device_mapping map;
525
526 map.memory = addr;
527 map.size = size;
528 map.flags = 0;
529 return pci_device_openbsd_unmap_range(dev, &map);
530}
531
397static const struct pci_system_methods openbsd_pci_methods = { 532static const struct pci_system_methods openbsd_pci_methods = {
398 pci_system_openbsd_destroy, 533 pci_system_openbsd_destroy,
399 NULL, 534 NULL,
@@ -403,7 +538,21 @@ static const struct pci_system_methods openbsd_pci_methods = {
403 pci_device_openbsd_unmap_range, 538 pci_device_openbsd_unmap_range,
404 pci_device_openbsd_read, 539 pci_device_openbsd_read,
405 pci_device_openbsd_write, 540 pci_device_openbsd_write,
406 pci_fill_capabilities_generic 541 pci_fill_capabilities_generic,
542 NULL,
543 NULL,
544 NULL,
545 NULL,
546 pci_device_openbsd_open_legacy_io,
547 NULL,
548 pci_device_openbsd_read32,
549 pci_device_openbsd_read16,
550 pci_device_openbsd_read8,
551 pci_device_openbsd_write32,
552 pci_device_openbsd_write16,
553 pci_device_openbsd_write8,
554 pci_device_openbsd_map_legacy,
555 pci_device_openbsd_unmap_legacy
407}; 556};
408 557
409int 558int
diff --git a/src/pciaccess_private.h b/src/pciaccess_private.h
index 1653b8b..32f8a75 100644
--- a/src/pciaccess_private.h
+++ b/src/pciaccess_private.h
@@ -94,6 +94,7 @@ struct pci_device_mapping {
94struct pci_io_handle { 94struct pci_io_handle {
95 pciaddr_t base; 95 pciaddr_t base;
96 pciaddr_t size; 96 pciaddr_t size;
97 void *memory;
97 int fd; 98 int fd;
98}; 99};
99 100