autoconf.c revision 1.1
11.1Smacallan/*	$NetBSD: autoconf.c,v 1.1 2019/02/14 21:47:52 macallan Exp $	*/
21.1Smacallan
31.1Smacallan/*-
41.1Smacallan * Copyright (c) 2001 The NetBSD Foundation, Inc.
51.1Smacallan * All rights reserved.
61.1Smacallan *
71.1Smacallan * This code is derived from software contributed to The NetBSD Foundation
81.1Smacallan * by Matt Thomas <matt@3am-software.com>.
91.1Smacallan *
101.1Smacallan * Redistribution and use in source and binary forms, with or without
111.1Smacallan * modification, are permitted provided that the following conditions
121.1Smacallan * are met:
131.1Smacallan * 1. Redistributions of source code must retain the above copyright
141.1Smacallan *    notice, this list of conditions and the following disclaimer.
151.1Smacallan * 2. Redistributions in binary form must reproduce the above copyright
161.1Smacallan *    notice, this list of conditions and the following disclaimer in the
171.1Smacallan *    documentation and/or other materials provided with the distribution.
181.1Smacallan *
191.1Smacallan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.1Smacallan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Smacallan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Smacallan * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.1Smacallan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Smacallan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Smacallan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Smacallan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Smacallan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Smacallan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Smacallan * POSSIBILITY OF SUCH DAMAGE.
301.1Smacallan */
311.1Smacallan
321.1Smacallan#include <sys/cdefs.h>
331.1Smacallan__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.1 2019/02/14 21:47:52 macallan Exp $");
341.1Smacallan
351.1Smacallan#include "opt_md.h"
361.1Smacallan
371.1Smacallan#include <sys/param.h>
381.1Smacallan#include <sys/systm.h>
391.1Smacallan#include <sys/reboot.h>
401.1Smacallan#include <sys/disklabel.h>
411.1Smacallan#include <sys/device.h>
421.1Smacallan#include <sys/conf.h>
431.1Smacallan#include <sys/kernel.h>
441.1Smacallan#include <sys/malloc.h>
451.1Smacallan
461.1Smacallan#include <net/if.h>
471.1Smacallan#include <net/if_ether.h>
481.1Smacallan
491.1Smacallan#include <machine/autoconf.h>
501.1Smacallan#include <machine/intr.h>
511.1Smacallan
521.1Smacallan#include <evbarm/iyonix/iyonixvar.h>
531.1Smacallan
541.1Smacallan#include <acorn32/include/bootconfig.h>
551.1Smacallan
561.1Smacallanextern struct bootconfig bootconfig;
571.1Smacallan
581.1Smacallan/*
591.1Smacallan * Set up the root device from the boot args
601.1Smacallan */
611.1Smacallanvoid
621.1Smacallancpu_rootconf(void)
631.1Smacallan{
641.1Smacallan	aprint_normal("boot device: %s\n",
651.1Smacallan	    booted_device != NULL ? device_xname(booted_device) : "<unknown>");
661.1Smacallan	rootconf();
671.1Smacallan}
681.1Smacallan
691.1Smacallan
701.1Smacallan/*
711.1Smacallan * void cpu_configure()
721.1Smacallan *
731.1Smacallan * Configure all the root devices
741.1Smacallan * The root devices are expected to configure their own children
751.1Smacallan */
761.1Smacallanvoid
771.1Smacallancpu_configure(void)
781.1Smacallan{
791.1Smacallan	struct mainbus_attach_args maa;
801.1Smacallan
811.1Smacallan	(void) splhigh();
821.1Smacallan	(void) splserial();	/* XXX need an splextreme() */
831.1Smacallan
841.1Smacallan	maa.ma_name = "mainbus";
851.1Smacallan
861.1Smacallan	config_rootfound("mainbus", &maa);
871.1Smacallan
881.1Smacallan	/* Time to start taking interrupts so lets open the flood gates .... */
891.1Smacallan	spl0();
901.1Smacallan}
911.1Smacallan
921.1Smacallan#define BUILTIN_ETHERNET_P(pa)	\
931.1Smacallan	((pa)->pa_bus == 0 && (pa)->pa_device == 4 && (pa)->pa_function == 0)
941.1Smacallan
951.1Smacallan#define SETPROP(x, y)							\
961.1Smacallan	do {								\
971.1Smacallan		if (prop_dictionary_set(device_properties(dev),		\
981.1Smacallan						x, y) == false) {	\
991.1Smacallan			printf("WARNING: unable to set " x " "		\
1001.1Smacallan			   "property for %s\n", device_xname(dev));	\
1011.1Smacallan		}							\
1021.1Smacallan		prop_object_release(y);					\
1031.1Smacallan	} while (/*CONSTCOND*/0)
1041.1Smacallan
1051.1Smacallanvoid
1061.1Smacallandevice_register(device_t dev, void *aux)
1071.1Smacallan{
1081.1Smacallan	device_t pdev;
1091.1Smacallan
1101.1Smacallan	if ((pdev = device_parent(dev)) != NULL &&
1111.1Smacallan	    device_is_a(pdev, "pci")) {
1121.1Smacallan		struct pci_attach_args *pa = aux;
1131.1Smacallan
1141.1Smacallan		if (BUILTIN_ETHERNET_P(pa)) {
1151.1Smacallan			prop_number_t cfg1, cfg2, swdpin;
1161.1Smacallan			prop_data_t mac;
1171.1Smacallan
1181.1Smacallan			/*
1191.1Smacallan			 * We set these configuration registers to 0,
1201.1Smacallan			 * because it's the closest we have to "leave them
1211.1Smacallan			 * alone". That and, it works.
1221.1Smacallan			 */
1231.1Smacallan			cfg1 = prop_number_create_integer(0);
1241.1Smacallan			KASSERT(cfg1 != NULL);
1251.1Smacallan			cfg2 = prop_number_create_integer(0);
1261.1Smacallan			KASSERT(cfg2 != NULL);
1271.1Smacallan			swdpin = prop_number_create_integer(0);
1281.1Smacallan			KASSERT(swdpin != NULL);
1291.1Smacallan
1301.1Smacallan			mac = prop_data_create_data_nocopy(iyonix_macaddr,
1311.1Smacallan							   ETHER_ADDR_LEN);
1321.1Smacallan			KASSERT(mac != NULL);
1331.1Smacallan
1341.1Smacallan			SETPROP("mac-address", mac);
1351.1Smacallan			SETPROP("i82543-cfg1", cfg1);
1361.1Smacallan			SETPROP("i82543-cfg2", cfg2);
1371.1Smacallan			SETPROP("i82543-swdpin", swdpin);
1381.1Smacallan		}
1391.1Smacallan	}
1401.1Smacallan
1411.1Smacallan	if ((device_is_a(dev, "genfb") || device_is_a(dev, "gffb")) &&
1421.1Smacallan	    device_is_a(device_parent(dev), "pci") ) {
1431.1Smacallan		prop_dictionary_t dict = device_properties(dev);
1441.1Smacallan		struct pci_attach_args *pa = aux;
1451.1Smacallan		pcireg_t bar0, bar1;
1461.1Smacallan		uint32_t fbaddr;
1471.1Smacallan		bus_space_handle_t vgah;
1481.1Smacallan
1491.1Smacallan		bar0 = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_START);
1501.1Smacallan		bar1 = pci_conf_read(pa->pa_pc, pa->pa_tag,
1511.1Smacallan			PCI_MAPREG_START + 0x04);
1521.1Smacallan
1531.1Smacallan		/*
1541.1Smacallan		 * We need to prod the VGA card to disable interrupts, since
1551.1Smacallan		 * RISC OS has been using them and we don't know how to
1561.1Smacallan		 * handle them. This assumes that we have a NVidia
1571.1Smacallan		 * GeForce 2 MX card as supplied with the Iyonix and
1581.1Smacallan		 * as (probably) required by RISC OS in order to boot.
1591.1Smacallan		 * If you write your own RISC OS driver for a different card,
1601.1Smacallan		 * you're on your own.
1611.1Smacallan		 */
1621.1Smacallan
1631.1Smacallan/* We're guessing at the numbers here, guys */
1641.1Smacallan#define VGASIZE 0x1000
1651.1Smacallan#define IRQENABLE_ADDR 0x140
1661.1Smacallan
1671.1Smacallan		bus_space_map(pa->pa_memt, PCI_MAPREG_MEM_ADDR(bar0),
1681.1Smacallan			VGASIZE, 0, &vgah);
1691.1Smacallan		bus_space_write_4(pa->pa_memt, vgah, 0x140, 0);
1701.1Smacallan		bus_space_unmap(pa->pa_memt, vgah, 0x1000);
1711.1Smacallan
1721.1Smacallan		fbaddr = PCI_MAPREG_MEM_ADDR(bar1);
1731.1Smacallan
1741.1Smacallan		prop_dictionary_set_bool(dict, "is_console", 1);
1751.1Smacallan		prop_dictionary_set_uint32(dict, "width",
1761.1Smacallan			bootconfig.width + 1);
1771.1Smacallan		prop_dictionary_set_uint32(dict, "height",
1781.1Smacallan			bootconfig.height + 1);
1791.1Smacallan		prop_dictionary_set_uint32(dict, "depth",
1801.1Smacallan			1 << bootconfig.log2_bpp);
1811.1Smacallan		/*
1821.1Smacallan		 * XXX
1831.1Smacallan		 * at least RISC OS 5.28 seems to use the graphics hardware in
1841.1Smacallan		 * BGR mode when in 32bit colour, so take that into account
1851.1Smacallan		 */
1861.1Smacallan		if (bootconfig.log2_bpp == 5)
1871.1Smacallan			prop_dictionary_set_bool(dict, "is_bgr", 1);
1881.1Smacallan		prop_dictionary_set_uint32(dict, "address", fbaddr);
1891.1Smacallan	}
1901.1Smacallan	if (device_is_a(dev, "dsrtc")) {
1911.1Smacallan		prop_dictionary_t dict = device_properties(dev);
1921.1Smacallan		prop_dictionary_set_bool(dict, "base_year_is_2000", 1);
1931.1Smacallan	}
1941.1Smacallan}
195