xref: /openbmc/qemu/hw/ppc/spapr_vio.c (revision 87776ab7)
1 /*
2  * QEMU sPAPR VIO code
3  *
4  * Copyright (c) 2010 David Gibson, IBM Corporation <dwg@au1.ibm.com>
5  * Based on the s390 virtio bus code:
6  * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "qemu/osdep.h"
23 #include "qapi/error.h"
24 #include "hw/hw.h"
25 #include "sysemu/sysemu.h"
26 #include "hw/boards.h"
27 #include "hw/loader.h"
28 #include "elf.h"
29 #include "hw/sysbus.h"
30 #include "sysemu/kvm.h"
31 #include "sysemu/device_tree.h"
32 #include "kvm_ppc.h"
33 
34 #include "hw/ppc/spapr.h"
35 #include "hw/ppc/spapr_vio.h"
36 #include "hw/ppc/xics.h"
37 
38 #include <libfdt.h>
39 
40 /* #define DEBUG_SPAPR */
41 
42 #ifdef DEBUG_SPAPR
43 #define DPRINTF(fmt, ...) \
44     do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
45 #else
46 #define DPRINTF(fmt, ...) \
47     do { } while (0)
48 #endif
49 
50 static Property spapr_vio_props[] = {
51     DEFINE_PROP_UINT32("irq", VIOsPAPRDevice, irq, 0), \
52     DEFINE_PROP_END_OF_LIST(),
53 };
54 
55 static char *spapr_vio_get_dev_name(DeviceState *qdev)
56 {
57     VIOsPAPRDevice *dev = VIO_SPAPR_DEVICE(qdev);
58     VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
59     char *name;
60 
61     /* Device tree style name device@reg */
62     name = g_strdup_printf("%s@%x", pc->dt_name, dev->reg);
63 
64     return name;
65 }
66 
67 static void spapr_vio_bus_class_init(ObjectClass *klass, void *data)
68 {
69     BusClass *k = BUS_CLASS(klass);
70 
71     k->get_dev_path = spapr_vio_get_dev_name;
72     k->get_fw_dev_path = spapr_vio_get_dev_name;
73 }
74 
75 static const TypeInfo spapr_vio_bus_info = {
76     .name = TYPE_SPAPR_VIO_BUS,
77     .parent = TYPE_BUS,
78     .class_init = spapr_vio_bus_class_init,
79     .instance_size = sizeof(VIOsPAPRBus),
80 };
81 
82 VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg)
83 {
84     BusChild *kid;
85     VIOsPAPRDevice *dev = NULL;
86 
87     QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
88         dev = (VIOsPAPRDevice *)kid->child;
89         if (dev->reg == reg) {
90             return dev;
91         }
92     }
93 
94     return NULL;
95 }
96 
97 static int vio_make_devnode(VIOsPAPRDevice *dev,
98                             void *fdt)
99 {
100     VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
101     int vdevice_off, node_off, ret;
102     char *dt_name;
103 
104     vdevice_off = fdt_path_offset(fdt, "/vdevice");
105     if (vdevice_off < 0) {
106         return vdevice_off;
107     }
108 
109     dt_name = spapr_vio_get_dev_name(DEVICE(dev));
110     node_off = fdt_add_subnode(fdt, vdevice_off, dt_name);
111     g_free(dt_name);
112     if (node_off < 0) {
113         return node_off;
114     }
115 
116     ret = fdt_setprop_cell(fdt, node_off, "reg", dev->reg);
117     if (ret < 0) {
118         return ret;
119     }
120 
121     if (pc->dt_type) {
122         ret = fdt_setprop_string(fdt, node_off, "device_type",
123                                  pc->dt_type);
124         if (ret < 0) {
125             return ret;
126         }
127     }
128 
129     if (pc->dt_compatible) {
130         ret = fdt_setprop_string(fdt, node_off, "compatible",
131                                  pc->dt_compatible);
132         if (ret < 0) {
133             return ret;
134         }
135     }
136 
137     if (dev->irq) {
138         uint32_t ints_prop[] = {cpu_to_be32(dev->irq), 0};
139 
140         ret = fdt_setprop(fdt, node_off, "interrupts", ints_prop,
141                           sizeof(ints_prop));
142         if (ret < 0) {
143             return ret;
144         }
145     }
146 
147     ret = spapr_tcet_dma_dt(fdt, node_off, "ibm,my-dma-window", dev->tcet);
148     if (ret < 0) {
149         return ret;
150     }
151 
152     if (pc->devnode) {
153         ret = (pc->devnode)(dev, fdt, node_off);
154         if (ret < 0) {
155             return ret;
156         }
157     }
158 
159     return node_off;
160 }
161 
162 /*
163  * CRQ handling
164  */
165 static target_ulong h_reg_crq(PowerPCCPU *cpu, sPAPRMachineState *spapr,
166                               target_ulong opcode, target_ulong *args)
167 {
168     target_ulong reg = args[0];
169     target_ulong queue_addr = args[1];
170     target_ulong queue_len = args[2];
171     VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
172 
173     if (!dev) {
174         hcall_dprintf("Unit 0x" TARGET_FMT_lx " does not exist\n", reg);
175         return H_PARAMETER;
176     }
177 
178     /* We can't grok a queue size bigger than 256M for now */
179     if (queue_len < 0x1000 || queue_len > 0x10000000) {
180         hcall_dprintf("Queue size too small or too big (0x" TARGET_FMT_lx
181                       ")\n", queue_len);
182         return H_PARAMETER;
183     }
184 
185     /* Check queue alignment */
186     if (queue_addr & 0xfff) {
187         hcall_dprintf("Queue not aligned (0x" TARGET_FMT_lx ")\n", queue_addr);
188         return H_PARAMETER;
189     }
190 
191     /* Check if device supports CRQs */
192     if (!dev->crq.SendFunc) {
193         hcall_dprintf("Device does not support CRQ\n");
194         return H_NOT_FOUND;
195     }
196 
197     /* Already a queue ? */
198     if (dev->crq.qsize) {
199         hcall_dprintf("CRQ already registered\n");
200         return H_RESOURCE;
201     }
202     dev->crq.qladdr = queue_addr;
203     dev->crq.qsize = queue_len;
204     dev->crq.qnext = 0;
205 
206     DPRINTF("CRQ for dev 0x" TARGET_FMT_lx " registered at 0x"
207             TARGET_FMT_lx "/0x" TARGET_FMT_lx "\n",
208             reg, queue_addr, queue_len);
209     return H_SUCCESS;
210 }
211 
212 static target_ulong free_crq(VIOsPAPRDevice *dev)
213 {
214     dev->crq.qladdr = 0;
215     dev->crq.qsize = 0;
216     dev->crq.qnext = 0;
217 
218     DPRINTF("CRQ for dev 0x%" PRIx32 " freed\n", dev->reg);
219 
220     return H_SUCCESS;
221 }
222 
223 static target_ulong h_free_crq(PowerPCCPU *cpu, sPAPRMachineState *spapr,
224                                target_ulong opcode, target_ulong *args)
225 {
226     target_ulong reg = args[0];
227     VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
228 
229     if (!dev) {
230         hcall_dprintf("Unit 0x" TARGET_FMT_lx " does not exist\n", reg);
231         return H_PARAMETER;
232     }
233 
234     return free_crq(dev);
235 }
236 
237 static target_ulong h_send_crq(PowerPCCPU *cpu, sPAPRMachineState *spapr,
238                                target_ulong opcode, target_ulong *args)
239 {
240     target_ulong reg = args[0];
241     target_ulong msg_hi = args[1];
242     target_ulong msg_lo = args[2];
243     VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
244     uint64_t crq_mangle[2];
245 
246     if (!dev) {
247         hcall_dprintf("Unit 0x" TARGET_FMT_lx " does not exist\n", reg);
248         return H_PARAMETER;
249     }
250     crq_mangle[0] = cpu_to_be64(msg_hi);
251     crq_mangle[1] = cpu_to_be64(msg_lo);
252 
253     if (dev->crq.SendFunc) {
254         return dev->crq.SendFunc(dev, (uint8_t *)crq_mangle);
255     }
256 
257     return H_HARDWARE;
258 }
259 
260 static target_ulong h_enable_crq(PowerPCCPU *cpu, sPAPRMachineState *spapr,
261                                  target_ulong opcode, target_ulong *args)
262 {
263     target_ulong reg = args[0];
264     VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
265 
266     if (!dev) {
267         hcall_dprintf("Unit 0x" TARGET_FMT_lx " does not exist\n", reg);
268         return H_PARAMETER;
269     }
270 
271     return 0;
272 }
273 
274 /* Returns negative error, 0 success, or positive: queue full */
275 int spapr_vio_send_crq(VIOsPAPRDevice *dev, uint8_t *crq)
276 {
277     int rc;
278     uint8_t byte;
279 
280     if (!dev->crq.qsize) {
281         fprintf(stderr, "spapr_vio_send_creq on uninitialized queue\n");
282         return -1;
283     }
284 
285     /* Maybe do a fast path for KVM just writing to the pages */
286     rc = spapr_vio_dma_read(dev, dev->crq.qladdr + dev->crq.qnext, &byte, 1);
287     if (rc) {
288         return rc;
289     }
290     if (byte != 0) {
291         return 1;
292     }
293 
294     rc = spapr_vio_dma_write(dev, dev->crq.qladdr + dev->crq.qnext + 8,
295                              &crq[8], 8);
296     if (rc) {
297         return rc;
298     }
299 
300     kvmppc_eieio();
301 
302     rc = spapr_vio_dma_write(dev, dev->crq.qladdr + dev->crq.qnext, crq, 8);
303     if (rc) {
304         return rc;
305     }
306 
307     dev->crq.qnext = (dev->crq.qnext + 16) % dev->crq.qsize;
308 
309     if (dev->signal_state & 1) {
310         qemu_irq_pulse(spapr_vio_qirq(dev));
311     }
312 
313     return 0;
314 }
315 
316 /* "quiesce" handling */
317 
318 static void spapr_vio_quiesce_one(VIOsPAPRDevice *dev)
319 {
320     if (dev->tcet) {
321         device_reset(DEVICE(dev->tcet));
322     }
323     free_crq(dev);
324 }
325 
326 void spapr_vio_set_bypass(VIOsPAPRDevice *dev, bool bypass)
327 {
328     if (!dev->tcet) {
329         return;
330     }
331 
332     memory_region_set_enabled(&dev->mrbypass, bypass);
333     memory_region_set_enabled(spapr_tce_get_iommu(dev->tcet), !bypass);
334 
335     dev->tcet->bypass = bypass;
336 }
337 
338 static void rtas_set_tce_bypass(PowerPCCPU *cpu, sPAPRMachineState *spapr,
339                                 uint32_t token,
340                                 uint32_t nargs, target_ulong args,
341                                 uint32_t nret, target_ulong rets)
342 {
343     VIOsPAPRBus *bus = spapr->vio_bus;
344     VIOsPAPRDevice *dev;
345     uint32_t unit, enable;
346 
347     if (nargs != 2) {
348         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
349         return;
350     }
351     unit = rtas_ld(args, 0);
352     enable = rtas_ld(args, 1);
353     dev = spapr_vio_find_by_reg(bus, unit);
354     if (!dev) {
355         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
356         return;
357     }
358 
359     if (!dev->tcet) {
360         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
361         return;
362     }
363 
364     spapr_vio_set_bypass(dev, !!enable);
365 
366     rtas_st(rets, 0, RTAS_OUT_SUCCESS);
367 }
368 
369 static void rtas_quiesce(PowerPCCPU *cpu, sPAPRMachineState *spapr,
370                          uint32_t token,
371                          uint32_t nargs, target_ulong args,
372                          uint32_t nret, target_ulong rets)
373 {
374     VIOsPAPRBus *bus = spapr->vio_bus;
375     BusChild *kid;
376     VIOsPAPRDevice *dev = NULL;
377 
378     if (nargs != 0) {
379         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
380         return;
381     }
382 
383     QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
384         dev = (VIOsPAPRDevice *)kid->child;
385         spapr_vio_quiesce_one(dev);
386     }
387 
388     rtas_st(rets, 0, RTAS_OUT_SUCCESS);
389 }
390 
391 static VIOsPAPRDevice *reg_conflict(VIOsPAPRDevice *dev)
392 {
393     VIOsPAPRBus *bus = SPAPR_VIO_BUS(dev->qdev.parent_bus);
394     BusChild *kid;
395     VIOsPAPRDevice *other;
396 
397     /*
398      * Check for a device other than the given one which is already
399      * using the requested address. We have to open code this because
400      * the given dev might already be in the list.
401      */
402     QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
403         other = VIO_SPAPR_DEVICE(kid->child);
404 
405         if (other != dev && other->reg == dev->reg) {
406             return other;
407         }
408     }
409 
410     return 0;
411 }
412 
413 static void spapr_vio_busdev_reset(DeviceState *qdev)
414 {
415     VIOsPAPRDevice *dev = VIO_SPAPR_DEVICE(qdev);
416     VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
417 
418     /* Shut down the request queue and TCEs if necessary */
419     spapr_vio_quiesce_one(dev);
420 
421     dev->signal_state = 0;
422 
423     spapr_vio_set_bypass(dev, false);
424     if (pc->reset) {
425         pc->reset(dev);
426     }
427 }
428 
429 static void spapr_vio_busdev_realize(DeviceState *qdev, Error **errp)
430 {
431     sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
432     VIOsPAPRDevice *dev = (VIOsPAPRDevice *)qdev;
433     VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
434     char *id;
435     Error *local_err = NULL;
436 
437     if (dev->reg != -1) {
438         /*
439          * Explicitly assigned address, just verify that no-one else
440          * is using it.  other mechanism). We have to open code this
441          * rather than using spapr_vio_find_by_reg() because sdev
442          * itself is already in the list.
443          */
444         VIOsPAPRDevice *other = reg_conflict(dev);
445 
446         if (other) {
447             error_setg(errp, "%s and %s devices conflict at address %#x",
448                        object_get_typename(OBJECT(qdev)),
449                        object_get_typename(OBJECT(&other->qdev)),
450                        dev->reg);
451             return;
452         }
453     } else {
454         /* Need to assign an address */
455         VIOsPAPRBus *bus = SPAPR_VIO_BUS(dev->qdev.parent_bus);
456 
457         do {
458             dev->reg = bus->next_reg++;
459         } while (reg_conflict(dev));
460     }
461 
462     /* Don't overwrite ids assigned on the command line */
463     if (!dev->qdev.id) {
464         id = spapr_vio_get_dev_name(DEVICE(dev));
465         dev->qdev.id = id;
466     }
467 
468     dev->irq = xics_alloc(spapr->icp, 0, dev->irq, false, &local_err);
469     if (local_err) {
470         error_propagate(errp, local_err);
471         return;
472     }
473 
474     if (pc->rtce_window_size) {
475         uint32_t liobn = SPAPR_VIO_LIOBN(dev->reg);
476 
477         memory_region_init(&dev->mrroot, OBJECT(dev), "iommu-spapr-root",
478                            ram_size);
479         memory_region_init_alias(&dev->mrbypass, OBJECT(dev),
480                                  "iommu-spapr-bypass", get_system_memory(),
481                                  0, ram_size);
482         memory_region_add_subregion_overlap(&dev->mrroot, 0, &dev->mrbypass, 1);
483         address_space_init(&dev->as, &dev->mrroot, qdev->id);
484 
485         dev->tcet = spapr_tce_new_table(qdev, liobn,
486                                         0,
487                                         SPAPR_TCE_PAGE_SHIFT,
488                                         pc->rtce_window_size >>
489                                         SPAPR_TCE_PAGE_SHIFT, false);
490         dev->tcet->vdev = dev;
491         memory_region_add_subregion_overlap(&dev->mrroot, 0,
492                                             spapr_tce_get_iommu(dev->tcet), 2);
493     }
494 
495     pc->realize(dev, errp);
496 }
497 
498 static target_ulong h_vio_signal(PowerPCCPU *cpu, sPAPRMachineState *spapr,
499                                  target_ulong opcode,
500                                  target_ulong *args)
501 {
502     target_ulong reg = args[0];
503     target_ulong mode = args[1];
504     VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
505     VIOsPAPRDeviceClass *pc;
506 
507     if (!dev) {
508         return H_PARAMETER;
509     }
510 
511     pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
512 
513     if (mode & ~pc->signal_mask) {
514         return H_PARAMETER;
515     }
516 
517     dev->signal_state = mode;
518 
519     return H_SUCCESS;
520 }
521 
522 VIOsPAPRBus *spapr_vio_bus_init(void)
523 {
524     VIOsPAPRBus *bus;
525     BusState *qbus;
526     DeviceState *dev;
527 
528     /* Create bridge device */
529     dev = qdev_create(NULL, TYPE_SPAPR_VIO_BRIDGE);
530     qdev_init_nofail(dev);
531 
532     /* Create bus on bridge device */
533     qbus = qbus_create(TYPE_SPAPR_VIO_BUS, dev, "spapr-vio");
534     bus = SPAPR_VIO_BUS(qbus);
535     bus->next_reg = 0x71000000;
536 
537     /* hcall-vio */
538     spapr_register_hypercall(H_VIO_SIGNAL, h_vio_signal);
539 
540     /* hcall-crq */
541     spapr_register_hypercall(H_REG_CRQ, h_reg_crq);
542     spapr_register_hypercall(H_FREE_CRQ, h_free_crq);
543     spapr_register_hypercall(H_SEND_CRQ, h_send_crq);
544     spapr_register_hypercall(H_ENABLE_CRQ, h_enable_crq);
545 
546     /* RTAS calls */
547     spapr_rtas_register(RTAS_IBM_SET_TCE_BYPASS, "ibm,set-tce-bypass",
548                         rtas_set_tce_bypass);
549     spapr_rtas_register(RTAS_QUIESCE, "quiesce", rtas_quiesce);
550 
551     return bus;
552 }
553 
554 /* Represents sPAPR hcall VIO devices */
555 
556 static int spapr_vio_bridge_init(SysBusDevice *dev)
557 {
558     /* nothing */
559     return 0;
560 }
561 
562 static void spapr_vio_bridge_class_init(ObjectClass *klass, void *data)
563 {
564     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
565     DeviceClass *dc = DEVICE_CLASS(klass);
566 
567     dc->fw_name = "vdevice";
568     k->init = spapr_vio_bridge_init;
569 }
570 
571 static const TypeInfo spapr_vio_bridge_info = {
572     .name          = TYPE_SPAPR_VIO_BRIDGE,
573     .parent        = TYPE_SYS_BUS_DEVICE,
574     .class_init    = spapr_vio_bridge_class_init,
575 };
576 
577 const VMStateDescription vmstate_spapr_vio = {
578     .name = "spapr_vio",
579     .version_id = 1,
580     .minimum_version_id = 1,
581     .fields = (VMStateField[]) {
582         /* Sanity check */
583         VMSTATE_UINT32_EQUAL(reg, VIOsPAPRDevice),
584         VMSTATE_UINT32_EQUAL(irq, VIOsPAPRDevice),
585 
586         /* General VIO device state */
587         VMSTATE_UINT64(signal_state, VIOsPAPRDevice),
588         VMSTATE_UINT64(crq.qladdr, VIOsPAPRDevice),
589         VMSTATE_UINT32(crq.qsize, VIOsPAPRDevice),
590         VMSTATE_UINT32(crq.qnext, VIOsPAPRDevice),
591 
592         VMSTATE_END_OF_LIST()
593     },
594 };
595 
596 static void vio_spapr_device_class_init(ObjectClass *klass, void *data)
597 {
598     DeviceClass *k = DEVICE_CLASS(klass);
599     k->realize = spapr_vio_busdev_realize;
600     k->reset = spapr_vio_busdev_reset;
601     k->bus_type = TYPE_SPAPR_VIO_BUS;
602     k->props = spapr_vio_props;
603 }
604 
605 static const TypeInfo spapr_vio_type_info = {
606     .name = TYPE_VIO_SPAPR_DEVICE,
607     .parent = TYPE_DEVICE,
608     .instance_size = sizeof(VIOsPAPRDevice),
609     .abstract = true,
610     .class_size = sizeof(VIOsPAPRDeviceClass),
611     .class_init = vio_spapr_device_class_init,
612 };
613 
614 static void spapr_vio_register_types(void)
615 {
616     type_register_static(&spapr_vio_bus_info);
617     type_register_static(&spapr_vio_bridge_info);
618     type_register_static(&spapr_vio_type_info);
619 }
620 
621 type_init(spapr_vio_register_types)
622 
623 static int compare_reg(const void *p1, const void *p2)
624 {
625     VIOsPAPRDevice const *dev1, *dev2;
626 
627     dev1 = (VIOsPAPRDevice *)*(DeviceState **)p1;
628     dev2 = (VIOsPAPRDevice *)*(DeviceState **)p2;
629 
630     if (dev1->reg < dev2->reg) {
631         return -1;
632     }
633     if (dev1->reg == dev2->reg) {
634         return 0;
635     }
636 
637     /* dev1->reg > dev2->reg */
638     return 1;
639 }
640 
641 int spapr_populate_vdevice(VIOsPAPRBus *bus, void *fdt)
642 {
643     DeviceState *qdev, **qdevs;
644     BusChild *kid;
645     int i, num, ret = 0;
646 
647     /* Count qdevs on the bus list */
648     num = 0;
649     QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
650         num++;
651     }
652 
653     /* Copy out into an array of pointers */
654     qdevs = g_malloc(sizeof(qdev) * num);
655     num = 0;
656     QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
657         qdevs[num++] = kid->child;
658     }
659 
660     /* Sort the array */
661     qsort(qdevs, num, sizeof(qdev), compare_reg);
662 
663     /* Hack alert. Give the devices to libfdt in reverse order, we happen
664      * to know that will mean they are in forward order in the tree. */
665     for (i = num - 1; i >= 0; i--) {
666         VIOsPAPRDevice *dev = (VIOsPAPRDevice *)(qdevs[i]);
667 
668         ret = vio_make_devnode(dev, fdt);
669 
670         if (ret < 0) {
671             goto out;
672         }
673     }
674 
675     ret = 0;
676 out:
677     g_free(qdevs);
678 
679     return ret;
680 }
681 
682 int spapr_populate_chosen_stdout(void *fdt, VIOsPAPRBus *bus)
683 {
684     VIOsPAPRDevice *dev;
685     char *name, *path;
686     int ret, offset;
687 
688     dev = spapr_vty_get_default(bus);
689     if (!dev)
690         return 0;
691 
692     offset = fdt_path_offset(fdt, "/chosen");
693     if (offset < 0) {
694         return offset;
695     }
696 
697     name = spapr_vio_get_dev_name(DEVICE(dev));
698     path = g_strdup_printf("/vdevice/%s", name);
699 
700     ret = fdt_setprop_string(fdt, offset, "linux,stdout-path", path);
701 
702     g_free(name);
703     g_free(path);
704 
705     return ret;
706 }
707