1/***********************license start***************
2 * Copyright (c) 2003-2010  Cavium Inc. (support@cavium.com). All rights
3 * reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 *   * Redistributions of source code must retain the above copyright
11 *     notice, this list of conditions and the following disclaimer.
12 *
13 *   * Redistributions in binary form must reproduce the above
14 *     copyright notice, this list of conditions and the following
15 *     disclaimer in the documentation and/or other materials provided
16 *     with the distribution.
17
18 *   * Neither the name of Cavium Inc. nor the names of
19 *     its contributors may be used to endorse or promote products
20 *     derived from this software without specific prior written
21 *     permission.
22
23 * This Software, including technical data, may be subject to U.S. export  control
24 * laws, including the U.S. Export Administration Act and its  associated
25 * regulations, and may be subject to export or import  regulations in other
26 * countries.
27
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
39
40
41#ifndef __CVMX_SHMEM_H__
42#define __CVMX_SHMEM_H__
43
44/**
45 * @file
46 *
47 * cvmx-shmem provides APIs for setting up shared memory between Linux
48 * and simple executive applications.
49 *
50 * <hr>$Revision: 41586 $<hr>
51 */
52
53
54#ifdef  __cplusplus
55extern "C" {
56#endif
57
58#include "cvmx-spinlock.h"
59
60#define CVMX_SHMEM_NUM_DSCPTR       8
61#define CVMX_SHMEM_DSCPTR_NAME         "SMDR"
62
63#define CVMX_SHMEM_O_RDONLY         0x00
64#define CVMX_SHMEM_O_WRONLY         0x01
65#define CVMX_SHMEM_O_RDWR           0x02
66#define CVMX_SHMEM_O_CREAT          0x04
67
68#define CVMX_SHMEM_MAP_PROT_READ    0x01
69#define CVMX_SHMEM_MAP_PROT_WRITE   0x02
70#define CVMX_SHMEM_MAP_EXEC         0x04
71
72#define CVMX_SHMEM_OWNER_NONE       0xff
73
74#define CVMX_SHMEM_VADDR64_START    0x500000000ULL
75#define CVMX_SHMEM_VADDR64_END      0x600000000ULL
76
77#define CVMX_SHMEM_VADDR32_START    0x10000000
78#define CVMX_SHMEM_VADDR32_END      0x18000000
79
80struct cvmx_shmem_dscptr {
81    cvmx_spinlock_t lock;
82    uint64_t owner:           8;
83    uint64_t is_named_block:  1;
84    uint64_t p_wronly:        1;
85    uint64_t p_rdwr:          1;
86    int32_t use_count;	      /* must use atomic operation to maintain count */
87    const char *name;
88    void *vaddr;
89    uint64_t paddr;
90    uint32_t size;
91    uint64_t alignment;
92};
93
94struct cvmx_shmem_smdr {
95    cvmx_spinlock_t lock;
96    struct cvmx_shmem_dscptr  shmd[CVMX_SHMEM_NUM_DSCPTR];
97    void *break64;    /* Keep track of unused 64 bit virtual address space */
98};
99
100
101struct cvmx_shmem_smdr *cvmx_shmem_init(void);
102
103/**
104 *  Create a piece memory out of named block
105 *
106 *  @param name Named block name
107 *  @param flag create flag
108 */
109struct cvmx_shmem_dscptr *cvmx_shmem_named_block_open(char *name, uint32_t size, int oflag);
110
111/**
112 *  Update TLB mapping based on the descriptor
113 */
114void*  cvmx_shmem_map(struct cvmx_shmem_dscptr *desc, int pflag);
115
116/**
117 *  Remove the TLB mapping created for the descriptor
118 */
119void   cvmx_shmem_unmap(struct cvmx_shmem_dscptr *desc);
120
121
122/**
123 *  Close the share memory,
124 *
125 *  @Param remove  Remove the named block if it is created by the application
126 */
127int cvmx_shmem_close(struct cvmx_shmem_dscptr *desc, int remove);
128
129/**
130 * Debug function, dump all SMDR descriptors
131 */
132void cvmx_shmem_show(void);
133
134
135#ifdef  __cplusplus
136}
137#endif
138
139#endif
140