2009-03-15 00:04:01 +03:00
|
|
|
/* $NetBSD: ixp12x0_pci.c,v 1.10 2009/03/14 21:04:05 dsl Exp $ */
|
2002-07-15 20:27:15 +04:00
|
|
|
/*
|
2003-02-17 23:51:52 +03:00
|
|
|
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
|
2002-07-15 20:27:15 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Ichiro FUKUHARA and Naoto Shimazaki.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-03-25 09:12:46 +03:00
|
|
|
#include <sys/cdefs.h>
|
2009-03-15 00:04:01 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ixp12x0_pci.c,v 1.10 2009/03/14 21:04:05 dsl Exp $");
|
2003-03-25 09:12:46 +03:00
|
|
|
|
2002-07-15 20:27:15 +04:00
|
|
|
/*
|
|
|
|
* PCI configuration support for IXP12x0 Network Processor chip.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/extent.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
|
|
|
#include <arm/ixp12x0/ixp12x0reg.h>
|
|
|
|
#include <arm/ixp12x0/ixp12x0var.h>
|
|
|
|
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
2002-10-09 04:11:15 +04:00
|
|
|
#include <dev/pci/pciconf.h>
|
2002-07-15 20:27:15 +04:00
|
|
|
|
|
|
|
#include "opt_pci.h"
|
|
|
|
#include "pci.h"
|
|
|
|
|
|
|
|
void ixp12x0_pci_attach_hook(struct device *, struct device *,
|
|
|
|
struct pcibus_attach_args *);
|
|
|
|
int ixp12x0_pci_bus_maxdevs(void *, int);
|
|
|
|
pcitag_t ixp12x0_pci_make_tag(void *, int, int, int);
|
|
|
|
void ixp12x0_pci_decompose_tag(void *, pcitag_t, int *, int *, int *);
|
|
|
|
pcireg_t ixp12x0_pci_conf_read(void *, pcitag_t, int);
|
|
|
|
void ixp12x0_pci_conf_write(void *, pcitag_t, int, pcireg_t);
|
|
|
|
|
2003-02-17 23:51:52 +03:00
|
|
|
static vaddr_t ixp12x0_pci_conf_setup(void *, struct ixp12x0_softc *, pcitag_t, int);
|
|
|
|
|
|
|
|
#define PCI_CONF_LOCK(s) (s) = disable_interrupts(I32_bit)
|
|
|
|
#define PCI_CONF_UNLOCK(s) restore_interrupts((s))
|
|
|
|
|
2002-12-08 16:21:44 +03:00
|
|
|
#define MAX_PCI_DEVICES 4
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IXM1200 PCI configuration Cycles
|
|
|
|
* Device Address
|
|
|
|
* -------------------------------------
|
|
|
|
* 0 IXP1200 0x0800 - 0x08FF
|
|
|
|
* 1 i21555 0x1000 - 0x10FF
|
|
|
|
* 2 i82559 0x2000 - 0x20FF
|
|
|
|
* 3 PMC expansion 0x4000 - 0x40FF
|
|
|
|
*/
|
2002-07-15 20:27:15 +04:00
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
ixp12x0_pci_init(pci_chipset_tag_t pc, void *cookie)
|
2002-07-15 20:27:15 +04:00
|
|
|
{
|
2003-02-17 23:51:52 +03:00
|
|
|
#if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
|
|
|
|
struct ixp12x0_softc *sc = cookie;
|
|
|
|
struct extent *ioext, *memext;
|
|
|
|
#endif
|
2002-07-15 20:27:15 +04:00
|
|
|
pc->pc_conf_v = cookie;
|
|
|
|
pc->pc_attach_hook = ixp12x0_pci_attach_hook;
|
|
|
|
pc->pc_bus_maxdevs = ixp12x0_pci_bus_maxdevs;
|
|
|
|
pc->pc_make_tag = ixp12x0_pci_make_tag;
|
|
|
|
pc->pc_decompose_tag = ixp12x0_pci_decompose_tag;
|
|
|
|
pc->pc_conf_read = ixp12x0_pci_conf_read;
|
|
|
|
pc->pc_conf_write = ixp12x0_pci_conf_write;
|
2003-02-17 23:51:52 +03:00
|
|
|
|
|
|
|
#if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
|
|
|
|
ioext = extent_create("pciio", 0, IXP12X0_PCI_IO_SIZE - 1,
|
|
|
|
M_DEVBUF, NULL, 0, EX_NOWAIT);
|
|
|
|
/* PCI MEM space is mapped same address as real memory */
|
|
|
|
memext = extent_create("pcimem", IXP12X0_PCI_MEM_HWBASE,
|
|
|
|
IXP12X0_PCI_MEM_HWBASE +
|
|
|
|
IXP12X0_PCI_MEM_SIZE - 1,
|
|
|
|
M_DEVBUF, NULL, 0, EX_NOWAIT);
|
|
|
|
printf("%s: configuring PCI bus\n", sc->sc_dev.dv_xname);
|
|
|
|
pci_configure_bus(pc, ioext, memext, NULL, 0 /* XXX bus = 0 */,
|
|
|
|
arm_dcache_align);
|
|
|
|
|
|
|
|
extent_destroy(ioext);
|
|
|
|
extent_destroy(memext);
|
|
|
|
#endif
|
2002-07-15 20:27:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-15 00:04:01 +03:00
|
|
|
pci_conf_interrupt(pci_chipset_tag_t pc, int a, int b, int c, int d, int *p)
|
2002-07-15 20:27:15 +04:00
|
|
|
{
|
|
|
|
/* Nothing */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
ixp12x0_pci_attach_hook(struct device *parent, struct device *self, struct pcibus_attach_args *pba)
|
2002-07-15 20:27:15 +04:00
|
|
|
{
|
|
|
|
/* Nothing to do. */
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
ixp12x0_pci_bus_maxdevs(void *v, int busno)
|
2002-07-15 20:27:15 +04:00
|
|
|
{
|
|
|
|
return(MAX_PCI_DEVICES);
|
|
|
|
}
|
|
|
|
|
|
|
|
pcitag_t
|
2009-03-15 00:04:01 +03:00
|
|
|
ixp12x0_pci_make_tag(void *v, int bus, int device, int function)
|
2002-07-15 20:27:15 +04:00
|
|
|
{
|
|
|
|
#ifdef PCI_DEBUG
|
|
|
|
printf("ixp12x0_pci_make_tag(v=%p, bus=%d, device=%d, function=%d)\n",
|
|
|
|
v, bus, device, function);
|
|
|
|
#endif
|
|
|
|
return ((bus << 16) | (device << 11) | (function << 8));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-15 00:04:01 +03:00
|
|
|
ixp12x0_pci_decompose_tag(void *v, pcitag_t tag, int *busp, int *devicep, int *functionp)
|
2002-07-15 20:27:15 +04:00
|
|
|
{
|
|
|
|
#ifdef PCI_DEBUG
|
|
|
|
printf("ixp12x0_pci_decompose_tag(v=%p, tag=0x%08lx, bp=%x, dp=%x, fp=%x)\n",
|
|
|
|
v, tag, (int)busp, (int)devicep, (int)functionp);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (busp != NULL)
|
|
|
|
*busp = (tag >> 16) & 0xff;
|
|
|
|
if (devicep != NULL)
|
|
|
|
*devicep = (tag >> 11) & 0x1f;
|
|
|
|
if (functionp != NULL)
|
|
|
|
*functionp = (tag >> 8) & 0x7;
|
|
|
|
}
|
|
|
|
|
2003-02-17 23:51:52 +03:00
|
|
|
static vaddr_t
|
2009-03-14 18:35:58 +03:00
|
|
|
ixp12x0_pci_conf_setup(void *v, struct ixp12x0_softc *sc, pcitag_t tag, int offset)
|
2002-07-15 20:27:15 +04:00
|
|
|
{
|
|
|
|
int bus, device, function;
|
2003-02-17 23:51:52 +03:00
|
|
|
vaddr_t addr;
|
2002-07-15 20:27:15 +04:00
|
|
|
|
|
|
|
ixp12x0_pci_decompose_tag(v, tag, &bus, &device, &function);
|
|
|
|
|
2003-02-17 23:51:52 +03:00
|
|
|
if (bus == 0) {
|
|
|
|
/* configuration type 0 */
|
|
|
|
addr = (vaddr_t) bus_space_vaddr(sc->sc_iot, sc->sc_conf0_ioh) +
|
2003-09-15 09:07:29 +04:00
|
|
|
((1 << (device + 10)) | (offset & ~3));
|
2003-02-17 23:51:52 +03:00
|
|
|
} else {
|
2003-09-15 09:07:29 +04:00
|
|
|
/* configuration type 1 */
|
|
|
|
addr = (vaddr_t) bus_space_vaddr(sc->sc_iot, sc->sc_conf1_ioh) +
|
|
|
|
((bus << 16) | (device << 11) |
|
|
|
|
(function << 8) | (offset & ~3) | 1);
|
2003-02-17 23:51:52 +03:00
|
|
|
}
|
2003-09-15 09:07:29 +04:00
|
|
|
return addr;
|
2003-02-17 23:51:52 +03:00
|
|
|
}
|
2002-07-15 20:27:15 +04:00
|
|
|
|
2003-02-17 23:51:52 +03:00
|
|
|
pcireg_t
|
2009-03-14 18:35:58 +03:00
|
|
|
ixp12x0_pci_conf_read(void *v, pcitag_t tag, int offset)
|
2003-02-17 23:51:52 +03:00
|
|
|
{
|
|
|
|
struct ixp12x0_softc *sc = v;
|
|
|
|
vaddr_t va = ixp12x0_pci_conf_setup(v, sc, tag, offset);
|
|
|
|
pcireg_t rv;
|
|
|
|
int s;
|
2002-07-15 20:27:15 +04:00
|
|
|
|
|
|
|
#ifdef PCI_DEBUG
|
2003-02-17 23:51:52 +03:00
|
|
|
printf("ixp12x0_pci_conf_read: base=%lx,va=%lx,tag=%lx,offset=%x\n",
|
|
|
|
sc->sc_conf0_ioh, va, tag, offset);
|
2002-12-08 16:21:44 +03:00
|
|
|
#endif
|
2003-02-17 23:51:52 +03:00
|
|
|
if (va == 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
PCI_CONF_LOCK(s);
|
|
|
|
|
|
|
|
if (badaddr_read((void *) va, sizeof(rv), &rv)) {
|
|
|
|
#ifdef PCI_DEBUG
|
|
|
|
printf("conf_read: %lx bad address\n", va);
|
2002-07-15 20:27:15 +04:00
|
|
|
#endif
|
2003-02-17 23:51:52 +03:00
|
|
|
rv = (pcireg_t) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
PCI_CONF_UNLOCK(s);
|
|
|
|
|
|
|
|
return rv;
|
2002-07-15 20:27:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
ixp12x0_pci_conf_write(void *v, pcitag_t tag, int offset, pcireg_t val)
|
2002-07-15 20:27:15 +04:00
|
|
|
{
|
2003-02-17 23:51:52 +03:00
|
|
|
struct ixp12x0_softc *sc = v;
|
|
|
|
vaddr_t va = ixp12x0_pci_conf_setup(v, sc, tag, offset);
|
|
|
|
int s;
|
2002-07-15 20:27:15 +04:00
|
|
|
|
2003-02-17 23:51:52 +03:00
|
|
|
#ifdef PCI_DEBUG
|
|
|
|
printf("ixp12x0_pci_conf_write: tag=%lx offset=%x -> va=%lx (base=%lx)\n",
|
|
|
|
tag, offset, va, sc->sc_conf0_ioh);
|
|
|
|
#endif
|
2002-07-15 20:27:15 +04:00
|
|
|
|
2003-02-17 23:51:52 +03:00
|
|
|
PCI_CONF_LOCK(s);
|
2002-12-08 16:21:44 +03:00
|
|
|
|
2003-02-17 23:51:52 +03:00
|
|
|
*(pcireg_t *) va = val;
|
2002-07-15 20:27:15 +04:00
|
|
|
|
2003-02-17 23:51:52 +03:00
|
|
|
PCI_CONF_UNLOCK(s);
|
2002-07-15 20:27:15 +04:00
|
|
|
}
|