1/* $OpenBSD: pci_machdep.h,v 1.4 2019/12/05 12:46:54 mpi Exp $ */
2/* $NetBSD: pci_machdep.h,v 1.7 2001/07/20 00:07:14 eeh Exp $ */
3
4/*
5 * Copyright (c) 1999 Matthew R. Green
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#ifndef _MACHINE_PCI_MACHDEP_H_
31#define _MACHINE_PCI_MACHDEP_H_
32
33extern struct powerpc_bus_dma_tag pci_bus_dma_tag;
34
35/*
36 * Forward declarations.
37 */
38struct pci_attach_args;
39
40/*
41 * define some bits used to glue into the common PCI code.
42 */
43
44typedef struct ppc_pci_chipset *pci_chipset_tag_t;
45
46typedef unsigned long pci_intr_handle_t;
47
48/*
49 * The stuuuuuuupid allegedly MI PCI code expects pcitag_t to be a
50 * scalar type. But we really need to store both the OFW node and
51 * the bus/device/function info in it. (We'd like to store more,
52 * like all the ofw properties, but we don't need to.) Luckily,
53 * both are 32-bit values, so we can squeeze them into a u_int64_t
54 * with a little help from some macros.
55 */
56
57#define PCITAG_NODE(x) (int)(((x)>>32)&0xffffffff)
58#define PCITAG_OFFSET(x) ((x)&0xffffffff)
59#define PCITAG_BUS(t) ((PCITAG_OFFSET(t)>>16)&0xff)
60#define PCITAG_DEV(t) ((PCITAG_OFFSET(t)>>11)&0x1f)
61#define PCITAG_FUN(t) ((PCITAG_OFFSET(t)>>8)&0x7)
62#define PCITAG_CREATE(n,b,d,f) (((uint64_t)(n)<<32)|((b)<<16)|((d)<<11)|((f)<<8))
63typedef uint64_t pcitag_t;
64
65struct ppc_pci_chipset {
66 void *pc_conf_v;
67 int pc_node;
68 int busnode[256];
69
70 pcireg_t (*pc_conf_read)(void *, pcitag_t, int);
71 void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t);
72};
73
74
75void pci_attach_hook(struct device *, struct device *,
76 struct pcibus_attach_args *);
77int pci_bus_maxdevs(pci_chipset_tag_t, int);
78pcitag_t pci_make_tag(pci_chipset_tag_t, int, int, int);
79void pci_decompose_tag(pci_chipset_tag_t, pcitag_t, int *, int *,
80 int *);
81int pci_conf_size(pci_chipset_tag_t, pcitag_t);
82pcireg_t pci_conf_read(pci_chipset_tag_t, pcitag_t, int);
83void pci_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t);
84int pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
85int pci_intr_map_msi(struct pci_attach_args *, pci_intr_handle_t *);
86#define pci_intr_map_msix(p, vec, ihp) (-1)
87int pci_intr_line(pci_chipset_tag_t, pci_intr_handle_t);
88const char *pci_intr_string(pci_chipset_tag_t, pci_intr_handle_t);
89void *pci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t,
90 int, int (*)(void *), void *, const char *);
91void pci_intr_disestablish(pci_chipset_tag_t, void *);
92int pci_ether_hw_addr(pci_chipset_tag_t, uint8_t *);
93
94#define pci_probe_device_hook(c, a) (0)
95
96#define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3)
97#define pci_set_powerstate_md(c, t, s, p)
98
99#define pci_dev_postattach(a, b)
100
101int ofw_intr_map(int, uint32_t *, uint32_t *);
102int ofw_enumerate_pcibus(struct pci_softc *,
103 int (*match)(struct pci_attach_args *),
104 struct pci_attach_args *);
105
106#define PCI_MACHDEP_ENUMERATE_BUS ofw_enumerate_pcibus
107
108#endif /* _MACHINE_PCI_MACHDEP_H_ */