]>
Commit | Line | Data |
---|---|---|
5bee27aa SG |
1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
2 | /* | |
3 | * Copyright 2019 Google LLC | |
4 | * Written by Simon Glass <[email protected]> | |
5 | */ | |
6 | ||
7 | #ifndef __p2sb_h | |
8 | #define __p2sb_h | |
9 | ||
10 | /* Port Id lives in bits 23:16 and register offset lives in 15:0 of address */ | |
11 | #define PCR_PORTID_SHIFT 16 | |
12 | ||
022256b9 SG |
13 | #if !defined(__ACPI__) |
14 | ||
15 | /* These registers contain IOAPIC and HPET devfn */ | |
16 | #define PCH_P2SB_IBDF 0x6c | |
17 | #define PCH_P2SB_HBDF 0x70 | |
18 | ||
5bee27aa | 19 | /** |
8a8d24bd | 20 | * struct p2sb_child_plat - Information about each child of a p2sb device |
5bee27aa SG |
21 | * |
22 | * @pid: Port ID for this child | |
23 | */ | |
8a8d24bd | 24 | struct p2sb_child_plat { |
5bee27aa SG |
25 | uint pid; |
26 | }; | |
27 | ||
28 | /** | |
29 | * struct p2sb_uc_priv - information for the uclass about each device | |
30 | * | |
31 | * This must be set up by the driver when it is probed | |
32 | * | |
33 | * @mmio_base: Base address of P2SB region | |
34 | */ | |
35 | struct p2sb_uc_priv { | |
36 | uint mmio_base; | |
37 | }; | |
38 | ||
39 | /** | |
6d349e2e | 40 | * struct p2sb_ops - Operations for the P2SB |
5bee27aa SG |
41 | */ |
42 | struct p2sb_ops { | |
6d349e2e SG |
43 | /** |
44 | * set_hide() - Set/clear the 'hide' bit on the p2sb | |
45 | * | |
46 | * This device can be hidden from the PCI bus if needed. This method | |
47 | * can be called before the p2sb is probed. | |
48 | * | |
49 | * @dev: P2SB device | |
50 | * @hide: true to hide the device, false to show it | |
51 | * @return 0 if OK, -ve on error | |
52 | */ | |
53 | int (*set_hide)(struct udevice *dev, bool hide); | |
5bee27aa SG |
54 | }; |
55 | ||
56 | #define p2sb_get_ops(dev) ((struct p2sb_ops *)(dev)->driver->ops) | |
57 | ||
6d349e2e SG |
58 | /** |
59 | * p2sb_set_hide() - Set/clear the 'hide' bit on the p2sb | |
60 | * | |
61 | * This device can be hidden from the PCI bus if needed. This method | |
62 | * can be called before the p2sb is probed. | |
63 | * | |
64 | * @dev: P2SB device | |
65 | * @hide: true to hide the device, false to show it | |
66 | * @return 0 if OK, -ve on error | |
67 | */ | |
68 | int p2sb_set_hide(struct udevice *dev, bool hide); | |
69 | ||
5bee27aa SG |
70 | /** |
71 | * pcr_read32/16/8() - Read from a PCR device | |
72 | * | |
73 | * Reads data from a PCR device within the P2SB | |
74 | * | |
75 | * @dev: Device to read from | |
76 | * @offset: Offset within device to read | |
77 | * @return value read | |
78 | */ | |
79 | uint pcr_read32(struct udevice *dev, uint offset); | |
80 | uint pcr_read16(struct udevice *dev, uint offset); | |
81 | uint pcr_read8(struct udevice *dev, uint offset); | |
82 | ||
83 | /** | |
84 | * pcr_read32/16/8() - Write to a PCR device | |
85 | * | |
86 | * Writes data to a PCR device within the P2SB | |
87 | * | |
88 | * @dev: Device to write to | |
89 | * @offset: Offset within device to write | |
90 | * @data: Data to write | |
91 | */ | |
92 | void pcr_write32(struct udevice *dev, uint offset, uint data); | |
93 | void pcr_write16(struct udevice *dev, uint offset, uint data); | |
94 | void pcr_write8(struct udevice *dev, uint offset, uint data); | |
95 | ||
96 | /** | |
97 | * pcr_clrsetbits32/16/8() - Update a PCR device | |
98 | * | |
99 | * Updates dat in a PCR device within the P2SB | |
100 | * | |
101 | * This reads from the device, clears and set bits, then writes back. | |
102 | * | |
103 | * new_data = (old_data & ~clr) | set | |
104 | * | |
105 | * @dev: Device to update | |
106 | * @offset: Offset within device to update | |
107 | * @clr: Bits to clear after reading | |
108 | * @set: Bits to set before writing | |
109 | */ | |
110 | void pcr_clrsetbits32(struct udevice *dev, uint offset, uint clr, uint set); | |
111 | void pcr_clrsetbits16(struct udevice *dev, uint offset, uint clr, uint set); | |
112 | void pcr_clrsetbits8(struct udevice *dev, uint offset, uint clr, uint set); | |
113 | ||
114 | static inline void pcr_setbits32(struct udevice *dev, uint offset, uint set) | |
115 | { | |
116 | return pcr_clrsetbits32(dev, offset, 0, set); | |
117 | } | |
118 | ||
119 | static inline void pcr_setbits16(struct udevice *dev, uint offset, uint set) | |
120 | { | |
121 | return pcr_clrsetbits16(dev, offset, 0, set); | |
122 | } | |
123 | ||
124 | static inline void pcr_setbits8(struct udevice *dev, uint offset, uint set) | |
125 | { | |
126 | return pcr_clrsetbits8(dev, offset, 0, set); | |
127 | } | |
128 | ||
129 | static inline void pcr_clrbits32(struct udevice *dev, uint offset, uint clr) | |
130 | { | |
131 | return pcr_clrsetbits32(dev, offset, clr, 0); | |
132 | } | |
133 | ||
134 | static inline void pcr_clrbits16(struct udevice *dev, uint offset, uint clr) | |
135 | { | |
136 | return pcr_clrsetbits16(dev, offset, clr, 0); | |
137 | } | |
138 | ||
139 | static inline void pcr_clrbits8(struct udevice *dev, uint offset, uint clr) | |
140 | { | |
141 | return pcr_clrsetbits8(dev, offset, clr, 0); | |
142 | } | |
143 | ||
144 | /** | |
145 | * p2sb_set_port_id() - Set the port ID for a p2sb child device | |
146 | * | |
147 | * This must be called in a device's bind() method when OF_PLATDATA is used | |
148 | * since the uclass cannot access the device's of-platdata. | |
149 | * | |
150 | * @dev: Child device (whose parent is UCLASS_P2SB) | |
151 | * @portid: Port ID of child device | |
152 | * @return 0 if OK, -ENODEV is the p2sb device could not be found | |
153 | */ | |
154 | int p2sb_set_port_id(struct udevice *dev, int portid); | |
155 | ||
156 | /** | |
157 | * p2sb_get_port_id() - Get the port ID for a p2sb child device | |
158 | * | |
159 | * @dev: Child device (whose parent is UCLASS_P2SB) | |
160 | * @return Port ID of that child | |
161 | */ | |
162 | int p2sb_get_port_id(struct udevice *dev); | |
163 | ||
4916f458 SG |
164 | /** |
165 | * pcr_reg_address() Convert an offset in p2sb space to an absolute address | |
166 | * | |
167 | * @dev: Child device (whose parent is UCLASS_P2SB) | |
168 | * @offset: Offset within that child's address space | |
169 | * @return pointer to that offset within the child's address space | |
170 | */ | |
171 | void *pcr_reg_address(struct udevice *dev, uint offset); | |
172 | ||
022256b9 SG |
173 | #endif /* !__ACPI__ */ |
174 | ||
5bee27aa | 175 | #endif |