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> |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 20 | #include <vppinfra/lock.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 21 | |
| 22 | typedef struct |
| 23 | { |
| 24 | volatile svm_fifo_t **fifos; |
| 25 | u8 *segment_name; |
| 26 | } svm_fifo_segment_header_t; |
| 27 | |
| 28 | typedef struct |
| 29 | { |
| 30 | ssvm_private_t ssvm; |
| 31 | svm_fifo_segment_header_t *h; |
| 32 | } svm_fifo_segment_private_t; |
| 33 | |
| 34 | typedef struct |
| 35 | { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 36 | volatile u32 lock; |
| 37 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 38 | /** pool of segments */ |
| 39 | svm_fifo_segment_private_t *segments; |
| 40 | /* Where to put the next one */ |
| 41 | u64 next_baseva; |
| 42 | u32 timeout_in_seconds; |
| 43 | } svm_fifo_segment_main_t; |
| 44 | |
| 45 | extern svm_fifo_segment_main_t svm_fifo_segment_main; |
| 46 | |
| 47 | typedef struct |
| 48 | { |
| 49 | char *segment_name; |
| 50 | u32 segment_size; |
| 51 | u32 new_segment_index; |
| 52 | } svm_fifo_segment_create_args_t; |
| 53 | |
| 54 | static inline svm_fifo_segment_private_t * |
| 55 | svm_fifo_get_segment (u32 segment_index) |
| 56 | { |
| 57 | svm_fifo_segment_main_t *ssm = &svm_fifo_segment_main; |
| 58 | return vec_elt_at_index (ssm->segments, segment_index); |
| 59 | } |
| 60 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 61 | static inline u8 |
| 62 | svm_fifo_segment_has_fifos (svm_fifo_segment_private_t * fifo_segment) |
| 63 | { |
| 64 | return vec_len ((svm_fifo_t **) fifo_segment->h->fifos) != 0; |
| 65 | } |
| 66 | |
| 67 | static inline svm_fifo_t ** |
| 68 | svm_fifo_segment_get_fifos (svm_fifo_segment_private_t * fifo_segment) |
| 69 | { |
| 70 | return (svm_fifo_t **) fifo_segment->h->fifos; |
| 71 | } |
| 72 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 73 | #define foreach_ssvm_fifo_segment_api_error \ |
| 74 | _(OUT_OF_SPACE, "Out of space in segment", -200) |
| 75 | |
| 76 | typedef enum |
| 77 | { |
| 78 | #define _(n,s,c) SSVM_FIFO_SEGMENT_API_ERROR_##n = c, |
| 79 | foreach_ssvm_fifo_segment_api_error |
| 80 | #undef _ |
| 81 | } ssvm_fifo_segment_api_error_enum_t; |
| 82 | |
| 83 | int svm_fifo_segment_create (svm_fifo_segment_create_args_t * a); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 84 | int svm_fifo_segment_create_process_private (svm_fifo_segment_create_args_t |
| 85 | * a); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 86 | int svm_fifo_segment_attach (svm_fifo_segment_create_args_t * a); |
| 87 | void svm_fifo_segment_delete (svm_fifo_segment_private_t * s); |
| 88 | |
| 89 | svm_fifo_t *svm_fifo_segment_alloc_fifo (svm_fifo_segment_private_t * s, |
| 90 | u32 data_size_in_bytes); |
| 91 | void svm_fifo_segment_free_fifo (svm_fifo_segment_private_t * s, |
| 92 | svm_fifo_t * f); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 93 | void svm_fifo_segment_init (u64 baseva, u32 timeout_in_seconds); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 94 | u32 svm_fifo_segment_index (svm_fifo_segment_private_t * s); |
| 95 | |
| 96 | #endif /* __included_ssvm_fifo_segment_h__ */ |
| 97 | |
| 98 | /* |
| 99 | * fd.io coding-style-patch-verification: ON |
| 100 | * |
| 101 | * Local Variables: |
| 102 | * eval: (c-set-style "gnu") |
| 103 | * End: |
| 104 | */ |