rumpdev_bus_space.c revision 1.1
1/* $NetBSD: rumpdev_bus_space.c,v 1.1 2014/04/04 12:53:59 pooka Exp $ */ 2 3/*- 4 * Copyright (c) 2013 Antti Kantee. All Rights Reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> 29 30#include <sys/param.h> 31 32#include <dev/pci/pcivar.h> 33 34#include "pci_user.h" 35 36int 37bus_space_map(bus_space_tag_t bst, bus_addr_t address, bus_size_t size, 38 int flags, bus_space_handle_t *handlep) 39{ 40 int rv; 41 42 /* 43 * I/O space we just "let it bli" in case someone wants to 44 * map it (e.g. on Xen) 45 * 46 * Memory space needs to be mapped into our guest, so we 47 * make a hypercall to request it. 48 */ 49 if (bst == 0) { 50 *handlep = address; 51 rv = 0; 52 } else { 53 *handlep = (bus_space_handle_t)rumpcomp_pci_map(address, size); 54 rv = *handlep ? 0 : EINVAL; 55 } 56 57 return rv; 58} 59 60uint8_t 61bus_space_read_1(bus_space_tag_t bst, bus_space_handle_t bsh, 62 bus_size_t offset) 63{ 64 uint8_t rv; 65 66 if (bst == 0) { 67 panic("8bit IO space not supported"); 68 } else { 69 rv = *(volatile uint8_t *)(bsh + offset); 70 } 71 72 return rv; 73} 74 75uint16_t 76bus_space_read_2(bus_space_tag_t bst, bus_space_handle_t bsh, 77 bus_size_t offset) 78{ 79 uint16_t rv; 80 81 if (bst == 0) { 82 panic("16bit IO space not supported"); 83 } else { 84 rv = *(volatile uint16_t *)(bsh + offset); 85 } 86 87 return rv; 88} 89 90uint32_t 91bus_space_read_4(bus_space_tag_t bst, bus_space_handle_t bsh, 92 bus_size_t offset) 93{ 94 uint32_t rv; 95 96 if (bst == 0) { 97#if 1 98 panic("IO space not supported in this build"); 99#else 100 unsigned short addr = bsh + offset; 101 __asm__ __volatile__("inl %1, %0" : "=a"(rv) : "d"(addr)); 102#endif 103 } else { 104 rv = *(volatile uint32_t *)(bsh + offset); 105 } 106 107 return rv; 108} 109 110void 111bus_space_write_1(bus_space_tag_t bst, bus_space_handle_t bsh, 112 bus_size_t offset, uint8_t v) 113{ 114 115 if (bst == 0) { 116#if 1 117 panic("IO space not supported in this build"); 118#endif 119 } else { 120 *(volatile uint8_t *)(bsh + offset) = v; 121 } 122} 123 124void 125bus_space_write_2(bus_space_tag_t bst, bus_space_handle_t bsh, 126 bus_size_t offset, uint16_t v) 127{ 128 129 if (bst == 0) { 130#if 1 131 panic("IO space not supported in this build"); 132#endif 133 } else { 134 *(volatile uint16_t *)(bsh + offset) = v; 135 } 136} 137 138void 139bus_space_write_4(bus_space_tag_t bst, bus_space_handle_t bsh, 140 bus_size_t offset, uint32_t v) 141{ 142 143 if (bst == 0) { 144#if 1 145 panic("IO space not supported in this build"); 146#else 147 unsigned short addr = bsh + offset; 148 __asm__ __volatile__("outl %0, %1" :: "a"(v), "d"(addr)); 149#endif 150 } else { 151 *(volatile uint32_t *)(bsh + offset) = v; 152 } 153} 154 155paddr_t 156bus_space_mmap(bus_space_tag_t bst, bus_addr_t addr, off_t off, 157 int prot, int flags) 158{ 159 160 panic("%s: unimplemented", __func__); 161} 162 163int 164bus_space_subregion(bus_space_tag_t bst, bus_space_handle_t bsh, 165 bus_size_t offset, bus_size_t size, bus_space_handle_t *nhandlep) 166{ 167 168 panic("%s: unimplemented", __func__); 169} 170 171void 172bus_space_unmap(bus_space_tag_t bst, bus_space_handle_t bsh, 173 bus_size_t size) 174{ 175 176 panic("%s: unimplemented", __func__); 177} 178