blob: c9f0078c5e4ce7ee38bd5ad08948138828b15f10 [file] [log] [blame]
Damjan Marion7f75e802023-11-03 21:57:42 +00001/* SPDX-License-Identifier: Apache-2.0
2 * Copyright (c) 2023 Cisco Systems, Inc.
Damjan Marion94100532020-11-06 23:25:57 +01003 */
4
5#include <vppinfra/clib.h>
Damjan Marion94100532020-11-06 23:25:57 +01006#include <vppinfra/interrupt.h>
Damjan Marion94100532020-11-06 23:25:57 +01007
8__clib_export void
Damjan Marion7f75e802023-11-03 21:57:42 +00009clib_interrupt_init (void **data, u32 n_int)
Damjan Marion94100532020-11-06 23:25:57 +010010{
11 clib_interrupt_header_t *h;
Damjan Marion7f75e802023-11-03 21:57:42 +000012 const u32 bits_in_cl = 8 << CLIB_LOG2_CACHE_LINE_BYTES;
13 u32 sz = sizeof (clib_interrupt_header_t);
14 u32 n_cl = round_pow2 (n_int, bits_in_cl) / bits_in_cl;
Damjan Marion94100532020-11-06 23:25:57 +010015
Damjan Marion7f75e802023-11-03 21:57:42 +000016 sz += 2 * n_cl * CLIB_CACHE_LINE_BYTES;
Damjan Marion94100532020-11-06 23:25:57 +010017 h = data[0] = clib_mem_alloc_aligned (sz, CLIB_CACHE_LINE_BYTES);
18 clib_memset (data[0], 0, sz);
19 h->n_int = n_int;
Damjan Marion7f75e802023-11-03 21:57:42 +000020 h->uwords_allocated = n_cl * bits_in_cl / uword_bits;
21 h->uwords_used = round_pow2 (n_int, uword_bits) / uword_bits;
22 h->local = (uword *) (h + 1);
23 h->remote = h->local + h->uwords_allocated;
Damjan Marion94100532020-11-06 23:25:57 +010024}
25
26__clib_export void
Damjan Marion7f75e802023-11-03 21:57:42 +000027clib_interrupt_resize (void **data, u32 n_int)
Damjan Marion94100532020-11-06 23:25:57 +010028{
29 clib_interrupt_header_t *h = data[0];
Damjan Marion7f75e802023-11-03 21:57:42 +000030 u32 new_n_uwords, i;
Damjan Marion94100532020-11-06 23:25:57 +010031
32 if (data[0] == 0)
33 {
34 clib_interrupt_init (data, n_int);
35 return;
36 }
37
Damjan Marion7f75e802023-11-03 21:57:42 +000038 if (n_int == h->n_int)
39 return;
40
41 new_n_uwords = round_pow2 (n_int, uword_bits) / uword_bits;
42
43 if (new_n_uwords > h->uwords_allocated)
Damjan Marion94100532020-11-06 23:25:57 +010044 {
Damjan Marion7f75e802023-11-03 21:57:42 +000045 clib_interrupt_header_t *nh;
46 clib_interrupt_init ((void **) &nh, n_int);
47 for (int i = 0; i < h->uwords_used; i++)
48 nh->local[i] = h->local[i] | h->remote[i];
49 clib_mem_free (data[0]);
50 data[0] = nh;
51 return;
Damjan Marion94100532020-11-06 23:25:57 +010052 }
Damjan Marion94100532020-11-06 23:25:57 +010053
Damjan Marion94100532020-11-06 23:25:57 +010054 h->n_int = n_int;
Damjan Marion7f75e802023-11-03 21:57:42 +000055 h->uwords_used = new_n_uwords;
56
57 for (i = 0; i < new_n_uwords; i++)
58 h->local[i] |= h->remote[i];
59
60 for (i = 0; i < h->uwords_allocated; i++)
61 h->remote[i] = 0;
62
63 for (i = new_n_uwords; i < h->uwords_allocated; i++)
64 h->local[i] = 0;
65
66 n_int &= pow2_mask (log2_uword_bits);
67
68 if (n_int)
69 h->local[n_int >> log2_uword_bits] &= pow2_mask (n_int);
Damjan Marion94100532020-11-06 23:25:57 +010070}
71