[258] | 1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : icu_driver.c |
---|
| 3 | // Date : 23/05/2013 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 7 | // The icu_driver.c and icu_driver.h files are part ot the GIET-VM nano-kernel. |
---|
| 8 | // This driver supports the SoCLib vci_icu component, That is a vectorised |
---|
| 9 | // interrupt controler. |
---|
| 10 | // |
---|
| 11 | // It can exist several interrupt controller unit in the architecture |
---|
| 12 | // (one per cluster), and each one can contain several channels. |
---|
| 13 | // The number of ICU channels is equal to NB_PROCS_MAX, because there is |
---|
| 14 | // one private ICU channel per processor in a cluster. |
---|
| 15 | //////////////////////////////////////////////////////////////////////////////// |
---|
| 16 | // The virtual base address of the segment associated to the component is: |
---|
| 17 | // |
---|
[263] | 18 | // seg_icu_base + cluster_xy * vseg_cluster_increment |
---|
[258] | 19 | // |
---|
| 20 | // The seg_icu_base and vseg_cluster_increment values must be defined |
---|
| 21 | // in giet_vsegs.ld file. |
---|
| 22 | //////////////////////////////////////////////////////////////////////////////// |
---|
| 23 | |
---|
| 24 | #include <giet_config.h> |
---|
| 25 | #include <icu_driver.h> |
---|
[263] | 26 | #include <tty_driver.h> |
---|
[258] | 27 | #include <utils.h> |
---|
| 28 | |
---|
[263] | 29 | #if !defined(X_SIZE) |
---|
| 30 | # error: You must define X_SIZE in the hard_config.h file |
---|
[258] | 31 | #endif |
---|
| 32 | |
---|
[263] | 33 | #if !defined(Y_SIZE) |
---|
| 34 | # error: You must define X_SIZE in the hard_config.h file |
---|
[258] | 35 | #endif |
---|
| 36 | |
---|
[263] | 37 | #if !defined(X_WIDTH) |
---|
| 38 | # error: You must define X_WIDTH in the hard_config.h file |
---|
| 39 | #endif |
---|
| 40 | |
---|
| 41 | #if !defined(Y_WIDTH) |
---|
| 42 | # error: You must define X_WIDTH in the hard_config.h file |
---|
| 43 | #endif |
---|
| 44 | |
---|
[258] | 45 | #if !defined(NB_PROCS_MAX) |
---|
| 46 | # error: You must define NB_PROCS_MAX in the hard_config.h file |
---|
| 47 | #endif |
---|
| 48 | |
---|
| 49 | #if !defined( USE_XICU ) |
---|
| 50 | # error: You must define USE_XICU in the hard_config.h file |
---|
| 51 | #endif |
---|
| 52 | |
---|
| 53 | //////////////////////////////////////////////////////////////////////////////// |
---|
| 54 | // _icu_set_mask() |
---|
| 55 | // This function set the mask register for the ICU channel identified |
---|
| 56 | // by the cluster index and the processor index. |
---|
| 57 | // All '1' bits are set / all '0' bits are not modified. |
---|
| 58 | // Returns 0 if success, > 0 if error. |
---|
| 59 | //////////////////////////////////////////////////////////////////////////////// |
---|
[263] | 60 | unsigned int _icu_set_mask( unsigned int cluster_xy, |
---|
[258] | 61 | unsigned int proc_id, |
---|
| 62 | unsigned int value ) |
---|
| 63 | { |
---|
| 64 | // parameters checking |
---|
[263] | 65 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 66 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
| 67 | if (x >= X_SIZE) return 1; |
---|
| 68 | if (y >= Y_SIZE) return 1; |
---|
| 69 | if (proc_id >= NB_PROCS_MAX) return 1; |
---|
[258] | 70 | |
---|
| 71 | #if USE_XICU |
---|
[263] | 72 | _puts("[GIET ERROR] _icu_set_mask() should not be used if USE_XICU is set\n"); |
---|
[258] | 73 | return 1; |
---|
| 74 | #else |
---|
| 75 | unsigned int * icu_address = (unsigned int *) ((unsigned int)&seg_icu_base + |
---|
[263] | 76 | (cluster_xy * (unsigned int)&vseg_cluster_increment)); |
---|
[258] | 77 | icu_address[proc_id * ICU_SPAN + ICU_MASK_SET] = value; |
---|
| 78 | return 0; |
---|
| 79 | #endif |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | //////////////////////////////////////////////////////////////////////////////// |
---|
| 83 | // _icu_get_index() |
---|
| 84 | // This function returns the index of the highest priority (smaller index) IRQ. |
---|
| 85 | // The ICU channel is identified by the cluster index and the processor index. |
---|
| 86 | // Returns 0 if success, > 0 if error. |
---|
| 87 | //////////////////////////////////////////////////////////////////////////////// |
---|
[263] | 88 | unsigned int _icu_get_index( unsigned int cluster_xy, |
---|
[258] | 89 | unsigned int proc_id, |
---|
| 90 | unsigned int * buffer) |
---|
| 91 | { |
---|
| 92 | // parameters checking |
---|
[263] | 93 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 94 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
| 95 | if (x >= X_SIZE) return 1; |
---|
| 96 | if (y >= Y_SIZE) return 1; |
---|
| 97 | if (proc_id >= NB_PROCS_MAX) return 1; |
---|
[258] | 98 | |
---|
| 99 | #if USE_XICU |
---|
[263] | 100 | _puts("[GIET ERROR] _icu_get_index() should not be used if USE_XICU is set\n"); |
---|
[258] | 101 | return 1; |
---|
| 102 | #else |
---|
| 103 | unsigned int* icu_address = (unsigned int *) ((unsigned int)&seg_icu_base + |
---|
[263] | 104 | (cluster_xy * (unsigned int)&vseg_cluster_increment)); |
---|
[258] | 105 | *buffer = icu_address[proc_id * ICU_SPAN + ICU_IT_VECTOR]; |
---|
| 106 | return 0; |
---|
| 107 | #endif |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | // Local Variables: |
---|
| 112 | // tab-width: 4 |
---|
| 113 | // c-basic-offset: 4 |
---|
| 114 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 115 | // indent-tabs-mode: nil |
---|
| 116 | // End: |
---|
| 117 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 118 | |
---|