ofw_pci.c revision 139825
1137015Sdes/*- 2162852Sdes * Copyright (c) 1999, 2000 Matthew R. Green 3137015Sdes * Copyright (c) 2001 - 2003 by Thomas Moestl <tmm@FreeBSD.org> 4137015Sdes * All rights reserved. 5137015Sdes * 6137015Sdes * Redistribution and use in source and binary forms, with or without 7137015Sdes * modification, are permitted provided that the following conditions 8137015Sdes * are met: 9137015Sdes * 1. Redistributions of source code must retain the above copyright 10137015Sdes * notice, this list of conditions and the following disclaimer. 11137015Sdes * 2. Redistributions in binary form must reproduce the above copyright 12137015Sdes * notice, this list of conditions and the following disclaimer in the 13137015Sdes * documentation and/or other materials provided with the distribution. 14137015Sdes * 3. The name of the author may not be used to endorse or promote products 15137015Sdes * derived from this software without specific prior written permission. 16137015Sdes * 17137015Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18137015Sdes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19137015Sdes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20137015Sdes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21137015Sdes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 22137015Sdes * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23137015Sdes * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 24137015Sdes * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25162852Sdes * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26162852Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27162852Sdes * SUCH DAMAGE. 28137015Sdes * 29137015Sdes * from: NetBSD: psycho.c,v 1.35 2001/09/10 16:17:06 eeh Exp 30137015Sdes * 31162852Sdes * $FreeBSD: head/sys/sparc64/pci/ofw_pci.c 139825 2005-01-07 02:29:27Z imp $ 32162852Sdes */ 33137015Sdes 34137015Sdes#include "opt_ofw_pci.h" 35137015Sdes 36137015Sdes#include <sys/param.h> 37137015Sdes#include <sys/kernel.h> 38137015Sdes#include <sys/systm.h> 39137015Sdes#include <sys/bus.h> 40137015Sdes 41137015Sdes#include <dev/ofw/openfirm.h> 42137015Sdes 43137015Sdes#include <machine/bus.h> 44137015Sdes 45137015Sdes#include <sparc64/pci/ofw_pci.h> 46137015Sdes 47137015Sdesstatic u_int8_t pci_bus_cnt; 48137015Sdesstatic phandle_t *pci_bus_map; 49137015Sdesstatic int pci_bus_map_sz; 50137015Sdes 51137015Sdes#define PCI_BUS_MAP_INC 10 52137015Sdes 53137015Sdesu_int8_t 54162852Sdesofw_pci_alloc_busno(phandle_t node) 55162852Sdes{ 56137015Sdes phandle_t *om; 57137015Sdes int osz; 58137015Sdes u_int8_t n; 59137015Sdes 60137015Sdes n = pci_bus_cnt++; 61162852Sdes /* Establish a mapping between bus numbers and device nodes. */ 62137015Sdes if (n >= pci_bus_map_sz) { 63137015Sdes osz = pci_bus_map_sz; 64137015Sdes om = pci_bus_map; 65162852Sdes pci_bus_map_sz = n + PCI_BUS_MAP_INC; 66162852Sdes pci_bus_map = malloc(sizeof(*pci_bus_map) * pci_bus_map_sz, 67162852Sdes M_DEVBUF, M_WAITOK | M_ZERO); 68162852Sdes if (om != NULL) { 69162852Sdes bcopy(om, pci_bus_map, sizeof(*om) * osz); 70162852Sdes free(om, M_DEVBUF); 71137015Sdes } 72137015Sdes } 73137015Sdes pci_bus_map[n] = node; 74137015Sdes return (n); 75137015Sdes} 76137015Sdes