pciconf_ofmethod.c revision 1.3 1 1.3 matt /* $NetBSD: pciconf_ofmethod.c,v 1.3 2011/06/17 19:03:01 matt Exp $ */
2 1.1 garbled
3 1.1 garbled /*-
4 1.1 garbled * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 1.1 garbled * All rights reserved.
6 1.1 garbled *
7 1.1 garbled * This code is derived from software contributed to The NetBSD Foundation
8 1.1 garbled * by Jochen Kunz and Tim Rightnour
9 1.1 garbled *
10 1.1 garbled * Redistribution and use in source and binary forms, with or without
11 1.1 garbled * modification, are permitted provided that the following conditions
12 1.1 garbled * are met:
13 1.1 garbled * 1. Redistributions of source code must retain the above copyright
14 1.1 garbled * notice, this list of conditions and the following disclaimer.
15 1.1 garbled * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 garbled * notice, this list of conditions and the following disclaimer in the
17 1.1 garbled * documentation and/or other materials provided with the distribution.
18 1.1 garbled *
19 1.1 garbled * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 garbled * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 garbled * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 garbled * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 garbled * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 garbled * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 garbled * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 garbled * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 garbled * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 garbled * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 garbled * POSSIBILITY OF SUCH DAMAGE.
30 1.1 garbled */
31 1.1 garbled
32 1.1 garbled /*
33 1.1 garbled * Generic PowerPC functions for talking to a PCI Bridge via the RTAS or
34 1.1 garbled * OF methods of the device.
35 1.1 garbled */
36 1.1 garbled
37 1.1 garbled #include <sys/cdefs.h>
38 1.3 matt __KERNEL_RCSID(0, "$NetBSD: pciconf_ofmethod.c,v 1.3 2011/06/17 19:03:01 matt Exp $");
39 1.1 garbled
40 1.1 garbled #include <sys/types.h>
41 1.1 garbled #include <sys/param.h>
42 1.1 garbled #include <sys/time.h>
43 1.1 garbled #include <sys/systm.h>
44 1.1 garbled #include <sys/errno.h>
45 1.1 garbled #include <sys/device.h>
46 1.1 garbled
47 1.1 garbled #include <uvm/uvm_extern.h>
48 1.1 garbled
49 1.1 garbled #define _POWERPC_BUS_DMA_PRIVATE
50 1.1 garbled #include <machine/bus.h>
51 1.1 garbled #include <machine/intr.h>
52 1.1 garbled #include <machine/pio.h>
53 1.1 garbled #include <dev/ofw/openfirm.h>
54 1.1 garbled #include <dev/ofw/ofw_pci.h>
55 1.1 garbled
56 1.1 garbled #if NISA > 0
57 1.1 garbled #include <dev/isa/isavar.h>
58 1.1 garbled #endif
59 1.1 garbled
60 1.1 garbled #include <dev/pci/pcivar.h>
61 1.1 garbled #include <dev/pci/pcireg.h>
62 1.1 garbled #include <dev/pci/pcidevs.h>
63 1.1 garbled
64 1.1 garbled void
65 1.3 matt genppc_pci_ofmethod_attach_hook(device_t parent, device_t self,
66 1.1 garbled struct pcibus_attach_args *pba)
67 1.1 garbled {
68 1.1 garbled
69 1.1 garbled if (pba->pba_bus != 0)
70 1.1 garbled return;
71 1.1 garbled
72 1.1 garbled aprint_normal(": OFW method configuration space access");
73 1.1 garbled }
74 1.1 garbled
75 1.1 garbled pcitag_t
76 1.1 garbled genppc_pci_ofmethod_make_tag(void *v, int bus, int dev, int func)
77 1.1 garbled {
78 1.1 garbled return ((bus << OFW_PCI_PHYS_HI_BUSSHIFT) & OFW_PCI_PHYS_HI_BUSMASK) |
79 1.1 garbled ((dev << OFW_PCI_PHYS_HI_DEVICESHIFT) & OFW_PCI_PHYS_HI_DEVICEMASK)|
80 1.1 garbled ((func << OFW_PCI_PHYS_HI_FUNCTIONSHIFT) &
81 1.1 garbled OFW_PCI_PHYS_HI_FUNCTIONMASK);
82 1.1 garbled }
83 1.1 garbled
84 1.1 garbled void
85 1.1 garbled genppc_pci_ofmethod_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp,
86 1.1 garbled int *fp)
87 1.1 garbled {
88 1.1 garbled
89 1.1 garbled if (bp != NULL)
90 1.1 garbled *bp = OFW_PCI_PHYS_HI_BUS(tag);
91 1.1 garbled if (dp != NULL)
92 1.1 garbled *dp = OFW_PCI_PHYS_HI_DEVICE(tag);
93 1.1 garbled if (fp != NULL)
94 1.1 garbled *fp = OFW_PCI_PHYS_HI_FUNCTION(tag);
95 1.1 garbled return;
96 1.1 garbled }
97 1.1 garbled
98 1.1 garbled pcireg_t
99 1.1 garbled genppc_pci_ofmethod_conf_read(void *v, pcitag_t tag, int reg)
100 1.1 garbled {
101 1.1 garbled pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
102 1.1 garbled pcireg_t data;
103 1.1 garbled
104 1.1 garbled tag &= OFW_PCI_PHYS_HI_BUSMASK | OFW_PCI_PHYS_HI_DEVICEMASK |
105 1.1 garbled OFW_PCI_PHYS_HI_FUNCTIONMASK;
106 1.1 garbled tag |= reg & OFW_PCI_PHYS_HI_REGISTERMASK;
107 1.1 garbled if (OF_call_method("config-l@", pc->pc_ihandle, 1, 1, tag, &data) < 0)
108 1.1 garbled return (pcireg_t) -1;
109 1.1 garbled /*printf("data=0x%x\n", data); */
110 1.1 garbled return data;
111 1.1 garbled }
112 1.1 garbled
113 1.1 garbled void
114 1.1 garbled genppc_pci_ofmethod_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
115 1.1 garbled {
116 1.1 garbled pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
117 1.1 garbled
118 1.1 garbled tag &= OFW_PCI_PHYS_HI_BUSMASK | OFW_PCI_PHYS_HI_DEVICEMASK |
119 1.1 garbled OFW_PCI_PHYS_HI_FUNCTIONMASK;
120 1.1 garbled tag |= reg & OFW_PCI_PHYS_HI_REGISTERMASK;
121 1.1 garbled OF_call_method("config-l!", pc->pc_ihandle, 2, 0, data, tag);
122 1.1 garbled }
123