github.com/ratrocket/u-root@v0.0.0-20180201221235-1cf9f48ee2cf/pkg/pci/devices.go (about)

     1  // Copyright 2012-2017 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 pci
     6  
     7  import (
     8  	"bytes"
     9  )
    10  
    11  //Devices contains a slice of one or more PCI devices
    12  type Devices []*PCI
    13  
    14  // String stringifies the PCI devices. Currently it just calls the device String().
    15  func (d Devices) String() string {
    16  	var buffer bytes.Buffer
    17  	for _, pci := range d {
    18  		buffer.WriteString(pci.String())
    19  		buffer.WriteString("\n")
    20  	}
    21  	return buffer.String()
    22  }
    23  
    24  // SetVendorDeviceName sets all numeric IDs of all the devices
    25  // using the pci device SetVendorDeviceName.
    26  func (d Devices) SetVendorDeviceName() {
    27  	for _, p := range d {
    28  		p.SetVendorDeviceName()
    29  	}
    30  }
    31  
    32  // ReadConfig reads the config info for all the devices.
    33  func (d Devices) ReadConfig() error {
    34  	for _, p := range d {
    35  		if err := p.ReadConfig(); err != nil {
    36  			return err
    37  		}
    38  	}
    39  	return nil
    40  }
    41  
    42  // ReadConfigRegister reads the config info for all the devices.
    43  func (d Devices) ReadConfigRegister(offset, size int64) ([]uint64, error) {
    44  	var vals []uint64
    45  	for _, p := range d {
    46  		val, err := p.ReadConfigRegister(offset, size)
    47  		if err != nil {
    48  			return nil, err
    49  		}
    50  		vals = append(vals, val)
    51  	}
    52  	return vals, nil
    53  }
    54  
    55  // WriteConfigRegister writes the config info for all the devices.
    56  func (d Devices) WriteConfigRegister(offset, size int64, val uint64) error {
    57  	for _, p := range d {
    58  		if err := p.WriteConfigRegister(offset, size, val); err != nil {
    59  			return err
    60  		}
    61  	}
    62  	return nil
    63  }