xref: /openbmc/qemu/include/hw/stream.h (revision 8fa3b702)
1 #ifndef STREAM_H
2 #define STREAM_H
3 
4 #include "qom/object.h"
5 
6 /* stream slave. Used until qdev provides a generic way.  */
7 #define TYPE_STREAM_SLAVE "stream-slave"
8 
9 typedef struct StreamSlaveClass StreamSlaveClass;
10 DECLARE_CLASS_CHECKERS(StreamSlaveClass, STREAM_SLAVE,
11                        TYPE_STREAM_SLAVE)
12 #define STREAM_SLAVE(obj) \
13      INTERFACE_CHECK(StreamSlave, (obj), TYPE_STREAM_SLAVE)
14 
15 typedef struct StreamSlave StreamSlave;
16 
17 typedef void (*StreamCanPushNotifyFn)(void *opaque);
18 
19 struct StreamSlaveClass {
20     InterfaceClass parent;
21     /**
22      * can push - determine if a stream slave is capable of accepting at least
23      * one byte of data. Returns false if cannot accept. If not implemented, the
24      * slave is assumed to always be capable of receiving.
25      * @notify: Optional callback that the slave will call when the slave is
26      * capable of receiving again. Only called if false is returned.
27      * @notify_opaque: opaque data to pass to notify call.
28      */
29     bool (*can_push)(StreamSlave *obj, StreamCanPushNotifyFn notify,
30                      void *notify_opaque);
31     /**
32      * push - push data to a Stream slave. The number of bytes pushed is
33      * returned. If the slave short returns, the master must wait before trying
34      * again, the slave may continue to just return 0 waiting for the vm time to
35      * advance. The can_push() function can be used to trap the point in time
36      * where the slave is ready to receive again, otherwise polling on a QEMU
37      * timer will work.
38      * @obj: Stream slave to push to
39      * @buf: Data to write
40      * @len: Maximum number of bytes to write
41      * @eop: End of packet flag
42      */
43     size_t (*push)(StreamSlave *obj, unsigned char *buf, size_t len, bool eop);
44 };
45 
46 size_t
47 stream_push(StreamSlave *sink, uint8_t *buf, size_t len, bool eop);
48 
49 bool
50 stream_can_push(StreamSlave *sink, StreamCanPushNotifyFn notify,
51                 void *notify_opaque);
52 
53 
54 #endif /* STREAM_H */
55