• Nathan Lynch's avatar
    powerpc/pseries: Add papr-vpd character driver for VPD retrieval · 514f6ff4
    Nathan Lynch authored
    PowerVM LPARs may retrieve Vital Product Data (VPD) for system
    components using the ibm,get-vpd RTAS function.
    
    We can expose this to user space with a /dev/papr-vpd character
    device, where the programming model is:
    
      struct papr_location_code plc = { .str = "", }; /* obtain all VPD */
      int devfd = open("/dev/papr-vpd", O_RDONLY);
      int vpdfd = ioctl(devfd, PAPR_VPD_CREATE_HANDLE, &plc);
      size_t size = lseek(vpdfd, 0, SEEK_END);
      char *buf = malloc(size);
      pread(devfd, buf, size, 0);
    
    When a file descriptor is obtained from ioctl(PAPR_VPD_CREATE_HANDLE),
    the file contains the result of a complete ibm,get-vpd sequence. The
    file contents are immutable from the POV of user space. To get a new
    view of the VPD, the client must create a new handle.
    
    This design choice insulates user space from most of the complexities
    that ibm,get-vpd brings:
    
    * ibm,get-vpd must be called more than once to obtain complete
      results.
    
    * Only one ibm,get-vpd call sequence should be in progress at a time;
      interleaved sequences will disrupt each other. Callers must have a
      protocol for serializing their use of the function.
    
    * A call sequence in progress may receive a "VPD changed, try again"
      status, requiring the client to abandon the sequence and start
      over.
    
    The memory required for the VPD buffers seems acceptable, around 20KB
    for all VPD on one of my systems. And the value of the
    /rtas/ibm,vpd-size DT property (the estimated maximum size of VPD) is
    consistently 300KB across various systems I've checked.
    
    I've implemented support for this new ABI in the rtas_get_vpd()
    function in librtas, which the vpdupdate command currently uses to
    populate its VPD database. I've verified that an unmodified vpdupdate
    binary generates an identical database when using a librtas.so that
    prefers the new ABI.
    
    Along with the papr-vpd.h header exposed to user space, this
    introduces a common papr-miscdev.h uapi header to share a base ioctl
    ID with similar drivers to come.
    Tested-by: default avatarMichal Suchánek <msuchanek@suse.de>
    Signed-off-by: default avatarNathan Lynch <nathanl@linux.ibm.com>
    Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
    Link: https://msgid.link/20231212-papr-sys_rtas-vs-lockdown-v6-9-e9eafd0c8c6c@linux.ibm.com
    514f6ff4
Makefile 1.43 KB