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