ofw_pci.c revision 139825
1132720Skan/*- 2132720Skan * Copyright (c) 1999, 2000 Matthew R. Green 3169691Skan * Copyright (c) 2001 - 2003 by Thomas Moestl <tmm@FreeBSD.org> 4169691Skan * All rights reserved. 5132720Skan * 6132720Skan * Redistribution and use in source and binary forms, with or without 7132720Skan * modification, are permitted provided that the following conditions 8132720Skan * are met: 9132720Skan * 1. Redistributions of source code must retain the above copyright 10132720Skan * notice, this list of conditions and the following disclaimer. 11132720Skan * 2. Redistributions in binary form must reproduce the above copyright 12132720Skan * notice, this list of conditions and the following disclaimer in the 13132720Skan * documentation and/or other materials provided with the distribution. 14132720Skan * 3. The name of the author may not be used to endorse or promote products 15132720Skan * derived from this software without specific prior written permission. 16132720Skan * 17132720Skan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18132720Skan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19169691Skan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20132720Skan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21132720Skan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 22132720Skan * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23132720Skan * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 24132720Skan * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25132720Skan * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26132720Skan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27132720Skan * SUCH DAMAGE. 28132720Skan * 29132720Skan * from: NetBSD: psycho.c,v 1.35 2001/09/10 16:17:06 eeh Exp 30132720Skan * 31132720Skan * $FreeBSD: head/sys/sparc64/pci/ofw_pci.c 139825 2005-01-07 02:29:27Z imp $ 32132720Skan */ 33132720Skan 34132720Skan#include "opt_ofw_pci.h" 35132720Skan 36132720Skan#include <sys/param.h> 37132720Skan#include <sys/kernel.h> 38132720Skan#include <sys/systm.h> 39132720Skan#include <sys/bus.h> 40132720Skan 41132720Skan#include <dev/ofw/openfirm.h> 42132720Skan 43132720Skan#include <machine/bus.h> 44132720Skan 45132720Skan#include <sparc64/pci/ofw_pci.h> 46132720Skan 47132720Skanstatic u_int8_t pci_bus_cnt; 48132720Skanstatic phandle_t *pci_bus_map; 49132720Skanstatic int pci_bus_map_sz; 50132720Skan 51132720Skan#define PCI_BUS_MAP_INC 10 52132720Skan 53132720Skanu_int8_t 54132720Skanofw_pci_alloc_busno(phandle_t node) 55169691Skan{ 56169691Skan phandle_t *om; 57169691Skan int osz; 58169691Skan u_int8_t n; 59132720Skan 60132720Skan n = pci_bus_cnt++; 61132720Skan /* Establish a mapping between bus numbers and device nodes. */ 62169691Skan if (n >= pci_bus_map_sz) { 63132720Skan osz = pci_bus_map_sz; 64132720Skan om = pci_bus_map; 65132720Skan pci_bus_map_sz = n + PCI_BUS_MAP_INC; 66132720Skan pci_bus_map = malloc(sizeof(*pci_bus_map) * pci_bus_map_sz, 67132720Skan M_DEVBUF, M_WAITOK | M_ZERO); 68132720Skan if (om != NULL) { 69132720Skan bcopy(om, pci_bus_map, sizeof(*om) * osz); 70132720Skan free(om, M_DEVBUF); 71132720Skan } 72132720Skan } 73132720Skan pci_bus_map[n] = node; 74132720Skan return (n); 75132720Skan} 76132720Skan