xref: /freebsd/sys/dev/thunderbolt/tb_pcib.h (revision d3e5082ce4dcb154cbf50cba05d8f1dbbd55a5fc)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2022 Scott Long
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * Thunderbolt PCIe bridge/switch definitions
29  */
30 
31 #ifndef _TB_PCIB_H
32 #define _TB_PCIB_H
33 
34 DECLARE_CLASS(tb_pcib_driver);
35 
36 /*
37  * The order of the fields is very important.  Class inherentence replies on
38  * implicitly knowing the location of the first 3 fields.
39  */
40 struct tb_pcib_softc {
41 	struct pcib_softc	pcibsc;
42 	ACPI_HANDLE		ap_handle;
43 	ACPI_BUFFER		ap_prt;
44 	device_t		dev;
45 	u_int			debug;
46 	int			vsec;
47 	int			flags;
48 	struct sysctl_ctx_list	*sysctl_ctx;
49 	struct sysctl_oid	*sysctl_tree;
50 };
51 
52 /* Flags for tb_softc */
53 #define TB_GEN_UNK	0x00
54 #define TB_GEN_TB1	0x01
55 #define TB_GEN_TB2	0x02
56 #define TB_GEN_TB3	0x03
57 #define TB_GEN_USB4	0x04
58 #define TB_GEN_MASK	0x0f
59 #define TB_HWIF_UNK	0x00
60 #define TB_HWIF_AR	0x10
61 #define TB_HWIF_TR	0x20
62 #define TB_HWIF_ICL	0x30
63 #define TB_HWIF_USB4	0x40
64 #define TB_HWIF_MASK	0xf0
65 #define TB_FLAGS_ISROOT	0x100
66 #define TB_FLAGS_ISUFP	0x200
67 
68 #define TB_IS_AR(sc)	(((sc)->flags & TB_HWIF_MASK) == TB_HWIF_AR)
69 #define TB_IS_TR(sc)	(((sc)->flags & TB_HWIF_MASK) == TB_HWIF_TR)
70 #define TB_IS_ICL(sc)	(((sc)->flags & TB_HWIF_MASK) == TB_HWIF_ICL)
71 #define TB_IS_USB4(sc)	(((sc)->flags & TB_HWIF_MASK) == TB_HWIF_USB4)
72 
73 #define TB_IS_ROOT(sc)	(((sc)->flags & TB_FLAGS_ISROOT) != 0)
74 #define TB_IS_UFP(sc)	(((sc)->flags & TB_FLAGS_ISUFP) != 0)
75 #define TB_IS_DFP(sc)	(((sc)->flags & TB_FLAGS_ISUFP) == 0)
76 
77 /* PCI IDs for the TB bridges */
78 #define TB_DEV_AR_2C		0x1576
79 #define TB_DEV_AR_LP		0x15c0
80 #define TB_DEV_AR_C_4C		0x15d3
81 #define TB_DEV_AR_C_2C		0x15da
82 #define TB_DEV_ICL_0		0x8a1d
83 #define TB_DEV_ICL_1		0x8a21
84 
85 #define TB_PCIB_VSEC(dev) ((struct tb_pcib_softc *)(device_get_softc(dev)))->vsec;
86 #define TB_DESC_MAX	80
87 
88 int tb_pcib_probe_common(device_t, char *);
89 int tb_pcib_attach_common(device_t dev);
90 
91 #endif /* _TB_PCIB_H */
92