rbus_machdep.c revision 1.4 1 1.4 matt /* $NetBSD: rbus_machdep.c,v 1.4 2010/12/20 00:25:32 matt Exp $ */
2 1.1 kiyohara
3 1.1 kiyohara /*
4 1.1 kiyohara * Copyright (c) 2003
5 1.1 kiyohara * KIYOHARA Takashi. All rights reserved.
6 1.1 kiyohara *
7 1.1 kiyohara * Redistribution and use in source and binary forms, with or without
8 1.1 kiyohara * modification, are permitted provided that the following conditions
9 1.1 kiyohara * are met:
10 1.1 kiyohara * 1. Redistributions of source code must retain the above copyright
11 1.1 kiyohara * notice, this list of conditions and the following disclaimer.
12 1.1 kiyohara * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 kiyohara * notice, this list of conditions and the following disclaimer in the
14 1.1 kiyohara * documentation and/or other materials provided with the distribution.
15 1.1 kiyohara *
16 1.1 kiyohara * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 kiyohara * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 kiyohara * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 kiyohara * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 kiyohara * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.1 kiyohara * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.1 kiyohara * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.1 kiyohara * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.1 kiyohara * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.1 kiyohara * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.1 kiyohara */
27 1.1 kiyohara
28 1.1 kiyohara #include <sys/cdefs.h>
29 1.1 kiyohara
30 1.1 kiyohara #include <sys/param.h>
31 1.1 kiyohara #include <sys/device.h>
32 1.1 kiyohara #include <sys/systm.h>
33 1.1 kiyohara
34 1.1 kiyohara #include <sys/extent.h>
35 1.1 kiyohara
36 1.1 kiyohara #include <machine/bus.h>
37 1.1 kiyohara
38 1.1 kiyohara #include <dev/pci/pcivar.h>
39 1.1 kiyohara #include <dev/pci/pcidevs.h>
40 1.1 kiyohara #include <dev/cardbus/rbus.h>
41 1.1 kiyohara
42 1.1 kiyohara #include "opt_pci.h"
43 1.1 kiyohara
44 1.1 kiyohara #ifndef PCI_NETBSD_CONFIGURE
45 1.1 kiyohara #error requird macro PCI_NETBSD_CONFIGURE
46 1.1 kiyohara #endif
47 1.1 kiyohara
48 1.1 kiyohara #ifdef RBUS_DEBUG
49 1.1 kiyohara # define DPRINTF printf
50 1.1 kiyohara #else
51 1.1 kiyohara # define DPRINTF while (0) printf
52 1.1 kiyohara #endif
53 1.1 kiyohara
54 1.1 kiyohara int
55 1.3 dsl md_space_map(bus_space_tag_t t, bus_addr_t bpa, bus_size_t size, int flags, bus_space_handle_t *bshp)
56 1.1 kiyohara {
57 1.1 kiyohara DPRINTF("md_space_map: 0x%x, 0x%x, 0x%x\n", t->pbs_base, bpa, size);
58 1.1 kiyohara
59 1.1 kiyohara return bus_space_map(t, bpa, size, flags, bshp);
60 1.1 kiyohara }
61 1.1 kiyohara
62 1.1 kiyohara void
63 1.3 dsl md_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t size, bus_addr_t *adrp)
64 1.1 kiyohara {
65 1.1 kiyohara paddr_t pa;
66 1.1 kiyohara
67 1.1 kiyohara DPRINTF("md_space_unmap: 0x%x 0x%x\n", t->pbs_base, bsh);
68 1.1 kiyohara
69 1.1 kiyohara if (adrp != NULL) {
70 1.1 kiyohara pmap_extract(pmap_kernel(), bsh, &pa);
71 1.1 kiyohara *adrp = pa - t->pbs_offset;
72 1.1 kiyohara }
73 1.1 kiyohara bus_space_unmap(t, bsh, size);
74 1.1 kiyohara }
75 1.1 kiyohara
76 1.1 kiyohara rbus_tag_t
77 1.3 dsl rbus_pccbb_parent_mem(struct pci_attach_args *pa)
78 1.1 kiyohara {
79 1.1 kiyohara bus_addr_t start;
80 1.1 kiyohara bus_size_t size;
81 1.1 kiyohara pci_chipset_tag_t pc = pa->pa_pc;
82 1.1 kiyohara struct extent *ex = pc->memext;
83 1.1 kiyohara
84 1.1 kiyohara start = ex->ex_start;
85 1.1 kiyohara size = ex->ex_end - start;
86 1.1 kiyohara
87 1.1 kiyohara return rbus_new_root_share(pa->pa_memt, ex, start, size, 0);
88 1.1 kiyohara }
89 1.1 kiyohara
90 1.1 kiyohara rbus_tag_t
91 1.3 dsl rbus_pccbb_parent_io(struct pci_attach_args *pa)
92 1.1 kiyohara {
93 1.1 kiyohara bus_addr_t start;
94 1.1 kiyohara bus_size_t size;
95 1.1 kiyohara pci_chipset_tag_t pc = pa->pa_pc;
96 1.1 kiyohara struct extent *ex = pc->ioext;
97 1.1 kiyohara
98 1.1 kiyohara start = ex->ex_start;
99 1.1 kiyohara size = ex->ex_end - start;
100 1.1 kiyohara
101 1.1 kiyohara return rbus_new_root_share(pa->pa_iot, ex, start, size, 0);
102 1.1 kiyohara }
103