cvmx-shmem.h revision 256281
11590Srgrimes/***********************license start***************
21590Srgrimes * Copyright (c) 2003-2010  Cavium Inc. (support@cavium.com). All rights
31590Srgrimes * reserved.
41590Srgrimes *
51590Srgrimes *
61590Srgrimes * Redistribution and use in source and binary forms, with or without
71590Srgrimes * modification, are permitted provided that the following conditions are
81590Srgrimes * met:
91590Srgrimes *
101590Srgrimes *   * Redistributions of source code must retain the above copyright
111590Srgrimes *     notice, this list of conditions and the following disclaimer.
121590Srgrimes *
131590Srgrimes *   * Redistributions in binary form must reproduce the above
141590Srgrimes *     copyright notice, this list of conditions and the following
151590Srgrimes *     disclaimer in the documentation and/or other materials provided
161590Srgrimes *     with the distribution.
171590Srgrimes
181590Srgrimes *   * Neither the name of Cavium Inc. nor the names of
191590Srgrimes *     its contributors may be used to endorse or promote products
201590Srgrimes *     derived from this software without specific prior written
211590Srgrimes *     permission.
221590Srgrimes
231590Srgrimes * This Software, including technical data, may be subject to U.S. export  control
241590Srgrimes * laws, including the U.S. Export Administration Act and its  associated
251590Srgrimes * regulations, and may be subject to export or import  regulations in other
261590Srgrimes * countries.
271590Srgrimes
281590Srgrimes * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
291590Srgrimes * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
3087687Smarkm * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
3187687Smarkm * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
3287687Smarkm * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
3387687Smarkm * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
341590Srgrimes * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
3528855Scharnier * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
361590Srgrimes * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
371590Srgrimes * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
3887687Smarkm ***********************license end**************************************/
391590Srgrimes
401590Srgrimes
4187687Smarkm#ifndef __CVMX_SHMEM_H__
4228855Scharnier#define __CVMX_SHMEM_H__
431590Srgrimes
441590Srgrimes/**
4587687Smarkm * @file
4628855Scharnier *
4728855Scharnier * cvmx-shmem provides APIs for setting up shared memory between Linux
4828855Scharnier * and simple executive applications.
4928855Scharnier *
501590Srgrimes * <hr>$Revision: 41586 $<hr>
5128855Scharnier */
521590Srgrimes
5387687Smarkm
541590Srgrimes#ifdef  __cplusplus
551590Srgrimesextern "C" {
561590Srgrimes#endif
571590Srgrimes
581590Srgrimes#include "cvmx-spinlock.h"
591590Srgrimes
601590Srgrimes#define CVMX_SHMEM_NUM_DSCPTR       8
611590Srgrimes#define CVMX_SHMEM_DSCPTR_NAME         "SMDR"
621590Srgrimes
631590Srgrimes#define CVMX_SHMEM_O_RDONLY         0x00
641590Srgrimes#define CVMX_SHMEM_O_WRONLY         0x01
65227247Sed#define CVMX_SHMEM_O_RDWR           0x02
661590Srgrimes#define CVMX_SHMEM_O_CREAT          0x04
67227247Sed
68227247Sed#define CVMX_SHMEM_MAP_PROT_READ    0x01
69227247Sed#define CVMX_SHMEM_MAP_PROT_WRITE   0x02
701590Srgrimes#define CVMX_SHMEM_MAP_EXEC         0x04
71227247Sed
72227247Sed#define CVMX_SHMEM_OWNER_NONE       0xff
73227247Sed
741590Srgrimes#define CVMX_SHMEM_VADDR64_START    0x500000000ULL
75227247Sed#define CVMX_SHMEM_VADDR64_END      0x600000000ULL
7687687Smarkm
77227247Sed#define CVMX_SHMEM_VADDR32_START    0x10000000
78227247Sed#define CVMX_SHMEM_VADDR32_END      0x18000000
79227247Sed
80227247Sedstruct cvmx_shmem_dscptr {
8128855Scharnier    cvmx_spinlock_t lock;
82227247Sed    uint64_t owner:           8;
83227247Sed    uint64_t is_named_block:  1;
8487687Smarkm    uint64_t p_wronly:        1;
8592922Simp    uint64_t p_rdwr:          1;
8687687Smarkm    int32_t use_count;	      /* must use atomic operation to maintain count */
87227247Sed    const char *name;
88227247Sed    void *vaddr;
89227247Sed    uint64_t paddr;
90227247Sed    uint32_t size;
91227247Sed    uint64_t alignment;
92227247Sed};
93227247Sed
9487687Smarkmstruct cvmx_shmem_smdr {
9528855Scharnier    cvmx_spinlock_t lock;
96102944Sdwmalone    struct cvmx_shmem_dscptr  shmd[CVMX_SHMEM_NUM_DSCPTR];
971590Srgrimes    void *break64;    /* Keep track of unused 64 bit virtual address space */
9828855Scharnier};
99178973Skevlo
1001590Srgrimes
10128855Scharnierstruct cvmx_shmem_smdr *cvmx_shmem_init(void);
10228855Scharnier
10328855Scharnier/**
1041590Srgrimes *  Create a piece memory out of named block
10528855Scharnier *
1061590Srgrimes *  @param name Named block name
1071590Srgrimes *  @param flag create flag
10828855Scharnier */
1091590Srgrimesstruct cvmx_shmem_dscptr *cvmx_shmem_named_block_open(char *name, uint32_t size, int oflag);
1101590Srgrimes
11128855Scharnier/**
1121590Srgrimes *  Update TLB mapping based on the descriptor
11328855Scharnier */
11428855Scharniervoid*  cvmx_shmem_map(struct cvmx_shmem_dscptr *desc, int pflag);
11528855Scharnier
11628855Scharnier/**
11728855Scharnier *  Remove the TLB mapping created for the descriptor
1181590Srgrimes */
1191590Srgrimesvoid   cvmx_shmem_unmap(struct cvmx_shmem_dscptr *desc);
12028855Scharnier
1211590Srgrimes
122178973Skevlo/**
123178973Skevlo *  Close the share memory,
124178973Skevlo *
125178973Skevlo *  @Param remove  Remove the named block if it is created by the application
126178973Skevlo */
127178973Skevloint cvmx_shmem_close(struct cvmx_shmem_dscptr *desc, int remove);
128178973Skevlo
129178973Skevlo/**
130178973Skevlo * Debug function, dump all SMDR descriptors
131178973Skevlo */
1321590Srgrimesvoid cvmx_shmem_show(void);
1331590Srgrimes
13428855Scharnier
1351590Srgrimes#ifdef  __cplusplus
13628855Scharnier}
1371590Srgrimes#endif
1381590Srgrimes
1391590Srgrimes#endif
1401590Srgrimes