1 /******************************************************************************
2 *
3 * Module Name: oszephyr - Zephyr OSL
4 *
5 *****************************************************************************/
6
7 /******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2023, Intel Corp.
12 * All rights reserved.
13 *
14 * 2. License
15 *
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
20 *
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
27 *
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
36 *
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
39 *
40 * 3. Conditions
41 *
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
53 *
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
65 *
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
71 *
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
74 *
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
79 *
80 * 4. Disclaimer and Export Compliance
81 *
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
89 *
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
98 *
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
113 *
114 *****************************************************************************
115 *
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
118 *
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
121 * are met:
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
133 *
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145 *
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
149 *
150 *****************************************************************************/
151
152 #include "acpi.h"
153 #include "accommon.h"
154 #include "acapps.h"
155 #include "aslcompiler.h"
156 #include <zephyr/arch/x86/x86_acpi_osal.h>
157 #include <zephyr/drivers/pcie/pcie.h>
158 #include <zephyr/dt-bindings/interrupt-controller/intel-ioapic.h>
159 #include <zephyr/sys/__assert.h>
160
161 #include <zephyr/logging/log.h>
162 LOG_MODULE_DECLARE(acpica, LOG_LEVEL_ERR);
163
164 typedef void (*zephyr_irq_t)(const void *);
165
166 /* Global varibles use from acpica lib. */
167 BOOLEAN AslGbl_DoTemplates = FALSE;
168 BOOLEAN AslGbl_VerboseTemplates = FALSE;
169
170 char AslGbl_MsgBuffer[ASL_MSG_BUFFER_SIZE];
171 static BOOLEAN EnDbgPrint;
172 static ACPI_PHYSICAL_ADDRESS RsdpPhyAdd;
173
174 /******************************************************************************
175 *
176 * FUNCTION: AcpiOsReadable
177 *
178 * PARAMETERS: Pointer - Area to be verified
179 * Length - Size of area
180 *
181 * RETURN: TRUE if readable for entire Length
182 *
183 * DESCRIPTION: Verify that a pointer is valid for reading
184 *
185 *****************************************************************************/
186
187 BOOLEAN
AcpiOsReadable(void * Pointer,ACPI_SIZE Length)188 AcpiOsReadable (
189 void *Pointer,
190 ACPI_SIZE Length)
191 {
192 return (TRUE);
193 }
194
195
196 /******************************************************************************
197 *
198 * FUNCTION: AcpiEnableDbgPrint
199 *
200 * PARAMETERS: en, - Enable/Disable debug print
201 *
202 * RETURN: None
203 *
204 * DESCRIPTION: Formatted output
205 *
206 *****************************************************************************/
207
208 void
AcpiEnableDbgPrint(bool Enable)209 AcpiEnableDbgPrint (
210 bool Enable)
211 {
212 if (Enable)
213 {
214 EnDbgPrint = TRUE;
215 }
216 else
217 {
218 EnDbgPrint = FALSE;
219 }
220 }
221
222
223 /******************************************************************************
224 *
225 * FUNCTION: AcpiOsPrintf
226 *
227 * PARAMETERS: Fmt, ... - Standard printf format
228 *
229 * RETURN: None
230 *
231 * DESCRIPTION: Formatted output
232 *
233 *****************************************************************************/
234
235 void ACPI_INTERNAL_VAR_XFACE
AcpiOsPrintf(const char * Fmt,...)236 AcpiOsPrintf (
237 const char *Fmt,
238 ...)
239 {
240 va_list args;
241
242 va_start (args, Fmt);
243
244 if (EnDbgPrint)
245 {
246 vprintk (Fmt, args);
247 }
248
249 va_end (args);
250 }
251
252
253 /******************************************************************************
254 *
255 * FUNCTION: AcpiOsGetLine
256 *
257 * PARAMETERS: Buffer - Where to return the command line
258 * BufferLength - Maximum Length of Buffer
259 * BytesRead - Where the actual byte count is returned
260 *
261 * RETURN: Status and actual bytes read
262 *
263 * DESCRIPTION: Formatted input with argument list pointer
264 *
265 *****************************************************************************/
266
267 ACPI_STATUS
AcpiOsGetLine(char * Buffer,UINT32 BufferLength,UINT32 * BytesRead)268 AcpiOsGetLine (
269 char *Buffer,
270 UINT32 BufferLength,
271 UINT32 *BytesRead)
272 {
273 return (-1);
274 }
275
276
277 /******************************************************************************
278 *
279 * FUNCTION: AcpiOsAllocate
280 *
281 * PARAMETERS: Size - Amount to allocate, in bytes
282 *
283 * RETURN: Pointer to the new allocation. Null on error.
284 *
285 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
286 *
287 *****************************************************************************/
288
289 void *
AcpiOsAllocate(ACPI_SIZE Size)290 AcpiOsAllocate (
291 ACPI_SIZE Size)
292 {
293 return (k_malloc (Size));
294 }
295
296
297 #ifdef USE_NATIVE_ALLOCATE_ZEROED
298 /******************************************************************************
299 *
300 * FUNCTION: AcpiOsAllocateZeroed
301 *
302 * PARAMETERS: Size - Amount to allocate, in bytes
303 *
304 * RETURN: Pointer to the new allocation. Null on error.
305 *
306 * DESCRIPTION: Allocate and zero memory. Algorithm is dependent on the OS.
307 *
308 *****************************************************************************/
309
310 void *
AcpiOsAllocateZeroed(ACPI_SIZE Size)311 AcpiOsAllocateZeroed (
312 ACPI_SIZE Size)
313 {
314 void *mem;
315
316 mem = AcpiOsAllocate (Size);
317
318 if (mem)
319 {
320 memset (mem, 0, Size);
321 }
322
323 return (mem);
324 }
325 #endif
326
327
328 /******************************************************************************
329 *
330 * FUNCTION: AcpiOsFree
331 *
332 * PARAMETERS: Mem - Pointer to previously allocated memory
333 *
334 * RETURN: None.
335 *
336 * DESCRIPTION: Free memory allocated via AcpiOsAllocate
337 *
338 *****************************************************************************/
339
340 void
AcpiOsFree(void * Mem)341 AcpiOsFree (
342 void *Mem)
343 {
344 k_free (Mem);
345 }
346
347
348 /******************************************************************************
349 *
350 * FUNCTION: AcpiOsReadMemory
351 *
352 * PARAMETERS: Address - Physical Memory Address to read
353 * Value - Where Value is placed
354 * Width - Number of bits (8,16,32, or 64)
355 *
356 * RETURN: Value read from physical memory Address. Always returned
357 * as a 64-bit integer, regardless of the read Width.
358 *
359 * DESCRIPTION: Read data from a physical memory Address
360 *
361 *****************************************************************************/
362
363 ACPI_STATUS
AcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS Address,UINT64 * Value,UINT32 Width)364 AcpiOsReadMemory (
365 ACPI_PHYSICAL_ADDRESS Address,
366 UINT64 *Value,
367 UINT32 Width)
368 {
369 switch (Width)
370 {
371 case 8:
372
373 *((UINT8 *) Value) = sys_read8 (Address);
374 break;
375
376 case 16:
377
378 *((UINT16 *) Value) = sys_read16 (Address);
379 break;
380
381 case 32:
382
383 *((UINT32 *) Value) = sys_read32 (Address);
384 break;
385 #if defined(__x86_64__)
386 case 64:
387
388 *((UINT64 *) Value) = sys_read64 (Address);
389 break;
390 #endif
391 default:
392
393 return (AE_BAD_PARAMETER);
394 }
395
396 return (AE_OK);
397 }
398
399
400 /******************************************************************************
401 *
402 * FUNCTION: AcpiOsWriteMemory
403 *
404 * PARAMETERS: Address - Physical Memory Address to write
405 * Value - Value to write
406 * Width - Number of bits (8,16,32, or 64)
407 *
408 * RETURN: None
409 *
410 * DESCRIPTION: Write data to a physical memory Address
411 *
412 *****************************************************************************/
413
414 ACPI_STATUS
AcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS Address,UINT64 Value,UINT32 Width)415 AcpiOsWriteMemory (
416 ACPI_PHYSICAL_ADDRESS Address,
417 UINT64 Value,
418 UINT32 Width)
419 {
420 switch (Width)
421 {
422 case 8:
423
424 sys_write8 ((UINT8) Value, Address);
425 break;
426
427 case 16:
428
429 sys_write16 ((UINT16) Value, Address);
430 break;
431
432 case 32:
433
434 sys_write32 ((UINT32) Value, Address);
435 break;
436 #if defined(__x86_64__)
437 case 64:
438
439 sys_write64 ((UINT64) Value, Address);
440 break;
441 #endif
442 default:
443
444 return (AE_BAD_PARAMETER);
445 }
446
447 return (AE_OK);
448 }
449
450
451 /******************************************************************************
452 *
453 * FUNCTION: AcpiOsReadPort
454 *
455 * PARAMETERS: Address - Address of I/O port/register to read
456 * Value - Where Value is placed
457 * Width - Number of bits
458 *
459 * RETURN: Value read from port
460 *
461 * DESCRIPTION: Read data from an I/O port or register
462 *
463 *****************************************************************************/
464
465 ACPI_STATUS
AcpiOsReadPort(ACPI_IO_ADDRESS Address,UINT32 * Value,UINT32 Width)466 AcpiOsReadPort (
467 ACPI_IO_ADDRESS Address,
468 UINT32 *Value,
469 UINT32 Width)
470 {
471
472 switch (Width)
473 {
474 case 8:
475
476 *((UINT8 *) Value) = sys_in8 (Address);
477 break;
478
479 case 16:
480
481 *((UINT16 *) Value) = sys_in16 (Address);
482 break;
483
484 case 32:
485
486 *((UINT32 *) Value) = sys_in32 (Address);
487 break;
488
489 case 64:
490
491 *((UINT32 *) Value) = sys_in32 (Address);
492 *((UINT32 *) Value + 4) = sys_in32 (Address + 4);
493 break;
494
495 default:
496
497 return (AE_BAD_PARAMETER);
498 }
499
500 return (AE_OK);
501 }
502
503
504 /******************************************************************************
505 *
506 * FUNCTION: AcpiOsWritePort
507 *
508 * PARAMETERS: Address - Address of I/O port/register to write
509 * Value - Value to write
510 * Width - Number of bits
511 *
512 * RETURN: None
513 *
514 * DESCRIPTION: Write data to an I/O port or register
515 *
516 *****************************************************************************/
517
518 ACPI_STATUS
AcpiOsWritePort(ACPI_IO_ADDRESS Address,UINT32 Value,UINT32 Width)519 AcpiOsWritePort (
520 ACPI_IO_ADDRESS Address,
521 UINT32 Value,
522 UINT32 Width)
523 {
524
525 switch (Width)
526 {
527 case 8:
528
529 sys_out8 ((UINT8) Value, Address);
530 break;
531
532 case 16:
533
534 sys_out16 ((UINT16) Value, Address);
535 break;
536
537 case 32:
538
539 sys_out32 ((UINT32) Value, Address);
540 break;
541
542 case 64:
543
544 sys_out32 ((UINT32) Value, Address);
545 sys_out32 ((UINT32) (Value + 4), (Address + 4));
546 break;
547
548 default:
549
550 return (AE_BAD_PARAMETER);
551 }
552
553 return (AE_OK);
554 }
555
556
557 /******************************************************************************
558 *
559 * FUNCTION: AcpiOsWritePciConfiguration
560 *
561 * PARAMETERS: PciId - Seg/Bus/Dev
562 * Register - Device Register
563 * Value - Value to be written
564 * Width - Number of bits
565 *
566 * RETURN: Status
567 *
568 * DESCRIPTION: Write data to PCI configuration space
569 *
570 *****************************************************************************/
571
572 ACPI_STATUS
AcpiOsWritePciConfiguration(ACPI_PCI_ID * PciId,UINT32 Register,UINT64 Value,UINT32 Width)573 AcpiOsWritePciConfiguration (
574 ACPI_PCI_ID *PciId,
575 UINT32 Register,
576 UINT64 Value,
577 UINT32 Width)
578 {
579 UINT32 value32;
580 pcie_bdf_t bdf = PCIE_BDF (PciId->Bus, PciId->Device, PciId->Function);
581
582
583 switch (Width)
584 {
585 case 8:
586
587 value32 = pcie_conf_read (bdf, Register);
588 value32 = (value32 & 0xffffff00) | (UINT8) Value;
589 pcie_conf_write (bdf, Register, value32);
590 break;
591
592 case 16:
593
594 value32 = pcie_conf_read (bdf, Register);
595 value32 = (value32 & 0xffff0000) | (UINT16) Value;
596 pcie_conf_write (bdf, Register, value32);
597 break;
598
599 case 32:
600
601 pcie_conf_write (bdf, Register, (UINT32) Value);
602 break;
603
604 case 64:
605
606 pcie_conf_write (bdf, Register, (UINT32) Value);
607 pcie_conf_write (bdf, (Register + 4), (UINT32) (Value >> 32));
608 break;
609
610 default:
611
612 return (AE_BAD_PARAMETER);
613 }
614
615 return (AE_OK);
616 }
617
618
619 /******************************************************************************
620 *
621 * FUNCTION: AcpiOsReadPciConfiguration
622 *
623 * PARAMETERS: PciId - Seg/Bus/Dev
624 * Register - Device Register
625 * Value - Buffer Where Value is placed
626 * Width - Number of bits
627 *
628 * RETURN: Status
629 *
630 * DESCRIPTION: Read data from PCI configuration space
631 *
632 *****************************************************************************/
633
634 ACPI_STATUS
AcpiOsReadPciConfiguration(ACPI_PCI_ID * PciId,UINT32 Register,UINT64 * Value,UINT32 Width)635 AcpiOsReadPciConfiguration (
636 ACPI_PCI_ID *PciId,
637 UINT32 Register,
638 UINT64 *Value,
639 UINT32 Width)
640 {
641
642 pcie_bdf_t bdf = PCIE_BDF (PciId->Bus, PciId->Device, PciId->Function);
643
644 switch (Width)
645 {
646 case 8:
647
648 *((UINT8 *) Value) = (UINT8) pcie_conf_read (bdf, Register);
649 break;
650
651 case 16:
652
653 *((UINT16 *) Value) = (UINT16) pcie_conf_read (bdf, Register);
654 break;
655
656 case 32:
657
658 *((UINT32 *) Value) = (UINT32) pcie_conf_read (bdf, Register);
659 break;
660
661 case 64:
662
663 *((UINT32 *) Value) = (UINT32) pcie_conf_read (bdf, Register);
664 *((UINT32 *) Value + 1) = (UINT32) pcie_conf_read (bdf, (Register + 4));
665 break;
666
667 default:
668
669 return (AE_BAD_PARAMETER);
670 }
671
672 return (AE_OK);
673 }
674
675
676 /******************************************************************************
677 *
678 * FUNCTION: AcpiOsRedirectOutput
679 *
680 * PARAMETERS: Destination - An open file handle/pointer
681 *
682 * RETURN: None
683 *
684 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
685 *
686 *****************************************************************************/
687
688 void
AcpiOsRedirectOutput(void * Destination)689 AcpiOsRedirectOutput (
690 void *Destination)
691 {
692
693 }
694
695
696 /******************************************************************************
697 *
698 * FUNCTION: AcpiOsPredefinedOverride
699 *
700 * PARAMETERS: InitVal - Initial Value of the predefined object
701 * NewVal - The new Value for the object
702 *
703 * RETURN: Status, pointer to Value. Null pointer returned if not
704 * overriding.
705 *
706 * DESCRIPTION: Allow the OS to override predefined names
707 *
708 *****************************************************************************/
709
710 ACPI_STATUS
AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES * InitVal,ACPI_STRING * NewVal)711 AcpiOsPredefinedOverride (
712 const ACPI_PREDEFINED_NAMES *InitVal,
713 ACPI_STRING *NewVal)
714 {
715
716 if (!InitVal || !NewVal)
717 {
718 return (AE_BAD_PARAMETER);
719 }
720
721 *NewVal = NULL;
722
723 return (AE_OK);
724 }
725
726
727 /******************************************************************************
728 *
729 * FUNCTION: AcpiOsTableOverride
730 *
731 * PARAMETERS: ExistingTable - Header of current table (probably firmware)
732 * NewTable - Where an entire new table is returned.
733 *
734 * RETURN: Status, pointer to new table. Null pointer returned if no
735 * table is available to override
736 *
737 * DESCRIPTION: Return a different version of a table if one is available
738 *
739 *****************************************************************************/
740
741 ACPI_STATUS
AcpiOsTableOverride(ACPI_TABLE_HEADER * ExistingTable,ACPI_TABLE_HEADER ** NewTable)742 AcpiOsTableOverride (
743 ACPI_TABLE_HEADER *ExistingTable,
744 ACPI_TABLE_HEADER **NewTable)
745 {
746
747 if (!ExistingTable || !NewTable)
748 {
749 return (AE_BAD_PARAMETER);
750 }
751
752 *NewTable = NULL;
753
754 return (AE_NO_ACPI_TABLES);
755 }
756
757
758 /******************************************************************************
759 *
760 * FUNCTION: AcpiOsGetRootPointer
761 *
762 * PARAMETERS: None
763 *
764 * RETURN: RSDP physical Address
765 *
766 * DESCRIPTION: Gets the root pointer (RSDP)
767 *
768 *****************************************************************************/
769
770 ACPI_PHYSICAL_ADDRESS
AcpiOsGetRootPointer(void)771 AcpiOsGetRootPointer (
772 void)
773 {
774 LOG_DBG ("");
775
776 if(RsdpPhyAdd)
777 {
778 return RsdpPhyAdd;
779 }
780
781 RsdpPhyAdd = (ACPI_PHYSICAL_ADDRESS)acpi_rsdp_get();
782
783 return RsdpPhyAdd;
784 }
785
786 #ifndef ACPI_USE_NATIVE_MEMORY_MAPPING
787 /******************************************************************************
788 *
789 * FUNCTION: AcpiOsMapMemory
790 *
791 * PARAMETERS: Where - Physical Address of memory to be mapped
792 * Length - How much memory to map
793 *
794 * RETURN: Pointer to mapped memory. Null on error.
795 *
796 * DESCRIPTION: Map physical memory into caller's Address space
797 *
798 *****************************************************************************/
799
800 void *
AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS Where,ACPI_SIZE Length)801 AcpiOsMapMemory (
802 ACPI_PHYSICAL_ADDRESS Where,
803 ACPI_SIZE Length)
804 {
805 uint8_t *VirtlAdd;
806
807 LOG_DBG ("");
808 z_phys_map (&VirtlAdd, Where, Length, K_MEM_PERM_RW);
809 return ((void *) VirtlAdd);
810 }
811 #endif
812
813
814 /******************************************************************************
815 *
816 * FUNCTION: AcpiOsUnmapMemory
817 *
818 * PARAMETERS: Where - Logical Address of memory to be unmapped
819 * Length - How much memory to unmap
820 *
821 * RETURN: None.
822 *
823 * DESCRIPTION: Delete a previously created mapping. Where and Length must
824 * correspond to a previous mapping exactly.
825 *
826 *****************************************************************************/
827
828 void
AcpiOsUnmapMemory(void * Where,ACPI_SIZE Length)829 AcpiOsUnmapMemory (
830 void *Where,
831 ACPI_SIZE Length)
832 {
833 LOG_DBG ("");
834 z_phys_unmap (Where, Length);
835 }
836
837
838 /******************************************************************************
839 *
840 * FUNCTION: AcpiOsPhysicalTableOverride
841 *
842 * PARAMETERS: ExistingTable - Header of current table (probably firmware)
843 * NewAddress - Where new table Address is returned
844 * (Physical Address)
845 * NewTableLength - Where new table Length is returned
846 *
847 * RETURN: Status, Address/Length of new table. Null pointer returned
848 * if no table is available to override.
849 *
850 * DESCRIPTION: Returns AE_SUPPORT, function not used in user space.
851 *
852 *****************************************************************************/
853
854 ACPI_STATUS
AcpiOsPhysicalTableOverride(ACPI_TABLE_HEADER * ExistingTable,ACPI_PHYSICAL_ADDRESS * NewAddress,UINT32 * NewTableLength)855 AcpiOsPhysicalTableOverride (
856 ACPI_TABLE_HEADER *ExistingTable,
857 ACPI_PHYSICAL_ADDRESS *NewAddress,
858 UINT32 *NewTableLength)
859 {
860
861 LOG_DBG ("");
862 return (AE_SUPPORT);
863 }
864
865
866 /******************************************************************************
867 *
868 * FUNCTION: AcpiOsInitialize
869 *
870 * PARAMETERS: None
871 *
872 * RETURN: Status
873 *
874 * DESCRIPTION: Init this OSL
875 *
876 *****************************************************************************/
877
878 ACPI_STATUS
AcpiOsInitialize(void)879 AcpiOsInitialize (
880 void)
881 {
882 LOG_DBG ("");
883 return (AE_OK);
884 }
885
886
887 /******************************************************************************
888 *
889 * FUNCTION: AcpiOsStall
890 *
891 * PARAMETERS: Microseconds - Time to stall
892 *
893 * RETURN: None. Blocks until stall is completed.
894 *
895 * DESCRIPTION: Sleep at microsecond granularity
896 *
897 *****************************************************************************/
898
899 void
AcpiOsStall(UINT32 Microseconds)900 AcpiOsStall (
901 UINT32 Microseconds)
902 {
903 k_busy_wait (Microseconds);
904 }
905
906
907 /******************************************************************************
908 *
909 * FUNCTION: AcpiOsSleep
910 *
911 * PARAMETERS: Milliseconds - Time to sleep
912 *
913 * RETURN: None. Blocks until sleep is completed.
914 *
915 * DESCRIPTION: Sleep at millisecond granularity
916 *
917 *****************************************************************************/
918
919 void
AcpiOsSleep(UINT64 Milliseconds)920 AcpiOsSleep (
921 UINT64 Milliseconds)
922 {
923 k_msleep ((UINT32) Milliseconds);
924 }
925
926
927 /******************************************************************************
928 *
929 * FUNCTION: AcpiOsEnterSleep
930 *
931 * PARAMETERS: SleepState - Which sleep state to enter
932 * RegaValue - Register A Value
933 * RegbValue - Register B Value
934 *
935 * RETURN: Status
936 *
937 * DESCRIPTION: A hook before writing sleep registers to enter the sleep
938 * state. Return AE_CTRL_SKIP to skip further sleep register
939 * writes.
940 *
941 *****************************************************************************/
942
943 ACPI_STATUS
AcpiOsEnterSleep(UINT8 SleepState,UINT32 RegaValue,UINT32 RegbValue)944 AcpiOsEnterSleep (
945 UINT8 SleepState,
946 UINT32 RegaValue,
947 UINT32 RegbValue)
948 {
949 __ASSERT (FALSE, "function Not implemented");
950 return (AE_OK);
951 }
952
953
954 /******************************************************************************
955 *
956 * FUNCTION: AcpiOsGetTimer
957 *
958 * PARAMETERS: None
959 *
960 * RETURN: Current ticks in 100-nanosecond units
961 *
962 * DESCRIPTION: Get the Value of a system timer
963 *
964 ******************************************************************************/
965
966 UINT64
AcpiOsGetTimer(void)967 AcpiOsGetTimer (
968 void)
969 {
970 return acpi_timer_get();
971 }
972
973 /******************************************************************************
974 *
975 * FUNCTION: AcpiOsInstallInterruptHandler
976 *
977 * PARAMETERS: InterruptNumber - Level handler should respond to.
978 * ServiceRoutine - Address of the ACPI interrupt handler
979 * Context - User context
980 *
981 * RETURN: Handle to the newly installed handler.
982 *
983 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
984 * OS-independent handler.
985 *
986 *****************************************************************************/
987
988 UINT32
AcpiOsInstallInterruptHandler(UINT32 InterruptNumber,ACPI_OSD_HANDLER ServiceRoutine,void * Context)989 AcpiOsInstallInterruptHandler (
990 UINT32 InterruptNumber,
991 ACPI_OSD_HANDLER ServiceRoutine,
992 void *Context)
993 {
994 LOG_DBG ("");
995 irq_connect_dynamic (InterruptNumber, 3, (zephyr_irq_t) ServiceRoutine, Context,
996 IRQ_TYPE_LOWEST_LEVEL_LOW);
997 irq_enable (InterruptNumber);
998 return (AE_OK);
999 }
1000
1001
1002 /******************************************************************************
1003 *
1004 * FUNCTION: AcpiOsRemoveInterruptHandler
1005 *
1006 * PARAMETERS: Handle - Returned when handler was installed
1007 *
1008 * RETURN: Status
1009 *
1010 * DESCRIPTION: Uninstalls an interrupt handler.
1011 *
1012 *****************************************************************************/
1013
1014 ACPI_STATUS
AcpiOsRemoveInterruptHandler(UINT32 InterruptNumber,ACPI_OSD_HANDLER ServiceRoutine)1015 AcpiOsRemoveInterruptHandler (
1016 UINT32 InterruptNumber,
1017 ACPI_OSD_HANDLER ServiceRoutine)
1018 {
1019
1020 LOG_DBG ("");
1021 irq_disable (InterruptNumber);
1022 return (AE_OK);
1023 }
1024
1025
1026 /******************************************************************************
1027 *
1028 * FUNCTION: AcpiOsSignal
1029 *
1030 * PARAMETERS: Function - ACPICA signal function code
1031 * Info - Pointer to function-dependent structure
1032 *
1033 * RETURN: Status
1034 *
1035 * DESCRIPTION: Miscellaneous functions. Example implementation only.
1036 *
1037 *****************************************************************************/
1038
1039 ACPI_STATUS
AcpiOsSignal(UINT32 Function,void * Info)1040 AcpiOsSignal (
1041 UINT32 Function,
1042 void *Info)
1043 {
1044 switch (Function)
1045 {
1046 case ACPI_SIGNAL_FATAL:
1047 LOG_DBG ("ACPI_SIGNAL_FATAL error");
1048 break;
1049
1050 case ACPI_SIGNAL_BREAKPOINT:
1051 LOG_DBG ("ACPI_SIGNAL_BREAKPOINT");
1052 break;
1053
1054 default:
1055 break;
1056 }
1057
1058 return (AE_OK);
1059 }
1060
1061
1062 /******************************************************************************
1063 *
1064 * FUNCTION: Spinlock/Semaphore interfaces
1065 *
1066 * DESCRIPTION: Map these interfaces to semaphore interfaces
1067 *
1068 *****************************************************************************/
1069
1070 #ifdef ACPI_SINGLE_THREADED
1071 ACPI_STATUS
AcpiOsCreateLock(ACPI_SPINLOCK * OutHandle)1072 AcpiOsCreateLock (
1073 ACPI_SPINLOCK *OutHandle)
1074 {
1075 LOG_DBG ("");
1076
1077 return (AE_OK);
1078 }
1079
1080 void
AcpiOsDeleteLock(ACPI_SPINLOCK Handle)1081 AcpiOsDeleteLock (
1082 ACPI_SPINLOCK Handle)
1083 {
1084 LOG_DBG ("");
1085 }
1086
1087 ACPI_CPU_FLAGS
AcpiOsAcquireLock(ACPI_SPINLOCK Handle)1088 AcpiOsAcquireLock (
1089 ACPI_SPINLOCK Handle)
1090 {
1091 LOG_DBG ("");
1092 return (0);
1093 }
1094
1095 void
AcpiOsReleaseLock(ACPI_SPINLOCK Handle,ACPI_CPU_FLAGS Flags)1096 AcpiOsReleaseLock (
1097 ACPI_SPINLOCK Handle,
1098 ACPI_CPU_FLAGS Flags)
1099 {
1100 LOG_DBG ("");
1101 }
1102
1103 ACPI_STATUS
AcpiOsCreateSemaphore(UINT32 MaxUnits,UINT32 InitialUnits,ACPI_HANDLE * OutHandle)1104 AcpiOsCreateSemaphore (
1105 UINT32 MaxUnits,
1106 UINT32 InitialUnits,
1107 ACPI_HANDLE *OutHandle)
1108 {
1109 *OutHandle = (ACPI_HANDLE) 1;
1110 return (AE_OK);
1111 }
1112
1113 ACPI_STATUS
AcpiOsDeleteSemaphore(ACPI_HANDLE Handle)1114 AcpiOsDeleteSemaphore (
1115 ACPI_HANDLE Handle)
1116 {
1117 return (AE_OK);
1118 }
1119
1120 ACPI_STATUS
AcpiOsWaitSemaphore(ACPI_HANDLE Handle,UINT32 Units,UINT16 Timeout)1121 AcpiOsWaitSemaphore (
1122 ACPI_HANDLE Handle,
1123 UINT32 Units,
1124 UINT16 Timeout)
1125 {
1126 return (AE_OK);
1127 }
1128
1129 ACPI_STATUS
AcpiOsSignalSemaphore(ACPI_HANDLE Handle,UINT32 Units)1130 AcpiOsSignalSemaphore (
1131 ACPI_HANDLE Handle,
1132 UINT32 Units)
1133 {
1134 return (AE_OK);
1135 }
1136
1137 ACPI_THREAD_ID
AcpiOsGetThreadId(void)1138 AcpiOsGetThreadId (
1139 void)
1140 {
1141 LOG_DBG ("");
1142 return (1);
1143 }
1144
1145 ACPI_STATUS
AcpiOsExecute(ACPI_EXECUTE_TYPE Type,ACPI_OSD_EXEC_CALLBACK Function,void * Context)1146 AcpiOsExecute (
1147 ACPI_EXECUTE_TYPE Type,
1148 ACPI_OSD_EXEC_CALLBACK Function,
1149 void *Context)
1150 {
1151 Function (Context);
1152 return (AE_OK);
1153 }
1154 #endif
1155