1 /* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
14 #include <linux/types.h>
25 GSI_STATUS_SUCCESS = 0,
27 GSI_STATUS_RING_INSUFFICIENT_SPACE = 2,
28 GSI_STATUS_RING_EMPTY = 3,
29 GSI_STATUS_RES_ALLOC_FAILURE = 4,
30 GSI_STATUS_BAD_STATE = 5,
31 GSI_STATUS_INVALID_PARAMS = 6,
32 GSI_STATUS_UNSUPPORTED_OP = 7,
34 GSI_STATUS_POLL_EMPTY = 9,
35 GSI_STATUS_EVT_RING_INCOMPATIBLE = 10,
36 GSI_STATUS_TIMED_OUT = 11,
37 GSI_STATUS_AGAIN = 12,
41 GSI_PER_EVT_GLOB_ERROR,
45 GSI_PER_EVT_GENERAL_BREAK_POINT,
46 GSI_PER_EVT_GENERAL_BUS_ERROR,
47 GSI_PER_EVT_GENERAL_CMD_FIFO_OVERFLOW,
48 GSI_PER_EVT_GENERAL_MCS_STACK_OVERFLOW,
52 * gsi_per_notify - Peripheral callback info
54 * @user_data: cookie supplied in gsi_register_device
55 * @evt_id: type of notification
56 * @err_desc: error related information
59 struct gsi_per_notify {
61 enum gsi_per_evt evt_id;
74 * gsi_per_props - Peripheral related properties
76 * @gsi: GSI core version
77 * @ee: EE where this driver and peripheral driver runs
78 * @intr: control interrupt type
79 * @intvec: write data for MSI write
80 * @msi_addr: MSI address
82 * @phys_addr: physical address of GSI block
83 * @size: register size of GSI block
84 * @notify_cb: general notification callback
85 * @req_clk_cb: callback to request peripheral clock
86 * granted should be set to true if request is completed
87 * synchronously, false otherwise (peripheral needs
88 * to call gsi_complete_clk_grant later when request is
90 * if this callback is not provided, then GSI will assume
91 * peripheral is clocked at all times
92 * @rel_clk_cb: callback to release peripheral clock
93 * @user_data: cookie used for notifications
95 * All the callbacks are in interrupt context
98 struct gsi_per_props {
101 enum gsi_intr_type intr;
105 phys_addr_t phys_addr;
107 void (*notify_cb)(struct gsi_per_notify *notify);
108 void (*req_clk_cb)(void *user_data, bool *granted);
109 int (*rel_clk_cb)(void *user_data);
114 GSI_EVT_OUT_OF_BUFFERS_ERR = 0x0,
115 GSI_EVT_OUT_OF_RESOURCES_ERR = 0x1,
116 GSI_EVT_UNSUPPORTED_INTER_EE_OP_ERR = 0x2,
117 GSI_EVT_EVT_RING_EMPTY_ERR = 0x3,
121 * gsi_evt_err_notify - event ring error callback info
123 * @user_data: cookie supplied in gsi_alloc_evt_ring
124 * @evt_id: type of error
125 * @err_desc: more info about the error
128 struct gsi_evt_err_notify {
130 enum gsi_evt_err evt_id;
134 enum gsi_evt_chtype {
135 GSI_EVT_CHTYPE_MHI_EV = 0x0,
136 GSI_EVT_CHTYPE_XHCI_EV = 0x1,
137 GSI_EVT_CHTYPE_GPI_EV = 0x2,
138 GSI_EVT_CHTYPE_XDCI_EV = 0x3
141 enum gsi_evt_ring_elem_size {
142 GSI_EVT_RING_RE_SIZE_4B = 4,
143 GSI_EVT_RING_RE_SIZE_16B = 16,
147 * gsi_evt_ring_props - Event ring related properties
149 * @intf: interface type (of the associated channel)
150 * @intr: interrupt type
151 * @re_size: size of event ring element
152 * @ring_len: length of ring in bytes (must be integral multiple of
154 * @ring_base_addr: physical base address of ring. Address must be aligned to
155 * ring_len rounded to power of two
156 * @ring_base_vaddr: virtual base address of ring (set to NULL when not
158 * @int_modt: cycles base interrupt moderation (32KHz clock)
159 * @int_modc: interrupt moderation packet counter
160 * @intvec: write data for MSI write
161 * @msi_addr: MSI address
162 * @rp_update_addr: physical address to which event read pointer should be
163 * written on every event generation. must be set to 0 when
164 * no update is desdired
165 * @exclusive: if true, only one GSI channel can be associated with this
166 * event ring. if false, the event ring can be shared among
167 * multiple GSI channels but in that case no polling
168 * (GSI_CHAN_MODE_POLL) is supported on any of those channels
169 * @err_cb: error notification callback
170 * @user_data: cookie used for error notifications
171 * @evchid_valid: is evchid valid?
172 * @evchid: the event ID that is being specifically requested (this is
173 * relevant for MHI where doorbell routing requires ERs to be
174 * physically contiguous)
176 struct gsi_evt_ring_props {
177 enum gsi_evt_chtype intf;
178 enum gsi_intr_type intr;
179 enum gsi_evt_ring_elem_size re_size;
181 uint64_t ring_base_addr;
182 void *ring_base_vaddr;
187 uint64_t rp_update_addr;
189 void (*err_cb)(struct gsi_evt_err_notify *notify);
196 GSI_CHAN_MODE_CALLBACK = 0x0,
197 GSI_CHAN_MODE_POLL = 0x1,
201 GSI_CHAN_PROT_MHI = 0x0,
202 GSI_CHAN_PROT_XHCI = 0x1,
203 GSI_CHAN_PROT_GPI = 0x2,
204 GSI_CHAN_PROT_XDCI = 0x3
208 GSI_CHAN_DIR_FROM_GSI = 0x0,
209 GSI_CHAN_DIR_TO_GSI = 0x1
212 enum gsi_max_prefetch {
213 GSI_ONE_PREFETCH_SEG = 0x0,
214 GSI_TWO_PREFETCH_SEG = 0x1
218 GSI_CHAN_EVT_INVALID = 0x0,
219 GSI_CHAN_EVT_SUCCESS = 0x1,
220 GSI_CHAN_EVT_EOT = 0x2,
221 GSI_CHAN_EVT_OVERFLOW = 0x3,
222 GSI_CHAN_EVT_EOB = 0x4,
223 GSI_CHAN_EVT_OOB = 0x5,
224 GSI_CHAN_EVT_DB_MODE = 0x6,
225 GSI_CHAN_EVT_UNDEFINED = 0x10,
226 GSI_CHAN_EVT_RE_ERROR = 0x11,
230 * gsi_chan_xfer_notify - Channel callback info
232 * @chan_user_data: cookie supplied in gsi_alloc_channel
233 * @xfer_user_data: cookie of the gsi_xfer_elem that caused the
234 * event to be generated
235 * @evt_id: type of event triggered by the associated TRE
236 * (corresponding to xfer_user_data)
237 * @bytes_xfered: number of bytes transferred by the associated TRE
238 * (corresponding to xfer_user_data)
241 struct gsi_chan_xfer_notify {
242 void *chan_user_data;
243 void *xfer_user_data;
244 enum gsi_chan_evt evt_id;
245 uint16_t bytes_xfered;
249 GSI_CHAN_INVALID_TRE_ERR = 0x0,
250 GSI_CHAN_NON_ALLOCATED_EVT_ACCESS_ERR = 0x1,
251 GSI_CHAN_OUT_OF_BUFFERS_ERR = 0x2,
252 GSI_CHAN_OUT_OF_RESOURCES_ERR = 0x3,
253 GSI_CHAN_UNSUPPORTED_INTER_EE_OP_ERR = 0x4,
254 GSI_CHAN_HWO_1_ERR = 0x5
258 * gsi_chan_err_notify - Channel general callback info
260 * @chan_user_data: cookie supplied in gsi_alloc_channel
261 * @evt_id: type of error
262 * @err_desc: more info about the error
265 struct gsi_chan_err_notify {
266 void *chan_user_data;
267 enum gsi_chan_err evt_id;
271 enum gsi_chan_ring_elem_size {
272 GSI_CHAN_RE_SIZE_4B = 4,
273 GSI_CHAN_RE_SIZE_16B = 16,
274 GSI_CHAN_RE_SIZE_32B = 32,
277 enum gsi_chan_use_db_eng {
278 GSI_CHAN_DIRECT_MODE = 0x0,
279 GSI_CHAN_DB_MODE = 0x1,
283 * gsi_chan_props - Channel related properties
285 * @prot: interface type
286 * @dir: channel direction
287 * @ch_id: virtual channel ID
288 * @evt_ring_hdl: handle of associated event ring. set to ~0 if no
289 * event ring associated
290 * @re_size: size of channel ring element
291 * @ring_len: length of ring in bytes (must be integral multiple of
293 * @max_re_expected: maximal number of ring elements expected to be queued.
294 * used for data path statistics gathering. if 0 provided
295 * ring_len / re_size will be used.
296 * @ring_base_addr: physical base address of ring. Address must be aligned to
297 * ring_len rounded to power of two
298 * @ring_base_vaddr: virtual base address of ring (set to NULL when not
300 * @use_db_eng: 0 => direct mode (doorbells are written directly to RE
302 * 1 => DB mode (doorbells are written to DB engine)
303 * @max_prefetch: limit number of pre-fetch segments for channel
304 * @low_weight: low channel weight (priority of channel for RE engine
305 * round robin algorithm); must be >= 1
306 * @xfer_cb: transfer notification callback, this callback happens
307 * on event boundaries
313 * RE1: EOT=0, EOB=0, CHAIN=1;
314 * RE2: EOT=0, EOB=0, CHAIN=1;
315 * RE3: EOT=1, EOB=0, CHAIN=0;
317 * the callback will be triggered for RE3 using the
318 * xfer_user_data of that RE
324 * RE1: EOT=1, EOB=0, CHAIN=0;
325 * RE2: EOT=1, EOB=0, CHAIN=0;
326 * RE3: EOT=1, EOB=0, CHAIN=0;
328 * received packet consumes all of RE1, RE2 and part of RE3
329 * for EOT condition. there will be three callbacks in below
332 * callback for RE1 using GSI_CHAN_EVT_OVERFLOW
333 * callback for RE2 using GSI_CHAN_EVT_OVERFLOW
334 * callback for RE3 using GSI_CHAN_EVT_EOT
336 * @err_cb: error notification callback
337 * @chan_user_data: cookie used for notifications
339 * All the callbacks are in interrupt context
342 struct gsi_chan_props {
343 enum gsi_chan_prot prot;
344 enum gsi_chan_dir dir;
346 unsigned long evt_ring_hdl;
347 enum gsi_chan_ring_elem_size re_size;
349 uint16_t max_re_expected;
350 uint64_t ring_base_addr;
351 void *ring_base_vaddr;
352 enum gsi_chan_use_db_eng use_db_eng;
353 enum gsi_max_prefetch max_prefetch;
355 void (*xfer_cb)(struct gsi_chan_xfer_notify *notify);
356 void (*err_cb)(struct gsi_chan_err_notify *notify);
357 void *chan_user_data;
361 GSI_XFER_FLAG_CHAIN = 0x1,
362 GSI_XFER_FLAG_EOB = 0x100,
363 GSI_XFER_FLAG_EOT = 0x200,
364 GSI_XFER_FLAG_BEI = 0x400
367 enum gsi_xfer_elem_type {
369 GSI_XFER_ELEM_IMME_CMD,
373 * gsi_xfer_elem - Metadata about a single transfer
375 * @addr: physical address of buffer
376 * @len: size of buffer for GSI_XFER_ELEM_DATA:
377 * for outbound transfers this is the number of bytes to
379 * for inbound transfers, this is the maximum number of
380 * bytes the host expects from device in this transfer
382 * immediate command opcode for GSI_XFER_ELEM_IMME_CMD
383 * @flags: transfer flags, OR of all the applicable flags
385 * GSI_XFER_FLAG_BEI: Block event interrupt
386 * 1: Event generated by this ring element must not assert
387 * an interrupt to the host
388 * 0: Event generated by this ring element must assert an
389 * interrupt to the host
391 * GSI_XFER_FLAG_EOT: Interrupt on end of transfer
392 * 1: If an EOT condition is encountered when processing
393 * this ring element, an event is generated by the device
394 * with its completion code set to EOT.
395 * 0: If an EOT condition is encountered for this ring
396 * element, a completion event is not be generated by the
397 * device, unless IEOB is 1
399 * GSI_XFER_FLAG_EOB: Interrupt on end of block
400 * 1: Device notifies host after processing this ring element
401 * by sending a completion event
402 * 0: Completion event is not required after processing this
405 * GSI_XFER_FLAG_CHAIN: Chain bit that identifies the ring
408 * @type: transfer type
410 * GSI_XFER_ELEM_DATA: for all data transfers
411 * GSI_XFER_ELEM_IMME_CMD: for IPA immediate commands
413 * @xfer_user_data: cookie used in xfer_cb
416 struct gsi_xfer_elem {
420 enum gsi_xfer_elem_type type;
421 void *xfer_user_data;
425 * gsi_gpi_channel_scratch - GPI protocol SW config area of
428 * @max_outstanding_tre: Used for the prefetch management sequence by the
429 * sequencer. Defines the maximum number of allowed
430 * outstanding TREs in IPA/GSI (in Bytes). RE engine
431 * prefetch will be limited by this configuration. It
432 * is suggested to configure this value to IPA_IF
433 * channel TLV queue size times element size. To disable
434 * the feature in doorbell mode (DB Mode=1). Maximum
435 * outstanding TREs should be set to 64KB
436 * (or any value larger or equal to ring length . RLEN)
437 * @outstanding_threshold: Used for the prefetch management sequence by the
438 * sequencer. Defines the threshold (in Bytes) as to when
439 * to update the channel doorbell. Should be smaller than
440 * Maximum outstanding TREs. value. It is suggested to
441 * configure this value to 2 * element size.
443 struct __packed gsi_gpi_channel_scratch {
446 uint32_t max_outstanding_tre:16;
448 uint32_t outstanding_threshold:16;
452 * gsi_mhi_channel_scratch - MHI protocol SW config area of
455 * @mhi_host_wp_addr: Valid only when UL/DL Sync En is asserted. Defines
456 * address in host from which channel write pointer
457 * should be read in polling mode
458 * @assert_bit40: 1: bit #41 in address should be asserted upon
459 * IPA_IF.ProcessDescriptor routine (for MHI over PCIe
461 * 0: bit #41 in address should be deasserted upon
462 * IPA_IF.ProcessDescriptor routine (for non-MHI over
464 * @polling_configuration: Uplink channels: Defines timer to poll on MHI
465 * context. Range: 1 to 31 milliseconds.
466 * Downlink channel: Defines transfer ring buffer
467 * availability threshold to poll on MHI context in
468 * multiple of 8. Range: 0 to 31, meaning 0 to 258 ring
469 * elements. E.g., value of 2 indicates 16 ring elements.
470 * Valid only when Burst Mode Enabled is set to 1
471 * @burst_mode_enabled: 0: Burst mode is disabled for this channel
472 * 1: Burst mode is enabled for this channel
473 * @polling_mode: 0: the channel is not in polling mode, meaning the
474 * host should ring DBs.
475 * 1: the channel is in polling mode, meaning the host
476 * @oob_mod_threshold: Defines OOB moderation threshold. Units are in 8
478 * should not ring DBs until notified of DB mode/OOB mode
479 * @max_outstanding_tre: Used for the prefetch management sequence by the
480 * sequencer. Defines the maximum number of allowed
481 * outstanding TREs in IPA/GSI (in Bytes). RE engine
482 * prefetch will be limited by this configuration. It
483 * is suggested to configure this value to IPA_IF
484 * channel TLV queue size times element size.
485 * To disable the feature in doorbell mode (DB Mode=1).
486 * Maximum outstanding TREs should be set to 64KB
487 * (or any value larger or equal to ring length . RLEN)
488 * @outstanding_threshold: Used for the prefetch management sequence by the
489 * sequencer. Defines the threshold (in Bytes) as to when
490 * to update the channel doorbell. Should be smaller than
491 * Maximum outstanding TREs. value. It is suggested to
492 * configure this value to min(TLV_FIFO_SIZE/2,8) *
495 struct __packed gsi_mhi_channel_scratch {
496 uint64_t mhi_host_wp_addr;
498 uint32_t assert_bit40:1;
499 uint32_t polling_configuration:5;
500 uint32_t burst_mode_enabled:1;
501 uint32_t polling_mode:1;
502 uint32_t oob_mod_threshold:5;
504 uint32_t max_outstanding_tre:16;
506 uint32_t outstanding_threshold:16;
510 * gsi_xdci_channel_scratch - xDCI protocol SW config area of
513 * @const_buffer_size: TRB buffer size in KB (similar to IPA aggregationi
514 * configuration). Must be aligned to Max USB Packet Size
515 * @xferrscidx: Transfer Resource Index (XferRscIdx). The hardware-assigned
516 * transfer resource index for the transfer, which was
517 * returned in response to the Start Transfer command.
518 * This field is used for "Update Transfer" command
519 * @last_trb_addr: Address (LSB - based on alignment restrictions) of
520 * last TRB in queue. Used to identify rollover case
521 * @depcmd_low_addr: Used to generate "Update Transfer" command
522 * @max_outstanding_tre: Used for the prefetch management sequence by the
523 * sequencer. Defines the maximum number of allowed
524 * outstanding TREs in IPA/GSI (in Bytes). RE engine
525 * prefetch will be limited by this configuration. It
526 * is suggested to configure this value to IPA_IF
527 * channel TLV queue size times element size.
528 * To disable the feature in doorbell mode (DB Mode=1)
529 * Maximum outstanding TREs should be set to 64KB
530 * (or any value larger or equal to ring length . RLEN)
531 * @depcmd_hi_addr: Used to generate "Update Transfer" command
532 * @outstanding_threshold: Used for the prefetch management sequence by the
533 * sequencer. Defines the threshold (in Bytes) as to when
534 * to update the channel doorbell. Should be smaller than
535 * Maximum outstanding TREs. value. It is suggested to
536 * configure this value to 2 * element size. for MBIM the
537 * suggested configuration is the element size.
539 struct __packed gsi_xdci_channel_scratch {
540 uint32_t last_trb_addr:16;
542 uint32_t xferrscidx:7;
543 uint32_t const_buffer_size:5;
544 uint32_t depcmd_low_addr;
545 uint32_t depcmd_hi_addr:8;
547 uint32_t max_outstanding_tre:16;
549 uint32_t outstanding_threshold:16;
553 * gsi_channel_scratch - channel scratch SW config area
556 union __packed gsi_channel_scratch {
557 struct __packed gsi_gpi_channel_scratch gpi;
558 struct __packed gsi_mhi_channel_scratch mhi;
559 struct __packed gsi_xdci_channel_scratch xdci;
569 * gsi_mhi_evt_scratch - MHI protocol SW config area of
572 struct __packed gsi_mhi_evt_scratch {
578 * gsi_xdci_evt_scratch - xDCI protocol SW config area of
582 struct __packed gsi_xdci_evt_scratch {
583 uint32_t gevntcount_low_addr;
584 uint32_t gevntcount_hi_addr:8;
589 * gsi_evt_scratch - event scratch SW config area
592 union __packed gsi_evt_scratch {
593 struct __packed gsi_mhi_evt_scratch mhi;
594 struct __packed gsi_xdci_evt_scratch xdci;
602 * gsi_device_scratch - EE scratch config parameters
604 * @mhi_base_chan_idx_valid: is mhi_base_chan_idx valid?
605 * @mhi_base_chan_idx: base index of IPA MHI channel indexes.
606 * IPA MHI channel index = GSI channel ID +
607 * MHI base channel index
608 * @max_usb_pkt_size_valid: is max_usb_pkt_size valid?
609 * @max_usb_pkt_size: max USB packet size in bytes (valid values are
612 struct gsi_device_scratch {
613 bool mhi_base_chan_idx_valid;
614 uint8_t mhi_base_chan_idx;
615 bool max_usb_pkt_size_valid;
616 uint16_t max_usb_pkt_size;
620 * gsi_chan_info - information about channel occupancy
622 * @wp: channel write pointer (physical address)
623 * @rp: channel read pointer (physical address)
624 * @evt_valid: is evt* info valid?
625 * @evt_wp: event ring write pointer (physical address)
626 * @evt_rp: event ring read pointer (physical address)
628 struct gsi_chan_info {
638 * gsi_register_device - Peripheral should call this function to
639 * register itself with GSI before invoking any other APIs
641 * @props: Peripheral properties
642 * @dev_hdl: Handle populated by GSI, opaque to client
644 * @Return -GSI_STATUS_AGAIN if request should be re-tried later
645 * other error codes for failure
647 int gsi_register_device(struct gsi_per_props *props, unsigned long *dev_hdl);
650 * gsi_complete_clk_grant - Peripheral should call this function to
651 * grant the clock resource requested by GSI previously that could not
652 * be granted synchronously. GSI will release the clock resource using
653 * the rel_clk_cb when appropriate
655 * @dev_hdl: Client handle previously obtained from
656 * gsi_register_device
660 int gsi_complete_clk_grant(unsigned long dev_hdl);
663 * gsi_write_device_scratch - Peripheral should call this function to
664 * write to the EE scratch area
666 * @dev_hdl: Client handle previously obtained from
667 * gsi_register_device
668 * @val: Value to write
672 int gsi_write_device_scratch(unsigned long dev_hdl,
673 struct gsi_device_scratch *val);
676 * gsi_deregister_device - Peripheral should call this function to
677 * de-register itself with GSI
679 * @dev_hdl: Client handle previously obtained from
680 * gsi_register_device
681 * @force: When set to true, cleanup is performed even if there
682 * are in use resources like channels, event rings, etc.
683 * this would be used after GSI reset to recover from some
685 * When set to false, there must not exist any allocated
686 * channels and event rings.
690 int gsi_deregister_device(unsigned long dev_hdl, bool force);
693 * gsi_alloc_evt_ring - Peripheral should call this function to
694 * allocate an event ring
696 * @props: Event ring properties
697 * @dev_hdl: Client handle previously obtained from
698 * gsi_register_device
699 * @evt_ring_hdl: Handle populated by GSI, opaque to client
701 * This function can sleep
705 int gsi_alloc_evt_ring(struct gsi_evt_ring_props *props, unsigned long dev_hdl,
706 unsigned long *evt_ring_hdl);
709 * gsi_write_evt_ring_scratch - Peripheral should call this function to
710 * write to the scratch area of the event ring context
712 * @evt_ring_hdl: Client handle previously obtained from
714 * @val: Value to write
718 int gsi_write_evt_ring_scratch(unsigned long evt_ring_hdl,
719 union __packed gsi_evt_scratch val);
722 * gsi_dealloc_evt_ring - Peripheral should call this function to
723 * de-allocate an event ring. There should not exist any active
724 * channels using this event ring
726 * @evt_ring_hdl: Client handle previously obtained from
729 * This function can sleep
733 int gsi_dealloc_evt_ring(unsigned long evt_ring_hdl);
736 * gsi_query_evt_ring_db_addr - Peripheral should call this function to
737 * query the physical addresses of the event ring doorbell registers
739 * @evt_ring_hdl: Client handle previously obtained from
741 * @db_addr_wp_lsb: Physical address of doorbell register where the 32
742 * LSBs of the doorbell value should be written
743 * @db_addr_wp_msb: Physical address of doorbell register where the 32
744 * MSBs of the doorbell value should be written
748 int gsi_query_evt_ring_db_addr(unsigned long evt_ring_hdl,
749 uint32_t *db_addr_wp_lsb, uint32_t *db_addr_wp_msb);
752 * gsi_ring_evt_ring_db - Peripheral should call this function for
753 * ringing the event ring doorbell with given value
755 * @evt_ring_hdl: Client handle previously obtained from
757 * @value: The value to be used for ringing the doorbell
761 int gsi_ring_evt_ring_db(unsigned long evt_ring_hdl, uint64_t value);
764 * gsi_reset_evt_ring - Peripheral should call this function to
765 * reset an event ring to recover from error state
767 * @evt_ring_hdl: Client handle previously obtained from
770 * This function can sleep
774 int gsi_reset_evt_ring(unsigned long evt_ring_hdl);
777 * gsi_get_evt_ring_cfg - This function returns the current config
778 * of the specified event ring
780 * @evt_ring_hdl: Client handle previously obtained from
782 * @props: where to copy properties to
783 * @scr: where to copy scratch info to
787 int gsi_get_evt_ring_cfg(unsigned long evt_ring_hdl,
788 struct gsi_evt_ring_props *props, union gsi_evt_scratch *scr);
791 * gsi_set_evt_ring_cfg - This function applies the supplied config
792 * to the specified event ring.
794 * exclusive property of the event ring cannot be changed after
797 * @evt_ring_hdl: Client handle previously obtained from
799 * @props: the properties to apply
800 * @scr: the scratch info to apply
804 int gsi_set_evt_ring_cfg(unsigned long evt_ring_hdl,
805 struct gsi_evt_ring_props *props, union gsi_evt_scratch *scr);
808 * gsi_alloc_channel - Peripheral should call this function to
811 * @props: Channel properties
812 * @dev_hdl: Client handle previously obtained from
813 * gsi_register_device
814 * @chan_hdl: Handle populated by GSI, opaque to client
816 * This function can sleep
820 int gsi_alloc_channel(struct gsi_chan_props *props, unsigned long dev_hdl,
821 unsigned long *chan_hdl);
824 * gsi_write_channel_scratch - Peripheral should call this function to
825 * write to the scratch area of the channel context
827 * @chan_hdl: Client handle previously obtained from
829 * @val: Value to write
833 int gsi_write_channel_scratch(unsigned long chan_hdl,
834 union __packed gsi_channel_scratch val);
837 * gsi_start_channel - Peripheral should call this function to
838 * start a channel i.e put into running state
840 * @chan_hdl: Client handle previously obtained from
843 * This function can sleep
847 int gsi_start_channel(unsigned long chan_hdl);
850 * gsi_stop_channel - Peripheral should call this function to
851 * stop a channel. Stop will happen on a packet boundary
853 * @chan_hdl: Client handle previously obtained from
856 * This function can sleep
858 * @Return -GSI_STATUS_AGAIN if client should call stop/stop_db again
859 * other error codes for failure
861 int gsi_stop_channel(unsigned long chan_hdl);
864 * gsi_reset_channel - Peripheral should call this function to
865 * reset a channel to recover from error state
867 * @chan_hdl: Client handle previously obtained from
870 * This function can sleep
874 int gsi_reset_channel(unsigned long chan_hdl);
877 * gsi_dealloc_channel - Peripheral should call this function to
878 * de-allocate a channel
880 * @chan_hdl: Client handle previously obtained from
883 * This function can sleep
887 int gsi_dealloc_channel(unsigned long chan_hdl);
890 * gsi_stop_db_channel - Peripheral should call this function to
891 * stop a channel when all transfer elements till the doorbell
892 * have been processed
894 * @chan_hdl: Client handle previously obtained from
897 * This function can sleep
899 * @Return -GSI_STATUS_AGAIN if client should call stop/stop_db again
900 * other error codes for failure
902 int gsi_stop_db_channel(unsigned long chan_hdl);
905 * gsi_query_channel_db_addr - Peripheral should call this function to
906 * query the physical addresses of the channel doorbell registers
908 * @chan_hdl: Client handle previously obtained from
910 * @db_addr_wp_lsb: Physical address of doorbell register where the 32
911 * LSBs of the doorbell value should be written
912 * @db_addr_wp_msb: Physical address of doorbell register where the 32
913 * MSBs of the doorbell value should be written
917 int gsi_query_channel_db_addr(unsigned long chan_hdl,
918 uint32_t *db_addr_wp_lsb, uint32_t *db_addr_wp_msb);
921 * gsi_query_channel_info - Peripheral can call this function to query the
922 * channel and associated event ring (if any) status.
924 * @chan_hdl: Client handle previously obtained from
926 * @info: Where to read the values into
930 int gsi_query_channel_info(unsigned long chan_hdl,
931 struct gsi_chan_info *info);
934 * gsi_is_channel_empty - Peripheral can call this function to query if
935 * the channel is empty. This is only applicable to GPI. "Empty" means
936 * GSI has consumed all descriptors for a TO_GSI channel and SW has
937 * processed all completed descriptors for a FROM_GSI channel.
939 * @chan_hdl: Client handle previously obtained from gsi_alloc_channel
940 * @is_empty: set by GSI based on channel emptiness
944 int gsi_is_channel_empty(unsigned long chan_hdl, bool *is_empty);
947 * gsi_get_channel_cfg - This function returns the current config
948 * of the specified channel
950 * @chan_hdl: Client handle previously obtained from
952 * @props: where to copy properties to
953 * @scr: where to copy scratch info to
957 int gsi_get_channel_cfg(unsigned long chan_hdl, struct gsi_chan_props *props,
958 union gsi_channel_scratch *scr);
961 * gsi_set_channel_cfg - This function applies the supplied config
962 * to the specified channel
964 * ch_id and evt_ring_hdl of the channel cannot be changed after
967 * @chan_hdl: Client handle previously obtained from
969 * @props: the properties to apply
970 * @scr: the scratch info to apply
974 int gsi_set_channel_cfg(unsigned long chan_hdl, struct gsi_chan_props *props,
975 union gsi_channel_scratch *scr);
978 * gsi_poll_channel - Peripheral should call this function to query for
979 * completed transfer descriptors.
981 * @chan_hdl: Client handle previously obtained from
983 * @notify: Information about the completed transfer if any
985 * @Return gsi_status (GSI_STATUS_POLL_EMPTY is returned if no transfers
988 int gsi_poll_channel(unsigned long chan_hdl,
989 struct gsi_chan_xfer_notify *notify);
992 * gsi_config_channel_mode - Peripheral should call this function
993 * to configure the channel mode.
995 * @chan_hdl: Client handle previously obtained from
997 * @mode: Mode to move the channel into
1001 int gsi_config_channel_mode(unsigned long chan_hdl, enum gsi_chan_mode mode);
1004 * gsi_queue_xfer - Peripheral should call this function
1005 * to queue transfers on the given channel
1007 * @chan_hdl: Client handle previously obtained from
1009 * @num_xfers: Number of transfer in the array @ xfer
1010 * @xfer: Array of num_xfers transfer descriptors
1011 * @ring_db: If true, tell HW about these queued xfers
1012 * If false, do not notify HW at this time
1014 * @Return gsi_status
1016 int gsi_queue_xfer(unsigned long chan_hdl, uint16_t num_xfers,
1017 struct gsi_xfer_elem *xfer, bool ring_db);
1020 * gsi_start_xfer - Peripheral should call this function to
1021 * inform HW about queued xfers
1023 * @chan_hdl: Client handle previously obtained from
1026 * @Return gsi_status
1028 int gsi_start_xfer(unsigned long chan_hdl);
1031 * gsi_configure_regs - Peripheral should call this function
1032 * to configure the GSI registers before/after the FW is
1033 * loaded but before it is enabled.
1035 * @gsi_base_addr: Base address of GSI register space
1036 * @gsi_size: Mapping size of the GSI register space
1037 * @per_base_addr: Base address of the peripheral using GSI
1039 * @Return gsi_status
1041 int gsi_configure_regs(phys_addr_t gsi_base_addr, u32 gsi_size,
1042 phys_addr_t per_base_addr);
1045 * gsi_enable_fw - Peripheral should call this function
1046 * to enable the GSI FW after the FW has been loaded to the SRAM.
1048 * @gsi_base_addr: Base address of GSI register space
1049 * @gsi_size: Mapping size of the GSI register space
1051 * @Return gsi_status
1053 int gsi_enable_fw(phys_addr_t gsi_base_addr, u32 gsi_size);
1056 * gsi_get_inst_ram_offset_and_size - Peripheral should call this function
1057 * to get instruction RAM base address offset and size. Peripheral typically
1058 * uses this info to load GSI FW into the IRAM.
1060 * @base_offset:[OUT] - IRAM base offset address
1061 * @size: [OUT] - IRAM size
1065 void gsi_get_inst_ram_offset_and_size(unsigned long *base_offset,
1066 unsigned long *size);
1069 * gsi_halt_channel_ee - Peripheral should call this function
1070 * to stop other EE's channel. This is usually used in SSR clean
1072 * @chan_idx: Virtual channel index
1074 * @code: [out] response code for operation
1076 * @Return gsi_status
1078 int gsi_halt_channel_ee(unsigned int chan_idx, unsigned int ee, int *code);
1081 * Here is a typical sequence of calls
1083 * gsi_register_device
1085 * gsi_write_device_scratch (if the protocol needs this)
1087 * gsi_alloc_evt_ring (for as many event rings as needed)
1088 * gsi_write_evt_ring_scratch
1090 * gsi_alloc_channel (for as many channels as needed; channels can have
1091 * no event ring, an exclusive event ring or a shared event ring)
1092 * gsi_write_channel_scratch
1094 * gsi_queue_xfer/gsi_start_xfer
1095 * gsi_config_channel_mode/gsi_poll_channel (if clients wants to poll on
1097 * gsi_stop_db_channel/gsi_stop_channel
1099 * gsi_dealloc_channel
1101 * gsi_dealloc_evt_ring
1103 * gsi_deregister_device
1107 static inline int gsi_register_device(struct gsi_per_props *props,
1108 unsigned long *dev_hdl)
1110 return -GSI_STATUS_UNSUPPORTED_OP;
1113 static inline int gsi_complete_clk_grant(unsigned long dev_hdl)
1115 return -GSI_STATUS_UNSUPPORTED_OP;
1118 static inline int gsi_write_device_scratch(unsigned long dev_hdl,
1119 struct gsi_device_scratch *val)
1121 return -GSI_STATUS_UNSUPPORTED_OP;
1124 static inline int gsi_deregister_device(unsigned long dev_hdl, bool force)
1126 return -GSI_STATUS_UNSUPPORTED_OP;
1129 static inline int gsi_alloc_evt_ring(struct gsi_evt_ring_props *props,
1130 unsigned long dev_hdl,
1131 unsigned long *evt_ring_hdl)
1133 return -GSI_STATUS_UNSUPPORTED_OP;
1136 static inline int gsi_write_evt_ring_scratch(unsigned long evt_ring_hdl,
1137 union __packed gsi_evt_scratch val)
1139 return -GSI_STATUS_UNSUPPORTED_OP;
1142 static inline int gsi_dealloc_evt_ring(unsigned long evt_ring_hdl)
1144 return -GSI_STATUS_UNSUPPORTED_OP;
1147 static inline int gsi_query_evt_ring_db_addr(unsigned long evt_ring_hdl,
1148 uint32_t *db_addr_wp_lsb, uint32_t *db_addr_wp_msb)
1150 return -GSI_STATUS_UNSUPPORTED_OP;
1153 static inline int gsi_ring_evt_ring_db(unsigned long evt_ring_hdl,
1156 return -GSI_STATUS_UNSUPPORTED_OP;
1159 static inline int gsi_reset_evt_ring(unsigned long evt_ring_hdl)
1161 return -GSI_STATUS_UNSUPPORTED_OP;
1164 static inline int gsi_alloc_channel(struct gsi_chan_props *props,
1165 unsigned long dev_hdl,
1166 unsigned long *chan_hdl)
1168 return -GSI_STATUS_UNSUPPORTED_OP;
1171 static inline int gsi_write_channel_scratch(unsigned long chan_hdl,
1172 union __packed gsi_channel_scratch val)
1174 return -GSI_STATUS_UNSUPPORTED_OP;
1177 static inline int gsi_start_channel(unsigned long chan_hdl)
1179 return -GSI_STATUS_UNSUPPORTED_OP;
1182 static inline int gsi_stop_channel(unsigned long chan_hdl)
1184 return -GSI_STATUS_UNSUPPORTED_OP;
1187 static inline int gsi_reset_channel(unsigned long chan_hdl)
1189 return -GSI_STATUS_UNSUPPORTED_OP;
1192 static inline int gsi_dealloc_channel(unsigned long chan_hdl)
1194 return -GSI_STATUS_UNSUPPORTED_OP;
1197 static inline int gsi_stop_db_channel(unsigned long chan_hdl)
1199 return -GSI_STATUS_UNSUPPORTED_OP;
1202 static inline int gsi_query_channel_db_addr(unsigned long chan_hdl,
1203 uint32_t *db_addr_wp_lsb, uint32_t *db_addr_wp_msb)
1205 return -GSI_STATUS_UNSUPPORTED_OP;
1208 static inline int gsi_query_channel_info(unsigned long chan_hdl,
1209 struct gsi_chan_info *info)
1211 return -GSI_STATUS_UNSUPPORTED_OP;
1214 static inline int gsi_is_channel_empty(unsigned long chan_hdl, bool *is_empty)
1216 return -GSI_STATUS_UNSUPPORTED_OP;
1219 static inline int gsi_poll_channel(unsigned long chan_hdl,
1220 struct gsi_chan_xfer_notify *notify)
1222 return -GSI_STATUS_UNSUPPORTED_OP;
1225 static inline int gsi_config_channel_mode(unsigned long chan_hdl,
1226 enum gsi_chan_mode mode)
1228 return -GSI_STATUS_UNSUPPORTED_OP;
1231 static inline int gsi_queue_xfer(unsigned long chan_hdl, uint16_t num_xfers,
1232 struct gsi_xfer_elem *xfer, bool ring_db)
1234 return -GSI_STATUS_UNSUPPORTED_OP;
1237 static inline int gsi_start_xfer(unsigned long chan_hdl)
1239 return -GSI_STATUS_UNSUPPORTED_OP;
1242 static inline int gsi_get_channel_cfg(unsigned long chan_hdl,
1243 struct gsi_chan_props *props,
1244 union gsi_channel_scratch *scr)
1246 return -GSI_STATUS_UNSUPPORTED_OP;
1249 static inline int gsi_set_channel_cfg(unsigned long chan_hdl,
1250 struct gsi_chan_props *props,
1251 union gsi_channel_scratch *scr)
1253 return -GSI_STATUS_UNSUPPORTED_OP;
1256 static inline int gsi_get_evt_ring_cfg(unsigned long evt_ring_hdl,
1257 struct gsi_evt_ring_props *props, union gsi_evt_scratch *scr)
1259 return -GSI_STATUS_UNSUPPORTED_OP;
1262 static inline int gsi_set_evt_ring_cfg(unsigned long evt_ring_hdl,
1263 struct gsi_evt_ring_props *props, union gsi_evt_scratch *scr)
1265 return -GSI_STATUS_UNSUPPORTED_OP;
1268 static inline int gsi_configure_regs(phys_addr_t gsi_base_addr, u32 gsi_size,
1269 phys_addr_t per_base_addr)
1271 return -GSI_STATUS_UNSUPPORTED_OP;
1274 static inline int gsi_enable_fw(phys_addr_t gsi_base_addr, u32 gsi_size)
1276 return -GSI_STATUS_UNSUPPORTED_OP;
1279 static inline void gsi_get_inst_ram_offset_and_size(unsigned long *base_offset,
1280 unsigned long *size)
1284 static inline int gsi_halt_channel_ee(unsigned int chan_idx, unsigned int ee,
1287 return -GSI_STATUS_UNSUPPORTED_OP;