]> git.ipfire.org Git - thirdparty/u-boot.git/blame - include/p2sb.h
configs: at91: sama7g54_curiosity: Add initial default configs
[thirdparty/u-boot.git] / include / p2sb.h
CommitLineData
5bee27aa
SG
1/* 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
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 24struct 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 */
35struct p2sb_uc_priv {
36 uint mmio_base;
37};
38
39/**
6d349e2e 40 * struct p2sb_ops - Operations for the P2SB
5bee27aa
SG
41 */
42struct 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
185f812c 66 * Return: 0 if OK, -ve on error
6d349e2e
SG
67 */
68int 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
185f812c 77 * Return: value read
5bee27aa
SG
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
185f812c 152 * Return: 0 if OK, -ENODEV is the p2sb device could not be found
5bee27aa
SG
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)
185f812c 160 * Return: Port ID of that child
5bee27aa
SG
161 */
162int 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
185f812c 169 * Return: pointer to that offset within the child's address space
4916f458
SG
170 */
171void *pcr_reg_address(struct udevice *dev, uint offset);
172
022256b9
SG
173#endif /* !__ACPI__ */
174
5bee27aa 175#endif