github.com/ethanhsieh/snapd@v0.0.0-20210615102523-3db9b8e4edc5/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 # another DSP device node 58 /dev/lens rw, 59 60 # also needed for interfacing with the DSP 61 /proc/ambarella/vin0_idsp rw, 62 ` 63 64 var ambarellaDspConnectedPlugUDev = []string{ 65 `KERNEL=="iav"`, 66 `KERNEL=="cavalry"`, 67 `KERNEL=="ucode"`, 68 `KERNEL=="lens"`, 69 } 70 71 type dspInterface struct { 72 commonInterface 73 } 74 75 func (iface *dspInterface) AppArmorConnectedPlug(spec *apparmor.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error { 76 // check the flavor of the slot 77 78 var flavor string 79 _ = slot.Attr("flavor", &flavor) 80 switch flavor { 81 // only supported flavor for now 82 case "ambarella": 83 spec.AddSnippet(ambarellaDspConnectedPlugApparmor) 84 } 85 86 return nil 87 } 88 89 func (iface *dspInterface) UDevConnectedPlug(spec *udev.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error { 90 // check the flavor of the slot 91 var flavor string 92 _ = slot.Attr("flavor", &flavor) 93 switch flavor { 94 // only supported flavor for now 95 case "ambarella": 96 for _, rule := range ambarellaDspConnectedPlugUDev { 97 spec.TagDevice(rule) 98 } 99 } 100 101 return nil 102 } 103 104 func init() { 105 registerIface(&dspInterface{commonInterface{ 106 name: "dsp", 107 summary: dspSummary, 108 baseDeclarationSlots: dspBaseDeclarationSlots, 109 }}) 110 }