1*9123ebc1Sozaki-r /* $NetBSD: shmifvar.h,v 1.12 2024/09/02 05:12:53 ozaki-r Exp $ */ 236e63e68Spooka 336e63e68Spooka /*- 423bbd0e0Spooka * Copyright (c) 2009, 2010 Antti Kantee. All Rights Reserved. 536e63e68Spooka * 636e63e68Spooka * Development of this software was supported by The Nokia Foundation. 736e63e68Spooka * 836e63e68Spooka * Redistribution and use in source and binary forms, with or without 936e63e68Spooka * modification, are permitted provided that the following conditions 1036e63e68Spooka * are met: 1136e63e68Spooka * 1. Redistributions of source code must retain the above copyright 1236e63e68Spooka * notice, this list of conditions and the following disclaimer. 1336e63e68Spooka * 2. Redistributions in binary form must reproduce the above copyright 1436e63e68Spooka * notice, this list of conditions and the following disclaimer in the 1536e63e68Spooka * documentation and/or other materials provided with the distribution. 1636e63e68Spooka * 1736e63e68Spooka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 1836e63e68Spooka * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 1936e63e68Spooka * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 2036e63e68Spooka * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2136e63e68Spooka * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2236e63e68Spooka * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 2336e63e68Spooka * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2436e63e68Spooka * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2536e63e68Spooka * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2636e63e68Spooka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2736e63e68Spooka * SUCH DAMAGE. 2836e63e68Spooka */ 2936e63e68Spooka 3036e63e68Spooka #ifndef _RUMP_NET_SHMIFVAR_H_ 3136e63e68Spooka #define _RUMP_NET_SHMIFVAR_H_ 3236e63e68Spooka 33d5a83df7Spooka #define SHMIF_MAGIC 0xca11d054 34bd5b4bd1Sozaki-r #define SHMIF_VERSION 3 35d5a83df7Spooka 3636e63e68Spooka struct shmif_mem { 37d5a83df7Spooka uint32_t shm_magic; 3836e63e68Spooka uint32_t shm_version; 39d5a83df7Spooka 40ce68b7aeSpooka uint64_t shm_gen; 41ce68b7aeSpooka 42d5a83df7Spooka uint32_t shm_first; 43d5a83df7Spooka uint32_t shm_last; 44d5a83df7Spooka 45d5a83df7Spooka uint32_t shm_lock; 46ce68b7aeSpooka uint32_t shm_spare[1]; 47d5a83df7Spooka 4836e63e68Spooka uint8_t shm_data[0]; 4936e63e68Spooka }; 5036e63e68Spooka 5136e63e68Spooka #define IFMEM_DATA (offsetof(struct shmif_mem, shm_data)) 5236e63e68Spooka #define IFMEM_WAKEUP (offsetof(struct shmif_mem, shm_version)) 53b97bdf94Spooka 54b97bdf94Spooka struct shmif_pkthdr { 55b97bdf94Spooka uint32_t sp_len; 56b97bdf94Spooka 57b97bdf94Spooka uint32_t sp_sec; 58b97bdf94Spooka uint32_t sp_usec; 595c34a715Sozaki-r 605c34a715Sozaki-r uint64_t sp_sender; 61b97bdf94Spooka }; 6236e63e68Spooka 6382ca9ad9Schristos #define BUSMEM_SIZE (1024*1024U) 64ce68b7aeSpooka #define BUSMEM_DATASIZE (BUSMEM_SIZE - sizeof(struct shmif_mem)) 65ce68b7aeSpooka 66*9123ebc1Sozaki-r #define LOCK_UNLOCKED 0 67*9123ebc1Sozaki-r #define LOCK_LOCKED 1 68*9123ebc1Sozaki-r #define LOCK_COOLDOWN 1001 69*9123ebc1Sozaki-r 70ce68b7aeSpooka #if 0 71ce68b7aeSpooka #ifdef _KERNEL 721a7f9ac6Spooka #include <rump/rumpuser.h> 73ce68b7aeSpooka #define DPRINTF(x) rumpuser_dprintf x 74ce68b7aeSpooka #else 7558dd466bSozaki-r #include <stdio.h> 76ce68b7aeSpooka #define DPRINTF(x) printf x 77ce68b7aeSpooka #endif 78ce68b7aeSpooka #else 79ce68b7aeSpooka #define DPRINTF(x) 80ce68b7aeSpooka #endif 81ce68b7aeSpooka 82ce68b7aeSpooka uint32_t shmif_advance(uint32_t, uint32_t); 83ce68b7aeSpooka uint32_t shmif_busread(struct shmif_mem *, 84ce68b7aeSpooka void *, uint32_t, size_t, bool *); 85ce68b7aeSpooka void shmif_advancefirst(struct shmif_mem *, uint32_t, size_t); 86ce68b7aeSpooka uint32_t shmif_buswrite(struct shmif_mem *, uint32_t, 87ce68b7aeSpooka void *, size_t, bool *); 88ce68b7aeSpooka uint32_t shmif_nextpktoff(struct shmif_mem *, uint32_t); 89ce68b7aeSpooka 9036e63e68Spooka #endif 91