github.com/david-imola/snapd@v0.0.0-20210611180407-2de8ddeece6d/interfaces/builtin/dsp.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2021 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package builtin
    21  
    22  import (
    23  	"fmt"
    24  
    25  	"github.com/snapcore/snapd/interfaces"
    26  	"github.com/snapcore/snapd/interfaces/apparmor"
    27  	"github.com/snapcore/snapd/interfaces/udev"
    28  )
    29  
    30  const dspSummary = `allows controlling digital signal processors on certain boards`
    31  
    32  const dspBaseDeclarationSlots = `
    33    dsp:
    34      allow-installation:
    35        slot-snap-type:
    36          - gadget
    37          - core
    38      deny-auto-connection: true
    39  `
    40  
    41  const ambarellaDspConnectedPlugApparmor = `
    42  # Description: can manage and control the integrated digital signal processor on
    43  # the ambarella device. This allows privileged access to hardware and kernel 
    44  # drivers related to the digital signal processor and thus is only allowed on
    45  # specific devices providing the slot via a gadget and is also not auto-
    46  # connected.
    47  
    48  # The ucode device node corresponds to the firmware on the digital signal 
    49  # processor
    50  /dev/ucode rw,
    51  
    52  # The iav device node is the device node exposed for the specific IAV linux
    53  # device driver used with the CV2x / S6Lm cores on an ambarella device
    54  /dev/iav rw,
    55  
    56  # The cavalry device node is used for managing the CV2x vector processor (VP).
    57  /dev/cavalry rw,
    58  
    59  # another DSP device node
    60  /dev/lens rw,
    61  
    62  # also needed for interfacing with the DSP
    63  /proc/ambarella/vin0_idsp rw,
    64  `
    65  
    66  var ambarellaDspConnectedPlugUDev = []string{
    67  	`KERNEL=="iav"`,
    68  	`KERNEL=="cavalry"`,
    69  	`KERNEL=="ucode"`,
    70  	`KERNEL=="lens"`,
    71  }
    72  
    73  type dspInterface struct {
    74  	commonInterface
    75  }
    76  
    77  func (iface *dspInterface) AppArmorConnectedPlug(spec *apparmor.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error {
    78  	// check the flavor of the slot
    79  
    80  	var flavor string
    81  	_ = slot.Attr("flavor", &flavor)
    82  	fmt.Println("slot flavor", flavor)
    83  	switch flavor {
    84  	// only supported flavor for now
    85  	case "ambarella":
    86  		spec.AddSnippet(ambarellaDspConnectedPlugApparmor)
    87  	}
    88  
    89  	return nil
    90  }
    91  
    92  func (iface *dspInterface) UDevConnectedPlug(spec *udev.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error {
    93  	// check the flavor of the slot
    94  	var flavor string
    95  	_ = slot.Attr("flavor", &flavor)
    96  	switch flavor {
    97  	// only supported flavor for now
    98  	case "ambarella":
    99  		for _, rule := range ambarellaDspConnectedPlugUDev {
   100  			spec.TagDevice(rule)
   101  		}
   102  	}
   103  
   104  	return nil
   105  }
   106  
   107  func init() {
   108  	registerIface(&dspInterface{commonInterface{
   109  		name:                 "dsp",
   110  		summary:              dspSummary,
   111  		baseDeclarationSlots: dspBaseDeclarationSlots,
   112  	}})
   113  }