]> Git Repo - u-boot.git/blob - test/dm/acpigen.c
acpi: Support writing Device Properties objects via _DSD
[u-boot.git] / test / dm / acpigen.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Tests for ACPI code generation
4  *
5  * Copyright 2019 Google LLC
6  * Written by Simon Glass <[email protected]>
7  */
8
9 #include <common.h>
10 #include <dm.h>
11 #include <irq.h>
12 #include <malloc.h>
13 #include <acpi/acpigen.h>
14 #include <acpi/acpi_device.h>
15 #include <asm/gpio.h>
16 #include <asm/unaligned.h>
17 #include <dm/acpi.h>
18 #include <dm/test.h>
19 #include <dm/uclass-internal.h>
20 #include <test/ut.h>
21 #include "acpi.h"
22
23 /* Maximum size of the ACPI context needed for most tests */
24 #define ACPI_CONTEXT_SIZE       150
25
26 #define TEST_STRING     "frogmore"
27 #define TEST_STRING2    "ranch"
28 #define TEST_STREAM2    "\xfa\xde"
29
30 #define TEST_INT8       0x7d
31 #define TEST_INT16      0x2345
32 #define TEST_INT32      0x12345678
33 #define TEST_INT64      0x4567890123456
34
35 int acpi_test_alloc_context_size(struct acpi_ctx **ctxp, int size)
36 {
37         struct acpi_ctx *ctx;
38
39         *ctxp = NULL;
40         ctx = malloc(sizeof(*ctx));
41         if (!ctx)
42                 return -ENOMEM;
43         ctx->base = malloc(size);
44         if (!ctx->base) {
45                 free(ctx);
46                 return -ENOMEM;
47         }
48         ctx->ltop = 0;
49         ctx->current = ctx->base;
50         *ctxp = ctx;
51
52         return 0;
53 }
54
55 int acpi_test_get_length(u8 *ptr)
56 {
57         if (!(*ptr & 0x80))
58                 return -EINVAL;
59
60         return (*ptr & 0xf) | ptr[1] << 4 | ptr[2] << 12;
61 }
62
63 static int alloc_context(struct acpi_ctx **ctxp)
64 {
65         return acpi_test_alloc_context_size(ctxp, ACPI_CONTEXT_SIZE);
66 }
67
68 static void free_context(struct acpi_ctx **ctxp)
69 {
70         free((*ctxp)->base);
71         free(*ctxp);
72         *ctxp = NULL;
73 }
74
75 /* Test emitting simple types and acpigen_get_current() */
76 static int dm_test_acpi_emit_simple(struct unit_test_state *uts)
77 {
78         struct acpi_ctx *ctx;
79         u8 *ptr;
80
81         ut_assertok(alloc_context(&ctx));
82
83         ptr = acpigen_get_current(ctx);
84         acpigen_emit_byte(ctx, 0x23);
85         ut_asserteq(1, acpigen_get_current(ctx) - ptr);
86         ut_asserteq(0x23, *(u8 *)ptr);
87
88         acpigen_emit_word(ctx, 0x1234);
89         ut_asserteq(3, acpigen_get_current(ctx) - ptr);
90         ut_asserteq(0x1234, get_unaligned((u16 *)(ptr + 1)));
91
92         acpigen_emit_dword(ctx, 0x87654321);
93         ut_asserteq(7, acpigen_get_current(ctx) - ptr);
94         ut_asserteq(0x87654321, get_unaligned((u32 *)(ptr + 3)));
95
96         free_context(&ctx);
97
98         return 0;
99 }
100 DM_TEST(dm_test_acpi_emit_simple, 0);
101
102 /* Test emitting a stream */
103 static int dm_test_acpi_emit_stream(struct unit_test_state *uts)
104 {
105         struct acpi_ctx *ctx;
106         u8 *ptr;
107
108         ut_assertok(alloc_context(&ctx));
109
110         ptr = acpigen_get_current(ctx);
111         acpigen_emit_stream(ctx, TEST_STREAM2, 2);
112         ut_asserteq(2, acpigen_get_current(ctx) - ptr);
113         ut_asserteq((u8)TEST_STREAM2[0], ptr[0]);
114         ut_asserteq((u8)TEST_STREAM2[1], ptr[1]);
115
116         free_context(&ctx);
117
118         return 0;
119 }
120 DM_TEST(dm_test_acpi_emit_stream, 0);
121
122 /* Test emitting a string */
123 static int dm_test_acpi_emit_string(struct unit_test_state *uts)
124 {
125         struct acpi_ctx *ctx;
126         u8 *ptr;
127
128         ut_assertok(alloc_context(&ctx));
129
130         ptr = acpigen_get_current(ctx);
131         acpigen_emit_string(ctx, TEST_STRING);
132         ut_asserteq(sizeof(TEST_STRING), acpigen_get_current(ctx) - ptr);
133         ut_asserteq_str(TEST_STRING, (char *)ptr);
134
135         free_context(&ctx);
136
137         return 0;
138 }
139 DM_TEST(dm_test_acpi_emit_string, 0);
140
141 /* Test emitting an interrupt descriptor */
142 static int dm_test_acpi_interrupt(struct unit_test_state *uts)
143 {
144         struct acpi_ctx *ctx;
145         struct udevice *dev;
146         struct irq irq;
147         u8 *ptr;
148
149         ut_assertok(alloc_context(&ctx));
150
151         ptr = acpigen_get_current(ctx);
152
153         ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev));
154         ut_assertok(irq_get_by_index(dev, 0, &irq));
155
156         /* See a-test, property interrupts-extended in the device tree */
157         ut_asserteq(3, acpi_device_write_interrupt_irq(ctx, &irq));
158         ut_asserteq(9, acpigen_get_current(ctx) - ptr);
159         ut_asserteq(ACPI_DESCRIPTOR_INTERRUPT, ptr[0]);
160         ut_asserteq(6, get_unaligned((u16 *)(ptr + 1)));
161         ut_asserteq(0x19, ptr[3]);
162         ut_asserteq(1, ptr[4]);
163         ut_asserteq(3, get_unaligned((u32 *)(ptr + 5)));
164
165         free_context(&ctx);
166
167         return 0;
168 }
169 DM_TEST(dm_test_acpi_interrupt, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
170
171 /* Test emitting a GPIO descriptor */
172 static int dm_test_acpi_gpio(struct unit_test_state *uts)
173 {
174         struct gpio_desc desc;
175         struct acpi_ctx *ctx;
176         struct udevice *dev;
177         u8 *ptr;
178
179         ut_assertok(alloc_context(&ctx));
180
181         ptr = acpigen_get_current(ctx);
182
183         ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev));
184         ut_asserteq_str("a-test", dev->name);
185         ut_assertok(gpio_request_by_name(dev, "test-gpios", 1, &desc, 0));
186
187         /* This should write GPIO pin 4 (see device tree test.dts ) */
188         ut_asserteq(4, acpi_device_write_gpio_desc(ctx, &desc));
189         ut_asserteq(35, acpigen_get_current(ctx) - ptr);
190         ut_asserteq(ACPI_DESCRIPTOR_GPIO, ptr[0]);
191         ut_asserteq(32, get_unaligned((u16 *)(ptr + 1)));
192         ut_asserteq(ACPI_GPIO_REVISION_ID, ptr[3]);
193         ut_asserteq(ACPI_GPIO_TYPE_IO, ptr[4]);
194         ut_asserteq(1, get_unaligned((u16 *)(ptr + 5)));
195         ut_asserteq(9, get_unaligned((u16 *)(ptr + 7)));
196         ut_asserteq(ACPI_GPIO_PULL_UP, ptr[9]);
197         ut_asserteq(1234, get_unaligned((u16 *)(ptr + 10)));
198         ut_asserteq(0, get_unaligned((u16 *)(ptr + 12)));
199         ut_asserteq(23, get_unaligned((u16 *)(ptr + 14)));
200         ut_asserteq(0, ptr[16]);
201         ut_asserteq(25, get_unaligned((u16 *)(ptr + 17)));
202         ut_asserteq(35, get_unaligned((u16 *)(ptr + 19)));
203         ut_asserteq(0, get_unaligned((u16 *)(ptr + 21)));
204
205         /* pin0 */
206         ut_asserteq(4, get_unaligned((u16 *)(ptr + 23)));
207
208         ut_asserteq_str("\\_SB.PINC", (char *)ptr + 25);
209
210         free_context(&ctx);
211
212         return 0;
213 }
214 DM_TEST(dm_test_acpi_gpio, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
215
216 /* Test emitting a GPIO descriptor with an interrupt */
217 static int dm_test_acpi_gpio_irq(struct unit_test_state *uts)
218 {
219         struct gpio_desc desc;
220         struct acpi_ctx *ctx;
221         struct udevice *dev;
222         u8 *ptr;
223
224         ut_assertok(alloc_context(&ctx));
225
226         ptr = acpigen_get_current(ctx);
227
228         ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev));
229         ut_asserteq_str("a-test", dev->name);
230         ut_assertok(gpio_request_by_name(dev, "test2-gpios", 2, &desc, 0));
231
232         /* This should write GPIO pin 6 (see device tree test.dts ) */
233         ut_asserteq(6, acpi_device_write_gpio_desc(ctx, &desc));
234         ut_asserteq(35, acpigen_get_current(ctx) - ptr);
235         ut_asserteq(ACPI_DESCRIPTOR_GPIO, ptr[0]);
236         ut_asserteq(32, get_unaligned((u16 *)(ptr + 1)));
237         ut_asserteq(ACPI_GPIO_REVISION_ID, ptr[3]);
238         ut_asserteq(ACPI_GPIO_TYPE_INTERRUPT, ptr[4]);
239         ut_asserteq(1, get_unaligned((u16 *)(ptr + 5)));
240         ut_asserteq(29, get_unaligned((u16 *)(ptr + 7)));
241         ut_asserteq(ACPI_GPIO_PULL_DOWN, ptr[9]);
242         ut_asserteq(0, get_unaligned((u16 *)(ptr + 10)));
243         ut_asserteq(4321, get_unaligned((u16 *)(ptr + 12)));
244         ut_asserteq(23, get_unaligned((u16 *)(ptr + 14)));
245         ut_asserteq(0, ptr[16]);
246         ut_asserteq(25, get_unaligned((u16 *)(ptr + 17)));
247         ut_asserteq(35, get_unaligned((u16 *)(ptr + 19)));
248         ut_asserteq(0, get_unaligned((u16 *)(ptr + 21)));
249
250         /* pin0 */
251         ut_asserteq(6, get_unaligned((u16 *)(ptr + 23)));
252
253         ut_asserteq_str("\\_SB.PINC", (char *)ptr + 25);
254
255         free_context(&ctx);
256
257         return 0;
258 }
259 DM_TEST(dm_test_acpi_gpio_irq, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
260
261 /* Test emitting either a GPIO or interrupt descriptor */
262 static int dm_test_acpi_interrupt_or_gpio(struct unit_test_state *uts)
263 {
264         struct acpi_ctx *ctx;
265         struct udevice *dev;
266         u8 *ptr;
267
268         ut_assertok(alloc_context(&ctx));
269
270         ptr = acpigen_get_current(ctx);
271
272         /* This should produce an interrupt, even though it also has a GPIO */
273         ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev));
274         ut_asserteq_str("a-test", dev->name);
275         ut_asserteq(3, acpi_device_write_interrupt_or_gpio(ctx, dev,
276                                                            "test2-gpios"));
277         ut_asserteq(ACPI_DESCRIPTOR_INTERRUPT, ptr[0]);
278
279         /* This has no interrupt so should produce a GPIO */
280         ptr = ctx->current;
281         ut_assertok(uclass_find_first_device(UCLASS_PANEL_BACKLIGHT, &dev));
282         ut_asserteq(1, acpi_device_write_interrupt_or_gpio(ctx, dev,
283                                                            "enable-gpios"));
284         ut_asserteq(ACPI_DESCRIPTOR_GPIO, ptr[0]);
285
286         /* This one has neither */
287         ptr = acpigen_get_current(ctx);
288         ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 3, &dev));
289         ut_asserteq_str("b-test", dev->name);
290         ut_asserteq(-ENOENT,
291                     acpi_device_write_interrupt_or_gpio(ctx, dev,
292                                                         "enable-gpios"));
293
294         free_context(&ctx);
295
296         return 0;
297 }
298 DM_TEST(dm_test_acpi_interrupt_or_gpio,
299         DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
300
301 /* Test emitting an I2C descriptor */
302 static int dm_test_acpi_i2c(struct unit_test_state *uts)
303 {
304         struct acpi_ctx *ctx;
305         struct udevice *dev;
306         u8 *ptr;
307
308         ut_assertok(alloc_context(&ctx));
309
310         ptr = acpigen_get_current(ctx);
311
312         ut_assertok(uclass_get_device(UCLASS_RTC, 0, &dev));
313         ut_asserteq(0x43, acpi_device_write_i2c_dev(ctx, dev));
314         ut_asserteq(28, acpigen_get_current(ctx) - ptr);
315         ut_asserteq(ACPI_DESCRIPTOR_SERIAL_BUS, ptr[0]);
316         ut_asserteq(25, get_unaligned((u16 *)(ptr + 1)));
317         ut_asserteq(ACPI_I2C_SERIAL_BUS_REVISION_ID, ptr[3]);
318         ut_asserteq(0, ptr[4]);
319         ut_asserteq(ACPI_SERIAL_BUS_TYPE_I2C, ptr[5]);
320         ut_asserteq(0, get_unaligned((u16 *)(ptr + 7)));
321         ut_asserteq(ACPI_I2C_TYPE_SPECIFIC_REVISION_ID, ptr[9]);
322         ut_asserteq(6, get_unaligned((u16 *)(ptr + 10)));
323         ut_asserteq(100000, get_unaligned((u32 *)(ptr + 12)));
324         ut_asserteq(0x43, get_unaligned((u16 *)(ptr + 16)));
325         ut_asserteq_str("\\_SB.I2C0", (char *)ptr + 18);
326
327         free_context(&ctx);
328
329         return 0;
330 }
331 DM_TEST(dm_test_acpi_i2c, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
332
333 /* Test emitting a SPI descriptor */
334 static int dm_test_acpi_spi(struct unit_test_state *uts)
335 {
336         struct acpi_ctx *ctx;
337         struct udevice *dev;
338         u8 *ptr;
339
340         ut_assertok(alloc_context(&ctx));
341
342         ptr = acpigen_get_current(ctx);
343
344         ut_assertok(uclass_first_device_err(UCLASS_SPI_FLASH, &dev));
345         ut_assertok(acpi_device_write_spi_dev(ctx, dev));
346         ut_asserteq(31, acpigen_get_current(ctx) - ptr);
347         ut_asserteq(ACPI_DESCRIPTOR_SERIAL_BUS, ptr[0]);
348         ut_asserteq(28, get_unaligned((u16 *)(ptr + 1)));
349         ut_asserteq(ACPI_SPI_SERIAL_BUS_REVISION_ID, ptr[3]);
350         ut_asserteq(0, ptr[4]);
351         ut_asserteq(ACPI_SERIAL_BUS_TYPE_SPI, ptr[5]);
352         ut_asserteq(2, ptr[6]);
353         ut_asserteq(0, get_unaligned((u16 *)(ptr + 7)));
354         ut_asserteq(ACPI_SPI_TYPE_SPECIFIC_REVISION_ID, ptr[9]);
355         ut_asserteq(9, get_unaligned((u16 *)(ptr + 10)));
356         ut_asserteq(40000000, get_unaligned((u32 *)(ptr + 12)));
357         ut_asserteq(8, ptr[16]);
358         ut_asserteq(0, ptr[17]);
359         ut_asserteq(0, ptr[18]);
360         ut_asserteq(0, get_unaligned((u16 *)(ptr + 19)));
361         ut_asserteq_str("\\_SB.SPI0", (char *)ptr + 21);
362
363         free_context(&ctx);
364
365         return 0;
366 }
367 DM_TEST(dm_test_acpi_spi, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
368
369 /* Test emitting a length */
370 static int dm_test_acpi_len(struct unit_test_state *uts)
371 {
372         const int size = 0xc0000;
373         struct acpi_ctx *ctx;
374         u8 *ptr;
375         int i;
376
377         ut_assertok(acpi_test_alloc_context_size(&ctx, size));
378
379         ptr = acpigen_get_current(ctx);
380
381         /* Write a byte and a 3-byte length */
382         acpigen_write_len_f(ctx);
383         acpigen_emit_byte(ctx, 0x23);
384         acpigen_pop_len(ctx);
385         ut_asserteq(1 + 3, acpi_test_get_length(ptr));
386
387         /* Write 200 bytes so we need two length bytes */
388         ptr = ctx->current;
389         acpigen_write_len_f(ctx);
390         for (i = 0; i < 200; i++)
391                 acpigen_emit_byte(ctx, 0x23);
392         acpigen_pop_len(ctx);
393         ut_asserteq(200 + 3, acpi_test_get_length(ptr));
394
395         /* Write 40KB so we need three length bytes */
396         ptr = ctx->current;
397         acpigen_write_len_f(ctx);
398         for (i = 0; i < 40000; i++)
399                 acpigen_emit_byte(ctx, 0x23);
400         acpigen_pop_len(ctx);
401         ut_asserteq(40000 + 3, acpi_test_get_length(ptr));
402
403         free_context(&ctx);
404
405         return 0;
406 }
407 DM_TEST(dm_test_acpi_len, 0);
408
409 /* Test writing a package */
410 static int dm_test_acpi_package(struct unit_test_state *uts)
411 {
412         struct acpi_ctx *ctx;
413         char *num_elements;
414         u8 *ptr;
415
416         ut_assertok(alloc_context(&ctx));
417
418         ptr = acpigen_get_current(ctx);
419
420         num_elements = acpigen_write_package(ctx, 3);
421         ut_asserteq_ptr(num_elements, ptr + 4);
422
423         /* For ease of testing, just emit a byte, not valid package contents */
424         acpigen_emit_byte(ctx, 0x23);
425         acpigen_pop_len(ctx);
426         ut_asserteq(PACKAGE_OP, ptr[0]);
427         ut_asserteq(5, acpi_test_get_length(ptr + 1));
428         ut_asserteq(3, ptr[4]);
429
430         free_context(&ctx);
431
432         return 0;
433 }
434 DM_TEST(dm_test_acpi_package, 0);
435
436 /* Test writing an integer */
437 static int dm_test_acpi_integer(struct unit_test_state *uts)
438 {
439         struct acpi_ctx *ctx;
440         u8 *ptr;
441
442         ut_assertok(alloc_context(&ctx));
443
444         ptr = acpigen_get_current(ctx);
445
446         acpigen_write_integer(ctx, 0);
447         acpigen_write_integer(ctx, 1);
448         acpigen_write_integer(ctx, TEST_INT8);
449         acpigen_write_integer(ctx, TEST_INT16);
450         acpigen_write_integer(ctx, TEST_INT32);
451         acpigen_write_integer(ctx, TEST_INT64);
452
453         ut_asserteq(6 + 1 + 2 + 4 + 8, acpigen_get_current(ctx) - ptr);
454
455         ut_asserteq(ZERO_OP, ptr[0]);
456
457         ut_asserteq(ONE_OP, ptr[1]);
458
459         ut_asserteq(BYTE_PREFIX, ptr[2]);
460         ut_asserteq(TEST_INT8, ptr[3]);
461
462         ut_asserteq(WORD_PREFIX, ptr[4]);
463         ut_asserteq(TEST_INT16, get_unaligned((u16 *)(ptr + 5)));
464
465         ut_asserteq(DWORD_PREFIX, ptr[7]);
466         ut_asserteq(TEST_INT32, get_unaligned((u32 *)(ptr + 8)));
467
468         ut_asserteq(QWORD_PREFIX, ptr[12]);
469         ut_asserteq_64(TEST_INT64, get_unaligned((u64 *)(ptr + 13)));
470
471         free_context(&ctx);
472
473         return 0;
474 }
475 DM_TEST(dm_test_acpi_integer, 0);
476
477 /* Test writing a string */
478 static int dm_test_acpi_string(struct unit_test_state *uts)
479 {
480         struct acpi_ctx *ctx;
481         u8 *ptr;
482
483         ut_assertok(alloc_context(&ctx));
484
485         ptr = acpigen_get_current(ctx);
486
487         acpigen_write_string(ctx, TEST_STRING);
488         acpigen_write_string(ctx, TEST_STRING2);
489
490         ut_asserteq(2 + sizeof(TEST_STRING) + sizeof(TEST_STRING2),
491                     acpigen_get_current(ctx) - ptr);
492         ut_asserteq(STRING_PREFIX, ptr[0]);
493         ut_asserteq_str(TEST_STRING, (char *)ptr + 1);
494         ptr += 1 + sizeof(TEST_STRING);
495         ut_asserteq(STRING_PREFIX, ptr[0]);
496         ut_asserteq_str(TEST_STRING2, (char *)ptr + 1);
497
498         free_context(&ctx);
499
500         return 0;
501 }
502 DM_TEST(dm_test_acpi_string, 0);
503
504 /* Test writing a name */
505 static int dm_test_acpi_name(struct unit_test_state *uts)
506 {
507         struct acpi_ctx *ctx;
508         u8 *ptr;
509
510         ut_assertok(alloc_context(&ctx));
511
512         ptr = acpigen_get_current(ctx);
513
514         /*
515          * The names here are made up for testing the various cases. The
516          * grammar is in the ACPI spec 6.3 section 19.2.2
517          */
518         acpigen_write_name(ctx, "\\_SB");
519         acpigen_write_name(ctx, "\\_SB.I2C0");
520         acpigen_write_name(ctx, "\\_SB.I2C0.TPM2");
521         acpigen_write_name(ctx, "\\_SB.I2C0.TPM2.LONG");
522         acpigen_write_name(ctx, "^^^^SPI0.FLAS");
523         acpigen_write_name(ctx, "NN");
524         acpigen_write_name(ctx, "^AB.CD.D.EFG");
525         acpigen_write_name(ctx, "^^^^");
526         acpigen_write_name(ctx, "\\");
527         acpigen_write_name(ctx, "\\ABCD");
528
529         ut_asserteq(107, acpigen_get_current(ctx) - ptr);
530         ut_asserteq(NAME_OP, ptr[0]);
531         ut_asserteq_strn("\\_SB_", (char *)ptr + 1);
532         ptr += 6;
533
534         ut_asserteq(NAME_OP, ptr[0]);
535         ut_asserteq('\\', ptr[1]);
536         ut_asserteq(DUAL_NAME_PREFIX, ptr[2]);
537         ut_asserteq_strn("_SB_I2C0", (char *)ptr + 3);
538         ptr += 11;
539
540         ut_asserteq(NAME_OP, ptr[0]);
541         ut_asserteq('\\', ptr[1]);
542         ut_asserteq(MULTI_NAME_PREFIX, ptr[2]);
543         ut_asserteq(3, ptr[3]);
544         ut_asserteq_strn("_SB_I2C0TPM2", (char *)ptr + 4);
545         ptr += 16;
546
547         ut_asserteq(NAME_OP, ptr[0]);
548         ut_asserteq('\\', ptr[1]);
549         ut_asserteq(MULTI_NAME_PREFIX, ptr[2]);
550         ut_asserteq(4, ptr[3]);
551         ut_asserteq_strn("_SB_I2C0TPM2LONG", (char *)ptr + 4);
552         ptr += 20;
553
554         ut_asserteq(NAME_OP, ptr[0]);
555         ut_asserteq('^', ptr[1]);
556         ut_asserteq('^', ptr[2]);
557         ut_asserteq('^', ptr[3]);
558         ut_asserteq('^', ptr[4]);
559         ut_asserteq(DUAL_NAME_PREFIX, ptr[5]);
560         ut_asserteq_strn("SPI0FLAS", (char *)ptr + 6);
561         ptr += 14;
562
563         ut_asserteq(NAME_OP, ptr[0]);
564         ut_asserteq_strn("NN__", (char *)ptr + 1);
565         ptr += 5;
566
567         ut_asserteq(NAME_OP, ptr[0]);
568         ut_asserteq('^', ptr[1]);
569         ut_asserteq(MULTI_NAME_PREFIX, ptr[2]);
570         ut_asserteq(4, ptr[3]);
571         ut_asserteq_strn("AB__CD__D___EFG_", (char *)ptr + 4);
572         ptr += 20;
573
574         ut_asserteq(NAME_OP, ptr[0]);
575         ut_asserteq('^', ptr[1]);
576         ut_asserteq('^', ptr[2]);
577         ut_asserteq('^', ptr[3]);
578         ut_asserteq('^', ptr[4]);
579         ut_asserteq(ZERO_OP, ptr[5]);
580         ptr += 6;
581
582         ut_asserteq(NAME_OP, ptr[0]);
583         ut_asserteq('\\', ptr[1]);
584         ut_asserteq(ZERO_OP, ptr[2]);
585         ptr += 3;
586
587         ut_asserteq(NAME_OP, ptr[0]);
588         ut_asserteq_strn("\\ABCD", (char *)ptr + 1);
589         ptr += 5;
590
591         free_context(&ctx);
592
593         return 0;
594 }
595 DM_TEST(dm_test_acpi_name, 0);
596
597 /* Test writing a UUID */
598 static int dm_test_acpi_uuid(struct unit_test_state *uts)
599 {
600         struct acpi_ctx *ctx;
601         u8 *ptr;
602
603         ut_assertok(alloc_context(&ctx));
604
605         ptr = acpigen_get_current(ctx);
606
607         ut_assertok(acpigen_write_uuid(ctx,
608                                        "dbb8e3e6-5886-4ba6-8795-1319f52a966b"));
609         ut_asserteq(23, acpigen_get_current(ctx) - ptr);
610         ut_asserteq(BUFFER_OP, ptr[0]);
611         ut_asserteq(22, acpi_test_get_length(ptr + 1));
612         ut_asserteq(0xdbb8e3e6, get_unaligned((u32 *)(ptr + 7)));
613         ut_asserteq(0x5886, get_unaligned((u16 *)(ptr + 11)));
614         ut_asserteq(0x4ba6, get_unaligned((u16 *)(ptr + 13)));
615         ut_asserteq(0x9587, get_unaligned((u16 *)(ptr + 15)));
616         ut_asserteq(0x2af51913, get_unaligned((u32 *)(ptr + 17)));
617         ut_asserteq(0x6b96, get_unaligned((u16 *)(ptr + 21)));
618
619         /* Try a bad UUID */
620         ut_asserteq(-EINVAL,
621                     acpigen_write_uuid(ctx,
622                                        "dbb8e3e6-5886-4ba6x8795-1319f52a966b"));
623
624         free_context(&ctx);
625
626         return 0;
627 }
628 DM_TEST(dm_test_acpi_uuid, 0);
This page took 0.061381 seconds and 4 git commands to generate.