rbus_machdep.c revision 1.6 1 1.6 matt /* $NetBSD: rbus_machdep.c,v 1.6 2011/01/18 01:08:55 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.6 matt #include <uvm/uvm_extern.h>
37 1.6 matt
38 1.1 kiyohara #include <machine/bus.h>
39 1.1 kiyohara
40 1.1 kiyohara #include <dev/pci/pcivar.h>
41 1.1 kiyohara #include <dev/pci/pcidevs.h>
42 1.1 kiyohara #include <dev/cardbus/rbus.h>
43 1.1 kiyohara
44 1.5 kiyohara #include <uvm/uvm_extern.h>
45 1.5 kiyohara
46 1.1 kiyohara #include "opt_pci.h"
47 1.1 kiyohara
48 1.1 kiyohara #ifndef PCI_NETBSD_CONFIGURE
49 1.1 kiyohara #error requird macro PCI_NETBSD_CONFIGURE
50 1.1 kiyohara #endif
51 1.1 kiyohara
52 1.1 kiyohara #ifdef RBUS_DEBUG
53 1.1 kiyohara # define DPRINTF printf
54 1.1 kiyohara #else
55 1.1 kiyohara # define DPRINTF while (0) printf
56 1.1 kiyohara #endif
57 1.1 kiyohara
58 1.1 kiyohara int
59 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)
60 1.1 kiyohara {
61 1.1 kiyohara DPRINTF("md_space_map: 0x%x, 0x%x, 0x%x\n", t->pbs_base, bpa, size);
62 1.1 kiyohara
63 1.1 kiyohara return bus_space_map(t, bpa, size, flags, bshp);
64 1.1 kiyohara }
65 1.1 kiyohara
66 1.1 kiyohara void
67 1.3 dsl md_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t size, bus_addr_t *adrp)
68 1.1 kiyohara {
69 1.1 kiyohara paddr_t pa;
70 1.1 kiyohara
71 1.1 kiyohara DPRINTF("md_space_unmap: 0x%x 0x%x\n", t->pbs_base, bsh);
72 1.1 kiyohara
73 1.1 kiyohara if (adrp != NULL) {
74 1.1 kiyohara pmap_extract(pmap_kernel(), bsh, &pa);
75 1.1 kiyohara *adrp = pa - t->pbs_offset;
76 1.1 kiyohara }
77 1.1 kiyohara bus_space_unmap(t, bsh, size);
78 1.1 kiyohara }
79 1.1 kiyohara
80 1.1 kiyohara rbus_tag_t
81 1.3 dsl rbus_pccbb_parent_mem(struct pci_attach_args *pa)
82 1.1 kiyohara {
83 1.1 kiyohara bus_addr_t start;
84 1.1 kiyohara bus_size_t size;
85 1.1 kiyohara pci_chipset_tag_t pc = pa->pa_pc;
86 1.1 kiyohara struct extent *ex = pc->memext;
87 1.1 kiyohara
88 1.1 kiyohara start = ex->ex_start;
89 1.1 kiyohara size = ex->ex_end - start;
90 1.1 kiyohara
91 1.1 kiyohara return rbus_new_root_share(pa->pa_memt, ex, start, size, 0);
92 1.1 kiyohara }
93 1.1 kiyohara
94 1.1 kiyohara rbus_tag_t
95 1.3 dsl rbus_pccbb_parent_io(struct pci_attach_args *pa)
96 1.1 kiyohara {
97 1.1 kiyohara bus_addr_t start;
98 1.1 kiyohara bus_size_t size;
99 1.1 kiyohara pci_chipset_tag_t pc = pa->pa_pc;
100 1.1 kiyohara struct extent *ex = pc->ioext;
101 1.1 kiyohara
102 1.1 kiyohara start = ex->ex_start;
103 1.1 kiyohara size = ex->ex_end - start;
104 1.1 kiyohara
105 1.1 kiyohara return rbus_new_root_share(pa->pa_iot, ex, start, size, 0);
106 1.1 kiyohara }
107