pciconf_ofmethod.c revision 1.6 1 1.6 rin /* $NetBSD: pciconf_ofmethod.c,v 1.6 2020/07/06 09:34:17 rin 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.6 rin #define _POWERPC_BUS_DMA_PRIVATE
38 1.6 rin
39 1.1 garbled #include <sys/cdefs.h>
40 1.6 rin __KERNEL_RCSID(0, "$NetBSD: pciconf_ofmethod.c,v 1.6 2020/07/06 09:34:17 rin Exp $");
41 1.1 garbled
42 1.1 garbled #include <sys/types.h>
43 1.1 garbled #include <sys/param.h>
44 1.1 garbled #include <sys/time.h>
45 1.1 garbled #include <sys/systm.h>
46 1.1 garbled #include <sys/errno.h>
47 1.1 garbled #include <sys/device.h>
48 1.4 matt #include <sys/bus.h>
49 1.4 matt #include <sys/intr.h>
50 1.1 garbled
51 1.1 garbled #include <uvm/uvm_extern.h>
52 1.1 garbled
53 1.1 garbled #include <machine/pio.h>
54 1.4 matt
55 1.1 garbled #include <dev/ofw/openfirm.h>
56 1.1 garbled #include <dev/ofw/ofw_pci.h>
57 1.1 garbled
58 1.1 garbled #if NISA > 0
59 1.1 garbled #include <dev/isa/isavar.h>
60 1.1 garbled #endif
61 1.1 garbled
62 1.1 garbled #include <dev/pci/pcivar.h>
63 1.1 garbled #include <dev/pci/pcireg.h>
64 1.1 garbled #include <dev/pci/pcidevs.h>
65 1.1 garbled
66 1.1 garbled void
67 1.3 matt genppc_pci_ofmethod_attach_hook(device_t parent, device_t self,
68 1.1 garbled struct pcibus_attach_args *pba)
69 1.1 garbled {
70 1.1 garbled
71 1.1 garbled if (pba->pba_bus != 0)
72 1.1 garbled return;
73 1.1 garbled
74 1.1 garbled aprint_normal(": OFW method configuration space access");
75 1.1 garbled }
76 1.1 garbled
77 1.1 garbled pcitag_t
78 1.1 garbled genppc_pci_ofmethod_make_tag(void *v, int bus, int dev, int func)
79 1.1 garbled {
80 1.1 garbled return ((bus << OFW_PCI_PHYS_HI_BUSSHIFT) & OFW_PCI_PHYS_HI_BUSMASK) |
81 1.1 garbled ((dev << OFW_PCI_PHYS_HI_DEVICESHIFT) & OFW_PCI_PHYS_HI_DEVICEMASK)|
82 1.1 garbled ((func << OFW_PCI_PHYS_HI_FUNCTIONSHIFT) &
83 1.1 garbled OFW_PCI_PHYS_HI_FUNCTIONMASK);
84 1.1 garbled }
85 1.1 garbled
86 1.1 garbled void
87 1.1 garbled genppc_pci_ofmethod_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp,
88 1.1 garbled int *fp)
89 1.1 garbled {
90 1.1 garbled
91 1.1 garbled if (bp != NULL)
92 1.1 garbled *bp = OFW_PCI_PHYS_HI_BUS(tag);
93 1.1 garbled if (dp != NULL)
94 1.1 garbled *dp = OFW_PCI_PHYS_HI_DEVICE(tag);
95 1.1 garbled if (fp != NULL)
96 1.1 garbled *fp = OFW_PCI_PHYS_HI_FUNCTION(tag);
97 1.1 garbled return;
98 1.1 garbled }
99 1.1 garbled
100 1.1 garbled pcireg_t
101 1.1 garbled genppc_pci_ofmethod_conf_read(void *v, pcitag_t tag, int reg)
102 1.1 garbled {
103 1.1 garbled pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
104 1.1 garbled pcireg_t data;
105 1.1 garbled
106 1.5 msaitoh if ((unsigned int)reg >= PCI_CONF_SIZE)
107 1.5 msaitoh return (pcireg_t) -1;
108 1.5 msaitoh
109 1.1 garbled tag &= OFW_PCI_PHYS_HI_BUSMASK | OFW_PCI_PHYS_HI_DEVICEMASK |
110 1.1 garbled OFW_PCI_PHYS_HI_FUNCTIONMASK;
111 1.1 garbled tag |= reg & OFW_PCI_PHYS_HI_REGISTERMASK;
112 1.1 garbled if (OF_call_method("config-l@", pc->pc_ihandle, 1, 1, tag, &data) < 0)
113 1.1 garbled return (pcireg_t) -1;
114 1.1 garbled /*printf("data=0x%x\n", data); */
115 1.1 garbled return data;
116 1.1 garbled }
117 1.1 garbled
118 1.1 garbled void
119 1.1 garbled genppc_pci_ofmethod_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
120 1.1 garbled {
121 1.1 garbled pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
122 1.1 garbled
123 1.5 msaitoh if ((unsigned int)reg >= PCI_CONF_SIZE)
124 1.5 msaitoh return;
125 1.5 msaitoh
126 1.1 garbled tag &= OFW_PCI_PHYS_HI_BUSMASK | OFW_PCI_PHYS_HI_DEVICEMASK |
127 1.1 garbled OFW_PCI_PHYS_HI_FUNCTIONMASK;
128 1.1 garbled tag |= reg & OFW_PCI_PHYS_HI_REGISTERMASK;
129 1.1 garbled OF_call_method("config-l!", pc->pc_ihandle, 2, 0, data, tag);
130 1.1 garbled }
131