1 /* SPDX-License-Identifier: GPL-2.0-only */
14 #if defined(__GLIBC__)
19 #if defined(__sun) && (defined(__i386) || defined(__amd64))
20 #define MEM_DEV "/dev/xsvc"
22 #define MEM_DEV "/dev/mem"
25 #define BUC_OFFSET 0x3414
26 #define GCS_OFFSET 0x3410
33 DESCRIPTOR_MAP_SECTION
= 0,
41 BUCTS_UNINITIALIZED
= -1,
46 static int fd_mem
= -1;
48 static void print_usage(const char *name
)
50 printf("usage: %s [-h?]\n", name
);
52 " -s | --set: Set the top swap bit to invert the bootblock region decoding\n"
53 " -u | --unset: Unset the top swap bit to have regular bootblock region decoding\n"
54 " -p | --print: print the current status of the hardware\n"
55 " -h | --help: print this help\n"
59 static void *sys_physmap(unsigned long phys_addr
, size_t len
)
62 mmap(0, len
, PROT_WRITE
| PROT_READ
, MAP_SHARED
, fd_mem
,
64 return virt_addr
== MAP_FAILED
? NULL
: virt_addr
;
67 static void physunmap(void *virt_addr
, size_t len
)
70 printf("Not unmapping zero size at %p\n", virt_addr
);
73 munmap(virt_addr
, len
);
76 static void *physmap(const char *descr
, unsigned long phys_addr
, size_t len
)
84 printf("Not mapping %s, zero size at 0x%08lx.\n", descr
,
89 if ((getpagesize() - 1) & len
)
90 fprintf(stderr
, "Unaligned size 0x%lx for %s at 0x%08lx!\n",
91 (unsigned long)len
, descr
, phys_addr
);
93 if ((getpagesize() - 1) & phys_addr
)
94 fprintf(stderr
, "Unaligned address 0x%08lx for %s!\n",
97 virt_addr
= sys_physmap(phys_addr
, len
);
99 fprintf(stderr
, "Error accessing 0x%lx bytes %s at 0x%08lx!\n",
100 (unsigned long)len
, descr
, phys_addr
);
101 perror("mmap(" MEM_DEV
")");
102 if (errno
== EINVAL
) {
103 fprintf(stderr
, "\n");
105 "In Linux this error can be caused by the CONFIG_NONPROMISC_DEVMEM (<2.6.27),\n");
107 "CONFIG_STRICT_DEVMEM (>=2.6.27) and CONFIG_X86_PAT kernel options.\n");
109 "Please check if either is enabled in your kernel before reporting a failure.\n");
111 "You can override CONFIG_X86_PAT at boot with the nopat kernel parameter but\n");
113 "disabling the other option unfortunately requires a kernel recompile. Sorry!\n");
120 static int get_platform_info(struct pci_dev
*sb
, int *has_var_bb
,
124 switch (sb
->device_id
) {
125 case 0x1c44: /* Z68 */
126 case 0x1c46: /* P67 */
127 case 0x1c47: /* UM67 */
128 case 0x1c49: /* HM68 */
129 case 0x1c4a: /* H67 */
130 case 0x1c4b: /* HM67 */
131 case 0x1c4c: /* Q65 */
132 case 0x1c4d: /* QS67 */
133 case 0x1c4e: /* Q67 */
134 case 0x1c4f: /* QM67 */
135 case 0x1c50: /* B65 */
136 case 0x1c52: /* C202 */
137 case 0x1c54: /* C204 */
138 case 0x1c56: /* C026 */
139 case 0x1c5c: /* H61 */
140 case 0x1d40: /* C60x/X79 */
141 case 0x1c41: /* C60x/X79 */
142 case 0x1e44: /* Z77 */
143 case 0x1e46: /* Z75 */
144 case 0x1e47: /* Q77 */
145 case 0x1e48: /* Q75 */
146 case 0x1e49: /* B75 */
147 case 0x1e4a: /* H77 */
148 case 0x1e53: /* C216 */
149 case 0x1e55: /* QM77 */
150 case 0x1e56: /* QS77 */
151 case 0x1e57: /* HM77 */
152 case 0x1e58: /* UM77 */
153 case 0x1e59: /* HM76 */
154 case 0x1e5d: /* HM75 */
155 case 0x1e5e: /* HM70 */
156 case 0x1e5f: /* NM70 */
157 case 0x3b02: /* P55 */
158 case 0x3b03: /* PM55 */
159 case 0x3b06: /* H55 */
160 case 0x3b07: /* QM55 */
161 case 0x3b08: /* H57 */
162 case 0x3b09: /* HM55 */
163 case 0x3b0a: /* Q57 */
164 case 0x3b0b: /* HM57 */
165 case 0x3b0d: /* PCH 3400 Mobile SFF */
166 case 0x3b0e: /* B55 */
167 case 0x3b0f: /* QS57 */
168 case 0x3b12: /* PCH 3400 */
169 case 0x3b14: /* PCH 3420 */
170 case 0x3b16: /* PCH 3450 */
171 case 0x3b1e: /* B55 */
172 case 0x8c40: /* Lynx Point */
173 case 0x8c41: /* Lynx Point Mobile Eng. Sample */
174 case 0x8c42: /* Lynx Point Desktop Eng. Sample */
175 case 0x8c43: /* Lynx Point */
176 case 0x8c44: /* Z87 */
177 case 0x8c45: /* Lynx Point */
180 case 0x2640: /* ICH6/ICH6R */
181 case 0x2641: /* ICH6-M */
182 case 0x2642: /* ICH6W/ICH6RW */
183 case 0x2670: /* 631xESB/632xESB/3100 */
184 case 0x27b0: /* ICH7DH */
185 case 0x27b8: /* ICH7/ICH7R */
186 case 0x27b9: /* ICH7M */
187 case 0x27bd: /* ICH7MDH */
188 case 0x27bc: /* NM10 */
189 case 0x2810: /* ICH8/ICH8R */
190 case 0x2811: /* ICH8M-E */
191 case 0x2812: /* ICH8DH */
192 case 0x2814: /* ICH8DO */
193 case 0x2815: /* ICH8M */
194 case 0x2910: /* ICH9 Eng. Sample */
195 case 0x2912: /* ICH9DH */
196 case 0x2914: /* ICH9DO */
197 case 0x2916: /* ICH9R */
198 case 0x2917: /* ICH9M-E */
199 case 0x2918: /* ICH9 */
200 case 0x2919: /* ICH9M */
201 case 0x3a10: /* ICH10R Eng. Sample */
202 case 0x3a14: /* ICH10D0 */
203 case 0x3a16: /* ICH10R */
204 case 0x3a18: /* ICH10 */
205 case 0x3a1a: /* ICH10D */
206 case 0x3a1e: /* ICH10 Eng. Sample*/
207 case 0x3b00: /* PCH 3400 Desktop */
208 case 0x3b01: /* PCH 3400 Mobile */
209 *rcba_addr
= pci_read_long(sb
, 0xf0) & ~1;
212 fprintf(stderr
, "Unsupported LPC bridge. Sorry.\n");
217 int print_status(uint32_t rcba_addr
, int has_var_bb
)
220 volatile uint8_t *rcba
;
221 int bild
, ts
, ts_size
= 64 << 10;
222 rcba
= physmap("RCBA", rcba_addr
, 0x4000);
226 bild
= rcba
[GCS_OFFSET
] & 1;
227 ts
= rcba
[BUC_OFFSET
] & 1;
228 int spi_is_bootdevice
=
229 ((*(uint16_t *)(rcba
+ GCS_OFFSET
) >> 10) & 3) == 3;
231 if (has_var_bb
&& spi_is_bootdevice
) {
232 *(uint32_t *)(rcba
+ SPIBAR
+ FDOC
) =
233 (PCHSTRAPS_SECTION
<< 12) | 0;
234 uint32_t pchstrap0
= *(uint32_t *)(rcba
+ SPIBAR
+ FDOD
);
235 switch (pchstrap0
>> 29) {
246 printf("Unknown BIOS Boot-Block size (BBBS)\n");
252 printf("\nSystem status\n=============\n");
253 printf("BILD (BIOS Interface Lock-Down) : %s\n", bild
254 ? "set, changing top swap not possible" : "unset, changing top swap is possible");
255 printf("Top Swap : %s\n", ts
? "Enabled" : "Disabled");
256 printf("BIOS Boot-block Size (BBDS) : %dK\n", ts_size
>> 10);
258 printf("Ranges swapped : 0x%llx-0x%08llx <-> 0x%08llx-0x%08llx",
259 ((4ULL << 30) - ts_size
),
261 (4ULL << 30) - 2 * ts_size
,
262 (4ULL << 30) - ts_size
- 1);
266 physunmap((void *)rcba
, 0x4000);
270 static int set_bucts(uint32_t rcba_addr
, int bucts_state
)
273 volatile uint8_t *rcba
;
275 rcba
= physmap("RCBA", rcba_addr
, 0x4000);
279 bild
= rcba
[GCS_OFFSET
] & 1;
281 printf("BIOS Interface Lock-Down set, Changing Top Swap not possible.\n");
287 rcba
[BUC_OFFSET
] = bucts_state
& 1;
288 if ((rcba
[BUC_OFFSET
] & 1) != bucts_state
) {
289 fprintf(stderr
, "Hu?! setting the top swap bit failed!\n");
292 printf("Setting top swap bit succeeded.\n");
297 physunmap((void *)rcba
, 0x4000);
301 int main(int argc
, char *argv
[])
303 struct pci_access
*pacc
;
304 struct pci_dev
*dev
, *sb
= NULL
;
305 #if defined(__FreeBSD__)
308 int opt
, option_index
= 0;
310 int bucts_state
= BUCTS_UNINITIALIZED
;
312 static struct option long_options
[] = {
313 {"unset", 0, 0, 'u'},
315 {"print", 0, 0, 'p'},
321 printf("bucts utility version '" VERSION
"'\n");
323 if (argv
[1] == NULL
) {
324 print_usage(argv
[0]);
328 while ((opt
= getopt_long(argc
, argv
, "usph?:",
329 long_options
, &option_index
)) != EOF
) {
332 if (bucts_state
!= BUCTS_UNINITIALIZED
) {
333 printf("Invalid setting: multiple set/unset arguments\n");
337 printf("Print and Set are mutually exclusive!\n");
340 bucts_state
= BUCTS_UNSET
;
343 if (bucts_state
!= BUCTS_UNINITIALIZED
) {
344 printf("Invalid setting: multiple set/unset arguments\n");
348 printf("Print and Set are mutually exclusive!\n");
351 bucts_state
= BUCTS_SET
;
354 if (bucts_state
!= BUCTS_UNINITIALIZED
) {
355 printf("Print and Set are mutually exclusive!\n");
361 print_usage(argv
[0]);
365 print_usage(argv
[0]);
371 fprintf(stderr
, "Error: Extra parameter found.\n");
372 print_usage(argv
[0]);
377 #if defined(__FreeBSD__)
378 if ((io_fd
= open("/dev/io", O_RDWR
)) < 0) {
379 perror("open(/dev/io)");
384 printf("You need to be root.\n");
388 if ((fd_mem
= open(MEM_DEV
, O_RDWR
| O_SYNC
)) == -1) {
389 perror("Error: open(" MEM_DEV
")");
396 for (dev
= pacc
->devices
; dev
&& !sb
; dev
= dev
->next
) {
397 pci_fill_info(dev
, PCI_FILL_IDENT
| PCI_FILL_CLASS
);
398 if (dev
->vendor_id
!= 0x8086 || dev
->device_class
!= 0x0601)
403 fprintf(stderr
, "Error: LPC bridge not found!\n");
407 printf("Using LPC bridge %04x:%04x at %02x%02x:%02x.%02x\n",
408 sb
->vendor_id
, sb
->device_id
, sb
->domain
, sb
->bus
, sb
->dev
,
414 if (get_platform_info(sb
, &has_var_bb
, &rcba_addr
))
418 print_status(rcba_addr
, has_var_bb
);
419 if (bucts_state
!= BUCTS_UNINITIALIZED
) {
420 set_bucts(rcba_addr
, bucts_state
);
421 print_status(rcba_addr
, has_var_bb
);