1 /*	$NetBSD: rbus_machdep.c,v 1.6 2014/06/29 23:21:28 jakllsch 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  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: rbus_machdep.c,v 1.6 2014/06/29 23:21:28 jakllsch Exp $");
30 
31 #include "opt_pcifixup.h"
32 
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/extent.h>
36 
37 #include <sys/sysctl.h>
38 
39 #include <sys/bus.h>
40 #include <dev/cardbus/rbus.h>
41 
42 #include <sys/device.h>
43 #include <dev/isa/isareg.h>
44 #include <dev/isa/isavar.h>
45 
46 #include <dev/pci/pcivar.h>
47 #if defined(PCI_ADDR_FIXUP)
48 #include <arch/x86/pci/pci_addr_fixup.h>
49 #endif
50 
51 #ifndef RBUS_IO_BASE
52 #define	RBUS_IO_BASE	0x4000
53 #endif
54 #ifndef RBUS_IO_SIZE
55 #define	RBUS_IO_SIZE	0x2000
56 #endif
57 
58 #ifndef RBUS_MIN_START
59 #define RBUS_MIN_START 0x0000000080000000	/* 2GB */
60 #endif
61 bus_addr_t rbus_min_start = RBUS_MIN_START;
62 
63 /*
64  * rbus_tag_t rbus_fakeparent_mem(struct pci_attach_args *pa)
65  *
66  *   This function makes an rbus tag for memory space.  This rbus tag
67  *   shares the all memory region of ex_iomem.
68  */
69 rbus_tag_t
rbus_pccbb_parent_mem(struct pci_attach_args * pa)70 rbus_pccbb_parent_mem(struct pci_attach_args *pa)
71 {
72 	bus_addr_t start;
73 	bus_size_t size;
74 	extern struct extent *iomem_ex;
75 	struct extent *ex = iomem_ex;
76 
77 #if defined(PCI_ADDR_FIXUP)
78 	if (pciaddr.extent_mem != NULL)
79 		ex = pciaddr.extent_mem;
80 #endif
81 
82 	start = ex->ex_start;
83 
84 	/*
85 	 * XXX: unfortunately, iomem_ex cannot be used for the dynamic
86 	 * bus_space allocation.  There are some hidden memory (or
87 	 * some obstacles which are not recognised by the kernel) in
88 	 * the region governed by iomem_ex.  So I decide to use only
89 	 * very high address region.
90 	 *
91 	 * If pcibios_addr_fixup() succeeded, the PCI device is using an area
92 	 * which is not recognised by the kernel as already reserved.
93 	 */
94 
95 	if (start < rbus_min_start)
96 		start = rbus_min_start;
97 
98 	size = ex->ex_end - start;
99 
100 	return rbus_new_root_share(pa->pa_memt, ex, start, size, 0);
101 }
102 
103 
104 /*
105  * rbus_tag_t rbus_pccbb_parent_io(struct pci_attach_args *pa)
106  */
107 rbus_tag_t
rbus_pccbb_parent_io(struct pci_attach_args * pa)108 rbus_pccbb_parent_io(struct pci_attach_args *pa)
109 {
110 	bus_addr_t start;
111 	bus_size_t size;
112 	rbus_tag_t ret;
113 	extern struct extent *ioport_ex;
114 	struct extent *ex = ioport_ex;
115 
116 #if defined(PCI_ADDR_FIXUP)
117 	if (pciaddr.extent_port != NULL)
118 		ex = pciaddr.extent_port;
119 #endif
120 
121 	start = RBUS_IO_BASE;
122 	size  = RBUS_IO_SIZE;
123 
124 	ret = rbus_new_root_share(pa->pa_iot, ex, start, size, 0);
125 	if (ret == NULL)
126 	  panic("failed to alloc I/O space");
127 
128 	return ret;
129 }
130