pciconf_ofmethod.c revision 1.7 1 1.7 rin /* $NetBSD: pciconf_ofmethod.c,v 1.7 2021/01/06 08:17:46 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.7 rin __KERNEL_RCSID(0, "$NetBSD: pciconf_ofmethod.c,v 1.7 2021/01/06 08:17:46 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 #include <dev/pci/pcivar.h>
59 1.1 garbled #include <dev/pci/pcireg.h>
60 1.1 garbled #include <dev/pci/pcidevs.h>
61 1.1 garbled
62 1.1 garbled void
63 1.3 matt genppc_pci_ofmethod_attach_hook(device_t parent, device_t self,
64 1.1 garbled struct pcibus_attach_args *pba)
65 1.1 garbled {
66 1.1 garbled
67 1.1 garbled if (pba->pba_bus != 0)
68 1.1 garbled return;
69 1.1 garbled
70 1.1 garbled aprint_normal(": OFW method configuration space access");
71 1.1 garbled }
72 1.1 garbled
73 1.1 garbled pcitag_t
74 1.1 garbled genppc_pci_ofmethod_make_tag(void *v, int bus, int dev, int func)
75 1.1 garbled {
76 1.1 garbled return ((bus << OFW_PCI_PHYS_HI_BUSSHIFT) & OFW_PCI_PHYS_HI_BUSMASK) |
77 1.1 garbled ((dev << OFW_PCI_PHYS_HI_DEVICESHIFT) & OFW_PCI_PHYS_HI_DEVICEMASK)|
78 1.1 garbled ((func << OFW_PCI_PHYS_HI_FUNCTIONSHIFT) &
79 1.1 garbled OFW_PCI_PHYS_HI_FUNCTIONMASK);
80 1.1 garbled }
81 1.1 garbled
82 1.1 garbled void
83 1.1 garbled genppc_pci_ofmethod_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp,
84 1.1 garbled int *fp)
85 1.1 garbled {
86 1.1 garbled
87 1.1 garbled if (bp != NULL)
88 1.1 garbled *bp = OFW_PCI_PHYS_HI_BUS(tag);
89 1.1 garbled if (dp != NULL)
90 1.1 garbled *dp = OFW_PCI_PHYS_HI_DEVICE(tag);
91 1.1 garbled if (fp != NULL)
92 1.1 garbled *fp = OFW_PCI_PHYS_HI_FUNCTION(tag);
93 1.1 garbled return;
94 1.1 garbled }
95 1.1 garbled
96 1.1 garbled pcireg_t
97 1.1 garbled genppc_pci_ofmethod_conf_read(void *v, pcitag_t tag, int reg)
98 1.1 garbled {
99 1.1 garbled pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
100 1.1 garbled pcireg_t data;
101 1.1 garbled
102 1.5 msaitoh if ((unsigned int)reg >= PCI_CONF_SIZE)
103 1.5 msaitoh return (pcireg_t) -1;
104 1.5 msaitoh
105 1.1 garbled tag &= OFW_PCI_PHYS_HI_BUSMASK | OFW_PCI_PHYS_HI_DEVICEMASK |
106 1.1 garbled OFW_PCI_PHYS_HI_FUNCTIONMASK;
107 1.1 garbled tag |= reg & OFW_PCI_PHYS_HI_REGISTERMASK;
108 1.1 garbled if (OF_call_method("config-l@", pc->pc_ihandle, 1, 1, tag, &data) < 0)
109 1.1 garbled return (pcireg_t) -1;
110 1.1 garbled /*printf("data=0x%x\n", data); */
111 1.1 garbled return data;
112 1.1 garbled }
113 1.1 garbled
114 1.1 garbled void
115 1.1 garbled genppc_pci_ofmethod_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
116 1.1 garbled {
117 1.1 garbled pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
118 1.1 garbled
119 1.5 msaitoh if ((unsigned int)reg >= PCI_CONF_SIZE)
120 1.5 msaitoh return;
121 1.5 msaitoh
122 1.1 garbled tag &= OFW_PCI_PHYS_HI_BUSMASK | OFW_PCI_PHYS_HI_DEVICEMASK |
123 1.1 garbled OFW_PCI_PHYS_HI_FUNCTIONMASK;
124 1.1 garbled tag |= reg & OFW_PCI_PHYS_HI_REGISTERMASK;
125 1.1 garbled OF_call_method("config-l!", pc->pc_ihandle, 2, 0, data, tag);
126 1.1 garbled }
127