1Dom0 kernel and ramdisk modules
2================================
3
4Xen is passed the dom0 kernel and initrd via a reference in the /chosen
5node of the device tree.
6
7Each node contains the following properties:
8
9- compatible
10
11	Must always include at least the generic compatiblity string:
12
13		"multiboot,module"
14
15	Optionally a more specific compatible string may be used in
16	addition to the above. One of:
17
18	- "multiboot,kernel"	-- the dom0 kernel
19	- "multiboot,ramdisk"	-- the dom0 ramdisk
20	- "xen,xsm-policy"	-- XSM policy blob
21
22	It is normally recommended to include a more specific
23	compatible string (if one applies) in addition to the generic
24	string (which must always be present).
25
26	Xen will assume that the first module which lacks a more
27	specific compatible string is a "multiboot,kernel".
28
29	Xen will examine each module, starting from the second
30	module that lacks a specific compatible string.  Xen will
31	check each such module for the XSM Magic number:
32
33	- For a module which has the XSM Magic number: it will be
34	  treated by Xen as if its compatible string was
35	  "xen,xsm-policy";
36
37	- For a module which does not have the XSM Magic: the second
38	  module lacking a compatible string will be treated by Xen as
39	  if its compatible string was "multiboot,ramdisk"; for the
40	  third and subsequent modules which lack a specific
41	  compatible string, Xen will not apply any special treatment.
42
43	This means if the ramdisk module is present and does not have the
44	compatible string "multiboot,ramdisk", then it must always be the
45	second module.
46
47	Note: This XSM Magic detection behavior was introduced by Xen 4.7.
48	Xen 4.6 (and downwards) still requires the XSM module to have the
49	compatible string "xen,xsm-policy".
50
51	Xen 4.4 supported a different set of legacy compatible strings
52	which remain supported such that systems supporting both 4.4
53	and later can use a single DTB.
54	However when booting Xen using UEFI, the legacy compatible
55	strings are not supported.
56
57	- "xen,multiboot-module" equivalent to "multiboot,module"
58	- "xen,linux-zimage"     equivalent to "multiboot,kernel"
59	- "xen,linux-initrd"     equivalent to "multiboot,ramdisk"
60
61	For compatibility with Xen 4.4 the more specific "xen,linux-*"
62	names are non-optional and must be included.
63
64- reg
65
66	Specifies the physical address of the module in RAM and the
67	length of the module.
68
69- bootargs (optional)
70
71	Command line associated with this module. See below for the
72	priority of this field vs. other mechanisms of specifying the
73	bootargs for the kernel.
74
75- xen,uefi-binary (UEFI boot only)
76
77	String property that specifies the file name to be loaded by the UEFI
78	boot for this module. If this is specified, there is no need to specify
79	the reg property because it will be created by the UEFI stub on boot.
80	This option is needed only when UEFI boot is used, the node needs to be
81	compatible with multiboot,kernel or multiboot,ramdisk.
82
83Examples
84========
85
86A boot module of unspecified type:
87
88	module@0xc0000000 {
89		compatible = "multiboot,module";
90		reg = <0xc0000000 0x1234>;
91		bootargs = "...";
92	};
93
94A boot module containing a ramdisk:
95
96	module@0xd0000000 {
97		compatible = "multiboot,ramdisk", "multiboot,module";
98		reg = <0xd0000000 0x5678>;
99	};
100
101The previous examples are compatible with Xen 4.5+ only.
102
103To be compatible with Xen 4.4 as well use the legacy names:
104
105	module@0xd0000000 {
106		compatible = "xen,linux-initrd", "xen,multiboot-module";
107		reg = <0xd0000000 0x5678>;
108	};
109
110Command lines
111=============
112
113Xen also checks for properties directly under /chosen to find suitable command
114lines for Xen and Dom0. The logic is the following:
115
116 - If xen,xen-bootargs is present, it will be used for Xen.
117 - If xen,dom0-bootargs is present, it will be used for Dom0.
118 - If xen,xen-bootargs is _not_ present, but xen,dom0-bootargs is,
119   bootargs will be used for Xen.
120 - If a kernel boot module is present and has a bootargs property then
121   the top-level bootargs will used for Xen.
122 - If no Xen specific properties are present, bootargs is for Dom0.
123 - If xen,xen-bootargs is present, but xen,dom0-bootargs is missing,
124   bootargs will be used for Dom0.
125
126Most of these cases is to make booting with Xen-unaware bootloaders easier.
127For those you would hardcode the Xen commandline in the DTB under
128/chosen/xen,xen-bootargs and would let the bootloader set the Dom0 command
129line by writing bootargs (as for native Linux).
130A Xen-aware bootloader would set xen,xen-bootargs for Xen, xen,dom0-bootargs
131for Dom0 and bootargs for native Linux.
132
133
134UEFI boot and DT
135================
136
137When Xen is booted using UEFI, it doesn't read the configuration file if any
138multiboot module is specified. To force Xen to load the configuration file, the
139boolean property xen,uefi-cfg-load must be declared in the /chosen node.
140
141
142Creating Multiple Domains directly from Xen
143===========================================
144
145It is possible to have Xen create other domains, in addition to dom0,
146out of the information provided via device tree. A kernel and initrd
147(optional) need to be specified for each guest.
148
149For each domain to be created there needs to be one node under /chosen
150with the following properties:
151
152- compatible
153
154    For domUs: "xen,domain"
155
156- memory
157
158	A 64-bit integer specifying the amount of kilobytes of RAM to
159    allocate to the guest.
160
161- cpus
162
163    An integer specifying the number of vcpus to allocate to the guest.
164
165- vpl011
166
167    An empty property to enable/disable a virtual pl011 for the guest to
168    use. The virtual pl011 uses SPI number 0 (see GUEST_VPL011_SPI).
169    Please note that the SPI used for the virtual pl011 could clash with the
170    physical SPI of a physical device assigned to the guest.
171
172- nr_spis
173
174    Optional. A 32-bit integer specifying the number of SPIs (Shared
175    Peripheral Interrupts) to allocate for the domain. If nr_spis is
176    missing, the max number of SPIs supported by the physical GIC is
177    used, or GUEST_VPL011_SPI+1 if vpl011 is enabled, whichever is
178    greater.
179
180- #address-cells and #size-cells
181
182    Both #address-cells and #size-cells need to be specified because
183    both sub-nodes (described shortly) have reg properties.
184
185- direct-map
186
187    Only available when statically allocated memory is used for the domain.
188    An empty property to request the memory of the domain to be
189    direct-map (guest physical address == physical address).
190
191- domain-cpupool
192
193    Optional. Handle to a xen,cpupool device tree node that identifies the
194    cpupool where the guest will be started at boot.
195
196- sve
197
198    Optional. The `sve` property enables Arm SVE usage for the domain and sets
199    the maximum SVE vector length, the option is applicable only to Arm64
200    guests.
201    A value equal to 0 disables the feature, this is the default value.
202    Specifying this property with no value, means that the SVE vector length
203    will be set equal to the maximum vector length supported by the platform.
204    Values above 0 explicitly set the maximum SVE vector length for the domain,
205    allowed values are from 128 to maximum 2048, being multiple of 128.
206    Please note that when the user explicitly specifies the value, if that value
207    is above the hardware supported maximum SVE vector length, the domain
208    creation will fail and the system will stop, the same will occur if the
209    option is provided with a non zero value, but the platform doesn't support
210    SVE.
211
212- xen,enhanced
213
214    A string property. Possible property values are:
215
216    - "enabled" (or missing property value)
217    Xen PV interfaces, including grant-table and xenstore, will be
218    enabled for the VM.
219
220    - "disabled"
221    Xen PV interfaces are disabled.
222
223    - "no-xenstore"
224    All default Xen PV interfaces, including grant-table will be enabled but
225    xenstore will be disabled for the VM.
226
227    If the xen,enhanced property is present with no value, it defaults
228    to "enabled". If the xen,enhanced property is not present, PV
229    interfaces are disabled.
230
231    In the future other possible property values might be added to
232    enable only selected interfaces.
233
234- xen,domain-p2m-mem-mb
235
236    Optional. A 32-bit integer specifying the amount of megabytes of RAM
237    used for the domain P2M pool. This is in-sync with the shadow_memory
238    option in xl.cfg. Leaving this field empty in device tree will lead to
239    the default size of domain P2M pool, i.e. 1MB per guest vCPU plus 4KB
240    per MB of guest RAM plus 512KB for guest extended regions.
241
242- max_grant_version
243
244    Optional. A 32-bit integer specifying the maximum grant table version
245    the domain is allowed to use (valid values are 1 or 2). If this property
246    is missing, the value specified by Xen command line parameter gnttab=max-ver
247    (or its default value if unspecified, i.e. 1) is used.
248
249- max_grant_frames
250
251    Optional. A 32-bit integer specifying the maximum number of grant frames
252    the domain is allowed to have. If this property is missing, the value
253    specified by Xen command line parameter gnttab_max_frames (or its default
254    value if unspecified, i.e. 64) is used.
255
256- max_maptrack_frames
257
258    Optional. A 32-bit integer specifying the maximum number of grant maptrack
259    frames the domain is allowed to have. If this property is missing, the
260    value specified by Xen command line parameter gnttab_max_maptrack_frames
261    (or its default value if unspecified, i.e. 1024) is used.
262
263- passthrough
264
265    A string property specifying whether IOMMU mappings are enabled for the
266    domain and hence whether it will be enabled for passthrough hardware.
267    Possible property values are:
268
269    - "enabled"
270    IOMMU mappings are enabled for the domain. Note that this option is the
271    default if the user provides the device partial passthrough device tree
272    for the domain.
273
274    - "disabled"
275    IOMMU mappings are disabled for the domain and so hardware may not be
276    passed through. This option is the default if this property is missing
277    and the user does not provide the device partial device tree for the domain.
278
279Under the "xen,domain" compatible node, one or more sub-nodes are present
280for the DomU kernel and ramdisk.
281
282The kernel sub-node has the following properties:
283
284- compatible
285
286    "multiboot,kernel", "multiboot,module"
287
288- reg
289
290    Specifies the physical address of the kernel in RAM and its
291    length.
292
293- bootargs (optional)
294
295    Command line parameters for the guest kernel.
296
297- xen,uefi-binary (UEFI boot only)
298
299    String property that specifies the file name to be loaded by the UEFI boot
300    for this module. If this is specified, there is no need to specify the reg
301    property because it will be created by the UEFI stub on boot.
302    This option is needed only when UEFI boot is used.
303
304The ramdisk sub-node has the following properties:
305
306- compatible
307
308    "multiboot,ramdisk", "multiboot,module"
309
310- reg
311
312    Specifies the physical address of the ramdisk in RAM and its
313    length.
314
315- xen,uefi-binary (UEFI boot only)
316
317    String property that specifies the file name to be loaded by the UEFI boot
318    for this module. If this is specified, there is no need to specify the reg
319    property because it will be created by the UEFI stub on boot.
320    This option is needed only when UEFI boot is used.
321
322
323Example
324=======
325
326chosen {
327    domU1 {
328        compatible = "xen,domain";
329        #address-cells = <0x2>;
330        #size-cells = <0x1>;
331        memory = <0 131072>;
332        cpus = <2>;
333        vpl011;
334
335        module@0x4a000000 {
336            compatible = "multiboot,kernel", "multiboot,module";
337            reg = <0x0 0x4a000000 0xffffff>;
338            bootargs = "console=ttyAMA0 init=/bin/sh";
339        };
340
341        module@0x4b000000 {
342            compatible = "multiboot,ramdisk", "multiboot,module";
343            reg = <0x0 0x4b000000 0xffffff>;
344        };
345    };
346
347    domU2 {
348        compatible = "xen,domain";
349        #address-cells = <0x2>;
350        #size-cells = <0x1>;
351        memory = <0 65536>;
352        cpus = <1>;
353
354        module@0x4c000000 {
355            compatible = "multiboot,kernel", "multiboot,module";
356            reg = <0x0 0x4c000000 0xffffff>;
357            bootargs = "console=ttyAMA0 init=/bin/sh";
358        };
359
360        module@0x4d000000 {
361            compatible = "multiboot,ramdisk", "multiboot,module";
362            reg = <0x0 0x4d000000 0xffffff>;
363        };
364    };
365};
366
367
368Device Assignment
369=================
370
371Device Assignment (Passthrough) is supported by adding another module,
372alongside the kernel and ramdisk, with the device tree fragment
373corresponding to the device node to assign to the guest.
374
375The dtb sub-node should have the following properties:
376
377- compatible
378
379    "multiboot,device-tree" and "multiboot,module"
380
381- reg
382
383    Specifies the physical address of the device tree binary fragment
384    RAM and its length.
385
386- xen,uefi-binary (UEFI boot only)
387
388    String property that specifies the file name to be loaded by the UEFI boot
389    for this module. If this is specified, there is no need to specify the reg
390    property because it will be created by the UEFI stub on boot.
391    This option is needed only when UEFI boot is used.
392
393As an example:
394
395        module@0xc000000 {
396            compatible = "multiboot,device-tree", "multiboot,module";
397            reg = <0x0 0xc000000 0xffffff>;
398        };
399
400The DTB fragment is loaded at 0xc000000 in the example above. It should
401follow the convention explained in docs/misc/arm/passthrough.txt. The
402DTB fragment will be added to the guest device tree, so that the guest
403kernel will be able to discover the device.
404
405
406Static Allocation
407=============
408
409Static Allocation refers to system or sub-system(domains) for which memory
410areas are pre-defined by configuration using physical address ranges.
411
412Memory can be statically allocated to a domain using the property "xen,static-
413mem" defined in the domain configuration. The number of cells for the address
414and the size must be defined respectively by the parent node properties
415"#address-cells" and "#size-cells".
416
417The property 'memory' is still needed and should match the amount of memory
418given to the guest. Currently, it either comes from static memory or lets Xen
419allocate from heap. *Mixing* is not supported.
420
421The static memory will be mapped in the guest at the usual guest memory
422addresses (GUEST_RAM0_BASE, GUEST_RAM1_BASE) defined by
423xen/include/public/arch-arm.h.
424
425Below is an example on how to specify the static memory region in the
426device-tree:
427
428    / {
429        chosen {
430            #address-cells = <0x1>;
431            #size-cells = <0x1>;
432            ...
433            domU1 {
434                compatible = "xen,domain";
435                cpus = <2>;
436                memory = <0x0 0x80000>;
437                xen,static-mem = <0x30000000 0x20000000>;
438                ...
439            };
440        };
441    };
442
443This will reserve a 512MB region starting at the host physical address
4440x30000000 to be exclusively used by DomU1.
445
446Static Event Channel
447====================
448The event channel communication will be established statically between two
449domains (dom0 and domU also). Event channel connection information between
450domains will be passed to Xen via the device tree node. The event channel
451will be created and established in Xen before the domain started. The domain
452does not need to do any operation to establish a connection. Domain only
453needs hypercall EVTCHNOP_send(local port) to send notifications to the
454remote guest.
455
456There is no need to describe the static event channel info in the domU device
457tree. Static event channels are only useful in fully static configurations,
458and in those configurations, the domU device tree dynamically generated by Xen
459is not needed.
460
461To enable the event-channel interface for domU guests include the
462xen,enhanced = "no-xenstore" property in the domU Xen device tree node.
463
464Under the "xen,domain" compatible node for domU, there needs to be sub-nodes
465with compatible "xen,evtchn" that describe the event channel connection
466between two domUs. For dom0, there needs to be sub-nodes with compatible
467"xen,evtchn" under the chosen node.
468
469The static event channel node has the following properties:
470
471- compatible
472
473    "xen,evtchn"
474
475- xen,evtchn
476
477    The property is tuples of two numbers
478    (local-evtchn link-to-foreign-evtchn) where:
479
480    local-evtchn is an integer value that will be used to allocate local port
481    for a domain to send and receive event notifications to/from the remote
482    domain. Maximum supported value is 2^17 for FIFO ABI and 4096 for 2L ABI.
483    It is recommended to use low event channel IDs.
484
485    link-to-foreign-evtchn is a single phandle to a remote evtchn to which
486    local-evtchn will be connected.
487
488Example
489=======
490
491chosen {
492
493    /* One sub-node per local event channel. This sub-node is for Dom0. */
494    ec1: evtchn@1 {
495         compatible = "xen,evtchn-v1";
496         /* local-evtchn link-to-foreign-evtchn */
497         xen,evtchn = <0xa &ec2>;
498    };
499
500    domU1 {
501        compatible = "xen,domain";
502        #address-cells = <0x2>;
503        #size-cells = <0x1>;
504        xen,enhanced = "no-xenstore";
505
506        /* One sub-node per local event channel */
507        ec2: evtchn@2 {
508            compatible = "xen,evtchn-v1";
509            /* local-evtchn link-to-foreign-evtchn */
510            xen,evtchn = <0xa &ec1>;
511        };
512
513        ec3: evtchn@3 {
514            compatible = "xen,evtchn-v1";
515            xen,evtchn = <0xb &ec5>;
516        };
517
518        ec4: evtchn@4 {
519            compatible = "xen,evtchn-v1";
520            xen,evtchn = <0xc &ec6>;
521        };
522    };
523
524    domU2 {
525        compatible = "xen,domain";
526        #address-cells = <0x2>;
527        #size-cells = <0x1>;
528        xen,enhanced = "no-xenstore";
529
530        /* One sub-node per local event channel */
531        ec5: evtchn@5 {
532            compatible = "xen,evtchn-v1";
533            /* local-evtchn link-to-foreign-evtchn */
534            xen,evtchn = <0xb &ec3>;
535        };
536
537        ec6: evtchn@6 {
538            compatible = "xen,evtchn-v1";
539            xen,evtchn = <0xd &ec4>;
540        };
541    };
542};
543
544Static Heap Memory
545==================
546
547The static heap memory refers to parts of RAM reserved in the beginning of
548boot time for heap. The memory is reserved by configuration in the device
549tree using physical address ranges.
550
551The static heap memory declared in the device tree defines the memory areas
552that will be reserved to be used exclusively as heap.
553
554- For Arm32, since there are separated heaps, the static heap will be used
555for both domheap and xenheap. The admin should make sure that the static
556heap region should contain enough memory below 4GB to cater 32-bit DMA.
557
558- For Arm64, since there is a single heap, the defined static heap areas
559shall always go to the heap allocator.
560
561The static heap memory is an optional feature and can be enabled by adding
562below device tree property.
563
564- xen,static-heap
565
566    Property under the top-level "chosen" node. It specifies the address
567    and size of Xen static heap memory. Number of address and size cells
568    for the "xen,static-heap" property is determined by the root node
569    "#address-cells" and "#size-cells". Note that at least a 64KB alignment
570    is required.
571
572Below is an example on how to specify the static heap in device tree:
573
574    / {
575        #address-cells = <0x2>;
576        #size-cells = <0x2>;
577        ...
578        chosen {
579            xen,static-heap = <0x0 0x30000000 0x0 0x40000000>;
580            ...
581        };
582    };
583
584RAM starting from the host physical address 0x30000000 of 1GB size will
585be reserved as static heap.
586
587Static Shared Memory
588====================
589
590The static shared memory device tree nodes allow users to statically set up
591shared memory on dom0less system, enabling domains to do shm-based
592communication.
593
594- compatible
595
596    "xen,domain-shared-memory-v1"
597
598- xen,shm-id
599
600    An arbitrary string that represents the unique identifier of the shared
601    memory region, with a strict limit on the number of characters(\0 included),
602    `MAX_SHM_ID_LENGTH(16)`. e.g. "xen,shm-id = "my-shared-mem-1"".
603
604- xen,shared-mem
605
606    An array takes a physical address, which is the base address of the
607    shared memory region in host physical address space, a size, and a guest
608    physical address, as the target address of the mapping.
609    e.g. xen,shared-mem = < [host physical address] [guest address] [size] >;
610    Note that if a domain is direct-mapped, i.e. the Dom0 and the Dom0less
611    DomUs with `direct-map` device tree property, the static shared memory
612    should also be direct-mapped (host physical address == guest address).
613
614    It shall also meet the following criteria:
615    1) If the SHM ID matches with an existing region, the address range of the
616    region shall also exactly match.
617    2) If the SHM ID does not match with any other existing region, it should
618    also not overlap with any other regions.
619
620    The number of cells for the host address (and size) is the same as the
621    guest pseudo-physical address and they are inherited from the parent node.
622
623    Host physical address is optional, when missing Xen decides the location.
624    e.g. xen,shared-mem = < [guest address] [size] >;
625
626- role (Optional)
627
628    A string property specifying the ownership of a shared memory region,
629    the value must be one of the following: "owner", or "borrower"
630    A shared memory region could be explicitly backed by one domain, which is
631    called "owner domain", and all the other domains who are also sharing
632    this region are called "borrower domain".
633    If not specified, the default value is "borrower" and owner is
634    DOMID_IO, a system domain.
635
636As an example:
637
638chosen {
639    #address-cells = <0x1>;
640    #size-cells = <0x1>;
641    xen,xen-bootargs = "console=dtuart dtuart=serial0 bootscrub=0";
642
643    ......
644
645    /* this is for Dom0 */
646    dom0-shared-mem@10000000 {
647        compatible = "xen,domain-shared-memory-v1";
648        role = "owner";
649        xen,shm-id = "my-shared-mem-0";
650        xen,shared-mem = <0x10000000 0x10000000 0x10000000>;
651    };
652
653    domU1 {
654        compatible = "xen,domain";
655        #address-cells = <0x1>;
656        #size-cells = <0x1>;
657        memory = <0 131072>;
658        cpus = <2>;
659        vpl011;
660
661        /*
662         * shared memory region "my-shared-mem-0" is shared
663         * between Dom0 and DomU1.
664         */
665        domU1-shared-mem@10000000 {
666            compatible = "xen,domain-shared-memory-v1";
667            role = "borrower";
668            xen,shm-id = "my-shared-mem-0";
669            xen,shared-mem = <0x10000000 0x50000000 0x10000000>;
670        };
671
672        /*
673         * shared memory region "my-shared-mem-1" is shared between
674         * DomU1 and DomU2.
675         */
676        domU1-shared-mem@50000000 {
677            compatible = "xen,domain-shared-memory-v1";
678            xen,shm-id = "my-shared-mem-1";
679            xen,shared-mem = <0x50000000 0x60000000 0x20000000>;
680        };
681
682        /*
683         * shared memory region "my-shared-mem-2" is shared between
684         * DomU1 and DomU2.
685         */
686        domU1-shared-mem-2 {
687            compatible = "xen,domain-shared-memory-v1";
688            xen,shm-id = "my-shared-mem-2";
689            role = "owner";
690            xen,shared-mem = <0x80000000 0x20000000>;
691        };
692
693        ......
694
695    };
696
697    domU2 {
698        compatible = "xen,domain";
699        #address-cells = <0x1>;
700        #size-cells = <0x1>;
701        memory = <0 65536>;
702        cpus = <1>;
703
704        /*
705         * shared memory region "my-shared-mem-1" is shared between
706         * domU1 and domU2.
707         */
708        domU2-shared-mem@50000000 {
709            compatible = "xen,domain-shared-memory-v1";
710            xen,shm-id = "my-shared-mem-1";
711            xen,shared-mem = <0x50000000 0x70000000 0x20000000>;
712        };
713
714        domU2-shared-mem-2 {
715            compatible = "xen,domain-shared-memory-v1";
716            xen,shm-id = "my-shared-mem-2";
717            role = "borrower";
718            xen,shared-mem = <0x90000000 0x20000000>;
719        };
720
721        ......
722    };
723};
724
725This is an example with two static shared memory regions.
726
727For the static shared memory region identified as "my-shared-mem-0", host
728physical address starting at 0x10000000 of 256MB will be reserved to be
729shared between Dom0 and DomU1. It will get mapped at 0x10000000 in Dom0 guest
730physical address space, and at 0x50000000 in DomU1 guest physical address space.
731Dom0 is explicitly defined as the owner domain, and DomU1 is the borrower domain.
732
733For the static shared memory region identified as "my-shared-mem-1", host
734physical address starting at 0x50000000 of 512MB will be reserved to be
735shared between DomU1 and DomU2. It will get mapped at 0x60000000 in DomU1 guest
736physical address space, and at 0x70000000 in DomU2 guest physical address space.
737DomU1 and DomU2 are both the borrower domain, the owner domain is the default
738owner domain DOMID_IO.
739
740For the static shared memory region "my-shared-mem-2", since host physical
741address is not provided by user, Xen will automatically allocate 512MB
742from heap as static shared memory to be shared between DomU1 and DomU2.
743The automatically allocated static shared memory will get mapped at
7440x80000000 in DomU1 guest physical address space, and at 0x90000000 in DomU2
745guest physical address space. DomU1 is explicitly defined as the owner domain,
746and DomU2 is the borrower domain.
747