gopkg.in/ubuntu-core/snappy.v0@v0.0.0-20210902073436-25a8614f10a6/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  	"github.com/snapcore/snapd/interfaces"
    24  	"github.com/snapcore/snapd/interfaces/apparmor"
    25  	"github.com/snapcore/snapd/interfaces/udev"
    26  )
    27  
    28  const dspSummary = `allows controlling digital signal processors on certain boards`
    29  
    30  const dspBaseDeclarationSlots = `
    31    dsp:
    32      allow-installation:
    33        slot-snap-type:
    34          - gadget
    35          - core
    36      deny-auto-connection: true
    37  `
    38  
    39  const ambarellaDspConnectedPlugApparmor = `
    40  # Description: can manage and control the integrated digital signal processor on
    41  # the ambarella device. This allows privileged access to hardware and kernel 
    42  # drivers related to the digital signal processor and thus is only allowed on
    43  # specific devices providing the slot via a gadget and is also not auto-
    44  # connected.
    45  
    46  # The ucode device node corresponds to the firmware on the digital signal 
    47  # processor
    48  /dev/ucode rw,
    49  
    50  # The iav device node is the device node exposed for the specific IAV linux
    51  # device driver used with the CV2x / S6Lm cores on an ambarella device
    52  /dev/iav rw,
    53  
    54  # The cavalry device node is used for managing the CV2x vector processor (VP).
    55  /dev/cavalry rw,
    56  
    57  # Ambarella kernel debug driver to allow user space setting the CV2x registers
    58  /dev/ambad rw,
    59  
    60  # another DSP device node
    61  /dev/lens rw,
    62  
    63  # also needed for interfacing with the DSP
    64  /proc/ambarella/vin0_idsp rw,
    65  `
    66  
    67  var ambarellaDspConnectedPlugUDev = []string{
    68  	`KERNEL=="iav"`,
    69  	`KERNEL=="cavalry"`,
    70  	`KERNEL=="ucode"`,
    71  	`KERNEL=="lens"`,
    72  	`KERNEL=="ambad"`,
    73  }
    74  
    75  type dspInterface struct {
    76  	commonInterface
    77  }
    78  
    79  func (iface *dspInterface) AppArmorConnectedPlug(spec *apparmor.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error {
    80  	// check the flavor of the slot
    81  
    82  	var flavor string
    83  	_ = slot.Attr("flavor", &flavor)
    84  	switch flavor {
    85  	// only supported flavor for now
    86  	case "ambarella":
    87  		spec.AddSnippet(ambarellaDspConnectedPlugApparmor)
    88  	}
    89  
    90  	return nil
    91  }
    92  
    93  func (iface *dspInterface) UDevConnectedPlug(spec *udev.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error {
    94  	// check the flavor of the slot
    95  	var flavor string
    96  	_ = slot.Attr("flavor", &flavor)
    97  	switch flavor {
    98  	// only supported flavor for now
    99  	case "ambarella":
   100  		for _, rule := range ambarellaDspConnectedPlugUDev {
   101  			spec.TagDevice(rule)
   102  		}
   103  	}
   104  
   105  	return nil
   106  }
   107  
   108  func init() {
   109  	registerIface(&dspInterface{commonInterface{
   110  		name:                 "dsp",
   111  		summary:              dspSummary,
   112  		baseDeclarationSlots: dspBaseDeclarationSlots,
   113  	}})
   114  }