xref: /freebsd/sys/dev/thunderbolt/tb_if.m (revision 2ed9833791f28e14843ac813f90cb030e45948dc)
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# $FreeBSD$
29#
30
31#include <sys/bus.h>
32#include <sys/types.h>
33#include <dev/thunderbolt/tb_reg.h>
34
35INTERFACE tb;
36
37CODE {
38	struct nhi_softc;
39
40	int
41	tb_generic_find_ufp(device_t dev, device_t *ufp)
42	{
43		device_t parent;
44
45		parent = device_get_parent(dev);
46		if (parent == NULL)
47			return (EOPNOTSUPP);
48
49		return (TB_FIND_UFP(parent, ufp));
50	}
51
52	int
53	tb_generic_get_debug(device_t dev, u_int *debug)
54	{
55		device_t parent;
56
57		parent = device_get_parent(dev);
58		if (parent == NULL)
59			return (EOPNOTSUPP);
60
61		return (TB_GET_DEBUG(parent, debug));
62	}
63
64}
65
66HEADER {
67	struct nhi_softc;
68
69	struct tb_lcmbox_cmd {
70		uint32_t cmd;
71		uint32_t cmd_resp;
72		uint32_t data_in;
73		uint32_t data_out;
74	};
75
76	int tb_generic_find_ufp(device_t, device_t *);
77	int tb_generic_get_debug(device_t, u_int *);
78}
79
80#
81# Read the LC Mailbox
82#
83METHOD int lc_mailbox {
84	device_t	dev;
85	struct tb_lcmbox_cmd	*cmd;
86};
87
88#
89# Read from the PCIE2CIO port
90#
91METHOD int pcie2cio_read {
92	device_t	dev;
93	u_int		space;
94	u_int		port;
95	u_int		index;
96	uint32_t	*val;
97}
98
99#
100# Write to the PCIE2CIO port
101#
102METHOD int pcie2cio_write {
103	device_t	dev;
104	u_int		space;
105	u_int		port;
106	u_int		index;
107	uint32_t	val;
108}
109
110#
111# Return the device that's the upstream facing port
112#
113METHOD int find_ufp {
114	device_t dev;
115	device_t *ufp;
116} DEFAULT tb_generic_find_ufp;
117
118METHOD int get_debug {
119	device_t dev;
120	u_int *debug;
121} DEFAULT tb_generic_get_debug;
122