xref: /netbsd/sys/arch/i386/i386/rbus_machdep.c (revision bf9ec67e)
1 /*	$NetBSD: rbus_machdep.c,v 1.14 2001/11/15 07:03:31 lukem Exp $	*/
2 
3 /*
4  * Copyright (c) 1999
5  *     HAYAKAWA Koichi.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by HAYAKAWA Koichi.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: rbus_machdep.c,v 1.14 2001/11/15 07:03:31 lukem Exp $");
35 
36 #include "opt_pcibios.h"
37 
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/extent.h>
41 
42 #include <uvm/uvm_extern.h>
43 
44 #include <sys/sysctl.h>
45 
46 #include <machine/bus.h>
47 #include <dev/cardbus/rbus.h>
48 
49 #include <sys/device.h>
50 #include <dev/isa/isareg.h>
51 #include <dev/isa/isavar.h>
52 
53 #include <dev/pci/pcivar.h>
54 #ifdef PCIBIOS_ADDR_FIXUP
55 #include <arch/i386/pci/pci_addr_fixup.h>
56 #endif
57 
58 #ifndef RBUS_IO_BASE
59 #define	RBUS_IO_BASE	0x4000
60 #endif
61 #ifndef RBUS_IO_SIZE
62 #define	RBUS_IO_SIZE	0x2000
63 #endif
64 
65 #ifndef RBUS_MIN_START
66 #define RBUS_MIN_START 0x40000000	/* 1GB */
67 #endif
68 bus_addr_t rbus_min_start = RBUS_MIN_START;
69 
70 /*
71  * rbus_tag_t rbus_fakeparent_mem(struct pci_attach_args *pa)
72  *
73  *   This function makes an rbus tag for memory space.  This rbus tag
74  *   shares the all memory region of ex_iomem.
75  */
76 rbus_tag_t
77 rbus_pccbb_parent_mem(pa)
78 	struct pci_attach_args *pa;
79 {
80 	bus_addr_t start, offset;
81 	bus_size_t size;
82 	struct extent *ex;
83 #ifdef PCIBIOS_ADDR_FIXUP
84 	ex = pciaddr.extent_mem;
85 #else
86 	extern struct extent *iomem_ex;
87 	ex = iomem_ex;
88 #endif
89 
90 	start = ex->ex_start;
91 
92 	/*
93 	 * XXX: unfortunately, iomem_ex cannot be used for the dynamic
94 	 * bus_space allocatoin.  There are some hidden memory (or
95 	 * some obstacles which do not recognised by the kernel) in
96 	 * the region governed by iomem_ex.  So I decide to use only
97 	 * very high address region.
98 	 *
99 	 * if defined PCIBIOS_ADDR_FIXUP, PCI device using area
100 	 * which do not recognised by the kernel are already reserved.
101 	 */
102 
103 	if (start < rbus_min_start)
104 		start = rbus_min_start;
105 
106 	size = ex->ex_end - start;
107 	offset = 0;
108 
109 	return rbus_new_root_share(pa->pa_memt, ex, start, size, 0);
110 }
111 
112 
113 /*
114  * rbus_tag_t rbus_pccbb_parent_io(struct pci_attach_args *pa)
115  */
116 rbus_tag_t
117 rbus_pccbb_parent_io(pa)
118 	struct pci_attach_args *pa;
119 {
120 	struct extent *ex;
121 	bus_addr_t start;
122 	bus_size_t size;
123 	rbus_tag_t ret;
124 #ifdef PCIBIOS_ADDR_FIXUP
125 	ex = pciaddr.extent_port;
126 #else
127 	extern struct extent *ioport_ex;
128 	ex = ioport_ex;
129 #endif
130 	start = RBUS_IO_BASE;
131 	size  = RBUS_IO_SIZE;
132 
133 	ret = rbus_new_root_share(pa->pa_iot, ex, start, size, 0);
134 	if(ret == NULL) {
135 	  panic("failed to alloc I/O space");
136 	}
137 	return ret;
138 }
139