gitee.com/mysnapcore/mysnapd@v0.1.0/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 "gitee.com/mysnapcore/mysnapd/interfaces" 24 "gitee.com/mysnapcore/mysnapd/interfaces/apparmor" 25 "gitee.com/mysnapcore/mysnapd/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 # various ambarella specific DSP control parameters 64 /proc/ambarella/iav r, 65 /proc/ambarella/ambnl/** rw, 66 /proc/ambarella/udc r, 67 /proc/ambarella/clock r, 68 /proc/ambarella/dsp_print rw, 69 /proc/ambarella/hdmi_edid r, 70 /proc/ambarella/cma r, 71 /proc/ambarella/ambarella_hwtimer rw, 72 /proc/ambarella/ambarella_hwtimer_outfreq rw, 73 /proc/ambarella/vapi_sync r, 74 /proc/ambarella/dsp_state r, 75 76 # to match vin0_idsp, vin1_idsp, vin2_idsp, etc. 77 /proc/ambarella/vin[0-9]_idsp r, 78 79 # to match e0021000.dma and e0020000.dma 80 /proc/ambarella/[0-9a-e][0-9a-e][0-9a-e][0-9a-e][0-9a-e][0-9a-e][0-9a-e][0-9a-e].dma rw, 81 82 # needed to control the usb device attached to the DSP 83 /proc/ambarella/usbphy0 rw, 84 ` 85 86 var ambarellaDspConnectedPlugUDev = []string{ 87 `KERNEL=="iav"`, 88 `KERNEL=="cavalry"`, 89 `KERNEL=="ucode"`, 90 `KERNEL=="lens"`, 91 `KERNEL=="ambad"`, 92 } 93 94 type dspInterface struct { 95 commonInterface 96 } 97 98 func (iface *dspInterface) AppArmorConnectedPlug(spec *apparmor.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error { 99 // check the flavor of the slot 100 101 var flavor string 102 _ = slot.Attr("flavor", &flavor) 103 switch flavor { 104 // only supported flavor for now 105 case "ambarella": 106 spec.AddSnippet(ambarellaDspConnectedPlugApparmor) 107 } 108 109 return nil 110 } 111 112 func (iface *dspInterface) UDevConnectedPlug(spec *udev.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error { 113 // check the flavor of the slot 114 var flavor string 115 _ = slot.Attr("flavor", &flavor) 116 switch flavor { 117 // only supported flavor for now 118 case "ambarella": 119 for _, rule := range ambarellaDspConnectedPlugUDev { 120 spec.TagDevice(rule) 121 } 122 } 123 124 return nil 125 } 126 127 func init() { 128 registerIface(&dspInterface{commonInterface{ 129 name: "dsp", 130 summary: dspSummary, 131 baseDeclarationSlots: dspBaseDeclarationSlots, 132 }}) 133 }