blob: 319a3ec512e6694198c4ec32d5a492204fb0a60f [file] [log] [blame]
Yan Hef879bb02011-12-22 15:38:03 -08001/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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.
6 *
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.
11 */
12
13/* Smart-Peripheral-Switch (SPS) API. */
14
15#ifndef _SPS_H_
16#define _SPS_H_
17
18#include <linux/types.h> /* u32 */
19
20/* SPS device handle indicating use of system memory */
21#define SPS_DEV_HANDLE_MEM ((u32)0x7ffffffful)
22
23/* SPS device handle indicating use of BAM-DMA */
24
25/* SPS device handle invalid value */
26#define SPS_DEV_HANDLE_INVALID ((u32)0)
27
28/* BAM invalid IRQ value */
29#define SPS_IRQ_INVALID 0
30
31/* Invalid address value */
32#define SPS_ADDR_INVALID 0
33
34/* Invalid peripheral device enumeration class */
35#define SPS_CLASS_INVALID ((u32)-1)
36
37/*
38 * This value specifies different configurations for an SPS connection.
39 * A non-default value instructs the SPS driver to search for the configuration
40 * in the fixed connection mapping table.
41 */
42#define SPS_CONFIG_DEFAULT 0
43
44/*
45 * This value instructs the SPS driver to use the default BAM-DMA channel
46 * threshold
47 */
48#define SPS_DMA_THRESHOLD_DEFAULT 0
49
50/* Flag bits supported by SPS hardware for struct sps_iovec */
51#define SPS_IOVEC_FLAG_INT 0x8000 /* Generate interrupt */
52#define SPS_IOVEC_FLAG_EOT 0x4000 /* Generate end-of-transfer indication */
53#define SPS_IOVEC_FLAG_EOB 0x2000 /* Generate end-of-block indication */
Yan Hef879bb02011-12-22 15:38:03 -080054#define SPS_IOVEC_FLAG_NWD 0x1000 /* notify when done */
55#define SPS_IOVEC_FLAG_CMD 0x0800 /* command descriptor */
56#define SPS_IOVEC_FLAG_LOCK 0x0400 /* pipe lock */
57#define SPS_IOVEC_FLAG_UNLOCK 0x0200 /* pipe unlock */
58#define SPS_IOVEC_FLAG_IMME 0x0100 /* immediate command descriptor */
59#define SPS_IOVEC_FLAG_NO_SUBMIT 0x0002 /* Do not submit descriptor to HW */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070060#define SPS_IOVEC_FLAG_DEFAULT 0x0001 /* Use driver default */
61
62/* BAM device options flags */
63
64/*
65 * BAM will be configured and enabled at boot. Otherwise, BAM will be
66 * configured and enabled when first pipe connect occurs.
67 */
68#define SPS_BAM_OPT_ENABLE_AT_BOOT 1UL
69/* BAM IRQ is disabled */
70#define SPS_BAM_OPT_IRQ_DISABLED (1UL << 1)
71/* BAM peripheral is a BAM-DMA */
72#define SPS_BAM_OPT_BAMDMA (1UL << 2)
Yan Hec324a792011-11-10 17:19:48 -080073/* BAM IRQ is registered for apps wakeup */
74#define SPS_BAM_OPT_IRQ_WAKEUP (1UL << 3)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070075
76/* BAM device management flags */
77
78/* BAM global device control is managed remotely */
79#define SPS_BAM_MGR_DEVICE_REMOTE 1UL
80/* BAM device supports multiple execution environments */
81#define SPS_BAM_MGR_MULTI_EE (1UL << 1)
82/* BAM pipes are *not* allocated locally */
83#define SPS_BAM_MGR_PIPE_NO_ALLOC (1UL << 2)
84/* BAM pipes are *not* configured locally */
85#define SPS_BAM_MGR_PIPE_NO_CONFIG (1UL << 3)
86/* BAM pipes are *not* controlled locally */
87#define SPS_BAM_MGR_PIPE_NO_CTRL (1UL << 4)
88/* "Globbed" management properties */
89#define SPS_BAM_MGR_NONE \
90 (SPS_BAM_MGR_DEVICE_REMOTE | SPS_BAM_MGR_PIPE_NO_ALLOC | \
91 SPS_BAM_MGR_PIPE_NO_CONFIG | SPS_BAM_MGR_PIPE_NO_CTRL)
92#define SPS_BAM_MGR_LOCAL 0
93#define SPS_BAM_MGR_LOCAL_SHARED SPS_BAM_MGR_MULTI_EE
94#define SPS_BAM_MGR_REMOTE_SHARED \
95 (SPS_BAM_MGR_DEVICE_REMOTE | SPS_BAM_MGR_MULTI_EE | \
96 SPS_BAM_MGR_PIPE_NO_ALLOC)
97#define SPS_BAM_MGR_ACCESS_MASK SPS_BAM_MGR_NONE
98
99/*
100 * BAM security configuration
101 */
102#define SPS_BAM_NUM_EES 4
103#define SPS_BAM_SEC_DO_NOT_CONFIG 0
104#define SPS_BAM_SEC_DO_CONFIG 0x0A434553
105
106/* This enum specifies the operational mode for an SPS connection */
107enum sps_mode {
108 SPS_MODE_SRC = 0, /* end point is the source (producer) */
109 SPS_MODE_DEST, /* end point is the destination (consumer) */
110};
111
112
113/*
114 * This enum is a set of bit flag options for SPS connection.
115 * The enums should be OR'd together to create the option set
116 * for the SPS connection.
117 */
118enum sps_option {
119 /*
120 * Options to enable specific SPS hardware interrupts.
121 * These bit flags are also used to indicate interrupt source
122 * for the SPS_EVENT_IRQ event.
123 */
124 SPS_O_DESC_DONE = 0x00000001, /* Descriptor processed */
125 SPS_O_INACTIVE = 0x00000002, /* Inactivity timeout */
126 SPS_O_WAKEUP = 0x00000004, /* Peripheral wake up */
127 SPS_O_OUT_OF_DESC = 0x00000008,/* Out of descriptors */
128 SPS_O_ERROR = 0x00000010, /* Error */
129 SPS_O_EOT = 0x00000020, /* End-of-transfer */
130
131 /* Options to enable hardware features */
132 SPS_O_STREAMING = 0x00010000, /* Enable streaming mode (no EOT) */
133 /* Use MTI/SETPEND instead of BAM interrupt */
134 SPS_O_IRQ_MTI = 0x00020000,
Yan Hef879bb02011-12-22 15:38:03 -0800135 /* NWD bit written with EOT for BAM2BAM producer pipe */
136 SPS_O_WRITE_NWD = 0x00040000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700137
138 /* Options to enable software features */
139 /* Transfer operation should be polled */
140 SPS_O_POLL = 0x01000000,
141 /* Disable queuing of transfer events for the connection end point */
142 SPS_O_NO_Q = 0x02000000,
143 SPS_O_FLOWOFF = 0x04000000, /* Graceful halt */
144 /* SPS_O_WAKEUP will be disabled after triggered */
145 SPS_O_WAKEUP_IS_ONESHOT = 0x08000000,
146 /**
147 * Client must read each descriptor from the FIFO
148 * using sps_get_iovec()
149 */
150 SPS_O_ACK_TRANSFERS = 0x10000000,
151 /* Connection is automatically enabled */
152 SPS_O_AUTO_ENABLE = 0x20000000,
153 /* DISABLE endpoint synchronization for config/enable/disable */
154 SPS_O_NO_EP_SYNC = 0x40000000,
155};
156
157/**
158 * This enum specifies BAM DMA channel priority. Clients should use
159 * SPS_DMA_PRI_DEFAULT unless a specific priority is required.
160 */
161enum sps_dma_priority {
162 SPS_DMA_PRI_DEFAULT = 0,
163 SPS_DMA_PRI_LOW,
164 SPS_DMA_PRI_MED,
165 SPS_DMA_PRI_HIGH,
166};
167
168/*
169 * This enum specifies the ownership of a connection resource.
170 * Remote or shared ownership is only possible/meaningful on the processor
171 * that controls resource.
172 */
173enum sps_owner {
174 SPS_OWNER_LOCAL = 0x1, /* Resource is owned by local processor */
175 SPS_OWNER_REMOTE = 0x2, /* Resource is owned by a satellite processor */
176};
177
178/* This enum indicates the event associated with a client event trigger */
179enum sps_event {
180 SPS_EVENT_INVALID = 0,
181
182 SPS_EVENT_EOT, /* End-of-transfer */
183 SPS_EVENT_DESC_DONE, /* Descriptor processed */
184 SPS_EVENT_OUT_OF_DESC, /* Out of descriptors */
185 SPS_EVENT_WAKEUP, /* Peripheral wake up */
186 SPS_EVENT_FLOWOFF, /* Graceful halt (idle) */
187 SPS_EVENT_INACTIVE, /* Inactivity timeout */
188 SPS_EVENT_ERROR, /* Error */
189 SPS_EVENT_MAX,
190};
191
192/*
193 * This enum specifies the event trigger mode and is an argument for the
194 * sps_register_event() function.
195 */
196enum sps_trigger {
197 /* Trigger with payload for callback */
198 SPS_TRIGGER_CALLBACK = 0,
199 /* Trigger without payload for wait or poll */
200 SPS_TRIGGER_WAIT,
201};
202
203/*
204 * This enum indicates the desired halting mechanism and is an argument for the
205 * sps_flow_off() function
206 */
207enum sps_flow_off {
208 SPS_FLOWOFF_FORCED = 0, /* Force hardware into halt state */
209 /* Allow hardware to empty pipe before halting */
210 SPS_FLOWOFF_GRACEFUL,
211};
212
213/*
214 * This enum indicates the target memory heap and is an argument for the
215 * sps_mem_alloc() function.
216 */
217enum sps_mem {
218 SPS_MEM_LOCAL = 0, /* SPS subsystem local (pipe) memory */
219 SPS_MEM_UC, /* Microcontroller (ARM7) local memory */
220};
221
222/*
223 * This enum indicates a timer control operation and is an argument for the
224 * sps_timer_ctrl() function.
225 */
226enum sps_timer_op {
227 SPS_TIMER_OP_CONFIG = 0,
228 SPS_TIMER_OP_RESET,
229/* SPS_TIMER_OP_START, Not supported by hardware yet */
230/* SPS_TIMER_OP_STOP, Not supported by hardware yet */
231 SPS_TIMER_OP_READ,
232};
233
234/*
235 * This enum indicates the inactivity timer operating mode and is an
236 * argument for the sps_timer_ctrl() function.
237 */
238enum sps_timer_mode {
239 SPS_TIMER_MODE_ONESHOT = 0,
240/* SPS_TIMER_MODE_PERIODIC, Not supported by hardware yet */
241};
242
Yan Hefcddf6f2012-03-13 12:41:18 -0700243/* This enum indicates the cases when callback the user of BAM */
244enum sps_callback_case {
245 SPS_CALLBACK_BAM_ERROR_IRQ = 1, /* BAM ERROR IRQ */
246 SPS_CALLBACK_BAM_HRESP_ERR_IRQ, /* Erroneous HResponse */
247};
248
Yan Hef879bb02011-12-22 15:38:03 -0800249/*
250 * This enum indicates the command type in a command element
251 */
252enum sps_command_type {
253 SPS_WRITE_COMMAND = 0,
254 SPS_READ_COMMAND,
255};
256
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700257/**
258 * This data type corresponds to the native I/O vector (BAM descriptor)
259 * supported by SPS hardware
260 *
261 * @addr - Buffer physical address.
262 * @size - Buffer size in bytes.
263 * @flags -Flag bitmask (see SPS_IOVEC_FLAG_ #defines).
264 *
265 */
266struct sps_iovec {
267 u32 addr;
268 u32 size:16;
269 u32 flags:16;
270};
271
Yan Hef879bb02011-12-22 15:38:03 -0800272/**
273 * This data type corresponds to the native Command Element
274 * supported by SPS hardware
275 *
276 * @addr - register address.
277 * @command - command type.
278 * @data - for write command: content to be written into peripheral register.
279 * for read command: dest addr to write peripheral register value to.
280 * @mask - register mask.
281 * @reserved - for future usage.
282 *
283 */
284struct sps_command_element {
285 u32 addr:24;
286 u32 command:8;
287 u32 data;
288 u32 mask;
289 u32 reserved;
290};
291
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700292/*
293 * BAM device's security configuation
294 */
295struct sps_bam_pipe_sec_config_props {
296 u32 pipe_mask;
297 u32 vmid;
298};
299
300struct sps_bam_sec_config_props {
301 /* Per-EE configuration - This is a pipe bit mask for each EE */
302 struct sps_bam_pipe_sec_config_props ees[SPS_BAM_NUM_EES];
303};
304
305/**
306 * This struct defines a BAM device. The client must memset() this struct to
307 * zero before writing device information. A value of zero for uninitialized
308 * values will instruct the SPS driver to use general defaults or
309 * hardware/BIOS supplied values.
310 *
311 *
312 * @options - See SPS_BAM_OPT_* bit flag.
313 * @phys_addr - BAM base physical address (not peripheral address).
314 * @virt_addr - BAM base virtual address.
315 * @virt_size - For virtual mapping.
316 * @irq - IRQ enum for use in ISR vector install.
317 * @num_pipes - number of pipes. Can be read from hardware.
318 * @summing_threshold - BAM event threshold.
319 *
320 * @periph_class - Peripheral device enumeration class.
321 * @periph_dev_id - Peripheral global device ID.
322 * @periph_phys_addr - Peripheral base physical address, for BAM-DMA only.
323 * @periph_virt_addr - Peripheral base virtual address.
324 * @periph_virt_size - Size for virtual mapping.
325 *
Yan Hefcddf6f2012-03-13 12:41:18 -0700326 * @callback - callback function for BAM user.
327 * @user - pointer to user data.
328 *
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700329 * @event_threshold - Pipe event threshold.
330 * @desc_size - Size (bytes) of descriptor FIFO.
331 * @data_size - Size (bytes) of data FIFO.
332 * @desc_mem_id - Heap ID for default descriptor FIFO allocations.
333 * @data_mem_id - Heap ID for default data FIFO allocations.
334 *
335 * @manage - BAM device management flags (see SPS_BAM_MGR_*).
336 * @restricted_pipes - Bitmask of pipes restricted from local use.
337 * @ee - Local execution environment index.
338 *
339 * @irq_gen_addr - MTI interrupt generation address. This configuration only
340 * applies to BAM rev 1 and 2 hardware. MTIs are only supported on BAMs when
341 * global config is controlled by a remote processor.
342 * NOTE: This address must correspond to the MTI associated with the "irq" IRQ
343 * enum specified above.
344 *
345 * @sec_config - must be set to SPS_BAM_SEC_DO_CONFIG to perform BAM security
346 * configuration. Only the processor that manages the BAM is allowed to
347 * perform the configuration. The global (top-level) BAM interrupt will be
348 * assigned to the EE of the processor that manages the BAM.
349 *
350 * @p_sec_config_props - BAM device's security configuation
351 *
352 */
353struct sps_bam_props {
354
355 /* BAM device properties. */
356
357 u32 options;
358 u32 phys_addr;
359 void *virt_addr;
360 u32 virt_size;
361 u32 irq;
362 u32 num_pipes;
363 u32 summing_threshold;
364
365 /* Peripheral device properties */
366
367 u32 periph_class;
368 u32 periph_dev_id;
369 u32 periph_phys_addr;
370 void *periph_virt_addr;
371 u32 periph_virt_size;
372
373 /* Connection pipe parameter defaults. */
374
375 u32 event_threshold;
376 u32 desc_size;
377 u32 data_size;
378 u32 desc_mem_id;
379 u32 data_mem_id;
380
Yan Hefcddf6f2012-03-13 12:41:18 -0700381 /* Feedback to BAM user */
382 void (*callback)(enum sps_callback_case, void *);
383 void *user;
384
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700385 /* Security properties */
386
387 u32 manage;
388 u32 restricted_pipes;
389 u32 ee;
390
391 /* BAM MTI interrupt generation */
392
393 u32 irq_gen_addr;
394
395 /* Security configuration properties */
396
397 u32 sec_config;
398 struct sps_bam_sec_config_props *p_sec_config_props;
399};
400
401/**
402 * This struct specifies memory buffer properties.
403 *
404 * @base - Buffer virtual address.
405 * @phys_base - Buffer physical address.
406 * @size - Specifies buffer size (or maximum size).
407 * @min_size - If non-zero, specifies buffer minimum size.
408 *
409 */
410struct sps_mem_buffer {
411 void *base;
412 u32 phys_base;
413 u32 size;
414 u32 min_size;
415};
416
417/**
418 * This struct defines a connection's end point and is used as the argument
419 * for the sps_connect(), sps_get_config(), and sps_set_config() functions.
420 * For system mode pipe, use SPS_DEV_HANDLE_MEM for the end point that
421 * corresponds to system memory.
422 *
423 * The client can force SPS to reserve a specific pipe on a BAM.
424 * If the pipe is in use, the sps_connect/set_config() will fail.
425 *
426 * @source - Source BAM.
427 * @src_pipe_index - BAM pipe index, 0 to 30.
428 * @destination - Destination BAM.
429 * @dest_pipe_index - BAM pipe index, 0 to 30.
430 *
431 * @mode - specifies which end (source or destination) of the connection will
432 * be controlled/referenced by the client.
433 *
434 * @config - This value is for future use and should be set to
435 * SPS_CONFIG_DEFAULT or left as default from sps_get_config().
436 *
437 * @options - OR'd connection end point options (see SPS_O defines).
438 *
439 * WARNING: The memory provided should be physically contiguous and non-cached.
440 * The user can use one of the following:
441 * 1. sps_alloc_mem() - allocated from pipe-memory.
442 * 2. dma_alloc_coherent() - allocate coherent DMA memory.
443 * 3. dma_map_single() - for using memory allocated by kmalloc().
444 *
445 * @desc - Descriptor FIFO.
446 * @data - Data FIFO (BAM-to-BAM mode only).
447 *
448 * @event_thresh - Pipe event threshold or derivative.
Yan Hef879bb02011-12-22 15:38:03 -0800449 * @lock_group - The lock group this pipe belongs to.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700450 *
451 * @sps_reserved - Reserved word - client must not modify.
452 *
453 */
454struct sps_connect {
455 u32 source;
456 u32 src_pipe_index;
457 u32 destination;
458 u32 dest_pipe_index;
459
460 enum sps_mode mode;
461
462 u32 config;
463
464 enum sps_option options;
465
466 struct sps_mem_buffer desc;
467 struct sps_mem_buffer data;
468
469 u32 event_thresh;
470
Yan Hef879bb02011-12-22 15:38:03 -0800471 u32 lock_group;
472
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700473 /* SETPEND/MTI interrupt generation parameters */
474
475 u32 irq_gen_addr;
476 u32 irq_gen_data;
477
478 u32 sps_reserved;
479
480};
481
482/**
483 * This struct defines a satellite connection's end point. The client of the
484 * SPS driver on the satellite processor must call sps_get_config() to
485 * initialize a struct sps_connect, then copy the values from the struct
486 * sps_satellite to the struct sps_connect before making the sps_connect()
487 * call to the satellite SPS driver.
488 *
489 */
490struct sps_satellite {
491 /**
492 * These values must be copied to either the source or destination
493 * corresponding values in the connect struct.
494 */
495 u32 dev;
496 u32 pipe_index;
497
498 /**
499 * These values must be copied to the corresponding values in the
500 * connect struct
501 */
502 u32 config;
503 enum sps_option options;
504
505};
506
507/**
508 * This struct defines parameters for allocation of a BAM DMA channel. The
509 * client must memset() this struct to zero before writing allocation
510 * information. A value of zero for uninitialized values will instruct
511 * the SPS driver to use defaults or "don't care".
512 *
513 * @dev - Associated BAM device handle, or SPS_DEV_HANDLE_DMA.
514 *
515 * @src_owner - Source owner processor ID.
516 * @dest_owner - Destination owner processor ID.
517 *
518 */
519struct sps_alloc_dma_chan {
520 u32 dev;
521
522 /* BAM DMA channel configuration parameters */
523
524 u32 threshold;
525 enum sps_dma_priority priority;
526
527 /**
528 * Owner IDs are global host processor identifiers used by the system
529 * SROT when establishing execution environments.
530 */
531 u32 src_owner;
532 u32 dest_owner;
533
534};
535
536/**
537 * This struct defines parameters for an allocated BAM DMA channel.
538 *
539 * @dev - BAM DMA device handle.
540 * @dest_pipe_index - Destination/input/write pipe index.
541 * @src_pipe_index - Source/output/read pipe index.
542 *
543 */
544struct sps_dma_chan {
545 u32 dev;
546 u32 dest_pipe_index;
547 u32 src_pipe_index;
548};
549
550/**
551 * This struct is an argument passed payload when triggering a callback event
552 * object registered for an SPS connection end point.
553 *
554 * @user - Pointer registered with sps_register_event().
555 *
556 * @event_id - Which event.
557 *
558 * @iovec - The associated I/O vector. If the end point is a system-mode
559 * producer, the size will reflect the actual number of bytes written to the
560 * buffer by the pipe. NOTE: If this I/O vector was part of a set submitted to
561 * sps_transfer(), then the vector array itself will be updated with all of
562 * the actual counts.
563 *
564 * @user - Pointer registered with the transfer.
565 *
566 */
567struct sps_event_notify {
568 void *user;
569
570 enum sps_event event_id;
571
572 /* Data associated with the event */
573
574 union {
575 /* Data for SPS_EVENT_IRQ */
576 struct {
577 u32 mask;
578 } irq;
579
580 /* Data for SPS_EVENT_EOT or SPS_EVENT_DESC_DONE */
581
582 struct {
583 struct sps_iovec iovec;
584 void *user;
585 } transfer;
586
587 /* Data for SPS_EVENT_ERROR */
588
589 struct {
590 u32 status;
591 } err;
592
593 } data;
594};
595
596/**
597 * This struct defines a event registration parameters and is used as the
598 * argument for the sps_register_event() function.
599 *
600 * @options - Event options that will trigger the event object.
601 * @mode - Event trigger mode.
602 *
603 * @xfer_done - a pointer to a completion object. NULL if not in use.
604 *
605 * @callback - a callback to call on completion. NULL if not in use.
606 *
607 * @user - User pointer that will be provided in event callback data.
608 *
609 */
610struct sps_register_event {
611 enum sps_option options;
612 enum sps_trigger mode;
613 struct completion *xfer_done;
614 void (*callback)(struct sps_event_notify *notify);
615 void *user;
616};
617
618/**
619 * This struct defines a system memory transfer's parameters and is used as the
620 * argument for the sps_transfer() function.
621 *
622 * @iovec_phys - Physical address of I/O vectors buffer.
623 * @iovec - Pointer to I/O vectors buffer.
624 * @iovec_count - Number of I/O vectors.
625 * @user - User pointer passed in callback event.
626 *
627 */
628struct sps_transfer {
629 u32 iovec_phys;
630 struct sps_iovec *iovec;
631 u32 iovec_count;
632 void *user;
633};
634
635/**
636 * This struct defines a timer control operation parameters and is used as an
637 * argument for the sps_timer_ctrl() function.
638 *
639 * @op - Timer control operation.
640 * @timeout_msec - Inactivity timeout (msec).
641 *
642 */
643struct sps_timer_ctrl {
644 enum sps_timer_op op;
645
646 /**
647 * The following configuration parameters must be set when the timer
648 * control operation is SPS_TIMER_OP_CONFIG.
649 */
650 enum sps_timer_mode mode;
651 u32 timeout_msec;
652};
653
654/**
655 * This struct defines a timer control operation result and is used as an
656 * argument for the sps_timer_ctrl() function.
657 */
658struct sps_timer_result {
659 u32 current_timer;
660};
661
662
663/*----------------------------------------------------------------------------
664 * Functions specific to sps interface
665 * -------------------------------------------------------------------------*/
666struct sps_pipe; /* Forward declaration */
667
Yan He2eafd742012-04-09 16:07:15 -0700668#ifdef CONFIG_SPS
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700669/**
670 * Register a BAM device
671 *
672 * This function registers a BAM device with the SPS driver. For each
673 *peripheral that includes a BAM, the peripheral driver must register
674 * the BAM with the SPS driver.
675 *
676 * A requirement is that the peripheral driver must remain attached
677 * to the SPS driver until the BAM is deregistered. Otherwise, the
678 * system may attempt to unload the SPS driver. BAM registrations would
679 * be lost.
680 *
681 * @bam_props - Pointer to struct for BAM device properties.
682 *
683 * @dev_handle - Device handle will be written to this location (output).
684 *
685 * @return 0 on success, negative value on error
686 *
687 */
688int sps_register_bam_device(const struct sps_bam_props *bam_props,
689 u32 *dev_handle);
690
691/**
692 * Deregister a BAM device
693 *
694 * This function deregisters a BAM device from the SPS driver. The peripheral
695 * driver should deregister a BAM when the peripheral driver is shut down or
696 * when BAM use should be disabled.
697 *
698 * A BAM cannot be deregistered if any of its pipes is in an active connection.
699 *
700 * When all BAMs have been deregistered, the system is free to unload the
701 * SPS driver.
702 *
703 * @dev_handle - BAM device handle.
704 *
705 * @return 0 on success, negative value on error
706 *
707 */
708int sps_deregister_bam_device(u32 dev_handle);
709
710/**
711 * Allocate client state context
712 *
713 * This function allocate and initializes a client state context struct.
714 *
715 * @return pointer to client state context
716 *
717 */
718struct sps_pipe *sps_alloc_endpoint(void);
719
720/**
721 * Free client state context
722 *
723 * This function de-initializes and free a client state context struct.
724 *
725 * @ctx - client context for SPS connection end point
726 *
727 * @return 0 on success, negative value on error
728 *
729 */
730int sps_free_endpoint(struct sps_pipe *h);
731
732/**
733 * Get the configuration parameters for an SPS connection end point
734 *
735 * This function retrieves the configuration parameters for an SPS connection
736 * end point.
737 * This function may be called before the end point is connected (before
738 * sps_connect is called). This allows the client to specify parameters before
739 * the connection is established.
740 *
741 * The client must call this function to fill it's struct sps_connect
742 * struct before modifying values and passing the struct to sps_set_config().
743 *
744 * @h - client context for SPS connection end point
745 *
746 * @config - Pointer to buffer for the end point's configuration parameters.
747 * Must not be NULL.
748 *
749 * @return 0 on success, negative value on error
750 *
751 */
752int sps_get_config(struct sps_pipe *h, struct sps_connect *config);
753
754/**
755 * Allocate memory from the SPS Pipe-Memory.
756 *
757 * @h - client context for SPS connection end point
758 *
759 * @mem - memory type - N/A.
760 *
761 * @mem_buffer - Pointer to struct for allocated memory properties.
762 *
763 * @return 0 on success, negative value on error
764 *
765 */
766int sps_alloc_mem(struct sps_pipe *h, enum sps_mem mem,
767 struct sps_mem_buffer *mem_buffer);
768
769/**
770 * Free memory from the SPS Pipe-Memory.
771 *
772 * @h - client context for SPS connection end point
773 *
774 * @mem_buffer - Pointer to struct for allocated memory properties.
775 *
776 * @return 0 on success, negative value on error
777 *
778 */
779int sps_free_mem(struct sps_pipe *h, struct sps_mem_buffer *mem_buffer);
780
781/**
782 * Connect an SPS connection end point
783 *
784 * This function creates a connection between two SPS peripherals or between
785 * an SPS peripheral and the local host processor (via system memory, end
786 *point SPS_DEV_HANDLE_MEM). Establishing the connection includes
787 * initialization of the SPS hardware and allocation of any other connection
788 * resources (buffer memory, etc.).
789 *
790 * This function requires the client to specify both the source and
791 * destination end points of the SPS connection. However, the handle
792 * returned applies only to the end point of the connection that the client
793 * controls. The end point under control must be specified by the
794 * enum sps_mode mode argument, either SPS_MODE_SRC, SPS_MODE_DEST, or
795 * SPS_MODE_CTL. Note that SPS_MODE_CTL is only supported for I/O
796 * accelerator connections, and only a limited set of control operations are
797 * allowed (TBD).
798 *
799 * For a connection involving system memory
800 * (SPS_DEV_HANDLE_MEM), the peripheral end point must be
801 * specified. For example, SPS_MODE_SRC must be specified for a
802 * BAM-to-system connection, since the BAM pipe is the data
803 * producer.
804 *
805 * For a specific peripheral-to-peripheral connection, there may be more than
806 * one required configuration. For example, there might be high-performance
807 * and low-power configurations for a connection between the two peripherals.
808 * The config argument allows the client to specify different configurations,
809 * which may require different system resource allocations and hardware
810 * initialization.
811 *
812 * A client is allowed to create one and only one connection for its
813 * struct sps_pipe. The handle is used to identify the connection end point
814 * in subsequent SPS driver calls. A specific connection source or
815 * destination end point can be associated with one and only one
816 * struct sps_pipe.
817 *
818 * The client must establish an open device handle to the SPS. To do so, the
819 * client must attach to the SPS driver and open the SPS device by calling
820 * the following functions.
821 *
822 * @h - client context for SPS connection end point
823 *
824 * @connect - Pointer to connection parameters
825 *
826 * @return 0 on success, negative value on error
827 *
828 */
829int sps_connect(struct sps_pipe *h, struct sps_connect *connect);
830
831/**
832 * Disconnect an SPS connection end point
833 *
834 * This function disconnects an SPS connection end point.
835 * The SPS hardware associated with that end point will be disabled.
836 * For a connection involving system memory (SPS_DEV_HANDLE_MEM), all
837 * connection resources are deallocated. For a peripheral-to-peripheral
838 * connection, the resources associated with the connection will not be
839 * deallocated until both end points are closed.
840 *
841 * The client must call sps_connect() for the handle before calling
842 * this function.
843 *
844 * @h - client context for SPS connection end point
845 *
846 * @return 0 on success, negative value on error
847 *
848 */
849int sps_disconnect(struct sps_pipe *h);
850
851/**
852 * Register an event object for an SPS connection end point
853 *
854 * This function registers a callback event object for an SPS connection end
855 *point. The registered event object will be triggered for the set of
856 * events specified in reg->options that are enabled for the end point.
857 *
858 * There can only be one registered event object for each event. If an event
859 * object is already registered for an event, it will be replaced. If
860 *reg->event handle is NULL, then any registered event object for the
861 * event will be deregistered. Option bits in reg->options not associated
862 * with events are ignored.
863 *
864 * The client must call sps_connect() for the handle before calling
865 * this function.
866 *
867 * @h - client context for SPS connection end point
868 *
869 * @reg - Pointer to event registration parameters
870 *
871 * @return 0 on success, negative value on error
872 *
873 */
874int sps_register_event(struct sps_pipe *h, struct sps_register_event *reg);
875
876/**
877 * Perform a single DMA transfer on an SPS connection end point
878 *
879 * This function submits a DMA transfer request consisting of a single buffer
880 * for an SPS connection end point associated with a peripheral-to/from-memory
881 * connection. The request will be submitted immediately to hardware if the
882 * hardware is idle (data flow off, no other pending transfers). Otherwise, it
883 * will be queued for later handling in the SPS driver work loop.
884 *
885 * The data buffer must be DMA ready. The client is responsible for insuring
886 *physically contiguous memory, cache maintenance, and memory barrier. For
887 * more information, see Appendix A.
888 *
889 * The client must not modify the data buffer until the completion indication is
890 * received.
891 *
892 * This function cannot be used if transfer queuing is disabled (see option
893 * SPS_O_NO_Q). The client must set the SPS_O_EOT option to receive a callback
894 * event trigger when the transfer is complete. The SPS driver will insure the
895 * appropriate flags in the I/O vectors are set to generate the completion
896 * indication.
897 *
898 * The return value from this function may indicate that an error occurred.
899 * Possible causes include invalid arguments.
900 *
901 * @h - client context for SPS connection end point
902 *
903 * @addr - Physical address of buffer to transfer.
904 *
905 * WARNING: The memory provided should be physically contiguous and
906 * non-cached.
907 *
908 * The user can use one of the following:
909 * 1. sps_alloc_mem() - allocated from pipe-memory.
910 * 2. dma_alloc_coherent() - allocate DMA memory.
911 * 3. dma_map_single() for memory allocated by kmalloc().
912 *
913 * @size - Size in bytes of buffer to transfer
914 *
915 * @user - User pointer that will be returned to user as part of
916 * event payload
917 *
918 * @return 0 on success, negative value on error
919 *
920 */
921int sps_transfer_one(struct sps_pipe *h, u32 addr, u32 size,
922 void *user, u32 flags);
923
924/**
925 * Read event queue for an SPS connection end point
926 *
927 * This function reads event queue for an SPS connection end point.
928 *
929 * @h - client context for SPS connection end point
930 *
931 * @event - pointer to client's event data buffer
932 *
933 * @return 0 on success, negative value on error
934 *
935 */
936int sps_get_event(struct sps_pipe *h, struct sps_event_notify *event);
937
938/**
939 * Get processed I/O vector (completed transfers)
940 *
941 * This function fetches the next processed I/O vector.
942 *
943 * @h - client context for SPS connection end point
944 *
945 * @iovec - Pointer to I/O vector struct (output).
946 * This struct will be zeroed if there are no more processed I/O vectors.
947 *
948 * @return 0 on success, negative value on error
949 *
950 */
951int sps_get_iovec(struct sps_pipe *h, struct sps_iovec *iovec);
952
953/**
954 * Enable an SPS connection end point
955 *
956 * This function enables an SPS connection end point.
957 *
958 * @h - client context for SPS connection end point
959 *
960 * @return 0 on success, negative value on error
961 *
962 */
963int sps_flow_on(struct sps_pipe *h);
964
965/**
966 * Disable an SPS connection end point
967 *
968 * This function disables an SPS connection end point.
969 *
970 * @h - client context for SPS connection end point
971 *
972 * @mode - Desired mode for disabling pipe data flow
973 *
974 * @return 0 on success, negative value on error
975 *
976 */
977int sps_flow_off(struct sps_pipe *h, enum sps_flow_off mode);
978
979/**
980 * Perform a Multiple DMA transfer on an SPS connection end point
981 *
982 * This function submits a DMA transfer request for an SPS connection end point
983 * associated with a peripheral-to/from-memory connection. The request will be
984 * submitted immediately to hardware if the hardware is idle (data flow off, no
985 * other pending transfers). Otherwise, it will be queued for later handling in
986 * the SPS driver work loop.
987 *
988 * The data buffers referenced by the I/O vectors must be DMA ready.
989 * The client is responsible for insuring physically contiguous memory,
990 * any cache maintenance, and memory barrier. For more information,
991 * see Appendix A.
992 *
993 * The I/O vectors must specify physical addresses for the referenced buffers.
994 *
995 * The client must not modify the data buffers referenced by I/O vectors until
996 * the completion indication is received.
997 *
998 * If transfer queuing is disabled (see option SPS_O_NO_Q), the client is
999 * responsible for setting the appropriate flags in the I/O vectors to generate
1000 * the completion indication. Also, the client is responsible for enabling the
1001 * appropriate connection callback event options for completion indication (see
1002 * sps_connect(), sps_set_config()).
1003 *
1004 * If transfer queuing is enabled, the client must set the SPS_O_EOT option to
1005 * receive a callback event trigger when the transfer is complete. The SPS
1006 * driver will insure the appropriate flags in the I/O vectors are set to
1007 * generate the completion indication. The client must not set any flags in the
1008 * I/O vectors, as this may cause the SPS driver to become out of sync with the
1009 * hardware.
1010 *
1011 * The return value from this function may indicate that an error occurred.
1012 * Possible causes include invalid arguments. If transfer queuing is disabled,
1013 * an error will occur if the pipe is already processing a transfer.
1014 *
1015 * @h - client context for SPS connection end point
1016 *
1017 * @transfer - Pointer to transfer parameter struct
1018 *
1019 * @return 0 on success, negative value on error
1020 *
1021 */
1022int sps_transfer(struct sps_pipe *h, struct sps_transfer *transfer);
1023
1024/**
1025 * Determine whether an SPS connection end point FIFO is empty
1026 *
1027 * This function returns the empty state of an SPS connection end point.
1028 *
1029 * @h - client context for SPS connection end point
1030 *
1031 * @empty - pointer to client's empty status word (boolean)
1032 *
1033 * @return 0 on success, negative value on error
1034 *
1035 */
1036int sps_is_pipe_empty(struct sps_pipe *h, u32 *empty);
1037
1038/**
1039 * Reset an SPS BAM device
1040 *
1041 * This function resets an SPS BAM device.
1042 *
1043 * @dev - device handle for the BAM
1044 *
1045 * @return 0 on success, negative value on error
1046 *
1047 */
1048int sps_device_reset(u32 dev);
1049
1050/**
1051 * Set the configuration parameters for an SPS connection end point
1052 *
1053 * This function sets the configuration parameters for an SPS connection
1054 * end point. This function may be called before the end point is connected
1055 * (before sps_connect is called). This allows the client to specify
1056 *parameters before the connection is established. The client is allowed
1057 * to pre-allocate resources and override driver defaults.
1058 *
1059 * The client must call sps_get_config() to fill it's struct sps_connect
1060 * struct before modifying values and passing the struct to this function.
1061 * Only those parameters that differ from the current configuration will
1062 * be processed.
1063 *
1064 * @h - client context for SPS connection end point
1065 *
1066 * @config - Pointer to the end point's new configuration parameters.
1067 *
1068 * @return 0 on success, negative value on error
1069 *
1070 */
1071int sps_set_config(struct sps_pipe *h, struct sps_connect *config);
1072
1073/**
1074 * Set ownership of an SPS connection end point
1075 *
1076 * This function sets the ownership of an SPS connection end point to
1077 * either local (default) or non-local. This function is used to
1078 * retrieve the struct sps_connect data that must be used by a
1079 * satellite processor when calling sps_connect().
1080 *
1081 * Non-local ownership is only possible/meaningful on the processor
1082 * that controls resource allocations (apps processor). Setting ownership
1083 * to non-local on a satellite processor will fail.
1084 *
1085 * Setting ownership from non-local to local will succeed only if the
1086 * owning satellite processor has properly brought the end point to
1087 * an idle condition.
1088 *
1089 * This function will succeed if the connection end point is already in
1090 * the specified ownership state.
1091 *
1092 * @h - client context for SPS connection end point
1093 *
1094 * @owner - New ownership of the connection end point
1095 *
1096 * @connect - Pointer to buffer for satellite processor connect data.
1097 * Can be NULL to avoid retrieving the connect data. Will be ignored
1098 * if the end point ownership is set to local.
1099 *
1100 * @return 0 on success, negative value on error
1101 *
1102 */
1103int sps_set_owner(struct sps_pipe *h, enum sps_owner owner,
1104 struct sps_satellite *connect);
1105
1106/**
1107 * Allocate a BAM DMA channel
1108 *
1109 * This function allocates a BAM DMA channel. A "BAM DMA" is a special
1110 * DMA peripheral with a BAM front end. The DMA peripheral acts as a conduit
1111 * for data to flow into a consumer pipe and then out of a producer pipe.
1112 * It's primarily purpose is to serve as a path for interprocessor communication
1113 * that allows each processor to control and protect it's own memory space.
1114 *
1115 * @alloc - Pointer to struct for BAM DMA channel allocation properties.
1116 *
1117 * @chan - Allocated channel information will be written to this
1118 * location (output).
1119 *
1120 * @return 0 on success, negative value on error
1121 *
1122 */
1123int sps_alloc_dma_chan(const struct sps_alloc_dma_chan *alloc,
1124 struct sps_dma_chan *chan);
1125
1126/**
1127 * Free a BAM DMA channel
1128 *
1129 * This function frees a BAM DMA channel.
1130 *
1131 * @chan - Pointer to information for channel to free
1132 *
1133 * @return 0 on success, negative value on error
1134 *
1135 */
1136int sps_free_dma_chan(struct sps_dma_chan *chan);
1137
1138/**
1139 * Get the BAM handle for BAM-DMA.
1140 *
1141 * The BAM handle should be use as source/destination in the sps_connect().
1142 *
1143 * @return handle on success, zero on error
1144 *
1145 */
1146u32 sps_dma_get_bam_handle(void);
1147
1148/**
1149 * Free the BAM handle for BAM-DMA.
1150 *
1151 */
1152void sps_dma_free_bam_handle(u32 h);
1153
1154
1155/**
1156 * Get number of free transfer entries for an SPS connection end point
1157 *
1158 * This function returns the number of free transfer entries for an
1159 * SPS connection end point.
1160 *
1161 * @h - client context for SPS connection end point
1162 *
1163 * @count - pointer to count status
1164 *
1165 * @return 0 on success, negative value on error
1166 *
1167 */
1168int sps_get_free_count(struct sps_pipe *h, u32 *count);
1169
1170/**
1171 * Perform timer control
1172 *
1173 * This function performs timer control operations.
1174 *
1175 * @h - client context for SPS connection end point
1176 *
1177 * @timer_ctrl - Pointer to timer control specification
1178 *
1179 * @timer_result - Pointer to buffer for timer operation result.
1180 * This argument can be NULL if no result is expected for the operation.
1181 * If non-NULL, the current timer value will always provided.
1182 *
1183 * @return 0 on success, negative value on error
1184 *
1185 */
1186int sps_timer_ctrl(struct sps_pipe *h,
1187 struct sps_timer_ctrl *timer_ctrl,
1188 struct sps_timer_result *timer_result);
1189
Yan He2027bd82011-11-05 14:43:01 -07001190/**
1191 * Find the handle of a BAM device based on the physical address
1192 *
1193 * This function finds a BAM device in the BAM registration list that
1194 * matches the specified physical address, and returns its handle.
1195 *
1196 * @phys_addr - physical address of the BAM
1197 *
1198 * @h - device handle of the BAM
1199 *
1200 * @return 0 on success, negative value on error
1201 *
1202 */
1203int sps_phy2h(u32 phys_addr, u32 *handle);
1204
1205/**
1206 * Setup desc/data FIFO for bam-to-bam connection
1207 *
1208 * @mem_buffer - Pointer to struct for allocated memory properties.
1209 *
1210 * @addr - address of FIFO
1211 *
1212 * @size - FIFO size
1213 *
1214 * @use_offset - use address offset instead of absolute address
1215 *
1216 * @return 0 on success, negative value on error
1217 *
1218 */
1219int sps_setup_bam2bam_fifo(struct sps_mem_buffer *mem_buffer,
1220 u32 addr, u32 size, int use_offset);
1221
Yan Hece596c12012-04-06 10:42:33 -07001222/**
1223 * Get the number of unused descriptors in the descriptor FIFO
1224 * of a pipe
1225 *
1226 * @h - client context for SPS connection end point
1227 *
1228 * @desc_num - number of unused descriptors
1229 *
1230 * @return 0 on success, negative value on error
1231 *
1232 */
1233int sps_get_unused_desc_num(struct sps_pipe *h, u32 *desc_num);
1234
Yan He2eafd742012-04-09 16:07:15 -07001235#else
1236static inline int sps_register_bam_device(const struct sps_bam_props
1237 *bam_props, u32 *dev_handle)
1238{
1239 return -EPERM;
1240}
1241
1242static inline int sps_deregister_bam_device(u32 dev_handle)
1243{
1244 return -EPERM;
1245}
1246
1247static inline struct sps_pipe *sps_alloc_endpoint(void)
1248{
1249 return NULL;
1250}
1251
1252static inline int sps_free_endpoint(struct sps_pipe *h)
1253{
1254 return -EPERM;
1255}
1256
1257static inline int sps_get_config(struct sps_pipe *h, struct sps_connect *config)
1258{
1259 return -EPERM;
1260}
1261
1262static inline int sps_alloc_mem(struct sps_pipe *h, enum sps_mem mem,
1263 struct sps_mem_buffer *mem_buffer)
1264{
1265 return -EPERM;
1266}
1267
1268static inline int sps_free_mem(struct sps_pipe *h,
1269 struct sps_mem_buffer *mem_buffer)
1270{
1271 return -EPERM;
1272}
1273
1274static inline int sps_connect(struct sps_pipe *h, struct sps_connect *connect)
1275{
1276 return -EPERM;
1277}
1278
1279static inline int sps_disconnect(struct sps_pipe *h)
1280{
1281 return -EPERM;
1282}
1283
1284static inline int sps_register_event(struct sps_pipe *h,
1285 struct sps_register_event *reg)
1286{
1287 return -EPERM;
1288}
1289
1290static inline int sps_transfer_one(struct sps_pipe *h, u32 addr, u32 size,
1291 void *user, u32 flags)
1292{
1293 return -EPERM;
1294}
1295
1296static inline int sps_get_event(struct sps_pipe *h,
1297 struct sps_event_notify *event)
1298{
1299 return -EPERM;
1300}
1301
1302static inline int sps_get_iovec(struct sps_pipe *h, struct sps_iovec *iovec)
1303{
1304 return -EPERM;
1305}
1306
1307static inline int sps_flow_on(struct sps_pipe *h)
1308{
1309 return -EPERM;
1310}
1311
1312static inline int sps_flow_off(struct sps_pipe *h, enum sps_flow_off mode)
1313{
1314 return -EPERM;
1315}
1316
1317static inline int sps_transfer(struct sps_pipe *h,
1318 struct sps_transfer *transfer)
1319{
1320 return -EPERM;
1321}
1322
1323static inline int sps_is_pipe_empty(struct sps_pipe *h, u32 *empty)
1324{
1325 return -EPERM;
1326}
1327
1328static inline int sps_device_reset(u32 dev)
1329{
1330 return -EPERM;
1331}
1332
1333static inline int sps_set_config(struct sps_pipe *h, struct sps_connect *config)
1334{
1335 return -EPERM;
1336}
1337
1338static inline int sps_set_owner(struct sps_pipe *h, enum sps_owner owner,
1339 struct sps_satellite *connect)
1340{
1341 return -EPERM;
1342}
1343
1344static inline int sps_get_free_count(struct sps_pipe *h, u32 *count)
1345{
1346 return -EPERM;
1347}
1348
1349static inline int sps_alloc_dma_chan(const struct sps_alloc_dma_chan *alloc,
1350 struct sps_dma_chan *chan)
1351{
1352 return -EPERM;
1353}
1354
1355static inline int sps_free_dma_chan(struct sps_dma_chan *chan)
1356{
1357 return -EPERM;
1358}
1359
1360static inline u32 sps_dma_get_bam_handle(void)
1361{
1362 return 0;
1363}
1364
1365static inline void sps_dma_free_bam_handle(u32 h)
1366{
1367}
1368
1369static inline int sps_timer_ctrl(struct sps_pipe *h,
1370 struct sps_timer_ctrl *timer_ctrl,
1371 struct sps_timer_result *timer_result)
1372{
1373 return -EPERM;
1374}
1375
1376static inline int sps_phy2h(u32 phys_addr, u32 *handle)
1377{
1378 return -EPERM;
1379}
1380
1381static inline int sps_setup_bam2bam_fifo(struct sps_mem_buffer *mem_buffer,
1382 u32 addr, u32 size, int use_offset)
1383{
1384 return -EPERM;
1385}
1386
1387static inline int sps_get_unused_desc_num(struct sps_pipe *h, u32 *desc_num)
1388{
1389 return -EPERM;
1390}
1391#endif
1392
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001393#endif /* _SPS_H_ */