ofw_pci.c revision 153057
1139825Simp/*-
286231Stmm * Copyright (c) 1999, 2000 Matthew R. Green
3117119Stmm * Copyright (c) 2001 - 2003 by Thomas Moestl <tmm@FreeBSD.org>
486231Stmm * All rights reserved.
586231Stmm *
686231Stmm * Redistribution and use in source and binary forms, with or without
786231Stmm * modification, are permitted provided that the following conditions
886231Stmm * are met:
986231Stmm * 1. Redistributions of source code must retain the above copyright
1086231Stmm *    notice, this list of conditions and the following disclaimer.
1186231Stmm * 2. Redistributions in binary form must reproduce the above copyright
1286231Stmm *    notice, this list of conditions and the following disclaimer in the
1386231Stmm *    documentation and/or other materials provided with the distribution.
1486231Stmm * 3. The name of the author may not be used to endorse or promote products
1586231Stmm *    derived from this software without specific prior written permission.
1686231Stmm *
1786231Stmm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1886231Stmm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1986231Stmm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2086231Stmm * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2186231Stmm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2286231Stmm * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2386231Stmm * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2486231Stmm * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2586231Stmm * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2686231Stmm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2786231Stmm * SUCH DAMAGE.
2886231Stmm *
2986231Stmm *	from: NetBSD: psycho.c,v 1.35 2001/09/10 16:17:06 eeh Exp
3086231Stmm */
3186231Stmm
32153057Smarius#include <sys/cdefs.h>
33153057Smarius__FBSDID("$FreeBSD: head/sys/sparc64/pci/ofw_pci.c 153057 2005-12-03 18:11:26Z marius $");
34153057Smarius
3586231Stmm#include "opt_ofw_pci.h"
3686231Stmm
3786231Stmm#include <sys/param.h>
3886231Stmm#include <sys/kernel.h>
3986231Stmm#include <sys/systm.h>
4086231Stmm#include <sys/bus.h>
4186231Stmm
4286231Stmm#include <dev/ofw/openfirm.h>
4386231Stmm
44115417Stmm#include <machine/bus.h>
4586231Stmm
46117119Stmm#include <sparc64/pci/ofw_pci.h>
47117119Stmm
48153057Smariusstatic uint8_t pci_bus_cnt;
49129051Smariusstatic phandle_t *pci_bus_map;
50129051Smariusstatic int pci_bus_map_sz;
5186231Stmm
52117119Stmm#define	PCI_BUS_MAP_INC	10
53117119Stmm
54153057Smariusuint8_t
5598148Stmmofw_pci_alloc_busno(phandle_t node)
5698148Stmm{
5798148Stmm	phandle_t *om;
5898148Stmm	int osz;
59153057Smarius	uint8_t n;
6098148Stmm
6198148Stmm	n = pci_bus_cnt++;
6298148Stmm	/* Establish a mapping between bus numbers and device nodes. */
6398148Stmm	if (n >= pci_bus_map_sz) {
6498148Stmm		osz = pci_bus_map_sz;
6598148Stmm		om = pci_bus_map;
6698148Stmm		pci_bus_map_sz = n + PCI_BUS_MAP_INC;
6798148Stmm		pci_bus_map = malloc(sizeof(*pci_bus_map) * pci_bus_map_sz,
68111119Simp		    M_DEVBUF, M_WAITOK | M_ZERO);
6998148Stmm		if (om != NULL) {
7098148Stmm			bcopy(om, pci_bus_map, sizeof(*om) * osz);
7198148Stmm			free(om, M_DEVBUF);
7298148Stmm		}
7398148Stmm	}
7498148Stmm	pci_bus_map[n] = node;
7598148Stmm	return (n);
7698148Stmm}
77