blob: ddbc8d5e14d87485c9b78b380e300d86d8653467 [file] [log] [blame]
Simon Glass5bee27a2019-12-06 21:41:55 -07001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright 2019 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
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
Simon Glass022256b2020-09-22 12:45:18 -060013#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
Simon Glass5bee27a2019-12-06 21:41:55 -070019/**
Simon Glass8a8d24b2020-12-03 16:55:23 -070020 * struct p2sb_child_plat - Information about each child of a p2sb device
Simon Glass5bee27a2019-12-06 21:41:55 -070021 *
22 * @pid: Port ID for this child
23 */
Simon Glass8a8d24b2020-12-03 16:55:23 -070024struct p2sb_child_plat {
Simon Glass5bee27a2019-12-06 21:41:55 -070025 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 */
35struct p2sb_uc_priv {
36 uint mmio_base;
37};
38
39/**
Simon Glass6d349e22020-07-07 21:32:30 -060040 * struct p2sb_ops - Operations for the P2SB
Simon Glass5bee27a2019-12-06 21:41:55 -070041 */
42struct p2sb_ops {
Simon Glass6d349e22020-07-07 21:32:30 -060043 /**
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);
Simon Glass5bee27a2019-12-06 21:41:55 -070054};
55
56#define p2sb_get_ops(dev) ((struct p2sb_ops *)(dev)->driver->ops)
57
58/**
Simon Glass6d349e22020-07-07 21:32:30 -060059 * 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 */
68int p2sb_set_hide(struct udevice *dev, bool hide);
69
70/**
Simon Glass5bee27a2019-12-06 21:41:55 -070071 * 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 */
79uint pcr_read32(struct udevice *dev, uint offset);
80uint pcr_read16(struct udevice *dev, uint offset);
81uint 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 */
92void pcr_write32(struct udevice *dev, uint offset, uint data);
93void pcr_write16(struct udevice *dev, uint offset, uint data);
94void 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 */
110void pcr_clrsetbits32(struct udevice *dev, uint offset, uint clr, uint set);
111void pcr_clrsetbits16(struct udevice *dev, uint offset, uint clr, uint set);
112void pcr_clrsetbits8(struct udevice *dev, uint offset, uint clr, uint set);
113
114static inline void pcr_setbits32(struct udevice *dev, uint offset, uint set)
115{
116 return pcr_clrsetbits32(dev, offset, 0, set);
117}
118
119static inline void pcr_setbits16(struct udevice *dev, uint offset, uint set)
120{
121 return pcr_clrsetbits16(dev, offset, 0, set);
122}
123
124static inline void pcr_setbits8(struct udevice *dev, uint offset, uint set)
125{
126 return pcr_clrsetbits8(dev, offset, 0, set);
127}
128
129static inline void pcr_clrbits32(struct udevice *dev, uint offset, uint clr)
130{
131 return pcr_clrsetbits32(dev, offset, clr, 0);
132}
133
134static inline void pcr_clrbits16(struct udevice *dev, uint offset, uint clr)
135{
136 return pcr_clrsetbits16(dev, offset, clr, 0);
137}
138
139static 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 */
154int 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 */
162int p2sb_get_port_id(struct udevice *dev);
163
Simon Glass4916f452020-07-07 21:32:19 -0600164/**
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 */
171void *pcr_reg_address(struct udevice *dev, uint offset);
172
Simon Glass022256b2020-09-22 12:45:18 -0600173#endif /* !__ACPI__ */
174
Simon Glass5bee27a2019-12-06 21:41:55 -0700175#endif