gitlab.com/apertussolutions/u-root@v7.0.0+incompatible/pkg/acpi/rsdp_linux.go (about)

     1  // Copyright 2019 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package acpi
     6  
     7  import (
     8  	"bufio"
     9  	"fmt"
    10  	"log"
    11  	"os"
    12  	"strconv"
    13  	"strings"
    14  )
    15  
    16  // GetRSDPEFI finds the RSDP in the EFI System Table.
    17  func GetRSDPEFI() (*RSDP, error) {
    18  	file, err := os.Open("/sys/firmware/efi/systab")
    19  	if err != nil {
    20  		return nil, err
    21  	}
    22  	defer file.Close()
    23  
    24  	const (
    25  		acpi20 = "ACPI20="
    26  		acpi   = "ACPI="
    27  	)
    28  
    29  	scanner := bufio.NewScanner(file)
    30  	for scanner.Scan() {
    31  		line := scanner.Text()
    32  		start := ""
    33  		if strings.HasPrefix(line, acpi20) {
    34  			start = strings.TrimPrefix(line, acpi20)
    35  		}
    36  		if strings.HasPrefix(line, acpi) {
    37  			start = strings.TrimPrefix(line, acpi)
    38  		}
    39  		if start == "" {
    40  			continue
    41  		}
    42  		base, err := strconv.ParseInt(start, 0, 63)
    43  		if err != nil {
    44  			continue
    45  		}
    46  		rsdp, err := readRSDP(base)
    47  		if err != nil {
    48  			continue
    49  		}
    50  		return rsdp, nil
    51  	}
    52  	if err := scanner.Err(); err != nil {
    53  		log.Printf("error while reading EFI systab: %v", err)
    54  	}
    55  	return nil, fmt.Errorf("invalid /sys/firmware/efi/systab file")
    56  }
    57  
    58  // You can change the getters if you wish for testing.
    59  var rsdpgetters = []func() (*RSDP, error){GetRSDPEFI, GetRSDPEBDA, GetRSDPMem}