[BACK]Return to cpc700.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / dev / ic

File: [cvs.NetBSD.org] / src / sys / dev / ic / cpc700.c (download)

Revision 1.19, Fri Jan 27 18:53:07 2012 UTC (12 years, 2 months ago) by para
Branch: MAIN
CVS Tags: yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, tls-maxphys-base-20171202, tls-maxphys-base, tls-maxphys, tls-earlyentropy-base, tls-earlyentropy, rmind-smpnet-nbase, rmind-smpnet-base, rmind-smpnet, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, phil-wifi-base, phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, phil-wifi-20191119, phil-wifi-20190609, phil-wifi, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, perseant-stdc-iso10646-base, perseant-stdc-iso10646, nick-nhusb-base-20170825, nick-nhusb-base-20170204, nick-nhusb-base-20161204, nick-nhusb-base-20161004, nick-nhusb-base-20160907, nick-nhusb-base-20160529, nick-nhusb-base-20160422, nick-nhusb-base-20160319, nick-nhusb-base-20151226, nick-nhusb-base-20150921, nick-nhusb-base-20150606, nick-nhusb-base-20150406, nick-nhusb-base, nick-nhusb, netbsd-9-base, netbsd-9-3-RELEASE, netbsd-9-2-RELEASE, netbsd-9-1-RELEASE, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-9, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, matt-nb8-mediatek-base, matt-nb8-mediatek, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, localcount-20160914, khorben-n900, jmcneill-usbmp-base9, jmcneill-usbmp-base8, jmcneill-usbmp-base7, jmcneill-usbmp-base6, jmcneill-usbmp-base5, jmcneill-usbmp-base4, jmcneill-usbmp-base3, jmcneill-usbmp-base2, jmcneill-usbmp-base10, jdolecek-ncqfixes-base, jdolecek-ncqfixes, jdolecek-ncq-base, jdolecek-ncq, isaki-audio2-base, isaki-audio2, is-mlppp-base, is-mlppp, bouyer-xenpvh-base2, bouyer-xenpvh-base1, bouyer-xenpvh-base, bouyer-xenpvh, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, agc-symver-base, agc-symver, ad-namecache-base3, ad-namecache-base2, ad-namecache-base1, ad-namecache-base, ad-namecache
Changes since 1.18: +4 -4 lines

converting extent(9) from malloc(9) to kmem(9)
preceding kmem-vmem-pool-uvm patch

releng@ acknowledged

/*	$NetBSD: cpc700.c,v 1.19 2012/01/27 18:53:07 para Exp $	*/

/*
 * Copyright (c) 2002 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Lennart Augustsson (lennart@augustsson.net) at Sandburst Corp.
 *
 * 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.
 */

/*
 * The IBM CPC700 is a bridge chip for the PowerPC.  It contains
 *  - CPU interface
 *  - DRAM controller
 *  - PCI bus master & slave controller
 *  - interrupt controller
 *  - timer
 *  - two UARTs
 *  - two IIC ports
 *
 *  This driver handles the overall device and enumeration of the
 *  supported subdevices.  NetBSD knows how to handle:
 *  - PCI master
 *  - interrupt controller
 *  - UARTs
 *  Skeleton drivers are provided for the timer and IIC.
 *
 * XXX This driver assumes that there is only one instance of it.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cpc700.c,v 1.19 2012/01/27 18:53:07 para Exp $");

#include "pci.h"
#include "opt_pci.h"

#include <sys/param.h>
#include <sys/extent.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/systm.h>

#include <sys/bus.h>
#include "locators.h"

#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pciconf.h>

#include <dev/ic/cpc700reg.h>
#include <dev/ic/cpc700var.h>
#include <dev/ic/cpc700uic.h>

union attach_args {
	struct pcibus_attach_args pba;
	struct cpcbus_attach_args cba;
};


void
cpc_attach(device_t self, pci_chipset_tag_t pc, bus_space_tag_t mem,
	   bus_space_tag_t pciio, bus_dma_tag_t tag, int attachpci,
	   uint freq);

static bus_space_tag_t the_cpc_tag;
static bus_space_handle_t the_cpc_handle;
#define INL(a) bus_space_read_stream_4(the_cpc_tag, the_cpc_handle, (a))
#define OUTL(a, d) bus_space_write_stream_4(the_cpc_tag, the_cpc_handle, (a), d)

static int
cpc_print(void *aux, const char *pnp)
{
	struct cpcbus_attach_args *caa = aux;

	if (pnp)
		aprint_normal("%s at %s", caa->cpca_name, pnp);

	aprint_normal(" addr 0x%08x", caa->cpca_addr);
	if (caa->cpca_irq != CPCBUSCF_IRQ_DEFAULT)
		aprint_normal(" irq %d", caa->cpca_irq);

	return (UNCONF);
}

static int
cpc_submatch(device_t parent, cfdata_t cf,
	     const int *ldesc, void *aux)
{
	struct cpcbus_attach_args *caa = aux;

	if (cf->cf_loc[CPCBUSCF_ADDR] != caa->cpca_addr)
		return (0);

	return (config_match(parent, cf, aux));
}

/*
 * Attach the cpc.
 */
void
cpc_attach(device_t self, pci_chipset_tag_t pc, bus_space_tag_t mem,
	   bus_space_tag_t pciio, bus_dma_tag_t dma, int attachpci,
	   uint freq)
{
	union attach_args aa;
	int i;
	pcitag_t tag;
	pcireg_t erren;
	pcireg_t v;
	static struct {
		const char *name;
		bus_addr_t addr;
		int irq;
	} devs[] = {
		{ "com",    CPC_COM0, CPC_IB_UART_0 },
		{ "com",    CPC_COM1, CPC_IB_UART_1 },
		{ "cpctim", CPC_TIMER, CPCBUSCF_IRQ_DEFAULT },
		{ "cpciic", CPC_IIC0, CPC_IB_IIC_0 },
		{ "cpciic", CPC_IIC1, CPC_IB_IIC_1 },
		{ NULL, 0 }
	};
#if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
	struct extent *ioext, *memext;
#ifdef PCI_CONFIGURE_VERBOSE
	extern int pci_conf_debug;

	pci_conf_debug = 1;
#endif
#endif

	printf(": IBM CPC700\n");

	the_cpc_tag = mem;
	if (bus_space_map(mem, CPC_UIC_BASE, CPC_UIC_SIZE, 0,
			  &the_cpc_handle)) {
		aprint_error_dev(self, "can't map i/o space\n");
		return;
	}

	aa.cba.cpca_tag = mem;
	aa.cba.cpca_freq = freq;
	for (i = 0; devs[i].name; i++) {
		aa.cba.cpca_name = devs[i].name;
		aa.cba.cpca_addr = devs[i].addr;
		aa.cba.cpca_irq = devs[i].irq;
		config_found_sm_loc(self, "cpcbus", NULL, &aa.cba,
				    cpc_print, cpc_submatch);
	}

	tag = pci_make_tag(pc, 0, 0, 0);

	aa.pba.pba_iot = pciio;
	aa.pba.pba_memt = mem;
	aa.pba.pba_dmat = dma;
	aa.pba.pba_pc = pc;
	aa.pba.pba_flags = PCI_FLAGS_MEM_OKAY | PCI_FLAGS_IO_OKAY;
	aa.pba.pba_bus = 0;

	/* Save PCI error condition reg. */
	erren = pci_conf_read(pc, tag, CPC_PCI_BRDGERR);
	/* Don't generate errors during probe. */
	pci_conf_write(pc, tag, CPC_PCI_BRDGERR, 0);

	/* Program MITL */
	v = pci_conf_read(pc, tag, CPC_BRIDGE_OPTIONS2);
	v &= ~(CPC_BRIDGE_O2_ILAT_MASK | CPC_BRIDGE_O2_SLAT_MASK);
	v |= (CPC_BRIDGE_O2_ILAT_PRIM_ASYNC << CPC_BRIDGE_O2_ILAT_SHIFT) |
	  (CPC_BRIDGE_O2_2LAT_PRIM_ASYNC << CPC_BRIDGE_O2_SLAT_SHIFT);
	pci_conf_write(pc, tag, CPC_BRIDGE_OPTIONS2, v);

#if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
	ioext  = extent_create("pciio",  CPC_PCI_IO_START, CPC_PCI_IO_END,
	    NULL, 0, EX_NOWAIT);
	memext = extent_create("pcimem", CPC_PCI_MEM_BASE, CPC_PCI_MEM_END,
	    NULL, 0, EX_NOWAIT);

	pci_configure_bus(0, ioext, memext, NULL, 0, 32);

	extent_destroy(ioext);
	extent_destroy(memext);
#endif

	config_found_ia(self, "pcibus", &aa.pba, pcibusprint);

	/* Restore error triggers, and clear errors */
	pci_conf_write(pc, tag, CPC_PCI_BRDGERR, erren | CPC_PCI_CLEARERR);
}

/***************************************************************************/

/*
 * Interrupt controller.
 */

void
cpc700_init_intr(bus_space_tag_t bt, bus_space_handle_t bh,
		 u_int32_t active, u_int32_t level)
{
	/* XXX */
	the_cpc_tag = bt;
	the_cpc_handle = bh;
	/*
	 * See CPC700 manual for information about what
	 * interrupts have which properties.
	 */
	OUTL(CPC_UIC_SR, 0xffffffff);    /* clear all intrs */
	OUTL(CPC_UIC_ER, 0x00000000);    /* disable all intrs */
	OUTL(CPC_UIC_CR, 0xffffffff);    /* gen INT not MCP */
	OUTL(CPC_UIC_PR, 0xffff8000 | active);    /* 0 = active low */
	OUTL(CPC_UIC_TR, 0xc0000000 | level);    /* 0 = level intr */
	OUTL(CPC_UIC_VR, CPC_UIC_CVR_PRI); /* intr 0 is highest */
}

int
cpc700_read_irq(void)
{
	int irq;
	u_int32_t irqs;

	irqs = INL(CPC_UIC_MSR);
	for (irq = 0; irq < ICU_LEN; irq++) {
		if (irqs & CPC_INTR_MASK(irq))
			return (irq);
	}
	return (-1);
}

void
cpc700_eoi(int irq)
{
	OUTL(CPC_UIC_SR, CPC_INTR_MASK(irq));
}

void
cpc700_disable_irq(int irq)
{
	u_int32_t reg;

	reg = INL(CPC_UIC_ER);
	reg &= ~CPC_INTR_MASK(irq);
	OUTL(CPC_UIC_ER, reg);
}

void
cpc700_enable_irq(int irq)
{
	u_int32_t reg;

	reg = INL(CPC_UIC_ER);
	reg |= CPC_INTR_MASK(irq);
	OUTL(CPC_UIC_ER, reg);
}