1*2df76cc2Sguenther /* $OpenBSD: irongate_pci.c,v 1.7 2014/03/29 18:09:28 guenther Exp $ */
2d40b48efSart /* $NetBSD: irongate_pci.c,v 1.2 2000/06/29 08:58:47 mrg Exp $ */
3d40b48efSart
4d40b48efSart /*-
5d40b48efSart * Copyright (c) 2000 The NetBSD Foundation, Inc.
6d40b48efSart * All rights reserved.
7d40b48efSart *
8d40b48efSart * This code is derived from software contributed to The NetBSD Foundation
9d40b48efSart * by Jason R. Thorpe.
10d40b48efSart *
11d40b48efSart * Redistribution and use in source and binary forms, with or without
12d40b48efSart * modification, are permitted provided that the following conditions
13d40b48efSart * are met:
14d40b48efSart * 1. Redistributions of source code must retain the above copyright
15d40b48efSart * notice, this list of conditions and the following disclaimer.
16d40b48efSart * 2. Redistributions in binary form must reproduce the above copyright
17d40b48efSart * notice, this list of conditions and the following disclaimer in the
18d40b48efSart * documentation and/or other materials provided with the distribution.
19d40b48efSart *
20d40b48efSart * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21d40b48efSart * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22d40b48efSart * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23d40b48efSart * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24d40b48efSart * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25d40b48efSart * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26d40b48efSart * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27d40b48efSart * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28d40b48efSart * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29d40b48efSart * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30d40b48efSart * POSSIBILITY OF SUCH DAMAGE.
31d40b48efSart */
32d40b48efSart
33d40b48efSart /*
34d40b48efSart * PCI Configuration Space support for the AMD 751 (``Irongate'') core logic
35d40b48efSart * chipset.
36d40b48efSart */
37d40b48efSart
38d40b48efSart #include <sys/param.h>
39d40b48efSart #include <sys/systm.h>
40d40b48efSart #include <sys/kernel.h>
41d40b48efSart #include <sys/device.h>
42d40b48efSart
43d40b48efSart #include <uvm/uvm_extern.h>
44d40b48efSart
45d40b48efSart #include <dev/pci/pcireg.h>
46d40b48efSart #include <dev/pci/pcivar.h>
47d40b48efSart #include <alpha/pci/irongatereg.h>
48d40b48efSart #include <alpha/pci/irongatevar.h>
49d40b48efSart
50c4071fd1Smillert void irongate_attach_hook(struct device *, struct device *,
51c4071fd1Smillert struct pcibus_attach_args *);
52c4071fd1Smillert int irongate_bus_maxdevs(void *, int);
53c4071fd1Smillert pcitag_t irongate_make_tag(void *, int, int, int);
54c4071fd1Smillert void irongate_decompose_tag(void *, pcitag_t, int *, int *,
55c4071fd1Smillert int *);
56b1926db3Smiod int irongate_conf_size(void *, pcitag_t);
57c4071fd1Smillert pcireg_t irongate_conf_read(void *, pcitag_t, int);
58c4071fd1Smillert void irongate_conf_write(void *, pcitag_t, int, pcireg_t);
59d40b48efSart
60d40b48efSart /* AMD 751 systems are always single-processor, so this is easy. */
61d40b48efSart #define PCI_CONF_LOCK(s) (s) = splhigh()
62d40b48efSart #define PCI_CONF_UNLOCK(s) splx((s))
63d40b48efSart
64d40b48efSart #define PCI_CONF_ADDR (IRONGATE_IO_BASE|IRONGATE_CONFADDR)
65d40b48efSart #define PCI_CONF_DATA (IRONGATE_IO_BASE|IRONGATE_CONFDATA)
66d40b48efSart
67*2df76cc2Sguenther #define REGVAL(r) (*(volatile u_int32_t *)ALPHA_PHYS_TO_K0SEG(r))
68d40b48efSart
69d40b48efSart void
irongate_pci_init(pci_chipset_tag_t pc,void * v)70d40b48efSart irongate_pci_init(pci_chipset_tag_t pc, void *v)
71d40b48efSart {
72d40b48efSart
73d40b48efSart pc->pc_conf_v = v;
74d40b48efSart pc->pc_attach_hook = irongate_attach_hook;
75d40b48efSart pc->pc_bus_maxdevs = irongate_bus_maxdevs;
76d40b48efSart pc->pc_make_tag = irongate_make_tag;
77d40b48efSart pc->pc_decompose_tag = irongate_decompose_tag;
78b1926db3Smiod pc->pc_conf_size = irongate_conf_size;
79d40b48efSart pc->pc_conf_read = irongate_conf_read;
80d40b48efSart pc->pc_conf_write = irongate_conf_write;
81d40b48efSart }
82d40b48efSart
83d40b48efSart void
irongate_attach_hook(struct device * parent,struct device * self,struct pcibus_attach_args * pba)84d40b48efSart irongate_attach_hook(struct device *parent, struct device *self,
85d40b48efSart struct pcibus_attach_args *pba)
86d40b48efSart {
87d40b48efSart }
88d40b48efSart
89d40b48efSart int
irongate_bus_maxdevs(void * ipv,int busno)90d40b48efSart irongate_bus_maxdevs(void *ipv, int busno)
91d40b48efSart {
92d40b48efSart
93d40b48efSart return 32;
94d40b48efSart }
95d40b48efSart
96d40b48efSart pcitag_t
irongate_make_tag(void * ipv,int b,int d,int f)97d40b48efSart irongate_make_tag(void *ipv, int b, int d, int f)
98d40b48efSart {
99d40b48efSart
100d40b48efSart return (b << 16) | (d << 11) | (f << 8);
101d40b48efSart }
102d40b48efSart
103d40b48efSart void
irongate_decompose_tag(void * ipv,pcitag_t tag,int * bp,int * dp,int * fp)104d40b48efSart irongate_decompose_tag(void *ipv, pcitag_t tag, int *bp, int *dp, int *fp)
105d40b48efSart {
106d40b48efSart
107d40b48efSart if (bp != NULL)
108d40b48efSart *bp = (tag >> 16) & 0xff;
109d40b48efSart if (dp != NULL)
110d40b48efSart *dp = (tag >> 11) & 0x1f;
111d40b48efSart if (fp != NULL)
112d40b48efSart *fp = (tag >> 8) & 0x7;
113d40b48efSart }
114d40b48efSart
115b1926db3Smiod int
irongate_conf_size(void * ipv,pcitag_t tag)116b1926db3Smiod irongate_conf_size(void *ipv, pcitag_t tag)
117b1926db3Smiod {
118b1926db3Smiod return PCI_CONFIG_SPACE_SIZE;
119b1926db3Smiod }
120b1926db3Smiod
121d40b48efSart pcireg_t
irongate_conf_read(void * ipv,pcitag_t tag,int offset)122d40b48efSart irongate_conf_read(void *ipv, pcitag_t tag, int offset)
123d40b48efSart {
124d40b48efSart int d;
125d40b48efSart
126d40b48efSart /*
127d40b48efSart * The AMD 751 appears in PCI configuration space, but
128d40b48efSart * that is ... counter-intuitive to the way we normally
129d40b48efSart * attach PCI-Host bridges on the Alpha. So, filter out
130d40b48efSart * the AMD 751 device here. We provide a private entry
131d40b48efSart * point for getting at it from machdep code.
132d40b48efSart */
133d40b48efSart irongate_decompose_tag(ipv, tag, NULL, &d, NULL);
134d40b48efSart if (d == IRONGATE_PCIHOST_DEV)
135d40b48efSart return ((pcireg_t) -1);
136d40b48efSart
137d40b48efSart return (irongate_conf_read0(ipv, tag, offset));
138d40b48efSart }
139d40b48efSart
140d40b48efSart pcireg_t
irongate_conf_read0(void * ipv,pcitag_t tag,int offset)141d40b48efSart irongate_conf_read0(void *ipv, pcitag_t tag, int offset)
142d40b48efSart {
143d40b48efSart pcireg_t data;
144d40b48efSart int s;
145d40b48efSart
146d40b48efSart PCI_CONF_LOCK(s);
147d40b48efSart REGVAL(PCI_CONF_ADDR) = (CONFADDR_ENABLE | tag | (offset & 0xff));
148d40b48efSart alpha_mb();
149d40b48efSart data = REGVAL(PCI_CONF_DATA);
150d40b48efSart REGVAL(PCI_CONF_ADDR) = 0;
151d40b48efSart alpha_mb();
152d40b48efSart PCI_CONF_UNLOCK(s);
153d40b48efSart
154d40b48efSart return (data);
155d40b48efSart }
156d40b48efSart
157d40b48efSart void
irongate_conf_write(void * ipv,pcitag_t tag,int offset,pcireg_t data)158d40b48efSart irongate_conf_write(void *ipv, pcitag_t tag, int offset, pcireg_t data)
159d40b48efSart {
160d40b48efSart int s;
161d40b48efSart
162d40b48efSart PCI_CONF_LOCK(s);
163d40b48efSart REGVAL(PCI_CONF_ADDR) = (CONFADDR_ENABLE | tag | (offset & 0xff));
164d40b48efSart alpha_mb();
165d40b48efSart REGVAL(PCI_CONF_DATA) = data;
166d40b48efSart alpha_mb();
167d40b48efSart REGVAL(PCI_CONF_ADDR) = 0;
168d40b48efSart alpha_mb();
169d40b48efSart PCI_CONF_UNLOCK(s);
170d40b48efSart }
171