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