Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | #ifndef __included_ssvm_fifo_segment_h__ |
| 16 | #define __included_ssvm_fifo_segment_h__ |
| 17 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 18 | #include <svm/svm_fifo.h> |
| 19 | #include <svm/ssvm.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 20 | |
| 21 | typedef struct |
| 22 | { |
| 23 | volatile svm_fifo_t **fifos; |
| 24 | u8 *segment_name; |
| 25 | } svm_fifo_segment_header_t; |
| 26 | |
| 27 | typedef struct |
| 28 | { |
| 29 | ssvm_private_t ssvm; |
| 30 | svm_fifo_segment_header_t *h; |
| 31 | } svm_fifo_segment_private_t; |
| 32 | |
| 33 | typedef struct |
| 34 | { |
| 35 | /** pool of segments */ |
| 36 | svm_fifo_segment_private_t *segments; |
| 37 | /* Where to put the next one */ |
| 38 | u64 next_baseva; |
| 39 | u32 timeout_in_seconds; |
| 40 | } svm_fifo_segment_main_t; |
| 41 | |
| 42 | extern svm_fifo_segment_main_t svm_fifo_segment_main; |
| 43 | |
| 44 | typedef struct |
| 45 | { |
| 46 | char *segment_name; |
| 47 | u32 segment_size; |
| 48 | u32 new_segment_index; |
| 49 | } svm_fifo_segment_create_args_t; |
| 50 | |
| 51 | static inline svm_fifo_segment_private_t * |
| 52 | svm_fifo_get_segment (u32 segment_index) |
| 53 | { |
| 54 | svm_fifo_segment_main_t *ssm = &svm_fifo_segment_main; |
| 55 | return vec_elt_at_index (ssm->segments, segment_index); |
| 56 | } |
| 57 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame^] | 58 | static inline u8 |
| 59 | svm_fifo_segment_has_fifos (svm_fifo_segment_private_t * fifo_segment) |
| 60 | { |
| 61 | return vec_len ((svm_fifo_t **) fifo_segment->h->fifos) != 0; |
| 62 | } |
| 63 | |
| 64 | static inline svm_fifo_t ** |
| 65 | svm_fifo_segment_get_fifos (svm_fifo_segment_private_t * fifo_segment) |
| 66 | { |
| 67 | return (svm_fifo_t **) fifo_segment->h->fifos; |
| 68 | } |
| 69 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 70 | #define foreach_ssvm_fifo_segment_api_error \ |
| 71 | _(OUT_OF_SPACE, "Out of space in segment", -200) |
| 72 | |
| 73 | typedef enum |
| 74 | { |
| 75 | #define _(n,s,c) SSVM_FIFO_SEGMENT_API_ERROR_##n = c, |
| 76 | foreach_ssvm_fifo_segment_api_error |
| 77 | #undef _ |
| 78 | } ssvm_fifo_segment_api_error_enum_t; |
| 79 | |
| 80 | int svm_fifo_segment_create (svm_fifo_segment_create_args_t * a); |
| 81 | int svm_fifo_segment_attach (svm_fifo_segment_create_args_t * a); |
| 82 | void svm_fifo_segment_delete (svm_fifo_segment_private_t * s); |
| 83 | |
| 84 | svm_fifo_t *svm_fifo_segment_alloc_fifo (svm_fifo_segment_private_t * s, |
| 85 | u32 data_size_in_bytes); |
| 86 | void svm_fifo_segment_free_fifo (svm_fifo_segment_private_t * s, |
| 87 | svm_fifo_t * f); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 88 | void svm_fifo_segment_init (u64 baseva, u32 timeout_in_seconds); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 89 | u32 svm_fifo_segment_index (svm_fifo_segment_private_t * s); |
| 90 | |
| 91 | #endif /* __included_ssvm_fifo_segment_h__ */ |
| 92 | |
| 93 | /* |
| 94 | * fd.io coding-style-patch-verification: ON |
| 95 | * |
| 96 | * Local Variables: |
| 97 | * eval: (c-set-style "gnu") |
| 98 | * End: |
| 99 | */ |