| [75] | 1 | /* |
|---|
| [138] | 2 | * soclib_xcu.c - x86 XCU driver API implementation. |
|---|
| [75] | 3 | * |
|---|
| [138] | 4 | * Copyright (c) 2017 Maxime Villard |
|---|
| [75] | 5 | * |
|---|
| 6 | * This file is part of ALMOS-MKH. |
|---|
| 7 | * |
|---|
| [138] | 8 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
|---|
| [75] | 9 | * under the terms of the GNU General Public License as published by |
|---|
| 10 | * the Free Software Foundation; version 2.0 of the License. |
|---|
| 11 | * |
|---|
| [138] | 12 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
|---|
| [75] | 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 15 | * General Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License |
|---|
| [138] | 18 | * along with ALMOS-MKH.; if not, write to the Free Software Foundation, |
|---|
| [75] | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | #include <soclib_xcu.h> |
|---|
| 23 | #include <hal_types.h> |
|---|
| 24 | #include <core.h> |
|---|
| 25 | #include <chdev.h> |
|---|
| 26 | |
|---|
| [135] | 27 | #include <hal_apic.h> |
|---|
| [138] | 28 | #include <hal_segmentation.h> |
|---|
| [129] | 29 | #include <hal_internal.h> |
|---|
| 30 | |
|---|
| [135] | 31 | extern size_t ioapic_pins; |
|---|
| 32 | |
|---|
| [137] | 33 | /* |
|---|
| 34 | * These indexes are used to translate a type::idx to a pin on the IOAPIC. |
|---|
| 35 | */ |
|---|
| 36 | uint32_t hwi_baseidx __in_kdata = 0; |
|---|
| 37 | uint32_t wti_baseidx __in_kdata = 0; |
|---|
| 38 | uint32_t pti_baseidx __in_kdata = 0; |
|---|
| 39 | |
|---|
| [138] | 40 | static uint32_t get_pin(uint32_t idx, uint32_t type) |
|---|
| 41 | { |
|---|
| 42 | switch (type) { |
|---|
| 43 | case HWI_TYPE: |
|---|
| 44 | return hwi_baseidx + idx; |
|---|
| 45 | case WTI_TYPE: |
|---|
| 46 | return wti_baseidx + idx; |
|---|
| 47 | case PTI_TYPE: |
|---|
| 48 | return pti_baseidx + idx; |
|---|
| 49 | default: |
|---|
| 50 | x86_panic("get_pin: wrong type"); |
|---|
| 51 | return 0; |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| [135] | 55 | void soclib_xcu_init(chdev_t *icu, lid_t lid) |
|---|
| [75] | 56 | { |
|---|
| [135] | 57 | size_t i; |
|---|
| 58 | |
|---|
| 59 | /* disable all IRQs */ |
|---|
| 60 | for (i = 0; i < ioapic_pins; i++) { |
|---|
| [137] | 61 | hal_ioapic_disable_entry(i); |
|---|
| [135] | 62 | } |
|---|
| 63 | |
|---|
| [129] | 64 | x86_panic((char *)__func__); |
|---|
| [75] | 65 | } |
|---|
| 66 | |
|---|
| [137] | 67 | void soclib_xcu_enable_irq(chdev_t *icu, uint32_t idx, uint32_t type, |
|---|
| 68 | lid_t lid) |
|---|
| [75] | 69 | { |
|---|
| [138] | 70 | uint8_t dest = (uint8_t)lid; /* XXX */ |
|---|
| [137] | 71 | uint32_t pin; |
|---|
| [138] | 72 | uint8_t vec; |
|---|
| [137] | 73 | |
|---|
| [138] | 74 | pin = get_pin(idx, type); |
|---|
| 75 | |
|---|
| [137] | 76 | switch (type) { |
|---|
| 77 | case HWI_TYPE: |
|---|
| [138] | 78 | vec = VECTOR_APIC_XCU_HWI; |
|---|
| [139] | 79 | break; |
|---|
| [137] | 80 | case WTI_TYPE: |
|---|
| [138] | 81 | vec = VECTOR_APIC_XCU_WTI; |
|---|
| [139] | 82 | break; |
|---|
| [137] | 83 | case PTI_TYPE: |
|---|
| [138] | 84 | vec = VECTOR_APIC_XCU_PTI; |
|---|
| [139] | 85 | break; |
|---|
| [137] | 86 | default: |
|---|
| 87 | x86_panic("enabling wrong irq"); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| [138] | 90 | hal_ioapic_set_entry(pin, vec, dest); |
|---|
| 91 | |
|---|
| [129] | 92 | x86_panic((char *)__func__); |
|---|
| [75] | 93 | } |
|---|
| 94 | |
|---|
| [137] | 95 | void soclib_xcu_disable_irq(chdev_t *icu, uint32_t idx, uint32_t type, |
|---|
| 96 | lid_t lid) |
|---|
| [75] | 97 | { |
|---|
| [138] | 98 | uint32_t pin = get_pin(idx, type); |
|---|
| 99 | |
|---|
| 100 | hal_ioapic_disable_entry(pin); |
|---|
| 101 | |
|---|
| [129] | 102 | x86_panic((char *)__func__); |
|---|
| [75] | 103 | } |
|---|
| 104 | |
|---|
| [138] | 105 | void soclib_xcu_get_masks(chdev_t *icu, lid_t lid, uint32_t *hwi_mask, |
|---|
| 106 | uint32_t *wti_mask, uint32_t *pti_mask) |
|---|
| [75] | 107 | { |
|---|
| [129] | 108 | x86_panic((char *)__func__); |
|---|
| [75] | 109 | } |
|---|
| 110 | |
|---|
| 111 | void soclib_xcu_set_period( chdev_t * icu, |
|---|
| 112 | uint32_t index, |
|---|
| 113 | uint32_t period ) |
|---|
| 114 | { |
|---|
| [129] | 115 | x86_panic((char *)__func__); |
|---|
| [75] | 116 | } |
|---|
| 117 | |
|---|
| 118 | uint32_t soclib_xcu_ack_timer( chdev_t * icu, |
|---|
| 119 | uint32_t index ) |
|---|
| 120 | { |
|---|
| [129] | 121 | x86_panic((char *)__func__); |
|---|
| [81] | 122 | return 0; |
|---|
| [75] | 123 | } |
|---|
| 124 | |
|---|
| [137] | 125 | void soclib_xcu_get_status(chdev_t *icu, lid_t lid, uint32_t *hwi_status, |
|---|
| 126 | uint32_t *wti_status, uint32_t *pti_status) |
|---|
| [75] | 127 | { |
|---|
| [137] | 128 | if (lid != 0) { |
|---|
| 129 | x86_panic("xcu_get_status should have lid==0"); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| [129] | 132 | x86_panic((char *)__func__); |
|---|
| [75] | 133 | } |
|---|
| 134 | |
|---|
| 135 | void soclib_xcu_send_ipi( xptr_t icu_xp, |
|---|
| 136 | lid_t lid ) |
|---|
| 137 | { |
|---|
| [129] | 138 | x86_panic((char *)__func__); |
|---|
| [75] | 139 | } |
|---|
| 140 | |
|---|
| 141 | uint32_t * soclib_xcu_wti_ptr( chdev_t * icu, |
|---|
| 142 | uint32_t index ) |
|---|
| 143 | { |
|---|
| [129] | 144 | x86_panic((char *)__func__); |
|---|
| [81] | 145 | return NULL; |
|---|
| [75] | 146 | } |
|---|