cvmx-shmem.h revision 215976
1260684Skaiw/***********************license start***************
2260684Skaiw * Copyright (c) 2003-2010  Cavium Networks (support@cavium.com). All rights
3260684Skaiw * reserved.
4260684Skaiw *
5260684Skaiw *
6260684Skaiw * Redistribution and use in source and binary forms, with or without
7260684Skaiw * modification, are permitted provided that the following conditions are
8260684Skaiw * met:
9260684Skaiw *
10260684Skaiw *   * Redistributions of source code must retain the above copyright
11260684Skaiw *     notice, this list of conditions and the following disclaimer.
12260684Skaiw *
13260684Skaiw *   * Redistributions in binary form must reproduce the above
14260684Skaiw *     copyright notice, this list of conditions and the following
15260684Skaiw *     disclaimer in the documentation and/or other materials provided
16260684Skaiw *     with the distribution.
17260684Skaiw
18260684Skaiw *   * Neither the name of Cavium Networks nor the names of
19260684Skaiw *     its contributors may be used to endorse or promote products
20260684Skaiw *     derived from this software without specific prior written
21260684Skaiw *     permission.
22260684Skaiw
23260684Skaiw * This Software, including technical data, may be subject to U.S. export  control
24260684Skaiw * laws, including the U.S. Export Administration Act and its  associated
25260684Skaiw * regulations, and may be subject to export or import  regulations in other
26260684Skaiw * countries.
27260684Skaiw
28260684Skaiw * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29260684Skaiw * AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR
30260684Skaiw * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31260684Skaiw * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32260684Skaiw * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33260684Skaiw * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34260684Skaiw * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35260684Skaiw * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36260684Skaiw * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
37260684Skaiw * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38260684Skaiw ***********************license end**************************************/
39260684Skaiw
40260684Skaiw
41260684Skaiw#ifndef __CVMX_SHMEM_H__
42260684Skaiw#define __CVMX_SHMEM_H__
43260684Skaiw
44260684Skaiw/**
45260684Skaiw * @file
46260684Skaiw *
47260684Skaiw * cvmx-shmem provides APIs for setting up shared memory between Linux
48260684Skaiw * and simple executive applications.
49260684Skaiw *
50260684Skaiw * <hr>$Revision: 41586 $<hr>
51260684Skaiw */
52260684Skaiw
53260684Skaiw
54260684Skaiw#ifdef  __cplusplus
55260684Skaiwextern "C" {
56260684Skaiw#endif
57260684Skaiw
58260684Skaiw#include "cvmx-spinlock.h"
59260684Skaiw
60260684Skaiw#define CVMX_SHMEM_NUM_DSCPTR       8
61260684Skaiw#define CVMX_SHMEM_DSCPTR_NAME         "SMDR"
62260684Skaiw
63260684Skaiw#define CVMX_SHMEM_O_RDONLY         0x00
64260684Skaiw#define CVMX_SHMEM_O_WRONLY         0x01
65260684Skaiw#define CVMX_SHMEM_O_RDWR           0x02
66260684Skaiw#define CVMX_SHMEM_O_CREAT          0x04
67260684Skaiw
68260684Skaiw#define CVMX_SHMEM_MAP_PROT_READ    0x01
69260684Skaiw#define CVMX_SHMEM_MAP_PROT_WRITE   0x02
70260684Skaiw#define CVMX_SHMEM_MAP_EXEC         0x04
71260684Skaiw
72260684Skaiw#define CVMX_SHMEM_OWNER_NONE       0xff
73260684Skaiw
74260684Skaiw#define CVMX_SHMEM_VADDR64_START    0x500000000ULL
75260684Skaiw#define CVMX_SHMEM_VADDR64_END      0x600000000ULL
76260684Skaiw
77260684Skaiw#define CVMX_SHMEM_VADDR32_START    0x10000000
78260684Skaiw#define CVMX_SHMEM_VADDR32_END      0x18000000
79260684Skaiw
80260684Skaiwstruct cvmx_shmem_dscptr {
81260684Skaiw    cvmx_spinlock_t lock;
82260684Skaiw    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