]>
Commit | Line | Data |
---|---|---|
c59fb4ee DC |
1 | Ext.define('PVE.qemu.PCIInputPanel', { |
2 | extend: 'Proxmox.panel.InputPanel', | |
3 | ||
4 | onlineHelp: 'qm_pci_passthrough', | |
5 | ||
6 | setVMConfig: function(vmconfig) { | |
7 | var me = this; | |
8 | me.vmconfig = vmconfig; | |
9 | ||
10 | var hostpci = me.vmconfig[me.confid] || ''; | |
11 | ||
12 | var values = PVE.Parser.parsePropertyString(hostpci, 'host'); | |
5b23d683 SR |
13 | if (values.host) { |
14 | if (!values.host.match(/^[0-9a-f]{4}:/i)) { // add optional domain | |
15 | values.host = "0000:" + values.host; | |
16 | } | |
17 | if (values.host.length < 11) { // 0000:00:00 format not 0000:00:00.0 | |
18 | values.host += ".0"; | |
19 | values.multifunction = true; | |
20 | } | |
c59fb4ee | 21 | } |
5b23d683 | 22 | |
c59fb4ee DC |
23 | values['x-vga'] = PVE.Parser.parseBoolean(values['x-vga'], 0); |
24 | values.pcie = PVE.Parser.parseBoolean(values.pcie, 0); | |
25 | values.rombar = PVE.Parser.parseBoolean(values.rombar, 1); | |
26 | ||
27 | me.setValues(values); | |
28 | if (!me.vmconfig.machine || me.vmconfig.machine.indexOf('q35') === -1) { | |
29 | // machine is not set to some variant of q35, so we disable pcie | |
30 | var pcie = me.down('field[name=pcie]'); | |
31 | pcie.setDisabled(true); | |
32 | pcie.setBoxLabel(gettext('Q35 only')); | |
33 | } | |
34 | ||
35 | if (values.romfile) { | |
36 | me.down('field[name=romfile]').setVisible(true); | |
37 | } | |
38 | }, | |
39 | ||
40 | onGetValues: function(values) { | |
41 | var me = this; | |
42 | var ret = {}; | |
8058410f | 43 | if (!me.confid) { |
c59fb4ee DC |
44 | var i; |
45 | for (i = 0; i < 5; i++) { | |
8058410f | 46 | if (!me.vmconfig['hostpci' + i.toString()]) { |
c59fb4ee DC |
47 | me.confid = 'hostpci' + i.toString(); |
48 | break; | |
49 | } | |
50 | } | |
51 | } | |
f36240c5 | 52 | // remove optional '0000' domain |
f6710aac | 53 | if (values.host.substring(0, 5) === '0000:') { |
f36240c5 DC |
54 | values.host = values.host.substring(5); |
55 | } | |
c59fb4ee DC |
56 | if (values.multifunction) { |
57 | // modify host to skip the '.X' | |
f36240c5 | 58 | values.host = values.host.substring(0, values.host.indexOf('.')); |
c59fb4ee DC |
59 | delete values.multifunction; |
60 | } | |
61 | ||
62 | if (values.rombar) { | |
63 | delete values.rombar; | |
64 | } else { | |
65 | values.rombar = 0; | |
66 | } | |
67 | ||
2b25a905 DC |
68 | if (!values.romfile) { |
69 | delete values.romfile; | |
70 | } | |
71 | ||
c59fb4ee DC |
72 | ret[me.confid] = PVE.Parser.printPropertyString(values, 'host'); |
73 | return ret; | |
74 | }, | |
75 | ||
76 | initComponent: function() { | |
77 | var me = this; | |
78 | ||
79 | me.nodename = me.pveSelNode.data.node; | |
80 | if (!me.nodename) { | |
81 | throw "no node name specified"; | |
82 | } | |
83 | ||
84 | me.column1 = [ | |
85 | { | |
86 | xtype: 'pvePCISelector', | |
87 | fieldLabel: gettext('Device'), | |
88 | name: 'host', | |
89 | nodename: me.nodename, | |
90 | allowBlank: false, | |
91 | onLoadCallBack: function(store, records, success) { | |
92 | if (!success || !records.length) { | |
93 | return; | |
94 | } | |
95 | ||
d3b3b4ad | 96 | if (records.every((val) => val.data.iommugroup === -1)) { |
c59fb4ee DC |
97 | // no iommu groups |
98 | var warning = Ext.create('Ext.form.field.Display', { | |
99 | columnWidth: 1, | |
100 | padding: '0 0 10 0', | |
101 | value: 'No IOMMU detected, please activate it.' + | |
102 | 'See Documentation for further information.', | |
f6710aac | 103 | userCls: 'pmx-hint', |
c59fb4ee DC |
104 | }); |
105 | me.items.insert(0, warning); | |
106 | me.updateLayout(); // insert does not trigger that | |
107 | } | |
108 | }, | |
109 | listeners: { | |
110 | change: function(pcisel, value) { | |
111 | if (!value) { | |
112 | return; | |
113 | } | |
114 | var pcidev = pcisel.getStore().getById(value); | |
115 | var mdevfield = me.down('field[name=mdev]'); | |
116 | mdevfield.setDisabled(!pcidev || !pcidev.data.mdev); | |
117 | if (!pcidev) { | |
118 | return; | |
119 | } | |
f6710aac | 120 | var id = pcidev.data.id.substring(0, 5); // 00:00 |
c59fb4ee DC |
121 | var iommu = pcidev.data.iommugroup; |
122 | // try to find out if there are more devices | |
123 | // in that iommu group | |
124 | if (iommu !== -1) { | |
125 | var count = 0; | |
126 | pcisel.getStore().each(function(record) { | |
61e05768 DJ |
127 | if ( |
128 | record.data.iommugroup === iommu && | |
129 | record.data.id.substring(0, 5) !== id | |
130 | ) { | |
c59fb4ee DC |
131 | count++; |
132 | return false; | |
133 | } | |
61e05768 | 134 | return true; |
c59fb4ee DC |
135 | }); |
136 | var warning = me.down('#iommuwarning'); | |
137 | if (count && !warning) { | |
138 | warning = Ext.create('Ext.form.field.Display', { | |
139 | columnWidth: 1, | |
140 | padding: '0 0 10 0', | |
141 | itemId: 'iommuwarning', | |
142 | value: 'The selected Device is not in a seperate' + | |
143 | 'IOMMU group, make sure this is intended.', | |
f6710aac | 144 | userCls: 'pmx-hint', |
c59fb4ee DC |
145 | }); |
146 | me.items.insert(0, warning); | |
147 | me.updateLayout(); // insert does not trigger that | |
148 | } else if (!count && warning) { | |
149 | me.remove(warning); | |
150 | } | |
151 | } | |
152 | if (pcidev.data.mdev) { | |
153 | mdevfield.setPciID(value); | |
154 | } | |
f6710aac TL |
155 | }, |
156 | }, | |
c59fb4ee DC |
157 | }, |
158 | { | |
159 | xtype: 'proxmoxcheckbox', | |
160 | fieldLabel: gettext('All Functions'), | |
f6710aac TL |
161 | name: 'multifunction', |
162 | }, | |
c59fb4ee DC |
163 | ]; |
164 | ||
165 | me.column2 = [ | |
166 | { | |
167 | xtype: 'pveMDevSelector', | |
168 | name: 'mdev', | |
169 | disabled: true, | |
170 | fieldLabel: gettext('MDev Type'), | |
171 | nodename: me.nodename, | |
172 | listeners: { | |
173 | change: function(field, value) { | |
174 | var mf = me.down('field[name=multifunction]'); | |
d2021707 | 175 | if (value) { |
c59fb4ee DC |
176 | mf.setValue(false); |
177 | } | |
178 | mf.setDisabled(!!value); | |
f6710aac TL |
179 | }, |
180 | }, | |
c59fb4ee DC |
181 | }, |
182 | { | |
183 | xtype: 'proxmoxcheckbox', | |
184 | fieldLabel: gettext('Primary GPU'), | |
f6710aac TL |
185 | name: 'x-vga', |
186 | }, | |
c59fb4ee DC |
187 | ]; |
188 | ||
189 | me.advancedColumn1 = [ | |
190 | { | |
191 | xtype: 'proxmoxcheckbox', | |
192 | fieldLabel: 'ROM-Bar', | |
f6710aac | 193 | name: 'rombar', |
c59fb4ee DC |
194 | }, |
195 | { | |
196 | xtype: 'displayfield', | |
197 | submitValue: true, | |
198 | hidden: true, | |
199 | fieldLabel: 'ROM-File', | |
f6710aac TL |
200 | name: 'romfile', |
201 | }, | |
c59fb4ee DC |
202 | ]; |
203 | ||
204 | me.advancedColumn2 = [ | |
205 | { | |
206 | xtype: 'proxmoxcheckbox', | |
207 | fieldLabel: 'PCI-Express', | |
f6710aac TL |
208 | name: 'pcie', |
209 | }, | |
c59fb4ee DC |
210 | ]; |
211 | ||
212 | me.callParent(); | |
f6710aac | 213 | }, |
c59fb4ee DC |
214 | }); |
215 | ||
216 | Ext.define('PVE.qemu.PCIEdit', { | |
217 | extend: 'Proxmox.window.Edit', | |
218 | ||
219 | vmconfig: undefined, | |
220 | ||
221 | isAdd: true, | |
222 | ||
223 | subject: gettext('PCI Device'), | |
224 | ||
225 | ||
8058410f | 226 | initComponent: function() { |
c59fb4ee DC |
227 | var me = this; |
228 | ||
229 | me.isCreate = !me.confid; | |
230 | ||
231 | var ipanel = Ext.create('PVE.qemu.PCIInputPanel', { | |
232 | confid: me.confid, | |
f6710aac | 233 | pveSelNode: me.pveSelNode, |
c59fb4ee DC |
234 | }); |
235 | ||
236 | Ext.apply(me, { | |
8058410f | 237 | items: [ipanel], |
c59fb4ee DC |
238 | }); |
239 | ||
240 | me.callParent(); | |
241 | ||
242 | me.load({ | |
243 | success: function(response) { | |
244 | ipanel.setVMConfig(response.result.data); | |
f6710aac | 245 | }, |
c59fb4ee | 246 | }); |
f6710aac | 247 | }, |
c59fb4ee | 248 | }); |