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