diff options
Diffstat (limited to 'drivers/hv/hv.c')
| -rw-r--r-- | drivers/hv/hv.c | 156 |
1 files changed, 4 insertions, 152 deletions
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index a1ea482183e8..6188fb7dda42 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | #include <linux/version.h> | 16 | #include <linux/version.h> |
| 17 | #include <linux/random.h> | 17 | #include <linux/random.h> |
| 18 | #include <linux/clockchips.h> | 18 | #include <linux/clockchips.h> |
| 19 | #include <clocksource/hyperv_timer.h> | ||
| 19 | #include <asm/mshyperv.h> | 20 | #include <asm/mshyperv.h> |
| 20 | #include "hyperv_vmbus.h" | 21 | #include "hyperv_vmbus.h" |
| 21 | 22 | ||
| @@ -23,21 +24,6 @@ | |||
| 23 | struct hv_context hv_context; | 24 | struct hv_context hv_context; |
| 24 | 25 | ||
| 25 | /* | 26 | /* |
| 26 | * If false, we're using the old mechanism for stimer0 interrupts | ||
| 27 | * where it sends a VMbus message when it expires. The old | ||
| 28 | * mechanism is used when running on older versions of Hyper-V | ||
| 29 | * that don't support Direct Mode. While Hyper-V provides | ||
| 30 | * four stimer's per CPU, Linux uses only stimer0. | ||
| 31 | */ | ||
| 32 | static bool direct_mode_enabled; | ||
| 33 | static int stimer0_irq; | ||
| 34 | static int stimer0_vector; | ||
| 35 | |||
| 36 | #define HV_TIMER_FREQUENCY (10 * 1000 * 1000) /* 100ns period */ | ||
| 37 | #define HV_MAX_MAX_DELTA_TICKS 0xffffffff | ||
| 38 | #define HV_MIN_DELTA_TICKS 1 | ||
| 39 | |||
| 40 | /* | ||
| 41 | * hv_init - Main initialization routine. | 27 | * hv_init - Main initialization routine. |
| 42 | * | 28 | * |
| 43 | * This routine must be called before any other routines in here are called | 29 | * This routine must be called before any other routines in here are called |
| @@ -47,9 +33,6 @@ int hv_init(void) | |||
| 47 | hv_context.cpu_context = alloc_percpu(struct hv_per_cpu_context); | 33 | hv_context.cpu_context = alloc_percpu(struct hv_per_cpu_context); |
| 48 | if (!hv_context.cpu_context) | 34 | if (!hv_context.cpu_context) |
| 49 | return -ENOMEM; | 35 | return -ENOMEM; |
| 50 | |||
| 51 | direct_mode_enabled = ms_hyperv.misc_features & | ||
| 52 | HV_STIMER_DIRECT_MODE_AVAILABLE; | ||
| 53 | return 0; | 36 | return 0; |
| 54 | } | 37 | } |
| 55 | 38 | ||
| @@ -88,89 +71,6 @@ int hv_post_message(union hv_connection_id connection_id, | |||
| 88 | return status & 0xFFFF; | 71 | return status & 0xFFFF; |
| 89 | } | 72 | } |
| 90 | 73 | ||
| 91 | /* | ||
| 92 | * ISR for when stimer0 is operating in Direct Mode. Direct Mode | ||
| 93 | * does not use VMbus or any VMbus messages, so process here and not | ||
| 94 | * in the VMbus driver code. | ||
| 95 | */ | ||
| 96 | |||
| 97 | static void hv_stimer0_isr(void) | ||
| 98 | { | ||
| 99 | struct hv_per_cpu_context *hv_cpu; | ||
| 100 | |||
| 101 | hv_cpu = this_cpu_ptr(hv_context.cpu_context); | ||
| 102 | hv_cpu->clk_evt->event_handler(hv_cpu->clk_evt); | ||
| 103 | add_interrupt_randomness(stimer0_vector, 0); | ||
| 104 | } | ||
| 105 | |||
| 106 | static int hv_ce_set_next_event(unsigned long delta, | ||
| 107 | struct clock_event_device *evt) | ||
| 108 | { | ||
| 109 | u64 current_tick; | ||
| 110 | |||
| 111 | WARN_ON(!clockevent_state_oneshot(evt)); | ||
| 112 | |||
| 113 | current_tick = hyperv_cs->read(NULL); | ||
| 114 | current_tick += delta; | ||
| 115 | hv_init_timer(0, current_tick); | ||
| 116 | return 0; | ||
| 117 | } | ||
| 118 | |||
| 119 | static int hv_ce_shutdown(struct clock_event_device *evt) | ||
| 120 | { | ||
| 121 | hv_init_timer(0, 0); | ||
| 122 | hv_init_timer_config(0, 0); | ||
| 123 | if (direct_mode_enabled) | ||
| 124 | hv_disable_stimer0_percpu_irq(stimer0_irq); | ||
| 125 | |||
| 126 | return 0; | ||
| 127 | } | ||
| 128 | |||
| 129 | static int hv_ce_set_oneshot(struct clock_event_device *evt) | ||
| 130 | { | ||
| 131 | union hv_stimer_config timer_cfg; | ||
| 132 | |||
| 133 | timer_cfg.as_uint64 = 0; | ||
| 134 | timer_cfg.enable = 1; | ||
| 135 | timer_cfg.auto_enable = 1; | ||
| 136 | if (direct_mode_enabled) { | ||
| 137 | /* | ||
| 138 | * When it expires, the timer will directly interrupt | ||
| 139 | * on the specified hardware vector/IRQ. | ||
| 140 | */ | ||
| 141 | timer_cfg.direct_mode = 1; | ||
| 142 | timer_cfg.apic_vector = stimer0_vector; | ||
| 143 | hv_enable_stimer0_percpu_irq(stimer0_irq); | ||
| 144 | } else { | ||
| 145 | /* | ||
| 146 | * When it expires, the timer will generate a VMbus message, | ||
| 147 | * to be handled by the normal VMbus interrupt handler. | ||
| 148 | */ | ||
| 149 | timer_cfg.direct_mode = 0; | ||
| 150 | timer_cfg.sintx = VMBUS_MESSAGE_SINT; | ||
| 151 | } | ||
| 152 | hv_init_timer_config(0, timer_cfg.as_uint64); | ||
| 153 | return 0; | ||
| 154 | } | ||
| 155 | |||
| 156 | static void hv_init_clockevent_device(struct clock_event_device *dev, int cpu) | ||
| 157 | { | ||
| 158 | dev->name = "Hyper-V clockevent"; | ||
| 159 | dev->features = CLOCK_EVT_FEAT_ONESHOT; | ||
| 160 | dev->cpumask = cpumask_of(cpu); | ||
| 161 | dev->rating = 1000; | ||
| 162 | /* | ||
| 163 | * Avoid settint dev->owner = THIS_MODULE deliberately as doing so will | ||
| 164 | * result in clockevents_config_and_register() taking additional | ||
| 165 | * references to the hv_vmbus module making it impossible to unload. | ||
| 166 | */ | ||
| 167 | |||
| 168 | dev->set_state_shutdown = hv_ce_shutdown; | ||
| 169 | dev->set_state_oneshot = hv_ce_set_oneshot; | ||
| 170 | dev->set_next_event = hv_ce_set_next_event; | ||
| 171 | } | ||
| 172 | |||
| 173 | |||
| 174 | int hv_synic_alloc(void) | 74 | int hv_synic_alloc(void) |
| 175 | { | 75 | { |
| 176 | int cpu; | 76 | int cpu; |
| @@ -199,14 +99,6 @@ int hv_synic_alloc(void) | |||
| 199 | tasklet_init(&hv_cpu->msg_dpc, | 99 | tasklet_init(&hv_cpu->msg_dpc, |
| 200 | vmbus_on_msg_dpc, (unsigned long) hv_cpu); | 100 | vmbus_on_msg_dpc, (unsigned long) hv_cpu); |
| 201 | 101 | ||
| 202 | hv_cpu->clk_evt = kzalloc(sizeof(struct clock_event_device), | ||
| 203 | GFP_KERNEL); | ||
| 204 | if (hv_cpu->clk_evt == NULL) { | ||
| 205 | pr_err("Unable to allocate clock event device\n"); | ||
| 206 | goto err; | ||
| 207 | } | ||
| 208 | hv_init_clockevent_device(hv_cpu->clk_evt, cpu); | ||
| 209 | |||
| 210 | hv_cpu->synic_message_page = | 102 | hv_cpu->synic_message_page = |
| 211 | (void *)get_zeroed_page(GFP_ATOMIC); | 103 | (void *)get_zeroed_page(GFP_ATOMIC); |
| 212 | if (hv_cpu->synic_message_page == NULL) { | 104 | if (hv_cpu->synic_message_page == NULL) { |
| @@ -229,11 +121,6 @@ int hv_synic_alloc(void) | |||
| 229 | INIT_LIST_HEAD(&hv_cpu->chan_list); | 121 | INIT_LIST_HEAD(&hv_cpu->chan_list); |
| 230 | } | 122 | } |
| 231 | 123 | ||
| 232 | if (direct_mode_enabled && | ||
| 233 | hv_setup_stimer0_irq(&stimer0_irq, &stimer0_vector, | ||
| 234 | hv_stimer0_isr)) | ||
| 235 | goto err; | ||
| 236 | |||
| 237 | return 0; | 124 | return 0; |
| 238 | err: | 125 | err: |
| 239 | /* | 126 | /* |
| @@ -252,7 +139,6 @@ void hv_synic_free(void) | |||
| 252 | struct hv_per_cpu_context *hv_cpu | 139 | struct hv_per_cpu_context *hv_cpu |
| 253 | = per_cpu_ptr(hv_context.cpu_context, cpu); | 140 | = per_cpu_ptr(hv_context.cpu_context, cpu); |
| 254 | 141 | ||
| 255 | kfree(hv_cpu->clk_evt); | ||
| 256 | free_page((unsigned long)hv_cpu->synic_event_page); | 142 | free_page((unsigned long)hv_cpu->synic_event_page); |
| 257 | free_page((unsigned long)hv_cpu->synic_message_page); | 143 | free_page((unsigned long)hv_cpu->synic_message_page); |
| 258 | free_page((unsigned long)hv_cpu->post_msg_page); | 144 | free_page((unsigned long)hv_cpu->post_msg_page); |
| @@ -311,36 +197,9 @@ int hv_synic_init(unsigned int cpu) | |||
| 311 | 197 | ||
| 312 | hv_set_synic_state(sctrl.as_uint64); | 198 | hv_set_synic_state(sctrl.as_uint64); |
| 313 | 199 | ||
| 314 | /* | 200 | hv_stimer_init(cpu); |
| 315 | * Register the per-cpu clockevent source. | ||
| 316 | */ | ||
| 317 | if (ms_hyperv.features & HV_MSR_SYNTIMER_AVAILABLE) | ||
| 318 | clockevents_config_and_register(hv_cpu->clk_evt, | ||
| 319 | HV_TIMER_FREQUENCY, | ||
| 320 | HV_MIN_DELTA_TICKS, | ||
| 321 | HV_MAX_MAX_DELTA_TICKS); | ||
| 322 | return 0; | ||
| 323 | } | ||
| 324 | |||
| 325 | /* | ||
| 326 | * hv_synic_clockevents_cleanup - Cleanup clockevent devices | ||
| 327 | */ | ||
| 328 | void hv_synic_clockevents_cleanup(void) | ||
| 329 | { | ||
| 330 | int cpu; | ||
| 331 | 201 | ||
| 332 | if (!(ms_hyperv.features & HV_MSR_SYNTIMER_AVAILABLE)) | 202 | return 0; |
| 333 | return; | ||
| 334 | |||
| 335 | if (direct_mode_enabled) | ||
| 336 | hv_remove_stimer0_irq(stimer0_irq); | ||
| 337 | |||
| 338 | for_each_present_cpu(cpu) { | ||
| 339 | struct hv_per_cpu_context *hv_cpu | ||
| 340 | = per_cpu_ptr(hv_context.cpu_context, cpu); | ||
| 341 | |||
| 342 | clockevents_unbind_device(hv_cpu->clk_evt, cpu); | ||
| 343 | } | ||
| 344 | } | 203 | } |
| 345 | 204 | ||
| 346 | /* | 205 | /* |
| @@ -388,14 +247,7 @@ int hv_synic_cleanup(unsigned int cpu) | |||
| 388 | if (channel_found && vmbus_connection.conn_state == CONNECTED) | 247 | if (channel_found && vmbus_connection.conn_state == CONNECTED) |
| 389 | return -EBUSY; | 248 | return -EBUSY; |
| 390 | 249 | ||
| 391 | /* Turn off clockevent device */ | 250 | hv_stimer_cleanup(cpu); |
| 392 | if (ms_hyperv.features & HV_MSR_SYNTIMER_AVAILABLE) { | ||
| 393 | struct hv_per_cpu_context *hv_cpu | ||
| 394 | = this_cpu_ptr(hv_context.cpu_context); | ||
| 395 | |||
| 396 | clockevents_unbind_device(hv_cpu->clk_evt, cpu); | ||
| 397 | hv_ce_shutdown(hv_cpu->clk_evt); | ||
| 398 | } | ||
| 399 | 251 | ||
| 400 | hv_get_synint_state(VMBUS_MESSAGE_SINT, shared_sint.as_uint64); | 252 | hv_get_synint_state(VMBUS_MESSAGE_SINT, shared_sint.as_uint64); |
| 401 | 253 | ||
