qemu/include/hw/remote-port.h
<<
>>
Prefs
   1/*
   2 * QEMU remote port.
   3 *
   4 * Copyright (c) 2013 Xilinx Inc
   5 * Written by Edgar E. Iglesias <edgar.iglesias@xilinx.com>
   6 *
   7 * This code is licensed under the GNU GPL.
   8 */
   9#ifndef REMOTE_PORT_H__
  10#define REMOTE_PORT_H__
  11
  12#include <stdbool.h>
  13#include "hw/remote-port-proto.h"
  14#include "hw/remote-port-device.h"
  15#include "chardev/char.h"
  16#include "chardev/char-fe.h"
  17#include "hw/ptimer.h"
  18
  19#define TYPE_REMOTE_PORT "remote-port"
  20#define REMOTE_PORT(obj) OBJECT_CHECK(RemotePort, (obj), TYPE_REMOTE_PORT)
  21
  22typedef struct RemotePortRespSlot {
  23            RemotePortDynPkt rsp;
  24            uint32_t id;
  25            bool used;
  26            bool valid;
  27} RemotePortRespSlot;
  28
  29struct RemotePort {
  30    DeviceState parent;
  31
  32    QemuThread thread;
  33    union {
  34       int pipes[2];
  35       struct {
  36           int read;
  37           int write;
  38       } pipe;
  39    } event;
  40    Chardev *chrdev;
  41    CharBackend chr;
  42    bool do_sync;
  43    bool doing_sync;
  44    bool finalizing;
  45    /* To serialize writes to fd.  */
  46    QemuMutex write_mutex;
  47
  48    char *chardesc;
  49    char *chrdev_id;
  50    struct rp_peer_state peer;
  51
  52    struct {
  53        ptimer_state *ptimer;
  54        ptimer_state *ptimer_resp;
  55        bool resp_timer_enabled;
  56        bool need_sync;
  57        struct rp_pkt rsp;
  58        uint64_t quantum;
  59    } sync;
  60
  61    QemuMutex rsp_mutex;
  62    QemuCond progress_cond;
  63
  64#define RX_QUEUE_SIZE 1024
  65    struct {
  66        /* This array must be sized minimum 2 and always a power of 2.  */
  67        RemotePortDynPkt pkt[RX_QUEUE_SIZE];
  68        bool inuse[RX_QUEUE_SIZE];
  69        QemuSemaphore sem;
  70        unsigned int wpos;
  71        unsigned int rpos;
  72    } rx_queue;
  73
  74    /*
  75     * rsp holds responses for the remote side.
  76     * Used by the slave.
  77     */
  78    RemotePortDynPkt rsp;
  79
  80    /*
  81     * rspqueue holds received responses from the remote side.
  82     * Only one for the moment but it might grow.
  83     * Used by the master.
  84     */
  85    RemotePortDynPkt rspqueue;
  86
  87    bool resets[32];
  88
  89    const char *prefix;
  90    const char *remote_prefix;
  91
  92    uint32_t current_id;
  93
  94#define REMOTE_PORT_MAX_DEVS 1024
  95#define RP_MAX_OUTSTANDING_TRANSACTIONS 32
  96    struct {
  97        RemotePortRespSlot rsp_queue[RP_MAX_OUTSTANDING_TRANSACTIONS];
  98    } dev_state[REMOTE_PORT_MAX_DEVS];
  99
 100    RemotePortDevice *devs[REMOTE_PORT_MAX_DEVS];
 101};
 102
 103/**
 104 * rp_device_attach:
 105 * @adaptor: The adaptor onto which to attach the device
 106 * @dev: The device to be attached to the adaptor
 107 * @rp_nr: The remote-port adaptor nr. A device may attach to multiple
 108 *         adaptors.
 109 * @dev_nr: The device/channel number to bind the device to.
 110 * @errp: returns an error if this function fails
 111 *
 112 * Attaches a device onto an adaptor and binds it to a device number.
 113 */
 114void rp_device_attach(Object *adaptor, Object *dev,
 115                      int rp_nr, int dev_nr,
 116                      Error **errp);
 117void rp_device_detach(Object *adaptor, Object *dev,
 118                      int rp_nr, int dev_nr,
 119                      Error **errp);
 120bool rp_time_warp_enable(bool en);
 121
 122/**
 123 * rp_device_add
 124 * @opts:  qdev opts created by the qdev subsystem
 125 * @dev: The device to be connected
 126 * @errp: Returns an error if the function fails
 127 *
 128 * Function used in qdev-monitor.c to connect remote port devices.
 129 * Returns teue on success and false on failure.
 130 */
 131bool rp_device_add(QemuOpts *opts, DeviceState *dev, Error **errp);
 132
 133static inline void rp_resp_slot_done(RemotePort *s,
 134                                     RemotePortRespSlot *rsp_slot)
 135{
 136    rp_dpkt_invalidate(&rsp_slot->rsp);
 137    rsp_slot->id = ~0;
 138    rsp_slot->used = false;
 139    rsp_slot->valid = false;
 140}
 141
 142RemotePortRespSlot *rp_dev_wait_resp(RemotePort *s, uint32_t dev, uint32_t id);
 143void rp_process(RemotePort *s);
 144
 145#endif
 146