rumpdev_pci.c revision 1.1
11.1Spooka/* $NetBSD: rumpdev_pci.c,v 1.1 2014/04/04 12:53:59 pooka Exp $ */ 21.1Spooka 31.1Spooka/* 41.1Spooka * Copyright (c) 2013 Antti Kantee. All Rights Reserved. 51.1Spooka * 61.1Spooka * Redistribution and use in source and binary forms, with or without 71.1Spooka * modification, are permitted provided that the following conditions 81.1Spooka * are met: 91.1Spooka * 1. Redistributions of source code must retain the above copyright 101.1Spooka * notice, this list of conditions and the following disclaimer. 111.1Spooka * 2. Redistributions in binary form must reproduce the above copyright 121.1Spooka * notice, this list of conditions and the following disclaimer in the 131.1Spooka * documentation and/or other materials provided with the distribution. 141.1Spooka * 151.1Spooka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 161.1Spooka * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 171.1Spooka * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 181.1Spooka * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 191.1Spooka * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 201.1Spooka * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 211.1Spooka * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 221.1Spooka * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 231.1Spooka * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 241.1Spooka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 251.1Spooka * SUCH DAMAGE. 261.1Spooka */ 271.1Spooka 281.1Spooka#include <sys/cdefs.h> 291.1Spooka__KERNEL_RCSID(0, "$NetBSD: rumpdev_pci.c,v 1.1 2014/04/04 12:53:59 pooka Exp $"); 301.1Spooka 311.1Spooka#include <sys/cdefs.h> 321.1Spooka#include <sys/param.h> 331.1Spooka 341.1Spooka#include <dev/pci/pcivar.h> 351.1Spooka 361.1Spooka#include "pci_user.h" 371.1Spooka 381.1Spookavoid 391.1Spookapci_attach_hook(device_t parent, device_t self, struct pcibus_attach_args *pba) 401.1Spooka{ 411.1Spooka 421.1Spooka /* nada */ 431.1Spooka} 441.1Spooka 451.1Spookaint 461.1Spookapci_bus_maxdevs(pci_chipset_tag_t pc, int busno) 471.1Spooka{ 481.1Spooka 491.1Spooka return 32; 501.1Spooka} 511.1Spooka 521.1Spookapcitag_t 531.1Spookapci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function) 541.1Spooka{ 551.1Spooka pcitag_t pt; 561.1Spooka int *tag; 571.1Spooka unsigned csr; 581.1Spooka int rv; 591.1Spooka 601.1Spooka CTASSERT(sizeof(pt) >= sizeof(int)); 611.1Spooka 621.1Spooka /* a "bit" ugly, but keeps us MI */ 631.1Spooka tag = (int *)&pt; 641.1Spooka *tag = (bus << 16) | (device << 8) | (function << 0); 651.1Spooka 661.1Spooka /* 671.1Spooka * On Xen, we need to enable the device io/mem space. 681.1Spooka * Doesn't really belong here, but we need to do it somewhere. 691.1Spooka */ 701.1Spooka rv = rumpcomp_pci_confread(bus, device, function, 711.1Spooka PCI_COMMAND_STATUS_REG, &csr); 721.1Spooka if (rv == 0 && (csr & PCI_COMMAND_MEM_ENABLE) == 0) { 731.1Spooka rumpcomp_pci_confwrite(bus, device, function, 741.1Spooka PCI_COMMAND_STATUS_REG, csr | PCI_COMMAND_MEM_ENABLE); 751.1Spooka } 761.1Spooka 771.1Spooka return pt; 781.1Spooka} 791.1Spooka 801.1Spookapcireg_t 811.1Spookapci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg) 821.1Spooka{ 831.1Spooka unsigned int rv; 841.1Spooka int bus, device, fun; 851.1Spooka 861.1Spooka pci_decompose_tag(pc, tag, &bus, &device, &fun); 871.1Spooka rumpcomp_pci_confread(bus, device, fun, reg, &rv); 881.1Spooka return rv; 891.1Spooka} 901.1Spooka 911.1Spookavoid 921.1Spookapci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data) 931.1Spooka{ 941.1Spooka int bus, device, fun; 951.1Spooka 961.1Spooka pci_decompose_tag(pc, tag, &bus, &device, &fun); 971.1Spooka rumpcomp_pci_confwrite(bus, device, fun, reg, data); 981.1Spooka} 991.1Spooka 1001.1Spookavoid 1011.1Spookapci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, 1021.1Spooka int *bp, int *dp, int *fp) 1031.1Spooka{ 1041.1Spooka int *t = (int *)&tag; 1051.1Spooka 1061.1Spooka *bp = (*t >> 16) & 0xff; 1071.1Spooka *dp = (*t >> 8) & 0xff; 1081.1Spooka *fp = (*t >> 0) & 0xff; 1091.1Spooka} 1101.1Spooka 1111.1Spookaint 1121.1Spookapci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ih) 1131.1Spooka{ 1141.1Spooka 1151.1Spooka *ih = pa->pa_intrline; 1161.1Spooka return 0; 1171.1Spooka} 1181.1Spooka 1191.1Spookaconst char * 1201.1Spookapci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih) 1211.1Spooka{ 1221.1Spooka 1231.1Spooka return "pausebreak"; 1241.1Spooka} 1251.1Spooka 1261.1Spookavoid * 1271.1Spookapci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, 1281.1Spooka int level, int (*func)(void *), void *arg) 1291.1Spooka{ 1301.1Spooka 1311.1Spooka return rumpcomp_pci_irq_establish(ih, func, arg); 1321.1Spooka} 1331.1Spooka 1341.1Spookavoid 1351.1Spookapci_intr_disestablish(pci_chipset_tag_t pc, void *ih) 1361.1Spooka{ 1371.1Spooka 1381.1Spooka panic("%s: unimplemented", __func__); 1391.1Spooka} 140