diff options
Diffstat (limited to 'arch/x86/kernel')
39 files changed, 413 insertions, 10857 deletions
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 7338ef2218bc..97ebf82e0b7f 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile | |||
| @@ -117,7 +117,7 @@ obj-$(CONFIG_OF) += devicetree.o | |||
| 117 | ifeq ($(CONFIG_X86_64),y) | 117 | ifeq ($(CONFIG_X86_64),y) |
| 118 | obj-$(CONFIG_AUDIT) += audit_64.o | 118 | obj-$(CONFIG_AUDIT) += audit_64.o |
| 119 | 119 | ||
| 120 | obj-$(CONFIG_GART_IOMMU) += pci-gart_64.o aperture_64.o | 120 | obj-$(CONFIG_GART_IOMMU) += amd_gart_64.o aperture_64.o |
| 121 | obj-$(CONFIG_CALGARY_IOMMU) += pci-calgary_64.o tce_64.o | 121 | obj-$(CONFIG_CALGARY_IOMMU) += pci-calgary_64.o tce_64.o |
| 122 | obj-$(CONFIG_AMD_IOMMU) += amd_iommu_init.o amd_iommu.o | 122 | obj-$(CONFIG_AMD_IOMMU) += amd_iommu_init.o amd_iommu.o |
| 123 | 123 | ||
diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c index ff93bc1b09c3..18a857ba7a25 100644 --- a/arch/x86/kernel/acpi/sleep.c +++ b/arch/x86/kernel/acpi/sleep.c | |||
| @@ -112,11 +112,6 @@ static int __init acpi_sleep_setup(char *str) | |||
| 112 | #ifdef CONFIG_HIBERNATION | 112 | #ifdef CONFIG_HIBERNATION |
| 113 | if (strncmp(str, "s4_nohwsig", 10) == 0) | 113 | if (strncmp(str, "s4_nohwsig", 10) == 0) |
| 114 | acpi_no_s4_hw_signature(); | 114 | acpi_no_s4_hw_signature(); |
| 115 | if (strncmp(str, "s4_nonvs", 8) == 0) { | ||
| 116 | pr_warning("ACPI: acpi_sleep=s4_nonvs is deprecated, " | ||
| 117 | "please use acpi_sleep=nonvs instead"); | ||
| 118 | acpi_nvs_nosave(); | ||
| 119 | } | ||
| 120 | #endif | 115 | #endif |
| 121 | if (strncmp(str, "nonvs", 5) == 0) | 116 | if (strncmp(str, "nonvs", 5) == 0) |
| 122 | acpi_nvs_nosave(); | 117 | acpi_nvs_nosave(); |
diff --git a/arch/x86/kernel/pci-gart_64.c b/arch/x86/kernel/amd_gart_64.c index b117efd24f71..b117efd24f71 100644 --- a/arch/x86/kernel/pci-gart_64.c +++ b/arch/x86/kernel/amd_gart_64.c | |||
diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c index 57ca77787220..873e7e1ead7b 100644 --- a/arch/x86/kernel/amd_iommu.c +++ b/arch/x86/kernel/amd_iommu.c | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | */ | 18 | */ |
| 19 | 19 | ||
| 20 | #include <linux/pci.h> | 20 | #include <linux/pci.h> |
| 21 | #include <linux/pci-ats.h> | ||
| 21 | #include <linux/bitmap.h> | 22 | #include <linux/bitmap.h> |
| 22 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
| 23 | #include <linux/debugfs.h> | 24 | #include <linux/debugfs.h> |
| @@ -25,6 +26,7 @@ | |||
| 25 | #include <linux/dma-mapping.h> | 26 | #include <linux/dma-mapping.h> |
| 26 | #include <linux/iommu-helper.h> | 27 | #include <linux/iommu-helper.h> |
| 27 | #include <linux/iommu.h> | 28 | #include <linux/iommu.h> |
| 29 | #include <linux/delay.h> | ||
| 28 | #include <asm/proto.h> | 30 | #include <asm/proto.h> |
| 29 | #include <asm/iommu.h> | 31 | #include <asm/iommu.h> |
| 30 | #include <asm/gart.h> | 32 | #include <asm/gart.h> |
| @@ -34,7 +36,7 @@ | |||
| 34 | 36 | ||
| 35 | #define CMD_SET_TYPE(cmd, t) ((cmd)->data[1] |= ((t) << 28)) | 37 | #define CMD_SET_TYPE(cmd, t) ((cmd)->data[1] |= ((t) << 28)) |
| 36 | 38 | ||
| 37 | #define EXIT_LOOP_COUNT 10000000 | 39 | #define LOOP_TIMEOUT 100000 |
| 38 | 40 | ||
| 39 | static DEFINE_RWLOCK(amd_iommu_devtable_lock); | 41 | static DEFINE_RWLOCK(amd_iommu_devtable_lock); |
| 40 | 42 | ||
| @@ -57,7 +59,6 @@ struct iommu_cmd { | |||
| 57 | u32 data[4]; | 59 | u32 data[4]; |
| 58 | }; | 60 | }; |
| 59 | 61 | ||
| 60 | static void reset_iommu_command_buffer(struct amd_iommu *iommu); | ||
| 61 | static void update_domain(struct protection_domain *domain); | 62 | static void update_domain(struct protection_domain *domain); |
| 62 | 63 | ||
| 63 | /**************************************************************************** | 64 | /**************************************************************************** |
| @@ -322,8 +323,6 @@ static void iommu_print_event(struct amd_iommu *iommu, void *__evt) | |||
| 322 | break; | 323 | break; |
| 323 | case EVENT_TYPE_ILL_CMD: | 324 | case EVENT_TYPE_ILL_CMD: |
| 324 | printk("ILLEGAL_COMMAND_ERROR address=0x%016llx]\n", address); | 325 | printk("ILLEGAL_COMMAND_ERROR address=0x%016llx]\n", address); |
| 325 | iommu->reset_in_progress = true; | ||
| 326 | reset_iommu_command_buffer(iommu); | ||
| 327 | dump_command(address); | 326 | dump_command(address); |
| 328 | break; | 327 | break; |
| 329 | case EVENT_TYPE_CMD_HARD_ERR: | 328 | case EVENT_TYPE_CMD_HARD_ERR: |
| @@ -367,7 +366,7 @@ static void iommu_poll_events(struct amd_iommu *iommu) | |||
| 367 | spin_unlock_irqrestore(&iommu->lock, flags); | 366 | spin_unlock_irqrestore(&iommu->lock, flags); |
| 368 | } | 367 | } |
| 369 | 368 | ||
| 370 | irqreturn_t amd_iommu_int_handler(int irq, void *data) | 369 | irqreturn_t amd_iommu_int_thread(int irq, void *data) |
| 371 | { | 370 | { |
| 372 | struct amd_iommu *iommu; | 371 | struct amd_iommu *iommu; |
| 373 | 372 | ||
| @@ -377,192 +376,300 @@ irqreturn_t amd_iommu_int_handler(int irq, void *data) | |||
| 377 | return IRQ_HANDLED; | 376 | return IRQ_HANDLED; |
| 378 | } | 377 | } |
| 379 | 378 | ||
| 379 | irqreturn_t amd_iommu_int_handler(int irq, void *data) | ||
| 380 | { | ||
| 381 | return IRQ_WAKE_THREAD; | ||
| 382 | } | ||
| 383 | |||
| 380 | /**************************************************************************** | 384 | /**************************************************************************** |
| 381 | * | 385 | * |
| 382 | * IOMMU command queuing functions | 386 | * IOMMU command queuing functions |
| 383 | * | 387 | * |
| 384 | ****************************************************************************/ | 388 | ****************************************************************************/ |
| 385 | 389 | ||
| 386 | /* | 390 | static int wait_on_sem(volatile u64 *sem) |
| 387 | * Writes the command to the IOMMUs command buffer and informs the | 391 | { |
| 388 | * hardware about the new command. Must be called with iommu->lock held. | 392 | int i = 0; |
| 389 | */ | 393 | |
| 390 | static int __iommu_queue_command(struct amd_iommu *iommu, struct iommu_cmd *cmd) | 394 | while (*sem == 0 && i < LOOP_TIMEOUT) { |
| 395 | udelay(1); | ||
| 396 | i += 1; | ||
| 397 | } | ||
| 398 | |||
| 399 | if (i == LOOP_TIMEOUT) { | ||
| 400 | pr_alert("AMD-Vi: Completion-Wait loop timed out\n"); | ||
| 401 | return -EIO; | ||
| 402 | } | ||
| 403 | |||
| 404 | return 0; | ||
| 405 | } | ||
| 406 | |||
| 407 | static void copy_cmd_to_buffer(struct amd_iommu *iommu, | ||
| 408 | struct iommu_cmd *cmd, | ||
| 409 | u32 tail) | ||
| 391 | { | 410 | { |
| 392 | u32 tail, head; | ||
| 393 | u8 *target; | 411 | u8 *target; |
| 394 | 412 | ||
| 395 | WARN_ON(iommu->cmd_buf_size & CMD_BUFFER_UNINITIALIZED); | ||
| 396 | tail = readl(iommu->mmio_base + MMIO_CMD_TAIL_OFFSET); | ||
| 397 | target = iommu->cmd_buf + tail; | 413 | target = iommu->cmd_buf + tail; |
| 398 | memcpy_toio(target, cmd, sizeof(*cmd)); | 414 | tail = (tail + sizeof(*cmd)) % iommu->cmd_buf_size; |
| 399 | tail = (tail + sizeof(*cmd)) % iommu->cmd_buf_size; | 415 | |
| 400 | head = readl(iommu->mmio_base + MMIO_CMD_HEAD_OFFSET); | 416 | /* Copy command to buffer */ |
| 401 | if (tail == head) | 417 | memcpy(target, cmd, sizeof(*cmd)); |
| 402 | return -ENOMEM; | 418 | |
| 419 | /* Tell the IOMMU about it */ | ||
| 403 | writel(tail, iommu->mmio_base + MMIO_CMD_TAIL_OFFSET); | 420 | writel(tail, iommu->mmio_base + MMIO_CMD_TAIL_OFFSET); |
| 421 | } | ||
| 404 | 422 | ||
| 405 | return 0; | 423 | static void build_completion_wait(struct iommu_cmd *cmd, u64 address) |
| 424 | { | ||
| 425 | WARN_ON(address & 0x7ULL); | ||
| 426 | |||
| 427 | memset(cmd, 0, sizeof(*cmd)); | ||
| 428 | cmd->data[0] = lower_32_bits(__pa(address)) | CMD_COMPL_WAIT_STORE_MASK; | ||
| 429 | cmd->data[1] = upper_32_bits(__pa(address)); | ||
| 430 | cmd->data[2] = 1; | ||
| 431 | CMD_SET_TYPE(cmd, CMD_COMPL_WAIT); | ||
| 432 | } | ||
| 433 | |||
| 434 | static void build_inv_dte(struct iommu_cmd *cmd, u16 devid) | ||
| 435 | { | ||
| 436 | memset(cmd, 0, sizeof(*cmd)); | ||
| 437 | cmd->data[0] = devid; | ||
| 438 | CMD_SET_TYPE(cmd, CMD_INV_DEV_ENTRY); | ||
| 439 | } | ||
| 440 | |||
| 441 | static void build_inv_iommu_pages(struct iommu_cmd *cmd, u64 address, | ||
| 442 | size_t size, u16 domid, int pde) | ||
| 443 | { | ||
| 444 | u64 pages; | ||
| 445 | int s; | ||
| 446 | |||
| 447 | pages = iommu_num_pages(address, size, PAGE_SIZE); | ||
| 448 | s = 0; | ||
| 449 | |||
| 450 | if (pages > 1) { | ||
| 451 | /* | ||
| 452 | * If we have to flush more than one page, flush all | ||
| 453 | * TLB entries for this domain | ||
| 454 | */ | ||
| 455 | address = CMD_INV_IOMMU_ALL_PAGES_ADDRESS; | ||
| 456 | s = 1; | ||
| 457 | } | ||
| 458 | |||
| 459 | address &= PAGE_MASK; | ||
| 460 | |||
| 461 | memset(cmd, 0, sizeof(*cmd)); | ||
| 462 | cmd->data[1] |= domid; | ||
| 463 | cmd->data[2] = lower_32_bits(address); | ||
| 464 | cmd->data[3] = upper_32_bits(address); | ||
| 465 | CMD_SET_TYPE(cmd, CMD_INV_IOMMU_PAGES); | ||
| 466 | if (s) /* size bit - we flush more than one 4kb page */ | ||
| 467 | cmd->data[2] |= CMD_INV_IOMMU_PAGES_SIZE_MASK; | ||
| 468 | if (pde) /* PDE bit - we wan't flush everything not only the PTEs */ | ||
| 469 | cmd->data[2] |= CMD_INV_IOMMU_PAGES_PDE_MASK; | ||
| 470 | } | ||
| 471 | |||
| 472 | static void build_inv_iotlb_pages(struct iommu_cmd *cmd, u16 devid, int qdep, | ||
| 473 | u64 address, size_t size) | ||
| 474 | { | ||
| 475 | u64 pages; | ||
| 476 | int s; | ||
| 477 | |||
| 478 | pages = iommu_num_pages(address, size, PAGE_SIZE); | ||
| 479 | s = 0; | ||
| 480 | |||
| 481 | if (pages > 1) { | ||
| 482 | /* | ||
| 483 | * If we have to flush more than one page, flush all | ||
| 484 | * TLB entries for this domain | ||
| 485 | */ | ||
| 486 | address = CMD_INV_IOMMU_ALL_PAGES_ADDRESS; | ||
| 487 | s = 1; | ||
| 488 | } | ||
| 489 | |||
| 490 | address &= PAGE_MASK; | ||
| 491 | |||
| 492 | memset(cmd, 0, sizeof(*cmd)); | ||
| 493 | cmd->data[0] = devid; | ||
| 494 | cmd->data[0] |= (qdep & 0xff) << 24; | ||
| 495 | cmd->data[1] = devid; | ||
| 496 | cmd->data[2] = lower_32_bits(address); | ||
| 497 | cmd->data[3] = upper_32_bits(address); | ||
| 498 | CMD_SET_TYPE(cmd, CMD_INV_IOTLB_PAGES); | ||
| 499 | if (s) | ||
| 500 | cmd->data[2] |= CMD_INV_IOMMU_PAGES_SIZE_MASK; | ||
| 501 | } | ||
| 502 | |||
| 503 | static void build_inv_all(struct iommu_cmd *cmd) | ||
| 504 | { | ||
| 505 | memset(cmd, 0, sizeof(*cmd)); | ||
| 506 | CMD_SET_TYPE(cmd, CMD_INV_ALL); | ||
| 406 | } | 507 | } |
| 407 | 508 | ||
| 408 | /* | 509 | /* |
| 409 | * General queuing function for commands. Takes iommu->lock and calls | 510 | * Writes the command to the IOMMUs command buffer and informs the |
| 410 | * __iommu_queue_command(). | 511 | * hardware about the new command. |
| 411 | */ | 512 | */ |
| 412 | static int iommu_queue_command(struct amd_iommu *iommu, struct iommu_cmd *cmd) | 513 | static int iommu_queue_command(struct amd_iommu *iommu, struct iommu_cmd *cmd) |
| 413 | { | 514 | { |
| 515 | u32 left, tail, head, next_tail; | ||
| 414 | unsigned long flags; | 516 | unsigned long flags; |
| 415 | int ret; | ||
| 416 | 517 | ||
| 518 | WARN_ON(iommu->cmd_buf_size & CMD_BUFFER_UNINITIALIZED); | ||
| 519 | |||
| 520 | again: | ||
| 417 | spin_lock_irqsave(&iommu->lock, flags); | 521 | spin_lock_irqsave(&iommu->lock, flags); |
| 418 | ret = __iommu_queue_command(iommu, cmd); | ||
| 419 | if (!ret) | ||
| 420 | iommu->need_sync = true; | ||
| 421 | spin_unlock_irqrestore(&iommu->lock, flags); | ||
| 422 | 522 | ||
| 423 | return ret; | 523 | head = readl(iommu->mmio_base + MMIO_CMD_HEAD_OFFSET); |
| 424 | } | 524 | tail = readl(iommu->mmio_base + MMIO_CMD_TAIL_OFFSET); |
| 525 | next_tail = (tail + sizeof(*cmd)) % iommu->cmd_buf_size; | ||
| 526 | left = (head - next_tail) % iommu->cmd_buf_size; | ||
| 425 | 527 | ||
| 426 | /* | 528 | if (left <= 2) { |
| 427 | * This function waits until an IOMMU has completed a completion | 529 | struct iommu_cmd sync_cmd; |
| 428 | * wait command | 530 | volatile u64 sem = 0; |
| 429 | */ | 531 | int ret; |
| 430 | static void __iommu_wait_for_completion(struct amd_iommu *iommu) | ||
| 431 | { | ||
| 432 | int ready = 0; | ||
| 433 | unsigned status = 0; | ||
| 434 | unsigned long i = 0; | ||
| 435 | 532 | ||
| 436 | INC_STATS_COUNTER(compl_wait); | 533 | build_completion_wait(&sync_cmd, (u64)&sem); |
| 534 | copy_cmd_to_buffer(iommu, &sync_cmd, tail); | ||
| 437 | 535 | ||
| 438 | while (!ready && (i < EXIT_LOOP_COUNT)) { | 536 | spin_unlock_irqrestore(&iommu->lock, flags); |
| 439 | ++i; | 537 | |
| 440 | /* wait for the bit to become one */ | 538 | if ((ret = wait_on_sem(&sem)) != 0) |
| 441 | status = readl(iommu->mmio_base + MMIO_STATUS_OFFSET); | 539 | return ret; |
| 442 | ready = status & MMIO_STATUS_COM_WAIT_INT_MASK; | 540 | |
| 541 | goto again; | ||
| 443 | } | 542 | } |
| 444 | 543 | ||
| 445 | /* set bit back to zero */ | 544 | copy_cmd_to_buffer(iommu, cmd, tail); |
| 446 | status &= ~MMIO_STATUS_COM_WAIT_INT_MASK; | 545 | |
| 447 | writel(status, iommu->mmio_base + MMIO_STATUS_OFFSET); | 546 | /* We need to sync now to make sure all commands are processed */ |
| 547 | iommu->need_sync = true; | ||
| 548 | |||
| 549 | spin_unlock_irqrestore(&iommu->lock, flags); | ||
| 448 | 550 | ||
| 449 | if (unlikely(i == EXIT_LOOP_COUNT)) | 551 | return 0; |
| 450 | iommu->reset_in_progress = true; | ||
| 451 | } | 552 | } |
| 452 | 553 | ||
| 453 | /* | 554 | /* |
| 454 | * This function queues a completion wait command into the command | 555 | * This function queues a completion wait command into the command |
| 455 | * buffer of an IOMMU | 556 | * buffer of an IOMMU |
| 456 | */ | 557 | */ |
| 457 | static int __iommu_completion_wait(struct amd_iommu *iommu) | 558 | static int iommu_completion_wait(struct amd_iommu *iommu) |
| 458 | { | 559 | { |
| 459 | struct iommu_cmd cmd; | 560 | struct iommu_cmd cmd; |
| 561 | volatile u64 sem = 0; | ||
| 562 | int ret; | ||
| 460 | 563 | ||
| 461 | memset(&cmd, 0, sizeof(cmd)); | 564 | if (!iommu->need_sync) |
| 462 | cmd.data[0] = CMD_COMPL_WAIT_INT_MASK; | 565 | return 0; |
| 463 | CMD_SET_TYPE(&cmd, CMD_COMPL_WAIT); | ||
| 464 | 566 | ||
| 465 | return __iommu_queue_command(iommu, &cmd); | 567 | build_completion_wait(&cmd, (u64)&sem); |
| 568 | |||
| 569 | ret = iommu_queue_command(iommu, &cmd); | ||
| 570 | if (ret) | ||
| 571 | return ret; | ||
| 572 | |||
| 573 | return wait_on_sem(&sem); | ||
| 466 | } | 574 | } |
| 467 | 575 | ||
| 468 | /* | 576 | static int iommu_flush_dte(struct amd_iommu *iommu, u16 devid) |
| 469 | * This function is called whenever we need to ensure that the IOMMU has | ||
| 470 | * completed execution of all commands we sent. It sends a | ||
| 471 | * COMPLETION_WAIT command and waits for it to finish. The IOMMU informs | ||
| 472 | * us about that by writing a value to a physical address we pass with | ||
| 473 | * the command. | ||
| 474 | */ | ||
| 475 | static int iommu_completion_wait(struct amd_iommu *iommu) | ||
| 476 | { | 577 | { |
| 477 | int ret = 0; | 578 | struct iommu_cmd cmd; |
| 478 | unsigned long flags; | ||
| 479 | 579 | ||
| 480 | spin_lock_irqsave(&iommu->lock, flags); | 580 | build_inv_dte(&cmd, devid); |
| 481 | 581 | ||
| 482 | if (!iommu->need_sync) | 582 | return iommu_queue_command(iommu, &cmd); |
| 483 | goto out; | 583 | } |
| 484 | 584 | ||
| 485 | ret = __iommu_completion_wait(iommu); | 585 | static void iommu_flush_dte_all(struct amd_iommu *iommu) |
| 586 | { | ||
| 587 | u32 devid; | ||
| 486 | 588 | ||
| 487 | iommu->need_sync = false; | 589 | for (devid = 0; devid <= 0xffff; ++devid) |
| 590 | iommu_flush_dte(iommu, devid); | ||
| 488 | 591 | ||
| 489 | if (ret) | 592 | iommu_completion_wait(iommu); |
| 490 | goto out; | 593 | } |
| 491 | |||
| 492 | __iommu_wait_for_completion(iommu); | ||
| 493 | 594 | ||
| 494 | out: | 595 | /* |
| 495 | spin_unlock_irqrestore(&iommu->lock, flags); | 596 | * This function uses heavy locking and may disable irqs for some time. But |
| 597 | * this is no issue because it is only called during resume. | ||
| 598 | */ | ||
| 599 | static void iommu_flush_tlb_all(struct amd_iommu *iommu) | ||
| 600 | { | ||
| 601 | u32 dom_id; | ||
| 496 | 602 | ||
| 497 | if (iommu->reset_in_progress) | 603 | for (dom_id = 0; dom_id <= 0xffff; ++dom_id) { |
| 498 | reset_iommu_command_buffer(iommu); | 604 | struct iommu_cmd cmd; |
| 605 | build_inv_iommu_pages(&cmd, 0, CMD_INV_IOMMU_ALL_PAGES_ADDRESS, | ||
| 606 | dom_id, 1); | ||
| 607 | iommu_queue_command(iommu, &cmd); | ||
| 608 | } | ||
| 499 | 609 | ||
| 500 | return 0; | 610 | iommu_completion_wait(iommu); |
| 501 | } | 611 | } |
| 502 | 612 | ||
| 503 | static void iommu_flush_complete(struct protection_domain *domain) | 613 | static void iommu_flush_all(struct amd_iommu *iommu) |
| 504 | { | 614 | { |
| 505 | int i; | 615 | struct iommu_cmd cmd; |
| 506 | 616 | ||
| 507 | for (i = 0; i < amd_iommus_present; ++i) { | 617 | build_inv_all(&cmd); |
| 508 | if (!domain->dev_iommu[i]) | ||
| 509 | continue; | ||
| 510 | 618 | ||
| 511 | /* | 619 | iommu_queue_command(iommu, &cmd); |
| 512 | * Devices of this domain are behind this IOMMU | 620 | iommu_completion_wait(iommu); |
| 513 | * We need to wait for completion of all commands. | 621 | } |
| 514 | */ | 622 | |
| 515 | iommu_completion_wait(amd_iommus[i]); | 623 | void iommu_flush_all_caches(struct amd_iommu *iommu) |
| 624 | { | ||
| 625 | if (iommu_feature(iommu, FEATURE_IA)) { | ||
| 626 | iommu_flush_all(iommu); | ||
| 627 | } else { | ||
| 628 | iommu_flush_dte_all(iommu); | ||
| 629 | iommu_flush_tlb_all(iommu); | ||
| 516 | } | 630 | } |
| 517 | } | 631 | } |
| 518 | 632 | ||
| 519 | /* | 633 | /* |
| 520 | * Command send function for invalidating a device table entry | 634 | * Command send function for flushing on-device TLB |
| 521 | */ | 635 | */ |
| 522 | static int iommu_flush_device(struct device *dev) | 636 | static int device_flush_iotlb(struct device *dev, u64 address, size_t size) |
| 523 | { | 637 | { |
| 638 | struct pci_dev *pdev = to_pci_dev(dev); | ||
| 524 | struct amd_iommu *iommu; | 639 | struct amd_iommu *iommu; |
| 525 | struct iommu_cmd cmd; | 640 | struct iommu_cmd cmd; |
| 526 | u16 devid; | 641 | u16 devid; |
| 642 | int qdep; | ||
| 527 | 643 | ||
| 644 | qdep = pci_ats_queue_depth(pdev); | ||
| 528 | devid = get_device_id(dev); | 645 | devid = get_device_id(dev); |
| 529 | iommu = amd_iommu_rlookup_table[devid]; | 646 | iommu = amd_iommu_rlookup_table[devid]; |
| 530 | 647 | ||
| 531 | /* Build command */ | 648 | build_inv_iotlb_pages(&cmd, devid, qdep, address, size); |
| 532 | memset(&cmd, 0, sizeof(cmd)); | ||
| 533 | CMD_SET_TYPE(&cmd, CMD_INV_DEV_ENTRY); | ||
| 534 | cmd.data[0] = devid; | ||
| 535 | 649 | ||
| 536 | return iommu_queue_command(iommu, &cmd); | 650 | return iommu_queue_command(iommu, &cmd); |
| 537 | } | 651 | } |
| 538 | 652 | ||
| 539 | static void __iommu_build_inv_iommu_pages(struct iommu_cmd *cmd, u64 address, | ||
| 540 | u16 domid, int pde, int s) | ||
| 541 | { | ||
| 542 | memset(cmd, 0, sizeof(*cmd)); | ||
| 543 | address &= PAGE_MASK; | ||
| 544 | CMD_SET_TYPE(cmd, CMD_INV_IOMMU_PAGES); | ||
| 545 | cmd->data[1] |= domid; | ||
| 546 | cmd->data[2] = lower_32_bits(address); | ||
| 547 | cmd->data[3] = upper_32_bits(address); | ||
| 548 | if (s) /* size bit - we flush more than one 4kb page */ | ||
| 549 | cmd->data[2] |= CMD_INV_IOMMU_PAGES_SIZE_MASK; | ||
| 550 | if (pde) /* PDE bit - we wan't flush everything not only the PTEs */ | ||
| 551 | cmd->data[2] |= CMD_INV_IOMMU_PAGES_PDE_MASK; | ||
| 552 | } | ||
| 553 | |||
| 554 | /* | 653 | /* |
| 555 | * Generic command send function for invalidaing TLB entries | 654 | * Command send function for invalidating a device table entry |
| 556 | */ | 655 | */ |
| 557 | static int iommu_queue_inv_iommu_pages(struct amd_iommu *iommu, | 656 | static int device_flush_dte(struct device *dev) |
| 558 | u64 address, u16 domid, int pde, int s) | ||
| 559 | { | 657 | { |
| 560 | struct iommu_cmd cmd; | 658 | struct amd_iommu *iommu; |
| 659 | struct pci_dev *pdev; | ||
| 660 | u16 devid; | ||
| 561 | int ret; | 661 | int ret; |
| 562 | 662 | ||
| 563 | __iommu_build_inv_iommu_pages(&cmd, address, domid, pde, s); | 663 | pdev = to_pci_dev(dev); |
| 664 | devid = get_device_id(dev); | ||
| 665 | iommu = amd_iommu_rlookup_table[devid]; | ||
| 564 | 666 | ||
| 565 | ret = iommu_queue_command(iommu, &cmd); | 667 | ret = iommu_flush_dte(iommu, devid); |
| 668 | if (ret) | ||
| 669 | return ret; | ||
| 670 | |||
| 671 | if (pci_ats_enabled(pdev)) | ||
| 672 | ret = device_flush_iotlb(dev, 0, ~0UL); | ||
| 566 | 673 | ||
| 567 | return ret; | 674 | return ret; |
| 568 | } | 675 | } |
| @@ -572,23 +679,14 @@ static int iommu_queue_inv_iommu_pages(struct amd_iommu *iommu, | |||
| 572 | * It invalidates a single PTE if the range to flush is within a single | 679 | * It invalidates a single PTE if the range to flush is within a single |
| 573 | * page. Otherwise it flushes the whole TLB of the IOMMU. | 680 | * page. Otherwise it flushes the whole TLB of the IOMMU. |
| 574 | */ | 681 | */ |
| 575 | static void __iommu_flush_pages(struct protection_domain *domain, | 682 | static void __domain_flush_pages(struct protection_domain *domain, |
| 576 | u64 address, size_t size, int pde) | 683 | u64 address, size_t size, int pde) |
| 577 | { | 684 | { |
| 578 | int s = 0, i; | 685 | struct iommu_dev_data *dev_data; |
| 579 | unsigned long pages = iommu_num_pages(address, size, PAGE_SIZE); | 686 | struct iommu_cmd cmd; |
| 580 | 687 | int ret = 0, i; | |
| 581 | address &= PAGE_MASK; | ||
| 582 | |||
| 583 | if (pages > 1) { | ||
| 584 | /* | ||
| 585 | * If we have to flush more than one page, flush all | ||
| 586 | * TLB entries for this domain | ||
| 587 | */ | ||
| 588 | address = CMD_INV_IOMMU_ALL_PAGES_ADDRESS; | ||
| 589 | s = 1; | ||
| 590 | } | ||
| 591 | 688 | ||
| 689 | build_inv_iommu_pages(&cmd, address, size, domain->id, pde); | ||
| 592 | 690 | ||
| 593 | for (i = 0; i < amd_iommus_present; ++i) { | 691 | for (i = 0; i < amd_iommus_present; ++i) { |
| 594 | if (!domain->dev_iommu[i]) | 692 | if (!domain->dev_iommu[i]) |
| @@ -598,101 +696,70 @@ static void __iommu_flush_pages(struct protection_domain *domain, | |||
| 598 | * Devices of this domain are behind this IOMMU | 696 | * Devices of this domain are behind this IOMMU |
| 599 | * We need a TLB flush | 697 | * We need a TLB flush |
| 600 | */ | 698 | */ |
| 601 | iommu_queue_inv_iommu_pages(amd_iommus[i], address, | 699 | ret |= iommu_queue_command(amd_iommus[i], &cmd); |
| 602 | domain->id, pde, s); | 700 | } |
| 701 | |||
| 702 | list_for_each_entry(dev_data, &domain->dev_list, list) { | ||
| 703 | struct pci_dev *pdev = to_pci_dev(dev_data->dev); | ||
| 704 | |||
| 705 | if (!pci_ats_enabled(pdev)) | ||
| 706 | continue; | ||
| 707 | |||
| 708 | ret |= device_flush_iotlb(dev_data->dev, address, size); | ||
| 603 | } | 709 | } |
| 604 | 710 | ||
| 605 | return; | 711 | WARN_ON(ret); |
| 606 | } | 712 | } |
| 607 | 713 | ||
| 608 | static void iommu_flush_pages(struct protection_domain *domain, | 714 | static void domain_flush_pages(struct protection_domain *domain, |
| 609 | u64 address, size_t size) | 715 | u64 address, size_t size) |
| 610 | { | 716 | { |
| 611 | __iommu_flush_pages(domain, address, size, 0); | 717 | __domain_flush_pages(domain, address, size, 0); |
| 612 | } | 718 | } |
| 613 | 719 | ||
| 614 | /* Flush the whole IO/TLB for a given protection domain */ | 720 | /* Flush the whole IO/TLB for a given protection domain */ |
| 615 | static void iommu_flush_tlb(struct protection_domain *domain) | 721 | static void domain_flush_tlb(struct protection_domain *domain) |
| 616 | { | 722 | { |
| 617 | __iommu_flush_pages(domain, 0, CMD_INV_IOMMU_ALL_PAGES_ADDRESS, 0); | 723 | __domain_flush_pages(domain, 0, CMD_INV_IOMMU_ALL_PAGES_ADDRESS, 0); |
| 618 | } | 724 | } |
| 619 | 725 | ||
| 620 | /* Flush the whole IO/TLB for a given protection domain - including PDE */ | 726 | /* Flush the whole IO/TLB for a given protection domain - including PDE */ |
| 621 | static void iommu_flush_tlb_pde(struct protection_domain *domain) | 727 | static void domain_flush_tlb_pde(struct protection_domain *domain) |
| 622 | { | 728 | { |
| 623 | __iommu_flush_pages(domain, 0, CMD_INV_IOMMU_ALL_PAGES_ADDRESS, 1); | 729 | __domain_flush_pages(domain, 0, CMD_INV_IOMMU_ALL_PAGES_ADDRESS, 1); |
| 624 | } | ||
| 625 | |||
| 626 | |||
| 627 | /* | ||
| 628 | * This function flushes the DTEs for all devices in domain | ||
| 629 | */ | ||
| 630 | static void iommu_flush_domain_devices(struct protection_domain *domain) | ||
| 631 | { | ||
| 632 | struct iommu_dev_data *dev_data; | ||
| 633 | unsigned long flags; | ||
| 634 | |||
| 635 | spin_lock_irqsave(&domain->lock, flags); | ||
| 636 | |||
| 637 | list_for_each_entry(dev_data, &domain->dev_list, list) | ||
| 638 | iommu_flush_device(dev_data->dev); | ||
| 639 | |||
| 640 | spin_unlock_irqrestore(&domain->lock, flags); | ||
| 641 | } | 730 | } |
| 642 | 731 | ||
| 643 | static void iommu_flush_all_domain_devices(void) | 732 | static void domain_flush_complete(struct protection_domain *domain) |
| 644 | { | 733 | { |
| 645 | struct protection_domain *domain; | 734 | int i; |
| 646 | unsigned long flags; | ||
| 647 | 735 | ||
| 648 | spin_lock_irqsave(&amd_iommu_pd_lock, flags); | 736 | for (i = 0; i < amd_iommus_present; ++i) { |
| 737 | if (!domain->dev_iommu[i]) | ||
| 738 | continue; | ||
| 649 | 739 | ||
| 650 | list_for_each_entry(domain, &amd_iommu_pd_list, list) { | 740 | /* |
| 651 | iommu_flush_domain_devices(domain); | 741 | * Devices of this domain are behind this IOMMU |
| 652 | iommu_flush_complete(domain); | 742 | * We need to wait for completion of all commands. |
| 743 | */ | ||
| 744 | iommu_completion_wait(amd_iommus[i]); | ||
| 653 | } | 745 | } |
| 654 | |||
| 655 | spin_unlock_irqrestore(&amd_iommu_pd_lock, flags); | ||
| 656 | } | 746 | } |
| 657 | 747 | ||
| 658 | void amd_iommu_flush_all_devices(void) | ||
| 659 | { | ||
| 660 | iommu_flush_all_domain_devices(); | ||
| 661 | } | ||
| 662 | 748 | ||
| 663 | /* | 749 | /* |
| 664 | * This function uses heavy locking and may disable irqs for some time. But | 750 | * This function flushes the DTEs for all devices in domain |
| 665 | * this is no issue because it is only called during resume. | ||
| 666 | */ | 751 | */ |
| 667 | void amd_iommu_flush_all_domains(void) | 752 | static void domain_flush_devices(struct protection_domain *domain) |
| 668 | { | 753 | { |
| 669 | struct protection_domain *domain; | 754 | struct iommu_dev_data *dev_data; |
| 670 | unsigned long flags; | 755 | unsigned long flags; |
| 671 | 756 | ||
| 672 | spin_lock_irqsave(&amd_iommu_pd_lock, flags); | 757 | spin_lock_irqsave(&domain->lock, flags); |
| 673 | |||
| 674 | list_for_each_entry(domain, &amd_iommu_pd_list, list) { | ||
| 675 | spin_lock(&domain->lock); | ||
| 676 | iommu_flush_tlb_pde(domain); | ||
| 677 | iommu_flush_complete(domain); | ||
| 678 | spin_unlock(&domain->lock); | ||
| 679 | } | ||
| 680 | |||
| 681 | spin_unlock_irqrestore(&amd_iommu_pd_lock, flags); | ||
| 682 | } | ||
| 683 | |||
| 684 | static void reset_iommu_command_buffer(struct amd_iommu *iommu) | ||
| 685 | { | ||
| 686 | pr_err("AMD-Vi: Resetting IOMMU command buffer\n"); | ||
| 687 | |||
| 688 | if (iommu->reset_in_progress) | ||
| 689 | panic("AMD-Vi: ILLEGAL_COMMAND_ERROR while resetting command buffer\n"); | ||
| 690 | 758 | ||
| 691 | amd_iommu_reset_cmd_buffer(iommu); | 759 | list_for_each_entry(dev_data, &domain->dev_list, list) |
| 692 | amd_iommu_flush_all_devices(); | 760 | device_flush_dte(dev_data->dev); |
| 693 | amd_iommu_flush_all_domains(); | ||
| 694 | 761 | ||
| 695 | iommu->reset_in_progress = false; | 762 | spin_unlock_irqrestore(&domain->lock, flags); |
| 696 | } | 763 | } |
| 697 | 764 | ||
| 698 | /**************************************************************************** | 765 | /**************************************************************************** |
| @@ -1410,17 +1477,22 @@ static bool dma_ops_domain(struct protection_domain *domain) | |||
| 1410 | return domain->flags & PD_DMA_OPS_MASK; | 1477 | return domain->flags & PD_DMA_OPS_MASK; |
| 1411 | } | 1478 | } |
| 1412 | 1479 | ||
| 1413 | static void set_dte_entry(u16 devid, struct protection_domain *domain) | 1480 | static void set_dte_entry(u16 devid, struct protection_domain *domain, bool ats) |
| 1414 | { | 1481 | { |
| 1415 | u64 pte_root = virt_to_phys(domain->pt_root); | 1482 | u64 pte_root = virt_to_phys(domain->pt_root); |
| 1483 | u32 flags = 0; | ||
| 1416 | 1484 | ||
| 1417 | pte_root |= (domain->mode & DEV_ENTRY_MODE_MASK) | 1485 | pte_root |= (domain->mode & DEV_ENTRY_MODE_MASK) |
| 1418 | << DEV_ENTRY_MODE_SHIFT; | 1486 | << DEV_ENTRY_MODE_SHIFT; |
| 1419 | pte_root |= IOMMU_PTE_IR | IOMMU_PTE_IW | IOMMU_PTE_P | IOMMU_PTE_TV; | 1487 | pte_root |= IOMMU_PTE_IR | IOMMU_PTE_IW | IOMMU_PTE_P | IOMMU_PTE_TV; |
| 1420 | 1488 | ||
| 1421 | amd_iommu_dev_table[devid].data[2] = domain->id; | 1489 | if (ats) |
| 1422 | amd_iommu_dev_table[devid].data[1] = upper_32_bits(pte_root); | 1490 | flags |= DTE_FLAG_IOTLB; |
| 1423 | amd_iommu_dev_table[devid].data[0] = lower_32_bits(pte_root); | 1491 | |
| 1492 | amd_iommu_dev_table[devid].data[3] |= flags; | ||
| 1493 | amd_iommu_dev_table[devid].data[2] = domain->id; | ||
| 1494 | amd_iommu_dev_table[devid].data[1] = upper_32_bits(pte_root); | ||
| 1495 | amd_iommu_dev_table[devid].data[0] = lower_32_bits(pte_root); | ||
| 1424 | } | 1496 | } |
| 1425 | 1497 | ||
| 1426 | static void clear_dte_entry(u16 devid) | 1498 | static void clear_dte_entry(u16 devid) |
| @@ -1437,34 +1509,42 @@ static void do_attach(struct device *dev, struct protection_domain *domain) | |||
| 1437 | { | 1509 | { |
| 1438 | struct iommu_dev_data *dev_data; | 1510 | struct iommu_dev_data *dev_data; |
| 1439 | struct amd_iommu *iommu; | 1511 | struct amd_iommu *iommu; |
| 1512 | struct pci_dev *pdev; | ||
| 1513 | bool ats = false; | ||
| 1440 | u16 devid; | 1514 | u16 devid; |
| 1441 | 1515 | ||
| 1442 | devid = get_device_id(dev); | 1516 | devid = get_device_id(dev); |
| 1443 | iommu = amd_iommu_rlookup_table[devid]; | 1517 | iommu = amd_iommu_rlookup_table[devid]; |
| 1444 | dev_data = get_dev_data(dev); | 1518 | dev_data = get_dev_data(dev); |
| 1519 | pdev = to_pci_dev(dev); | ||
| 1520 | |||
| 1521 | if (amd_iommu_iotlb_sup) | ||
| 1522 | ats = pci_ats_enabled(pdev); | ||
| 1445 | 1523 | ||
| 1446 | /* Update data structures */ | 1524 | /* Update data structures */ |
| 1447 | dev_data->domain = domain; | 1525 | dev_data->domain = domain; |
| 1448 | list_add(&dev_data->list, &domain->dev_list); | 1526 | list_add(&dev_data->list, &domain->dev_list); |
| 1449 | set_dte_entry(devid, domain); | 1527 | set_dte_entry(devid, domain, ats); |
| 1450 | 1528 | ||
| 1451 | /* Do reference counting */ | 1529 | /* Do reference counting */ |
| 1452 | domain->dev_iommu[iommu->index] += 1; | 1530 | domain->dev_iommu[iommu->index] += 1; |
| 1453 | domain->dev_cnt += 1; | 1531 | domain->dev_cnt += 1; |
| 1454 | 1532 | ||
| 1455 | /* Flush the DTE entry */ | 1533 | /* Flush the DTE entry */ |
| 1456 | iommu_flush_device(dev); | 1534 | device_flush_dte(dev); |
| 1457 | } | 1535 | } |
| 1458 | 1536 | ||
| 1459 | static void do_detach(struct device *dev) | 1537 | static void do_detach(struct device *dev) |
| 1460 | { | 1538 | { |
| 1461 | struct iommu_dev_data *dev_data; | 1539 | struct iommu_dev_data *dev_data; |
| 1462 | struct amd_iommu *iommu; | 1540 | struct amd_iommu *iommu; |
| 1541 | struct pci_dev *pdev; | ||
| 1463 | u16 devid; | 1542 | u16 devid; |
| 1464 | 1543 | ||
| 1465 | devid = get_device_id(dev); | 1544 | devid = get_device_id(dev); |
| 1466 | iommu = amd_iommu_rlookup_table[devid]; | 1545 | iommu = amd_iommu_rlookup_table[devid]; |
| 1467 | dev_data = get_dev_data(dev); | 1546 | dev_data = get_dev_data(dev); |
| 1547 | pdev = to_pci_dev(dev); | ||
| 1468 | 1548 | ||
| 1469 | /* decrease reference counters */ | 1549 | /* decrease reference counters */ |
| 1470 | dev_data->domain->dev_iommu[iommu->index] -= 1; | 1550 | dev_data->domain->dev_iommu[iommu->index] -= 1; |
| @@ -1476,7 +1556,7 @@ static void do_detach(struct device *dev) | |||
| 1476 | clear_dte_entry(devid); | 1556 | clear_dte_entry(devid); |
| 1477 | 1557 | ||
| 1478 | /* Flush the DTE entry */ | 1558 | /* Flush the DTE entry */ |
| 1479 | iommu_flush_device(dev); | 1559 | device_flush_dte(dev); |
| 1480 | } | 1560 | } |
| 1481 | 1561 | ||
| 1482 | /* | 1562 | /* |
| @@ -1539,9 +1619,13 @@ out_unlock: | |||
| 1539 | static int attach_device(struct device *dev, | 1619 | static int attach_device(struct device *dev, |
| 1540 | struct protection_domain *domain) | 1620 | struct protection_domain *domain) |
| 1541 | { | 1621 | { |
| 1622 | struct pci_dev *pdev = to_pci_dev(dev); | ||
| 1542 | unsigned long flags; | 1623 | unsigned long flags; |
| 1543 | int ret; | 1624 | int ret; |
| 1544 | 1625 | ||
| 1626 | if (amd_iommu_iotlb_sup) | ||
| 1627 | pci_enable_ats(pdev, PAGE_SHIFT); | ||
| 1628 | |||
| 1545 | write_lock_irqsave(&amd_iommu_devtable_lock, flags); | 1629 | write_lock_irqsave(&amd_iommu_devtable_lock, flags); |
| 1546 | ret = __attach_device(dev, domain); | 1630 | ret = __attach_device(dev, domain); |
| 1547 | write_unlock_irqrestore(&amd_iommu_devtable_lock, flags); | 1631 | write_unlock_irqrestore(&amd_iommu_devtable_lock, flags); |
| @@ -1551,7 +1635,7 @@ static int attach_device(struct device *dev, | |||
| 1551 | * left the caches in the IOMMU dirty. So we have to flush | 1635 | * left the caches in the IOMMU dirty. So we have to flush |
| 1552 | * here to evict all dirty stuff. | 1636 | * here to evict all dirty stuff. |
| 1553 | */ | 1637 | */ |
| 1554 | iommu_flush_tlb_pde(domain); | 1638 | domain_flush_tlb_pde(domain); |
| 1555 | 1639 | ||
| 1556 | return ret; | 1640 | return ret; |
| 1557 | } | 1641 | } |
| @@ -1598,12 +1682,16 @@ static void __detach_device(struct device *dev) | |||
| 1598 | */ | 1682 | */ |
| 1599 | static void detach_device(struct device *dev) | 1683 | static void detach_device(struct device *dev) |
| 1600 | { | 1684 | { |
| 1685 | struct pci_dev *pdev = to_pci_dev(dev); | ||
| 1601 | unsigned long flags; | 1686 | unsigned long flags; |
| 1602 | 1687 | ||
| 1603 | /* lock device table */ | 1688 | /* lock device table */ |
| 1604 | write_lock_irqsave(&amd_iommu_devtable_lock, flags); | 1689 | write_lock_irqsave(&amd_iommu_devtable_lock, flags); |
| 1605 | __detach_device(dev); | 1690 | __detach_device(dev); |
| 1606 | write_unlock_irqrestore(&amd_iommu_devtable_lock, flags); | 1691 | write_unlock_irqrestore(&amd_iommu_devtable_lock, flags); |
| 1692 | |||
| 1693 | if (amd_iommu_iotlb_sup && pci_ats_enabled(pdev)) | ||
| 1694 | pci_disable_ats(pdev); | ||
| 1607 | } | 1695 | } |
| 1608 | 1696 | ||
| 1609 | /* | 1697 | /* |
| @@ -1692,7 +1780,7 @@ static int device_change_notifier(struct notifier_block *nb, | |||
| 1692 | goto out; | 1780 | goto out; |
| 1693 | } | 1781 | } |
| 1694 | 1782 | ||
| 1695 | iommu_flush_device(dev); | 1783 | device_flush_dte(dev); |
| 1696 | iommu_completion_wait(iommu); | 1784 | iommu_completion_wait(iommu); |
| 1697 | 1785 | ||
| 1698 | out: | 1786 | out: |
| @@ -1753,8 +1841,9 @@ static void update_device_table(struct protection_domain *domain) | |||
| 1753 | struct iommu_dev_data *dev_data; | 1841 | struct iommu_dev_data *dev_data; |
| 1754 | 1842 | ||
| 1755 | list_for_each_entry(dev_data, &domain->dev_list, list) { | 1843 | list_for_each_entry(dev_data, &domain->dev_list, list) { |
| 1844 | struct pci_dev *pdev = to_pci_dev(dev_data->dev); | ||
| 1756 | u16 devid = get_device_id(dev_data->dev); | 1845 | u16 devid = get_device_id(dev_data->dev); |
| 1757 | set_dte_entry(devid, domain); | 1846 | set_dte_entry(devid, domain, pci_ats_enabled(pdev)); |
| 1758 | } | 1847 | } |
| 1759 | } | 1848 | } |
| 1760 | 1849 | ||
| @@ -1764,8 +1853,9 @@ static void update_domain(struct protection_domain *domain) | |||
| 1764 | return; | 1853 | return; |
| 1765 | 1854 | ||
| 1766 | update_device_table(domain); | 1855 | update_device_table(domain); |
| 1767 | iommu_flush_domain_devices(domain); | 1856 | |
| 1768 | iommu_flush_tlb_pde(domain); | 1857 | domain_flush_devices(domain); |
| 1858 | domain_flush_tlb_pde(domain); | ||
| 1769 | 1859 | ||
| 1770 | domain->updated = false; | 1860 | domain->updated = false; |
| 1771 | } | 1861 | } |
| @@ -1924,10 +2014,10 @@ retry: | |||
| 1924 | ADD_STATS_COUNTER(alloced_io_mem, size); | 2014 | ADD_STATS_COUNTER(alloced_io_mem, size); |
| 1925 | 2015 | ||
| 1926 | if (unlikely(dma_dom->need_flush && !amd_iommu_unmap_flush)) { | 2016 | if (unlikely(dma_dom->need_flush && !amd_iommu_unmap_flush)) { |
| 1927 | iommu_flush_tlb(&dma_dom->domain); | 2017 | domain_flush_tlb(&dma_dom->domain); |
| 1928 | dma_dom->need_flush = false; | 2018 | dma_dom->need_flush = false; |
| 1929 | } else if (unlikely(amd_iommu_np_cache)) | 2019 | } else if (unlikely(amd_iommu_np_cache)) |
| 1930 | iommu_flush_pages(&dma_dom->domain, address, size); | 2020 | domain_flush_pages(&dma_dom->domain, address, size); |
| 1931 | 2021 | ||
| 1932 | out: | 2022 | out: |
| 1933 | return address; | 2023 | return address; |
| @@ -1976,7 +2066,7 @@ static void __unmap_single(struct dma_ops_domain *dma_dom, | |||
| 1976 | dma_ops_free_addresses(dma_dom, dma_addr, pages); | 2066 | dma_ops_free_addresses(dma_dom, dma_addr, pages); |
| 1977 | 2067 | ||
| 1978 | if (amd_iommu_unmap_flush || dma_dom->need_flush) { | 2068 | if (amd_iommu_unmap_flush || dma_dom->need_flush) { |
| 1979 | iommu_flush_pages(&dma_dom->domain, flush_addr, size); | 2069 | domain_flush_pages(&dma_dom->domain, flush_addr, size); |
| 1980 | dma_dom->need_flush = false; | 2070 | dma_dom->need_flush = false; |
| 1981 | } | 2071 | } |
| 1982 | } | 2072 | } |
| @@ -2012,7 +2102,7 @@ static dma_addr_t map_page(struct device *dev, struct page *page, | |||
| 2012 | if (addr == DMA_ERROR_CODE) | 2102 | if (addr == DMA_ERROR_CODE) |
| 2013 | goto out; | 2103 | goto out; |
| 2014 | 2104 | ||
| 2015 | iommu_flush_complete(domain); | 2105 | domain_flush_complete(domain); |
| 2016 | 2106 | ||
| 2017 | out: | 2107 | out: |
| 2018 | spin_unlock_irqrestore(&domain->lock, flags); | 2108 | spin_unlock_irqrestore(&domain->lock, flags); |
| @@ -2039,7 +2129,7 @@ static void unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size, | |||
| 2039 | 2129 | ||
| 2040 | __unmap_single(domain->priv, dma_addr, size, dir); | 2130 | __unmap_single(domain->priv, dma_addr, size, dir); |
| 2041 | 2131 | ||
| 2042 | iommu_flush_complete(domain); | 2132 | domain_flush_complete(domain); |
| 2043 | 2133 | ||
| 2044 | spin_unlock_irqrestore(&domain->lock, flags); | 2134 | spin_unlock_irqrestore(&domain->lock, flags); |
| 2045 | } | 2135 | } |
| @@ -2104,7 +2194,7 @@ static int map_sg(struct device *dev, struct scatterlist *sglist, | |||
| 2104 | goto unmap; | 2194 | goto unmap; |
| 2105 | } | 2195 | } |
| 2106 | 2196 | ||
| 2107 | iommu_flush_complete(domain); | 2197 | domain_flush_complete(domain); |
| 2108 | 2198 | ||
| 2109 | out: | 2199 | out: |
| 2110 | spin_unlock_irqrestore(&domain->lock, flags); | 2200 | spin_unlock_irqrestore(&domain->lock, flags); |
| @@ -2150,7 +2240,7 @@ static void unmap_sg(struct device *dev, struct scatterlist *sglist, | |||
| 2150 | s->dma_address = s->dma_length = 0; | 2240 | s->dma_address = s->dma_length = 0; |
| 2151 | } | 2241 | } |
| 2152 | 2242 | ||
| 2153 | iommu_flush_complete(domain); | 2243 | domain_flush_complete(domain); |
| 2154 | 2244 | ||
| 2155 | spin_unlock_irqrestore(&domain->lock, flags); | 2245 | spin_unlock_irqrestore(&domain->lock, flags); |
| 2156 | } | 2246 | } |
| @@ -2200,7 +2290,7 @@ static void *alloc_coherent(struct device *dev, size_t size, | |||
| 2200 | goto out_free; | 2290 | goto out_free; |
| 2201 | } | 2291 | } |
| 2202 | 2292 | ||
| 2203 | iommu_flush_complete(domain); | 2293 | domain_flush_complete(domain); |
| 2204 | 2294 | ||
| 2205 | spin_unlock_irqrestore(&domain->lock, flags); | 2295 | spin_unlock_irqrestore(&domain->lock, flags); |
| 2206 | 2296 | ||
| @@ -2232,7 +2322,7 @@ static void free_coherent(struct device *dev, size_t size, | |||
| 2232 | 2322 | ||
| 2233 | __unmap_single(domain->priv, dma_addr, size, DMA_BIDIRECTIONAL); | 2323 | __unmap_single(domain->priv, dma_addr, size, DMA_BIDIRECTIONAL); |
| 2234 | 2324 | ||
| 2235 | iommu_flush_complete(domain); | 2325 | domain_flush_complete(domain); |
| 2236 | 2326 | ||
| 2237 | spin_unlock_irqrestore(&domain->lock, flags); | 2327 | spin_unlock_irqrestore(&domain->lock, flags); |
| 2238 | 2328 | ||
| @@ -2476,7 +2566,7 @@ static void amd_iommu_detach_device(struct iommu_domain *dom, | |||
| 2476 | if (!iommu) | 2566 | if (!iommu) |
| 2477 | return; | 2567 | return; |
| 2478 | 2568 | ||
| 2479 | iommu_flush_device(dev); | 2569 | device_flush_dte(dev); |
| 2480 | iommu_completion_wait(iommu); | 2570 | iommu_completion_wait(iommu); |
| 2481 | } | 2571 | } |
| 2482 | 2572 | ||
| @@ -2542,7 +2632,7 @@ static int amd_iommu_unmap(struct iommu_domain *dom, unsigned long iova, | |||
| 2542 | unmap_size = iommu_unmap_page(domain, iova, page_size); | 2632 | unmap_size = iommu_unmap_page(domain, iova, page_size); |
| 2543 | mutex_unlock(&domain->api_lock); | 2633 | mutex_unlock(&domain->api_lock); |
| 2544 | 2634 | ||
| 2545 | iommu_flush_tlb_pde(domain); | 2635 | domain_flush_tlb_pde(domain); |
| 2546 | 2636 | ||
| 2547 | return get_order(unmap_size); | 2637 | return get_order(unmap_size); |
| 2548 | } | 2638 | } |
diff --git a/arch/x86/kernel/amd_iommu_init.c b/arch/x86/kernel/amd_iommu_init.c index 246d727b65b7..9179c21120a8 100644 --- a/arch/x86/kernel/amd_iommu_init.c +++ b/arch/x86/kernel/amd_iommu_init.c | |||
| @@ -137,6 +137,7 @@ int amd_iommus_present; | |||
| 137 | 137 | ||
| 138 | /* IOMMUs have a non-present cache? */ | 138 | /* IOMMUs have a non-present cache? */ |
| 139 | bool amd_iommu_np_cache __read_mostly; | 139 | bool amd_iommu_np_cache __read_mostly; |
| 140 | bool amd_iommu_iotlb_sup __read_mostly = true; | ||
| 140 | 141 | ||
| 141 | /* | 142 | /* |
| 142 | * The ACPI table parsing functions set this variable on an error | 143 | * The ACPI table parsing functions set this variable on an error |
| @@ -180,6 +181,12 @@ static u32 dev_table_size; /* size of the device table */ | |||
| 180 | static u32 alias_table_size; /* size of the alias table */ | 181 | static u32 alias_table_size; /* size of the alias table */ |
| 181 | static u32 rlookup_table_size; /* size if the rlookup table */ | 182 | static u32 rlookup_table_size; /* size if the rlookup table */ |
| 182 | 183 | ||
| 184 | /* | ||
| 185 | * This function flushes all internal caches of | ||
| 186 | * the IOMMU used by this driver. | ||
| 187 | */ | ||
| 188 | extern void iommu_flush_all_caches(struct amd_iommu *iommu); | ||
| 189 | |||
| 183 | static inline void update_last_devid(u16 devid) | 190 | static inline void update_last_devid(u16 devid) |
| 184 | { | 191 | { |
| 185 | if (devid > amd_iommu_last_bdf) | 192 | if (devid > amd_iommu_last_bdf) |
| @@ -293,9 +300,23 @@ static void iommu_feature_disable(struct amd_iommu *iommu, u8 bit) | |||
| 293 | /* Function to enable the hardware */ | 300 | /* Function to enable the hardware */ |
| 294 | static void iommu_enable(struct amd_iommu *iommu) | 301 | static void iommu_enable(struct amd_iommu *iommu) |
| 295 | { | 302 | { |
| 296 | printk(KERN_INFO "AMD-Vi: Enabling IOMMU at %s cap 0x%hx\n", | 303 | static const char * const feat_str[] = { |
| 304 | "PreF", "PPR", "X2APIC", "NX", "GT", "[5]", | ||
| 305 | "IA", "GA", "HE", "PC", NULL | ||
| 306 | }; | ||
| 307 | int i; | ||
| 308 | |||
| 309 | printk(KERN_INFO "AMD-Vi: Enabling IOMMU at %s cap 0x%hx", | ||
| 297 | dev_name(&iommu->dev->dev), iommu->cap_ptr); | 310 | dev_name(&iommu->dev->dev), iommu->cap_ptr); |
| 298 | 311 | ||
| 312 | if (iommu->cap & (1 << IOMMU_CAP_EFR)) { | ||
| 313 | printk(KERN_CONT " extended features: "); | ||
| 314 | for (i = 0; feat_str[i]; ++i) | ||
| 315 | if (iommu_feature(iommu, (1ULL << i))) | ||
| 316 | printk(KERN_CONT " %s", feat_str[i]); | ||
| 317 | } | ||
| 318 | printk(KERN_CONT "\n"); | ||
| 319 | |||
| 299 | iommu_feature_enable(iommu, CONTROL_IOMMU_EN); | 320 | iommu_feature_enable(iommu, CONTROL_IOMMU_EN); |
| 300 | } | 321 | } |
| 301 | 322 | ||
| @@ -651,7 +672,7 @@ static void __init set_device_exclusion_range(u16 devid, struct ivmd_header *m) | |||
| 651 | static void __init init_iommu_from_pci(struct amd_iommu *iommu) | 672 | static void __init init_iommu_from_pci(struct amd_iommu *iommu) |
| 652 | { | 673 | { |
| 653 | int cap_ptr = iommu->cap_ptr; | 674 | int cap_ptr = iommu->cap_ptr; |
| 654 | u32 range, misc; | 675 | u32 range, misc, low, high; |
| 655 | int i, j; | 676 | int i, j; |
| 656 | 677 | ||
| 657 | pci_read_config_dword(iommu->dev, cap_ptr + MMIO_CAP_HDR_OFFSET, | 678 | pci_read_config_dword(iommu->dev, cap_ptr + MMIO_CAP_HDR_OFFSET, |
| @@ -667,6 +688,15 @@ static void __init init_iommu_from_pci(struct amd_iommu *iommu) | |||
| 667 | MMIO_GET_LD(range)); | 688 | MMIO_GET_LD(range)); |
| 668 | iommu->evt_msi_num = MMIO_MSI_NUM(misc); | 689 | iommu->evt_msi_num = MMIO_MSI_NUM(misc); |
| 669 | 690 | ||
| 691 | if (!(iommu->cap & (1 << IOMMU_CAP_IOTLB))) | ||
| 692 | amd_iommu_iotlb_sup = false; | ||
| 693 | |||
| 694 | /* read extended feature bits */ | ||
| 695 | low = readl(iommu->mmio_base + MMIO_EXT_FEATURES); | ||
| 696 | high = readl(iommu->mmio_base + MMIO_EXT_FEATURES + 4); | ||
| 697 | |||
| 698 | iommu->features = ((u64)high << 32) | low; | ||
| 699 | |||
| 670 | if (!is_rd890_iommu(iommu->dev)) | 700 | if (!is_rd890_iommu(iommu->dev)) |
| 671 | return; | 701 | return; |
| 672 | 702 | ||
| @@ -1004,10 +1034,11 @@ static int iommu_setup_msi(struct amd_iommu *iommu) | |||
| 1004 | if (pci_enable_msi(iommu->dev)) | 1034 | if (pci_enable_msi(iommu->dev)) |
| 1005 | return 1; | 1035 | return 1; |
| 1006 | 1036 | ||
| 1007 | r = request_irq(iommu->dev->irq, amd_iommu_int_handler, | 1037 | r = request_threaded_irq(iommu->dev->irq, |
| 1008 | IRQF_SAMPLE_RANDOM, | 1038 | amd_iommu_int_handler, |
| 1009 | "AMD-Vi", | 1039 | amd_iommu_int_thread, |
| 1010 | NULL); | 1040 | 0, "AMD-Vi", |
| 1041 | iommu->dev); | ||
| 1011 | 1042 | ||
| 1012 | if (r) { | 1043 | if (r) { |
| 1013 | pci_disable_msi(iommu->dev); | 1044 | pci_disable_msi(iommu->dev); |
| @@ -1244,6 +1275,7 @@ static void enable_iommus(void) | |||
| 1244 | iommu_set_exclusion_range(iommu); | 1275 | iommu_set_exclusion_range(iommu); |
| 1245 | iommu_init_msi(iommu); | 1276 | iommu_init_msi(iommu); |
| 1246 | iommu_enable(iommu); | 1277 | iommu_enable(iommu); |
| 1278 | iommu_flush_all_caches(iommu); | ||
| 1247 | } | 1279 | } |
| 1248 | } | 1280 | } |
| 1249 | 1281 | ||
| @@ -1274,8 +1306,8 @@ static void amd_iommu_resume(void) | |||
| 1274 | * we have to flush after the IOMMUs are enabled because a | 1306 | * we have to flush after the IOMMUs are enabled because a |
| 1275 | * disabled IOMMU will never execute the commands we send | 1307 | * disabled IOMMU will never execute the commands we send |
| 1276 | */ | 1308 | */ |
| 1277 | amd_iommu_flush_all_devices(); | 1309 | for_each_iommu(iommu) |
| 1278 | amd_iommu_flush_all_domains(); | 1310 | iommu_flush_all_caches(iommu); |
| 1279 | } | 1311 | } |
| 1280 | 1312 | ||
| 1281 | static int amd_iommu_suspend(void) | 1313 | static int amd_iommu_suspend(void) |
diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c index 33b10a0fc095..7acd2d2ac965 100644 --- a/arch/x86/kernel/apic/x2apic_uv_x.c +++ b/arch/x86/kernel/apic/x2apic_uv_x.c | |||
| @@ -37,6 +37,13 @@ | |||
| 37 | #include <asm/smp.h> | 37 | #include <asm/smp.h> |
| 38 | #include <asm/x86_init.h> | 38 | #include <asm/x86_init.h> |
| 39 | #include <asm/emergency-restart.h> | 39 | #include <asm/emergency-restart.h> |
| 40 | #include <asm/nmi.h> | ||
| 41 | |||
| 42 | /* BMC sets a bit this MMR non-zero before sending an NMI */ | ||
| 43 | #define UVH_NMI_MMR UVH_SCRATCH5 | ||
| 44 | #define UVH_NMI_MMR_CLEAR (UVH_NMI_MMR + 8) | ||
| 45 | #define UV_NMI_PENDING_MASK (1UL << 63) | ||
| 46 | DEFINE_PER_CPU(unsigned long, cpu_last_nmi_count); | ||
| 40 | 47 | ||
| 41 | DEFINE_PER_CPU(int, x2apic_extra_bits); | 48 | DEFINE_PER_CPU(int, x2apic_extra_bits); |
| 42 | 49 | ||
| @@ -642,18 +649,46 @@ void __cpuinit uv_cpu_init(void) | |||
| 642 | */ | 649 | */ |
| 643 | int uv_handle_nmi(struct notifier_block *self, unsigned long reason, void *data) | 650 | int uv_handle_nmi(struct notifier_block *self, unsigned long reason, void *data) |
| 644 | { | 651 | { |
| 652 | unsigned long real_uv_nmi; | ||
| 653 | int bid; | ||
| 654 | |||
| 645 | if (reason != DIE_NMIUNKNOWN) | 655 | if (reason != DIE_NMIUNKNOWN) |
| 646 | return NOTIFY_OK; | 656 | return NOTIFY_OK; |
| 647 | 657 | ||
| 648 | if (in_crash_kexec) | 658 | if (in_crash_kexec) |
| 649 | /* do nothing if entering the crash kernel */ | 659 | /* do nothing if entering the crash kernel */ |
| 650 | return NOTIFY_OK; | 660 | return NOTIFY_OK; |
| 661 | |||
| 651 | /* | 662 | /* |
| 652 | * Use a lock so only one cpu prints at a time | 663 | * Each blade has an MMR that indicates when an NMI has been sent |
| 653 | * to prevent intermixed output. | 664 | * to cpus on the blade. If an NMI is detected, atomically |
| 665 | * clear the MMR and update a per-blade NMI count used to | ||
| 666 | * cause each cpu on the blade to notice a new NMI. | ||
| 667 | */ | ||
| 668 | bid = uv_numa_blade_id(); | ||
| 669 | real_uv_nmi = (uv_read_local_mmr(UVH_NMI_MMR) & UV_NMI_PENDING_MASK); | ||
| 670 | |||
| 671 | if (unlikely(real_uv_nmi)) { | ||
| 672 | spin_lock(&uv_blade_info[bid].nmi_lock); | ||
| 673 | real_uv_nmi = (uv_read_local_mmr(UVH_NMI_MMR) & UV_NMI_PENDING_MASK); | ||
| 674 | if (real_uv_nmi) { | ||
| 675 | uv_blade_info[bid].nmi_count++; | ||
| 676 | uv_write_local_mmr(UVH_NMI_MMR_CLEAR, UV_NMI_PENDING_MASK); | ||
| 677 | } | ||
| 678 | spin_unlock(&uv_blade_info[bid].nmi_lock); | ||
| 679 | } | ||
| 680 | |||
| 681 | if (likely(__get_cpu_var(cpu_last_nmi_count) == uv_blade_info[bid].nmi_count)) | ||
| 682 | return NOTIFY_DONE; | ||
| 683 | |||
| 684 | __get_cpu_var(cpu_last_nmi_count) = uv_blade_info[bid].nmi_count; | ||
| 685 | |||
| 686 | /* | ||
| 687 | * Use a lock so only one cpu prints at a time. | ||
| 688 | * This prevents intermixed output. | ||
| 654 | */ | 689 | */ |
| 655 | spin_lock(&uv_nmi_lock); | 690 | spin_lock(&uv_nmi_lock); |
| 656 | pr_info("NMI stack dump cpu %u:\n", smp_processor_id()); | 691 | pr_info("UV NMI stack dump cpu %u:\n", smp_processor_id()); |
| 657 | dump_stack(); | 692 | dump_stack(); |
| 658 | spin_unlock(&uv_nmi_lock); | 693 | spin_unlock(&uv_nmi_lock); |
| 659 | 694 | ||
| @@ -661,7 +696,8 @@ int uv_handle_nmi(struct notifier_block *self, unsigned long reason, void *data) | |||
| 661 | } | 696 | } |
| 662 | 697 | ||
| 663 | static struct notifier_block uv_dump_stack_nmi_nb = { | 698 | static struct notifier_block uv_dump_stack_nmi_nb = { |
| 664 | .notifier_call = uv_handle_nmi | 699 | .notifier_call = uv_handle_nmi, |
| 700 | .priority = NMI_LOCAL_LOW_PRIOR - 1, | ||
| 665 | }; | 701 | }; |
| 666 | 702 | ||
| 667 | void uv_register_nmi_notifier(void) | 703 | void uv_register_nmi_notifier(void) |
| @@ -720,8 +756,9 @@ void __init uv_system_init(void) | |||
| 720 | printk(KERN_DEBUG "UV: Found %d blades\n", uv_num_possible_blades()); | 756 | printk(KERN_DEBUG "UV: Found %d blades\n", uv_num_possible_blades()); |
| 721 | 757 | ||
| 722 | bytes = sizeof(struct uv_blade_info) * uv_num_possible_blades(); | 758 | bytes = sizeof(struct uv_blade_info) * uv_num_possible_blades(); |
| 723 | uv_blade_info = kmalloc(bytes, GFP_KERNEL); | 759 | uv_blade_info = kzalloc(bytes, GFP_KERNEL); |
| 724 | BUG_ON(!uv_blade_info); | 760 | BUG_ON(!uv_blade_info); |
| 761 | |||
| 725 | for (blade = 0; blade < uv_num_possible_blades(); blade++) | 762 | for (blade = 0; blade < uv_num_possible_blades(); blade++) |
| 726 | uv_blade_info[blade].memory_nid = -1; | 763 | uv_blade_info[blade].memory_nid = -1; |
| 727 | 764 | ||
| @@ -747,6 +784,7 @@ void __init uv_system_init(void) | |||
| 747 | uv_blade_info[blade].pnode = pnode; | 784 | uv_blade_info[blade].pnode = pnode; |
| 748 | uv_blade_info[blade].nr_possible_cpus = 0; | 785 | uv_blade_info[blade].nr_possible_cpus = 0; |
| 749 | uv_blade_info[blade].nr_online_cpus = 0; | 786 | uv_blade_info[blade].nr_online_cpus = 0; |
| 787 | spin_lock_init(&uv_blade_info[blade].nmi_lock); | ||
| 750 | max_pnode = max(pnode, max_pnode); | 788 | max_pnode = max(pnode, max_pnode); |
| 751 | blade++; | 789 | blade++; |
| 752 | } | 790 | } |
diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c index adee12e0da1f..3bfa02235965 100644 --- a/arch/x86/kernel/apm_32.c +++ b/arch/x86/kernel/apm_32.c | |||
| @@ -1238,7 +1238,6 @@ static int suspend(int vetoable) | |||
| 1238 | dpm_suspend_noirq(PMSG_SUSPEND); | 1238 | dpm_suspend_noirq(PMSG_SUSPEND); |
| 1239 | 1239 | ||
| 1240 | local_irq_disable(); | 1240 | local_irq_disable(); |
| 1241 | sysdev_suspend(PMSG_SUSPEND); | ||
| 1242 | syscore_suspend(); | 1241 | syscore_suspend(); |
| 1243 | 1242 | ||
| 1244 | local_irq_enable(); | 1243 | local_irq_enable(); |
| @@ -1258,7 +1257,6 @@ static int suspend(int vetoable) | |||
| 1258 | err = (err == APM_SUCCESS) ? 0 : -EIO; | 1257 | err = (err == APM_SUCCESS) ? 0 : -EIO; |
| 1259 | 1258 | ||
| 1260 | syscore_resume(); | 1259 | syscore_resume(); |
| 1261 | sysdev_resume(); | ||
| 1262 | local_irq_enable(); | 1260 | local_irq_enable(); |
| 1263 | 1261 | ||
| 1264 | dpm_resume_noirq(PMSG_RESUME); | 1262 | dpm_resume_noirq(PMSG_RESUME); |
| @@ -1282,7 +1280,6 @@ static void standby(void) | |||
| 1282 | dpm_suspend_noirq(PMSG_SUSPEND); | 1280 | dpm_suspend_noirq(PMSG_SUSPEND); |
| 1283 | 1281 | ||
| 1284 | local_irq_disable(); | 1282 | local_irq_disable(); |
| 1285 | sysdev_suspend(PMSG_SUSPEND); | ||
| 1286 | syscore_suspend(); | 1283 | syscore_suspend(); |
| 1287 | local_irq_enable(); | 1284 | local_irq_enable(); |
| 1288 | 1285 | ||
| @@ -1292,7 +1289,6 @@ static void standby(void) | |||
| 1292 | 1289 | ||
| 1293 | local_irq_disable(); | 1290 | local_irq_disable(); |
| 1294 | syscore_resume(); | 1291 | syscore_resume(); |
| 1295 | sysdev_resume(); | ||
| 1296 | local_irq_enable(); | 1292 | local_irq_enable(); |
| 1297 | 1293 | ||
| 1298 | dpm_resume_noirq(PMSG_RESUME); | 1294 | dpm_resume_noirq(PMSG_RESUME); |
diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile index 3f0ebe429a01..6042981d0309 100644 --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile | |||
| @@ -30,7 +30,6 @@ obj-$(CONFIG_PERF_EVENTS) += perf_event.o | |||
| 30 | 30 | ||
| 31 | obj-$(CONFIG_X86_MCE) += mcheck/ | 31 | obj-$(CONFIG_X86_MCE) += mcheck/ |
| 32 | obj-$(CONFIG_MTRR) += mtrr/ | 32 | obj-$(CONFIG_MTRR) += mtrr/ |
| 33 | obj-$(CONFIG_CPU_FREQ) += cpufreq/ | ||
| 34 | 33 | ||
| 35 | obj-$(CONFIG_X86_LOCAL_APIC) += perfctr-watchdog.o | 34 | obj-$(CONFIG_X86_LOCAL_APIC) += perfctr-watchdog.o |
| 36 | 35 | ||
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index bb9eb29a52dd..6f9d1f6063e9 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c | |||
| @@ -613,7 +613,7 @@ static void __cpuinit init_amd(struct cpuinfo_x86 *c) | |||
| 613 | #endif | 613 | #endif |
| 614 | 614 | ||
| 615 | /* As a rule processors have APIC timer running in deep C states */ | 615 | /* As a rule processors have APIC timer running in deep C states */ |
| 616 | if (c->x86 >= 0xf && !cpu_has_amd_erratum(amd_erratum_400)) | 616 | if (c->x86 > 0xf && !cpu_has_amd_erratum(amd_erratum_400)) |
| 617 | set_cpu_cap(c, X86_FEATURE_ARAT); | 617 | set_cpu_cap(c, X86_FEATURE_ARAT); |
| 618 | 618 | ||
| 619 | /* | 619 | /* |
| @@ -698,7 +698,7 @@ cpu_dev_register(amd_cpu_dev); | |||
| 698 | */ | 698 | */ |
| 699 | 699 | ||
| 700 | const int amd_erratum_400[] = | 700 | const int amd_erratum_400[] = |
| 701 | AMD_OSVW_ERRATUM(1, AMD_MODEL_RANGE(0x0f, 0x4, 0x2, 0xff, 0xf), | 701 | AMD_OSVW_ERRATUM(1, AMD_MODEL_RANGE(0xf, 0x41, 0x2, 0xff, 0xf), |
| 702 | AMD_MODEL_RANGE(0x10, 0x2, 0x1, 0xff, 0xf)); | 702 | AMD_MODEL_RANGE(0x10, 0x2, 0x1, 0xff, 0xf)); |
| 703 | EXPORT_SYMBOL_GPL(amd_erratum_400); | 703 | EXPORT_SYMBOL_GPL(amd_erratum_400); |
| 704 | 704 | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/Kconfig b/arch/x86/kernel/cpu/cpufreq/Kconfig deleted file mode 100644 index 870e6cc6ad28..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/Kconfig +++ /dev/null | |||
| @@ -1,266 +0,0 @@ | |||
| 1 | # | ||
| 2 | # CPU Frequency scaling | ||
| 3 | # | ||
| 4 | |||
| 5 | menu "CPU Frequency scaling" | ||
| 6 | |||
| 7 | source "drivers/cpufreq/Kconfig" | ||
| 8 | |||
| 9 | if CPU_FREQ | ||
| 10 | |||
| 11 | comment "CPUFreq processor drivers" | ||
| 12 | |||
| 13 | config X86_PCC_CPUFREQ | ||
| 14 | tristate "Processor Clocking Control interface driver" | ||
| 15 | depends on ACPI && ACPI_PROCESSOR | ||
| 16 | help | ||
| 17 | This driver adds support for the PCC interface. | ||
| 18 | |||
| 19 | For details, take a look at: | ||
| 20 | <file:Documentation/cpu-freq/pcc-cpufreq.txt>. | ||
| 21 | |||
| 22 | To compile this driver as a module, choose M here: the | ||
| 23 | module will be called pcc-cpufreq. | ||
| 24 | |||
| 25 | If in doubt, say N. | ||
| 26 | |||
| 27 | config X86_ACPI_CPUFREQ | ||
| 28 | tristate "ACPI Processor P-States driver" | ||
| 29 | select CPU_FREQ_TABLE | ||
| 30 | depends on ACPI_PROCESSOR | ||
| 31 | help | ||
| 32 | This driver adds a CPUFreq driver which utilizes the ACPI | ||
| 33 | Processor Performance States. | ||
| 34 | This driver also supports Intel Enhanced Speedstep. | ||
| 35 | |||
| 36 | To compile this driver as a module, choose M here: the | ||
| 37 | module will be called acpi-cpufreq. | ||
| 38 | |||
| 39 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
| 40 | |||
| 41 | If in doubt, say N. | ||
| 42 | |||
| 43 | config ELAN_CPUFREQ | ||
| 44 | tristate "AMD Elan SC400 and SC410" | ||
| 45 | select CPU_FREQ_TABLE | ||
| 46 | depends on X86_ELAN | ||
| 47 | ---help--- | ||
| 48 | This adds the CPUFreq driver for AMD Elan SC400 and SC410 | ||
| 49 | processors. | ||
| 50 | |||
| 51 | You need to specify the processor maximum speed as boot | ||
| 52 | parameter: elanfreq=maxspeed (in kHz) or as module | ||
| 53 | parameter "max_freq". | ||
| 54 | |||
| 55 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
| 56 | |||
| 57 | If in doubt, say N. | ||
| 58 | |||
| 59 | config SC520_CPUFREQ | ||
| 60 | tristate "AMD Elan SC520" | ||
| 61 | select CPU_FREQ_TABLE | ||
| 62 | depends on X86_ELAN | ||
| 63 | ---help--- | ||
| 64 | This adds the CPUFreq driver for AMD Elan SC520 processor. | ||
| 65 | |||
| 66 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
| 67 | |||
| 68 | If in doubt, say N. | ||
| 69 | |||
| 70 | |||
| 71 | config X86_POWERNOW_K6 | ||
| 72 | tristate "AMD Mobile K6-2/K6-3 PowerNow!" | ||
| 73 | select CPU_FREQ_TABLE | ||
| 74 | depends on X86_32 | ||
| 75 | help | ||
| 76 | This adds the CPUFreq driver for mobile AMD K6-2+ and mobile | ||
| 77 | AMD K6-3+ processors. | ||
| 78 | |||
| 79 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
| 80 | |||
| 81 | If in doubt, say N. | ||
| 82 | |||
| 83 | config X86_POWERNOW_K7 | ||
| 84 | tristate "AMD Mobile Athlon/Duron PowerNow!" | ||
| 85 | select CPU_FREQ_TABLE | ||
| 86 | depends on X86_32 | ||
| 87 | help | ||
| 88 | This adds the CPUFreq driver for mobile AMD K7 mobile processors. | ||
| 89 | |||
| 90 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
| 91 | |||
| 92 | If in doubt, say N. | ||
| 93 | |||
| 94 | config X86_POWERNOW_K7_ACPI | ||
| 95 | bool | ||
| 96 | depends on X86_POWERNOW_K7 && ACPI_PROCESSOR | ||
| 97 | depends on !(X86_POWERNOW_K7 = y && ACPI_PROCESSOR = m) | ||
| 98 | depends on X86_32 | ||
| 99 | default y | ||
| 100 | |||
| 101 | config X86_POWERNOW_K8 | ||
| 102 | tristate "AMD Opteron/Athlon64 PowerNow!" | ||
| 103 | select CPU_FREQ_TABLE | ||
| 104 | depends on ACPI && ACPI_PROCESSOR | ||
| 105 | help | ||
| 106 | This adds the CPUFreq driver for K8/K10 Opteron/Athlon64 processors. | ||
| 107 | |||
| 108 | To compile this driver as a module, choose M here: the | ||
| 109 | module will be called powernow-k8. | ||
| 110 | |||
| 111 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
| 112 | |||
| 113 | config X86_GX_SUSPMOD | ||
| 114 | tristate "Cyrix MediaGX/NatSemi Geode Suspend Modulation" | ||
| 115 | depends on X86_32 && PCI | ||
| 116 | help | ||
| 117 | This add the CPUFreq driver for NatSemi Geode processors which | ||
| 118 | support suspend modulation. | ||
| 119 | |||
| 120 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
| 121 | |||
| 122 | If in doubt, say N. | ||
| 123 | |||
| 124 | config X86_SPEEDSTEP_CENTRINO | ||
| 125 | tristate "Intel Enhanced SpeedStep (deprecated)" | ||
| 126 | select CPU_FREQ_TABLE | ||
| 127 | select X86_SPEEDSTEP_CENTRINO_TABLE if X86_32 | ||
| 128 | depends on X86_32 || (X86_64 && ACPI_PROCESSOR) | ||
| 129 | help | ||
| 130 | This is deprecated and this functionality is now merged into | ||
| 131 | acpi_cpufreq (X86_ACPI_CPUFREQ). Use that driver instead of | ||
| 132 | speedstep_centrino. | ||
| 133 | This adds the CPUFreq driver for Enhanced SpeedStep enabled | ||
| 134 | mobile CPUs. This means Intel Pentium M (Centrino) CPUs | ||
| 135 | or 64bit enabled Intel Xeons. | ||
| 136 | |||
| 137 | To compile this driver as a module, choose M here: the | ||
| 138 | module will be called speedstep-centrino. | ||
| 139 | |||
| 140 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
| 141 | |||
| 142 | If in doubt, say N. | ||
| 143 | |||
| 144 | config X86_SPEEDSTEP_CENTRINO_TABLE | ||
| 145 | bool "Built-in tables for Banias CPUs" | ||
| 146 | depends on X86_32 && X86_SPEEDSTEP_CENTRINO | ||
| 147 | default y | ||
| 148 | help | ||
| 149 | Use built-in tables for Banias CPUs if ACPI encoding | ||
| 150 | is not available. | ||
| 151 | |||
| 152 | If in doubt, say N. | ||
| 153 | |||
| 154 | config X86_SPEEDSTEP_ICH | ||
| 155 | tristate "Intel Speedstep on ICH-M chipsets (ioport interface)" | ||
| 156 | select CPU_FREQ_TABLE | ||
| 157 | depends on X86_32 | ||
| 158 | help | ||
| 159 | This adds the CPUFreq driver for certain mobile Intel Pentium III | ||
| 160 | (Coppermine), all mobile Intel Pentium III-M (Tualatin) and all | ||
| 161 | mobile Intel Pentium 4 P4-M on systems which have an Intel ICH2, | ||
| 162 | ICH3 or ICH4 southbridge. | ||
| 163 | |||
| 164 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
| 165 | |||
| 166 | If in doubt, say N. | ||
| 167 | |||
| 168 | config X86_SPEEDSTEP_SMI | ||
| 169 | tristate "Intel SpeedStep on 440BX/ZX/MX chipsets (SMI interface)" | ||
| 170 | select CPU_FREQ_TABLE | ||
| 171 | depends on X86_32 && EXPERIMENTAL | ||
| 172 | help | ||
| 173 | This adds the CPUFreq driver for certain mobile Intel Pentium III | ||
| 174 | (Coppermine), all mobile Intel Pentium III-M (Tualatin) | ||
| 175 | on systems which have an Intel 440BX/ZX/MX southbridge. | ||
| 176 | |||
| 177 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
| 178 | |||
| 179 | If in doubt, say N. | ||
| 180 | |||
| 181 | config X86_P4_CLOCKMOD | ||
| 182 | tristate "Intel Pentium 4 clock modulation" | ||
| 183 | select CPU_FREQ_TABLE | ||
| 184 | help | ||
| 185 | This adds the CPUFreq driver for Intel Pentium 4 / XEON | ||
| 186 | processors. When enabled it will lower CPU temperature by skipping | ||
| 187 | clocks. | ||
| 188 | |||
| 189 | This driver should be only used in exceptional | ||
| 190 | circumstances when very low power is needed because it causes severe | ||
| 191 | slowdowns and noticeable latencies. Normally Speedstep should be used | ||
| 192 | instead. | ||
| 193 | |||
| 194 | To compile this driver as a module, choose M here: the | ||
| 195 | module will be called p4-clockmod. | ||
| 196 | |||
| 197 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
| 198 | |||
| 199 | Unless you are absolutely sure say N. | ||
| 200 | |||
| 201 | config X86_CPUFREQ_NFORCE2 | ||
| 202 | tristate "nVidia nForce2 FSB changing" | ||
| 203 | depends on X86_32 && EXPERIMENTAL | ||
| 204 | help | ||
| 205 | This adds the CPUFreq driver for FSB changing on nVidia nForce2 | ||
| 206 | platforms. | ||
| 207 | |||
| 208 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
| 209 | |||
| 210 | If in doubt, say N. | ||
| 211 | |||
| 212 | config X86_LONGRUN | ||
| 213 | tristate "Transmeta LongRun" | ||
| 214 | depends on X86_32 | ||
| 215 | help | ||
| 216 | This adds the CPUFreq driver for Transmeta Crusoe and Efficeon processors | ||
| 217 | which support LongRun. | ||
| 218 | |||
| 219 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
| 220 | |||
| 221 | If in doubt, say N. | ||
| 222 | |||
| 223 | config X86_LONGHAUL | ||
| 224 | tristate "VIA Cyrix III Longhaul" | ||
| 225 | select CPU_FREQ_TABLE | ||
| 226 | depends on X86_32 && ACPI_PROCESSOR | ||
| 227 | help | ||
| 228 | This adds the CPUFreq driver for VIA Samuel/CyrixIII, | ||
| 229 | VIA Cyrix Samuel/C3, VIA Cyrix Ezra and VIA Cyrix Ezra-T | ||
| 230 | processors. | ||
| 231 | |||
| 232 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
| 233 | |||
| 234 | If in doubt, say N. | ||
| 235 | |||
| 236 | config X86_E_POWERSAVER | ||
| 237 | tristate "VIA C7 Enhanced PowerSaver (DANGEROUS)" | ||
| 238 | select CPU_FREQ_TABLE | ||
| 239 | depends on X86_32 && EXPERIMENTAL | ||
| 240 | help | ||
| 241 | This adds the CPUFreq driver for VIA C7 processors. However, this driver | ||
| 242 | does not have any safeguards to prevent operating the CPU out of spec | ||
| 243 | and is thus considered dangerous. Please use the regular ACPI cpufreq | ||
| 244 | driver, enabled by CONFIG_X86_ACPI_CPUFREQ. | ||
| 245 | |||
| 246 | If in doubt, say N. | ||
| 247 | |||
| 248 | comment "shared options" | ||
| 249 | |||
| 250 | config X86_SPEEDSTEP_LIB | ||
| 251 | tristate | ||
| 252 | default (X86_SPEEDSTEP_ICH || X86_SPEEDSTEP_SMI || X86_P4_CLOCKMOD) | ||
| 253 | |||
| 254 | config X86_SPEEDSTEP_RELAXED_CAP_CHECK | ||
| 255 | bool "Relaxed speedstep capability checks" | ||
| 256 | depends on X86_32 && (X86_SPEEDSTEP_SMI || X86_SPEEDSTEP_ICH) | ||
| 257 | help | ||
| 258 | Don't perform all checks for a speedstep capable system which would | ||
| 259 | normally be done. Some ancient or strange systems, though speedstep | ||
| 260 | capable, don't always indicate that they are speedstep capable. This | ||
| 261 | option lets the probing code bypass some of those checks if the | ||
| 262 | parameter "relaxed_check=1" is passed to the module. | ||
| 263 | |||
| 264 | endif # CPU_FREQ | ||
| 265 | |||
| 266 | endmenu | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/Makefile b/arch/x86/kernel/cpu/cpufreq/Makefile deleted file mode 100644 index bd54bf67e6fb..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/Makefile +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | # Link order matters. K8 is preferred to ACPI because of firmware bugs in early | ||
| 2 | # K8 systems. ACPI is preferred to all other hardware-specific drivers. | ||
| 3 | # speedstep-* is preferred over p4-clockmod. | ||
| 4 | |||
| 5 | obj-$(CONFIG_X86_POWERNOW_K8) += powernow-k8.o mperf.o | ||
| 6 | obj-$(CONFIG_X86_ACPI_CPUFREQ) += acpi-cpufreq.o mperf.o | ||
| 7 | obj-$(CONFIG_X86_PCC_CPUFREQ) += pcc-cpufreq.o | ||
| 8 | obj-$(CONFIG_X86_POWERNOW_K6) += powernow-k6.o | ||
| 9 | obj-$(CONFIG_X86_POWERNOW_K7) += powernow-k7.o | ||
| 10 | obj-$(CONFIG_X86_LONGHAUL) += longhaul.o | ||
| 11 | obj-$(CONFIG_X86_E_POWERSAVER) += e_powersaver.o | ||
| 12 | obj-$(CONFIG_ELAN_CPUFREQ) += elanfreq.o | ||
| 13 | obj-$(CONFIG_SC520_CPUFREQ) += sc520_freq.o | ||
| 14 | obj-$(CONFIG_X86_LONGRUN) += longrun.o | ||
| 15 | obj-$(CONFIG_X86_GX_SUSPMOD) += gx-suspmod.o | ||
| 16 | obj-$(CONFIG_X86_SPEEDSTEP_ICH) += speedstep-ich.o | ||
| 17 | obj-$(CONFIG_X86_SPEEDSTEP_LIB) += speedstep-lib.o | ||
| 18 | obj-$(CONFIG_X86_SPEEDSTEP_SMI) += speedstep-smi.o | ||
| 19 | obj-$(CONFIG_X86_SPEEDSTEP_CENTRINO) += speedstep-centrino.o | ||
| 20 | obj-$(CONFIG_X86_P4_CLOCKMOD) += p4-clockmod.o | ||
| 21 | obj-$(CONFIG_X86_CPUFREQ_NFORCE2) += cpufreq-nforce2.o | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c b/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c deleted file mode 100644 index a2baafb2fe6d..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c +++ /dev/null | |||
| @@ -1,776 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * acpi-cpufreq.c - ACPI Processor P-States Driver | ||
| 3 | * | ||
| 4 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> | ||
| 5 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | ||
| 6 | * Copyright (C) 2002 - 2004 Dominik Brodowski <linux@brodo.de> | ||
| 7 | * Copyright (C) 2006 Denis Sadykov <denis.m.sadykov@intel.com> | ||
| 8 | * | ||
| 9 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 10 | * | ||
| 11 | * This program is free software; you can redistribute it and/or modify | ||
| 12 | * it under the terms of the GNU General Public License as published by | ||
| 13 | * the Free Software Foundation; either version 2 of the License, or (at | ||
| 14 | * your option) any later version. | ||
| 15 | * | ||
| 16 | * This program is distributed in the hope that it will be useful, but | ||
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 19 | * General Public License for more details. | ||
| 20 | * | ||
| 21 | * You should have received a copy of the GNU General Public License along | ||
| 22 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
| 23 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | ||
| 24 | * | ||
| 25 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 26 | */ | ||
| 27 | |||
| 28 | #include <linux/kernel.h> | ||
| 29 | #include <linux/module.h> | ||
| 30 | #include <linux/init.h> | ||
| 31 | #include <linux/smp.h> | ||
| 32 | #include <linux/sched.h> | ||
| 33 | #include <linux/cpufreq.h> | ||
| 34 | #include <linux/compiler.h> | ||
| 35 | #include <linux/dmi.h> | ||
| 36 | #include <linux/slab.h> | ||
| 37 | |||
| 38 | #include <linux/acpi.h> | ||
| 39 | #include <linux/io.h> | ||
| 40 | #include <linux/delay.h> | ||
| 41 | #include <linux/uaccess.h> | ||
| 42 | |||
| 43 | #include <acpi/processor.h> | ||
| 44 | |||
| 45 | #include <asm/msr.h> | ||
| 46 | #include <asm/processor.h> | ||
| 47 | #include <asm/cpufeature.h> | ||
| 48 | #include "mperf.h" | ||
| 49 | |||
| 50 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
| 51 | "acpi-cpufreq", msg) | ||
| 52 | |||
| 53 | MODULE_AUTHOR("Paul Diefenbaugh, Dominik Brodowski"); | ||
| 54 | MODULE_DESCRIPTION("ACPI Processor P-States Driver"); | ||
| 55 | MODULE_LICENSE("GPL"); | ||
| 56 | |||
| 57 | enum { | ||
| 58 | UNDEFINED_CAPABLE = 0, | ||
| 59 | SYSTEM_INTEL_MSR_CAPABLE, | ||
| 60 | SYSTEM_IO_CAPABLE, | ||
| 61 | }; | ||
| 62 | |||
| 63 | #define INTEL_MSR_RANGE (0xffff) | ||
| 64 | |||
| 65 | struct acpi_cpufreq_data { | ||
| 66 | struct acpi_processor_performance *acpi_data; | ||
| 67 | struct cpufreq_frequency_table *freq_table; | ||
| 68 | unsigned int resume; | ||
| 69 | unsigned int cpu_feature; | ||
| 70 | }; | ||
| 71 | |||
| 72 | static DEFINE_PER_CPU(struct acpi_cpufreq_data *, acfreq_data); | ||
| 73 | |||
| 74 | /* acpi_perf_data is a pointer to percpu data. */ | ||
| 75 | static struct acpi_processor_performance __percpu *acpi_perf_data; | ||
| 76 | |||
| 77 | static struct cpufreq_driver acpi_cpufreq_driver; | ||
| 78 | |||
| 79 | static unsigned int acpi_pstate_strict; | ||
| 80 | |||
| 81 | static int check_est_cpu(unsigned int cpuid) | ||
| 82 | { | ||
| 83 | struct cpuinfo_x86 *cpu = &cpu_data(cpuid); | ||
| 84 | |||
| 85 | return cpu_has(cpu, X86_FEATURE_EST); | ||
| 86 | } | ||
| 87 | |||
| 88 | static unsigned extract_io(u32 value, struct acpi_cpufreq_data *data) | ||
| 89 | { | ||
| 90 | struct acpi_processor_performance *perf; | ||
| 91 | int i; | ||
| 92 | |||
| 93 | perf = data->acpi_data; | ||
| 94 | |||
| 95 | for (i = 0; i < perf->state_count; i++) { | ||
| 96 | if (value == perf->states[i].status) | ||
| 97 | return data->freq_table[i].frequency; | ||
| 98 | } | ||
| 99 | return 0; | ||
| 100 | } | ||
| 101 | |||
| 102 | static unsigned extract_msr(u32 msr, struct acpi_cpufreq_data *data) | ||
| 103 | { | ||
| 104 | int i; | ||
| 105 | struct acpi_processor_performance *perf; | ||
| 106 | |||
| 107 | msr &= INTEL_MSR_RANGE; | ||
| 108 | perf = data->acpi_data; | ||
| 109 | |||
| 110 | for (i = 0; data->freq_table[i].frequency != CPUFREQ_TABLE_END; i++) { | ||
| 111 | if (msr == perf->states[data->freq_table[i].index].status) | ||
| 112 | return data->freq_table[i].frequency; | ||
| 113 | } | ||
| 114 | return data->freq_table[0].frequency; | ||
| 115 | } | ||
| 116 | |||
| 117 | static unsigned extract_freq(u32 val, struct acpi_cpufreq_data *data) | ||
| 118 | { | ||
| 119 | switch (data->cpu_feature) { | ||
| 120 | case SYSTEM_INTEL_MSR_CAPABLE: | ||
| 121 | return extract_msr(val, data); | ||
| 122 | case SYSTEM_IO_CAPABLE: | ||
| 123 | return extract_io(val, data); | ||
| 124 | default: | ||
| 125 | return 0; | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 129 | struct msr_addr { | ||
| 130 | u32 reg; | ||
| 131 | }; | ||
| 132 | |||
| 133 | struct io_addr { | ||
| 134 | u16 port; | ||
| 135 | u8 bit_width; | ||
| 136 | }; | ||
| 137 | |||
| 138 | struct drv_cmd { | ||
| 139 | unsigned int type; | ||
| 140 | const struct cpumask *mask; | ||
| 141 | union { | ||
| 142 | struct msr_addr msr; | ||
| 143 | struct io_addr io; | ||
| 144 | } addr; | ||
| 145 | u32 val; | ||
| 146 | }; | ||
| 147 | |||
| 148 | /* Called via smp_call_function_single(), on the target CPU */ | ||
| 149 | static void do_drv_read(void *_cmd) | ||
| 150 | { | ||
| 151 | struct drv_cmd *cmd = _cmd; | ||
| 152 | u32 h; | ||
| 153 | |||
| 154 | switch (cmd->type) { | ||
| 155 | case SYSTEM_INTEL_MSR_CAPABLE: | ||
| 156 | rdmsr(cmd->addr.msr.reg, cmd->val, h); | ||
| 157 | break; | ||
| 158 | case SYSTEM_IO_CAPABLE: | ||
| 159 | acpi_os_read_port((acpi_io_address)cmd->addr.io.port, | ||
| 160 | &cmd->val, | ||
| 161 | (u32)cmd->addr.io.bit_width); | ||
| 162 | break; | ||
| 163 | default: | ||
| 164 | break; | ||
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 | /* Called via smp_call_function_many(), on the target CPUs */ | ||
| 169 | static void do_drv_write(void *_cmd) | ||
| 170 | { | ||
| 171 | struct drv_cmd *cmd = _cmd; | ||
| 172 | u32 lo, hi; | ||
| 173 | |||
| 174 | switch (cmd->type) { | ||
| 175 | case SYSTEM_INTEL_MSR_CAPABLE: | ||
| 176 | rdmsr(cmd->addr.msr.reg, lo, hi); | ||
| 177 | lo = (lo & ~INTEL_MSR_RANGE) | (cmd->val & INTEL_MSR_RANGE); | ||
| 178 | wrmsr(cmd->addr.msr.reg, lo, hi); | ||
| 179 | break; | ||
| 180 | case SYSTEM_IO_CAPABLE: | ||
| 181 | acpi_os_write_port((acpi_io_address)cmd->addr.io.port, | ||
| 182 | cmd->val, | ||
| 183 | (u32)cmd->addr.io.bit_width); | ||
| 184 | break; | ||
| 185 | default: | ||
| 186 | break; | ||
| 187 | } | ||
| 188 | } | ||
| 189 | |||
| 190 | static void drv_read(struct drv_cmd *cmd) | ||
| 191 | { | ||
| 192 | int err; | ||
| 193 | cmd->val = 0; | ||
| 194 | |||
| 195 | err = smp_call_function_any(cmd->mask, do_drv_read, cmd, 1); | ||
| 196 | WARN_ON_ONCE(err); /* smp_call_function_any() was buggy? */ | ||
| 197 | } | ||
| 198 | |||
| 199 | static void drv_write(struct drv_cmd *cmd) | ||
| 200 | { | ||
| 201 | int this_cpu; | ||
| 202 | |||
| 203 | this_cpu = get_cpu(); | ||
| 204 | if (cpumask_test_cpu(this_cpu, cmd->mask)) | ||
| 205 | do_drv_write(cmd); | ||
| 206 | smp_call_function_many(cmd->mask, do_drv_write, cmd, 1); | ||
| 207 | put_cpu(); | ||
| 208 | } | ||
| 209 | |||
| 210 | static u32 get_cur_val(const struct cpumask *mask) | ||
| 211 | { | ||
| 212 | struct acpi_processor_performance *perf; | ||
| 213 | struct drv_cmd cmd; | ||
| 214 | |||
| 215 | if (unlikely(cpumask_empty(mask))) | ||
| 216 | return 0; | ||
| 217 | |||
| 218 | switch (per_cpu(acfreq_data, cpumask_first(mask))->cpu_feature) { | ||
| 219 | case SYSTEM_INTEL_MSR_CAPABLE: | ||
| 220 | cmd.type = SYSTEM_INTEL_MSR_CAPABLE; | ||
| 221 | cmd.addr.msr.reg = MSR_IA32_PERF_STATUS; | ||
| 222 | break; | ||
| 223 | case SYSTEM_IO_CAPABLE: | ||
| 224 | cmd.type = SYSTEM_IO_CAPABLE; | ||
| 225 | perf = per_cpu(acfreq_data, cpumask_first(mask))->acpi_data; | ||
| 226 | cmd.addr.io.port = perf->control_register.address; | ||
| 227 | cmd.addr.io.bit_width = perf->control_register.bit_width; | ||
| 228 | break; | ||
| 229 | default: | ||
| 230 | return 0; | ||
| 231 | } | ||
| 232 | |||
| 233 | cmd.mask = mask; | ||
| 234 | drv_read(&cmd); | ||
| 235 | |||
| 236 | dprintk("get_cur_val = %u\n", cmd.val); | ||
| 237 | |||
| 238 | return cmd.val; | ||
| 239 | } | ||
| 240 | |||
| 241 | static unsigned int get_cur_freq_on_cpu(unsigned int cpu) | ||
| 242 | { | ||
| 243 | struct acpi_cpufreq_data *data = per_cpu(acfreq_data, cpu); | ||
| 244 | unsigned int freq; | ||
| 245 | unsigned int cached_freq; | ||
| 246 | |||
| 247 | dprintk("get_cur_freq_on_cpu (%d)\n", cpu); | ||
| 248 | |||
| 249 | if (unlikely(data == NULL || | ||
| 250 | data->acpi_data == NULL || data->freq_table == NULL)) { | ||
| 251 | return 0; | ||
| 252 | } | ||
| 253 | |||
| 254 | cached_freq = data->freq_table[data->acpi_data->state].frequency; | ||
| 255 | freq = extract_freq(get_cur_val(cpumask_of(cpu)), data); | ||
| 256 | if (freq != cached_freq) { | ||
| 257 | /* | ||
| 258 | * The dreaded BIOS frequency change behind our back. | ||
| 259 | * Force set the frequency on next target call. | ||
| 260 | */ | ||
| 261 | data->resume = 1; | ||
| 262 | } | ||
| 263 | |||
| 264 | dprintk("cur freq = %u\n", freq); | ||
| 265 | |||
| 266 | return freq; | ||
| 267 | } | ||
| 268 | |||
| 269 | static unsigned int check_freqs(const struct cpumask *mask, unsigned int freq, | ||
| 270 | struct acpi_cpufreq_data *data) | ||
| 271 | { | ||
| 272 | unsigned int cur_freq; | ||
| 273 | unsigned int i; | ||
| 274 | |||
| 275 | for (i = 0; i < 100; i++) { | ||
| 276 | cur_freq = extract_freq(get_cur_val(mask), data); | ||
| 277 | if (cur_freq == freq) | ||
| 278 | return 1; | ||
| 279 | udelay(10); | ||
| 280 | } | ||
| 281 | return 0; | ||
| 282 | } | ||
| 283 | |||
| 284 | static int acpi_cpufreq_target(struct cpufreq_policy *policy, | ||
| 285 | unsigned int target_freq, unsigned int relation) | ||
| 286 | { | ||
| 287 | struct acpi_cpufreq_data *data = per_cpu(acfreq_data, policy->cpu); | ||
| 288 | struct acpi_processor_performance *perf; | ||
| 289 | struct cpufreq_freqs freqs; | ||
| 290 | struct drv_cmd cmd; | ||
| 291 | unsigned int next_state = 0; /* Index into freq_table */ | ||
| 292 | unsigned int next_perf_state = 0; /* Index into perf table */ | ||
| 293 | unsigned int i; | ||
| 294 | int result = 0; | ||
| 295 | |||
| 296 | dprintk("acpi_cpufreq_target %d (%d)\n", target_freq, policy->cpu); | ||
| 297 | |||
| 298 | if (unlikely(data == NULL || | ||
| 299 | data->acpi_data == NULL || data->freq_table == NULL)) { | ||
| 300 | return -ENODEV; | ||
| 301 | } | ||
| 302 | |||
| 303 | perf = data->acpi_data; | ||
| 304 | result = cpufreq_frequency_table_target(policy, | ||
| 305 | data->freq_table, | ||
| 306 | target_freq, | ||
| 307 | relation, &next_state); | ||
| 308 | if (unlikely(result)) { | ||
| 309 | result = -ENODEV; | ||
| 310 | goto out; | ||
| 311 | } | ||
| 312 | |||
| 313 | next_perf_state = data->freq_table[next_state].index; | ||
| 314 | if (perf->state == next_perf_state) { | ||
| 315 | if (unlikely(data->resume)) { | ||
| 316 | dprintk("Called after resume, resetting to P%d\n", | ||
| 317 | next_perf_state); | ||
| 318 | data->resume = 0; | ||
| 319 | } else { | ||
| 320 | dprintk("Already at target state (P%d)\n", | ||
| 321 | next_perf_state); | ||
| 322 | goto out; | ||
| 323 | } | ||
| 324 | } | ||
| 325 | |||
| 326 | switch (data->cpu_feature) { | ||
| 327 | case SYSTEM_INTEL_MSR_CAPABLE: | ||
| 328 | cmd.type = SYSTEM_INTEL_MSR_CAPABLE; | ||
| 329 | cmd.addr.msr.reg = MSR_IA32_PERF_CTL; | ||
| 330 | cmd.val = (u32) perf->states[next_perf_state].control; | ||
| 331 | break; | ||
| 332 | case SYSTEM_IO_CAPABLE: | ||
| 333 | cmd.type = SYSTEM_IO_CAPABLE; | ||
| 334 | cmd.addr.io.port = perf->control_register.address; | ||
| 335 | cmd.addr.io.bit_width = perf->control_register.bit_width; | ||
| 336 | cmd.val = (u32) perf->states[next_perf_state].control; | ||
| 337 | break; | ||
| 338 | default: | ||
| 339 | result = -ENODEV; | ||
| 340 | goto out; | ||
| 341 | } | ||
| 342 | |||
| 343 | /* cpufreq holds the hotplug lock, so we are safe from here on */ | ||
| 344 | if (policy->shared_type != CPUFREQ_SHARED_TYPE_ANY) | ||
| 345 | cmd.mask = policy->cpus; | ||
| 346 | else | ||
| 347 | cmd.mask = cpumask_of(policy->cpu); | ||
| 348 | |||
| 349 | freqs.old = perf->states[perf->state].core_frequency * 1000; | ||
| 350 | freqs.new = data->freq_table[next_state].frequency; | ||
| 351 | for_each_cpu(i, policy->cpus) { | ||
| 352 | freqs.cpu = i; | ||
| 353 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
| 354 | } | ||
| 355 | |||
| 356 | drv_write(&cmd); | ||
| 357 | |||
| 358 | if (acpi_pstate_strict) { | ||
| 359 | if (!check_freqs(cmd.mask, freqs.new, data)) { | ||
| 360 | dprintk("acpi_cpufreq_target failed (%d)\n", | ||
| 361 | policy->cpu); | ||
| 362 | result = -EAGAIN; | ||
| 363 | goto out; | ||
| 364 | } | ||
| 365 | } | ||
| 366 | |||
| 367 | for_each_cpu(i, policy->cpus) { | ||
| 368 | freqs.cpu = i; | ||
| 369 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 370 | } | ||
| 371 | perf->state = next_perf_state; | ||
| 372 | |||
| 373 | out: | ||
| 374 | return result; | ||
| 375 | } | ||
| 376 | |||
| 377 | static int acpi_cpufreq_verify(struct cpufreq_policy *policy) | ||
| 378 | { | ||
| 379 | struct acpi_cpufreq_data *data = per_cpu(acfreq_data, policy->cpu); | ||
| 380 | |||
| 381 | dprintk("acpi_cpufreq_verify\n"); | ||
| 382 | |||
| 383 | return cpufreq_frequency_table_verify(policy, data->freq_table); | ||
| 384 | } | ||
| 385 | |||
| 386 | static unsigned long | ||
| 387 | acpi_cpufreq_guess_freq(struct acpi_cpufreq_data *data, unsigned int cpu) | ||
| 388 | { | ||
| 389 | struct acpi_processor_performance *perf = data->acpi_data; | ||
| 390 | |||
| 391 | if (cpu_khz) { | ||
| 392 | /* search the closest match to cpu_khz */ | ||
| 393 | unsigned int i; | ||
| 394 | unsigned long freq; | ||
| 395 | unsigned long freqn = perf->states[0].core_frequency * 1000; | ||
| 396 | |||
| 397 | for (i = 0; i < (perf->state_count-1); i++) { | ||
| 398 | freq = freqn; | ||
| 399 | freqn = perf->states[i+1].core_frequency * 1000; | ||
| 400 | if ((2 * cpu_khz) > (freqn + freq)) { | ||
| 401 | perf->state = i; | ||
| 402 | return freq; | ||
| 403 | } | ||
| 404 | } | ||
| 405 | perf->state = perf->state_count-1; | ||
| 406 | return freqn; | ||
| 407 | } else { | ||
| 408 | /* assume CPU is at P0... */ | ||
| 409 | perf->state = 0; | ||
| 410 | return perf->states[0].core_frequency * 1000; | ||
| 411 | } | ||
| 412 | } | ||
| 413 | |||
| 414 | static void free_acpi_perf_data(void) | ||
| 415 | { | ||
| 416 | unsigned int i; | ||
| 417 | |||
| 418 | /* Freeing a NULL pointer is OK, and alloc_percpu zeroes. */ | ||
| 419 | for_each_possible_cpu(i) | ||
| 420 | free_cpumask_var(per_cpu_ptr(acpi_perf_data, i) | ||
| 421 | ->shared_cpu_map); | ||
| 422 | free_percpu(acpi_perf_data); | ||
| 423 | } | ||
| 424 | |||
| 425 | /* | ||
| 426 | * acpi_cpufreq_early_init - initialize ACPI P-States library | ||
| 427 | * | ||
| 428 | * Initialize the ACPI P-States library (drivers/acpi/processor_perflib.c) | ||
| 429 | * in order to determine correct frequency and voltage pairings. We can | ||
| 430 | * do _PDC and _PSD and find out the processor dependency for the | ||
| 431 | * actual init that will happen later... | ||
| 432 | */ | ||
| 433 | static int __init acpi_cpufreq_early_init(void) | ||
| 434 | { | ||
| 435 | unsigned int i; | ||
| 436 | dprintk("acpi_cpufreq_early_init\n"); | ||
| 437 | |||
| 438 | acpi_perf_data = alloc_percpu(struct acpi_processor_performance); | ||
| 439 | if (!acpi_perf_data) { | ||
| 440 | dprintk("Memory allocation error for acpi_perf_data.\n"); | ||
| 441 | return -ENOMEM; | ||
| 442 | } | ||
| 443 | for_each_possible_cpu(i) { | ||
| 444 | if (!zalloc_cpumask_var_node( | ||
| 445 | &per_cpu_ptr(acpi_perf_data, i)->shared_cpu_map, | ||
| 446 | GFP_KERNEL, cpu_to_node(i))) { | ||
| 447 | |||
| 448 | /* Freeing a NULL pointer is OK: alloc_percpu zeroes. */ | ||
| 449 | free_acpi_perf_data(); | ||
| 450 | return -ENOMEM; | ||
| 451 | } | ||
| 452 | } | ||
| 453 | |||
| 454 | /* Do initialization in ACPI core */ | ||
| 455 | acpi_processor_preregister_performance(acpi_perf_data); | ||
| 456 | return 0; | ||
| 457 | } | ||
| 458 | |||
| 459 | #ifdef CONFIG_SMP | ||
| 460 | /* | ||
| 461 | * Some BIOSes do SW_ANY coordination internally, either set it up in hw | ||
| 462 | * or do it in BIOS firmware and won't inform about it to OS. If not | ||
| 463 | * detected, this has a side effect of making CPU run at a different speed | ||
| 464 | * than OS intended it to run at. Detect it and handle it cleanly. | ||
| 465 | */ | ||
| 466 | static int bios_with_sw_any_bug; | ||
| 467 | |||
| 468 | static int sw_any_bug_found(const struct dmi_system_id *d) | ||
| 469 | { | ||
| 470 | bios_with_sw_any_bug = 1; | ||
| 471 | return 0; | ||
| 472 | } | ||
| 473 | |||
| 474 | static const struct dmi_system_id sw_any_bug_dmi_table[] = { | ||
| 475 | { | ||
| 476 | .callback = sw_any_bug_found, | ||
| 477 | .ident = "Supermicro Server X6DLP", | ||
| 478 | .matches = { | ||
| 479 | DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"), | ||
| 480 | DMI_MATCH(DMI_BIOS_VERSION, "080010"), | ||
| 481 | DMI_MATCH(DMI_PRODUCT_NAME, "X6DLP"), | ||
| 482 | }, | ||
| 483 | }, | ||
| 484 | { } | ||
| 485 | }; | ||
| 486 | |||
| 487 | static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c) | ||
| 488 | { | ||
| 489 | /* Intel Xeon Processor 7100 Series Specification Update | ||
| 490 | * http://www.intel.com/Assets/PDF/specupdate/314554.pdf | ||
| 491 | * AL30: A Machine Check Exception (MCE) Occurring during an | ||
| 492 | * Enhanced Intel SpeedStep Technology Ratio Change May Cause | ||
| 493 | * Both Processor Cores to Lock Up. */ | ||
| 494 | if (c->x86_vendor == X86_VENDOR_INTEL) { | ||
| 495 | if ((c->x86 == 15) && | ||
| 496 | (c->x86_model == 6) && | ||
| 497 | (c->x86_mask == 8)) { | ||
| 498 | printk(KERN_INFO "acpi-cpufreq: Intel(R) " | ||
| 499 | "Xeon(R) 7100 Errata AL30, processors may " | ||
| 500 | "lock up on frequency changes: disabling " | ||
| 501 | "acpi-cpufreq.\n"); | ||
| 502 | return -ENODEV; | ||
| 503 | } | ||
| 504 | } | ||
| 505 | return 0; | ||
| 506 | } | ||
| 507 | #endif | ||
| 508 | |||
| 509 | static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) | ||
| 510 | { | ||
| 511 | unsigned int i; | ||
| 512 | unsigned int valid_states = 0; | ||
| 513 | unsigned int cpu = policy->cpu; | ||
| 514 | struct acpi_cpufreq_data *data; | ||
| 515 | unsigned int result = 0; | ||
| 516 | struct cpuinfo_x86 *c = &cpu_data(policy->cpu); | ||
| 517 | struct acpi_processor_performance *perf; | ||
| 518 | #ifdef CONFIG_SMP | ||
| 519 | static int blacklisted; | ||
| 520 | #endif | ||
| 521 | |||
| 522 | dprintk("acpi_cpufreq_cpu_init\n"); | ||
| 523 | |||
| 524 | #ifdef CONFIG_SMP | ||
| 525 | if (blacklisted) | ||
| 526 | return blacklisted; | ||
| 527 | blacklisted = acpi_cpufreq_blacklist(c); | ||
| 528 | if (blacklisted) | ||
| 529 | return blacklisted; | ||
| 530 | #endif | ||
| 531 | |||
| 532 | data = kzalloc(sizeof(struct acpi_cpufreq_data), GFP_KERNEL); | ||
| 533 | if (!data) | ||
| 534 | return -ENOMEM; | ||
| 535 | |||
| 536 | data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu); | ||
| 537 | per_cpu(acfreq_data, cpu) = data; | ||
| 538 | |||
| 539 | if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) | ||
| 540 | acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS; | ||
| 541 | |||
| 542 | result = acpi_processor_register_performance(data->acpi_data, cpu); | ||
| 543 | if (result) | ||
| 544 | goto err_free; | ||
| 545 | |||
| 546 | perf = data->acpi_data; | ||
| 547 | policy->shared_type = perf->shared_type; | ||
| 548 | |||
| 549 | /* | ||
| 550 | * Will let policy->cpus know about dependency only when software | ||
| 551 | * coordination is required. | ||
| 552 | */ | ||
| 553 | if (policy->shared_type == CPUFREQ_SHARED_TYPE_ALL || | ||
| 554 | policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) { | ||
| 555 | cpumask_copy(policy->cpus, perf->shared_cpu_map); | ||
| 556 | } | ||
| 557 | cpumask_copy(policy->related_cpus, perf->shared_cpu_map); | ||
| 558 | |||
| 559 | #ifdef CONFIG_SMP | ||
| 560 | dmi_check_system(sw_any_bug_dmi_table); | ||
| 561 | if (bios_with_sw_any_bug && cpumask_weight(policy->cpus) == 1) { | ||
| 562 | policy->shared_type = CPUFREQ_SHARED_TYPE_ALL; | ||
| 563 | cpumask_copy(policy->cpus, cpu_core_mask(cpu)); | ||
| 564 | } | ||
| 565 | #endif | ||
| 566 | |||
| 567 | /* capability check */ | ||
| 568 | if (perf->state_count <= 1) { | ||
| 569 | dprintk("No P-States\n"); | ||
| 570 | result = -ENODEV; | ||
| 571 | goto err_unreg; | ||
| 572 | } | ||
| 573 | |||
| 574 | if (perf->control_register.space_id != perf->status_register.space_id) { | ||
| 575 | result = -ENODEV; | ||
| 576 | goto err_unreg; | ||
| 577 | } | ||
| 578 | |||
| 579 | switch (perf->control_register.space_id) { | ||
| 580 | case ACPI_ADR_SPACE_SYSTEM_IO: | ||
| 581 | dprintk("SYSTEM IO addr space\n"); | ||
| 582 | data->cpu_feature = SYSTEM_IO_CAPABLE; | ||
| 583 | break; | ||
| 584 | case ACPI_ADR_SPACE_FIXED_HARDWARE: | ||
| 585 | dprintk("HARDWARE addr space\n"); | ||
| 586 | if (!check_est_cpu(cpu)) { | ||
| 587 | result = -ENODEV; | ||
| 588 | goto err_unreg; | ||
| 589 | } | ||
| 590 | data->cpu_feature = SYSTEM_INTEL_MSR_CAPABLE; | ||
| 591 | break; | ||
| 592 | default: | ||
| 593 | dprintk("Unknown addr space %d\n", | ||
| 594 | (u32) (perf->control_register.space_id)); | ||
| 595 | result = -ENODEV; | ||
| 596 | goto err_unreg; | ||
| 597 | } | ||
| 598 | |||
| 599 | data->freq_table = kmalloc(sizeof(struct cpufreq_frequency_table) * | ||
| 600 | (perf->state_count+1), GFP_KERNEL); | ||
| 601 | if (!data->freq_table) { | ||
| 602 | result = -ENOMEM; | ||
| 603 | goto err_unreg; | ||
| 604 | } | ||
| 605 | |||
| 606 | /* detect transition latency */ | ||
| 607 | policy->cpuinfo.transition_latency = 0; | ||
| 608 | for (i = 0; i < perf->state_count; i++) { | ||
| 609 | if ((perf->states[i].transition_latency * 1000) > | ||
| 610 | policy->cpuinfo.transition_latency) | ||
| 611 | policy->cpuinfo.transition_latency = | ||
| 612 | perf->states[i].transition_latency * 1000; | ||
| 613 | } | ||
| 614 | |||
| 615 | /* Check for high latency (>20uS) from buggy BIOSes, like on T42 */ | ||
| 616 | if (perf->control_register.space_id == ACPI_ADR_SPACE_FIXED_HARDWARE && | ||
| 617 | policy->cpuinfo.transition_latency > 20 * 1000) { | ||
| 618 | policy->cpuinfo.transition_latency = 20 * 1000; | ||
| 619 | printk_once(KERN_INFO | ||
| 620 | "P-state transition latency capped at 20 uS\n"); | ||
| 621 | } | ||
| 622 | |||
| 623 | /* table init */ | ||
| 624 | for (i = 0; i < perf->state_count; i++) { | ||
| 625 | if (i > 0 && perf->states[i].core_frequency >= | ||
| 626 | data->freq_table[valid_states-1].frequency / 1000) | ||
| 627 | continue; | ||
| 628 | |||
| 629 | data->freq_table[valid_states].index = i; | ||
| 630 | data->freq_table[valid_states].frequency = | ||
| 631 | perf->states[i].core_frequency * 1000; | ||
| 632 | valid_states++; | ||
| 633 | } | ||
| 634 | data->freq_table[valid_states].frequency = CPUFREQ_TABLE_END; | ||
| 635 | perf->state = 0; | ||
| 636 | |||
| 637 | result = cpufreq_frequency_table_cpuinfo(policy, data->freq_table); | ||
| 638 | if (result) | ||
| 639 | goto err_freqfree; | ||
| 640 | |||
| 641 | if (perf->states[0].core_frequency * 1000 != policy->cpuinfo.max_freq) | ||
| 642 | printk(KERN_WARNING FW_WARN "P-state 0 is not max freq\n"); | ||
| 643 | |||
| 644 | switch (perf->control_register.space_id) { | ||
| 645 | case ACPI_ADR_SPACE_SYSTEM_IO: | ||
| 646 | /* Current speed is unknown and not detectable by IO port */ | ||
| 647 | policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu); | ||
| 648 | break; | ||
| 649 | case ACPI_ADR_SPACE_FIXED_HARDWARE: | ||
| 650 | acpi_cpufreq_driver.get = get_cur_freq_on_cpu; | ||
| 651 | policy->cur = get_cur_freq_on_cpu(cpu); | ||
| 652 | break; | ||
| 653 | default: | ||
| 654 | break; | ||
| 655 | } | ||
| 656 | |||
| 657 | /* notify BIOS that we exist */ | ||
| 658 | acpi_processor_notify_smm(THIS_MODULE); | ||
| 659 | |||
| 660 | /* Check for APERF/MPERF support in hardware */ | ||
| 661 | if (cpu_has(c, X86_FEATURE_APERFMPERF)) | ||
| 662 | acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf; | ||
| 663 | |||
| 664 | dprintk("CPU%u - ACPI performance management activated.\n", cpu); | ||
| 665 | for (i = 0; i < perf->state_count; i++) | ||
| 666 | dprintk(" %cP%d: %d MHz, %d mW, %d uS\n", | ||
| 667 | (i == perf->state ? '*' : ' '), i, | ||
| 668 | (u32) perf->states[i].core_frequency, | ||
| 669 | (u32) perf->states[i].power, | ||
| 670 | (u32) perf->states[i].transition_latency); | ||
| 671 | |||
| 672 | cpufreq_frequency_table_get_attr(data->freq_table, policy->cpu); | ||
| 673 | |||
| 674 | /* | ||
| 675 | * the first call to ->target() should result in us actually | ||
| 676 | * writing something to the appropriate registers. | ||
| 677 | */ | ||
| 678 | data->resume = 1; | ||
| 679 | |||
| 680 | return result; | ||
| 681 | |||
| 682 | err_freqfree: | ||
| 683 | kfree(data->freq_table); | ||
| 684 | err_unreg: | ||
| 685 | acpi_processor_unregister_performance(perf, cpu); | ||
| 686 | err_free: | ||
| 687 | kfree(data); | ||
| 688 | per_cpu(acfreq_data, cpu) = NULL; | ||
| 689 | |||
| 690 | return result; | ||
| 691 | } | ||
| 692 | |||
| 693 | static int acpi_cpufreq_cpu_exit(struct cpufreq_policy *policy) | ||
| 694 | { | ||
| 695 | struct acpi_cpufreq_data *data = per_cpu(acfreq_data, policy->cpu); | ||
| 696 | |||
| 697 | dprintk("acpi_cpufreq_cpu_exit\n"); | ||
| 698 | |||
| 699 | if (data) { | ||
| 700 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
| 701 | per_cpu(acfreq_data, policy->cpu) = NULL; | ||
| 702 | acpi_processor_unregister_performance(data->acpi_data, | ||
| 703 | policy->cpu); | ||
| 704 | kfree(data->freq_table); | ||
| 705 | kfree(data); | ||
| 706 | } | ||
| 707 | |||
| 708 | return 0; | ||
| 709 | } | ||
| 710 | |||
| 711 | static int acpi_cpufreq_resume(struct cpufreq_policy *policy) | ||
| 712 | { | ||
| 713 | struct acpi_cpufreq_data *data = per_cpu(acfreq_data, policy->cpu); | ||
| 714 | |||
| 715 | dprintk("acpi_cpufreq_resume\n"); | ||
| 716 | |||
| 717 | data->resume = 1; | ||
| 718 | |||
| 719 | return 0; | ||
| 720 | } | ||
| 721 | |||
| 722 | static struct freq_attr *acpi_cpufreq_attr[] = { | ||
| 723 | &cpufreq_freq_attr_scaling_available_freqs, | ||
| 724 | NULL, | ||
| 725 | }; | ||
| 726 | |||
| 727 | static struct cpufreq_driver acpi_cpufreq_driver = { | ||
| 728 | .verify = acpi_cpufreq_verify, | ||
| 729 | .target = acpi_cpufreq_target, | ||
| 730 | .bios_limit = acpi_processor_get_bios_limit, | ||
| 731 | .init = acpi_cpufreq_cpu_init, | ||
| 732 | .exit = acpi_cpufreq_cpu_exit, | ||
| 733 | .resume = acpi_cpufreq_resume, | ||
| 734 | .name = "acpi-cpufreq", | ||
| 735 | .owner = THIS_MODULE, | ||
| 736 | .attr = acpi_cpufreq_attr, | ||
| 737 | }; | ||
| 738 | |||
| 739 | static int __init acpi_cpufreq_init(void) | ||
| 740 | { | ||
| 741 | int ret; | ||
| 742 | |||
| 743 | if (acpi_disabled) | ||
| 744 | return 0; | ||
| 745 | |||
| 746 | dprintk("acpi_cpufreq_init\n"); | ||
| 747 | |||
| 748 | ret = acpi_cpufreq_early_init(); | ||
| 749 | if (ret) | ||
| 750 | return ret; | ||
| 751 | |||
| 752 | ret = cpufreq_register_driver(&acpi_cpufreq_driver); | ||
| 753 | if (ret) | ||
| 754 | free_acpi_perf_data(); | ||
| 755 | |||
| 756 | return ret; | ||
| 757 | } | ||
| 758 | |||
| 759 | static void __exit acpi_cpufreq_exit(void) | ||
| 760 | { | ||
| 761 | dprintk("acpi_cpufreq_exit\n"); | ||
| 762 | |||
| 763 | cpufreq_unregister_driver(&acpi_cpufreq_driver); | ||
| 764 | |||
| 765 | free_percpu(acpi_perf_data); | ||
| 766 | } | ||
| 767 | |||
| 768 | module_param(acpi_pstate_strict, uint, 0644); | ||
| 769 | MODULE_PARM_DESC(acpi_pstate_strict, | ||
| 770 | "value 0 or non-zero. non-zero -> strict ACPI checks are " | ||
| 771 | "performed during frequency changes."); | ||
| 772 | |||
| 773 | late_initcall(acpi_cpufreq_init); | ||
| 774 | module_exit(acpi_cpufreq_exit); | ||
| 775 | |||
| 776 | MODULE_ALIAS("acpi"); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c b/arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c deleted file mode 100644 index 141abebc4516..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c +++ /dev/null | |||
| @@ -1,446 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * (C) 2004-2006 Sebastian Witt <se.witt@gmx.net> | ||
| 3 | * | ||
| 4 | * Licensed under the terms of the GNU GPL License version 2. | ||
| 5 | * Based upon reverse engineered information | ||
| 6 | * | ||
| 7 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include <linux/kernel.h> | ||
| 11 | #include <linux/module.h> | ||
| 12 | #include <linux/moduleparam.h> | ||
| 13 | #include <linux/init.h> | ||
| 14 | #include <linux/cpufreq.h> | ||
| 15 | #include <linux/pci.h> | ||
| 16 | #include <linux/delay.h> | ||
| 17 | |||
| 18 | #define NFORCE2_XTAL 25 | ||
| 19 | #define NFORCE2_BOOTFSB 0x48 | ||
| 20 | #define NFORCE2_PLLENABLE 0xa8 | ||
| 21 | #define NFORCE2_PLLREG 0xa4 | ||
| 22 | #define NFORCE2_PLLADR 0xa0 | ||
| 23 | #define NFORCE2_PLL(mul, div) (0x100000 | (mul << 8) | div) | ||
| 24 | |||
| 25 | #define NFORCE2_MIN_FSB 50 | ||
| 26 | #define NFORCE2_SAFE_DISTANCE 50 | ||
| 27 | |||
| 28 | /* Delay in ms between FSB changes */ | ||
| 29 | /* #define NFORCE2_DELAY 10 */ | ||
| 30 | |||
| 31 | /* | ||
| 32 | * nforce2_chipset: | ||
| 33 | * FSB is changed using the chipset | ||
| 34 | */ | ||
| 35 | static struct pci_dev *nforce2_dev; | ||
| 36 | |||
| 37 | /* fid: | ||
| 38 | * multiplier * 10 | ||
| 39 | */ | ||
| 40 | static int fid; | ||
| 41 | |||
| 42 | /* min_fsb, max_fsb: | ||
| 43 | * minimum and maximum FSB (= FSB at boot time) | ||
| 44 | */ | ||
| 45 | static int min_fsb; | ||
| 46 | static int max_fsb; | ||
| 47 | |||
| 48 | MODULE_AUTHOR("Sebastian Witt <se.witt@gmx.net>"); | ||
| 49 | MODULE_DESCRIPTION("nForce2 FSB changing cpufreq driver"); | ||
| 50 | MODULE_LICENSE("GPL"); | ||
| 51 | |||
| 52 | module_param(fid, int, 0444); | ||
| 53 | module_param(min_fsb, int, 0444); | ||
| 54 | |||
| 55 | MODULE_PARM_DESC(fid, "CPU multiplier to use (11.5 = 115)"); | ||
| 56 | MODULE_PARM_DESC(min_fsb, | ||
| 57 | "Minimum FSB to use, if not defined: current FSB - 50"); | ||
| 58 | |||
| 59 | #define PFX "cpufreq-nforce2: " | ||
| 60 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
| 61 | "cpufreq-nforce2", msg) | ||
| 62 | |||
| 63 | /** | ||
| 64 | * nforce2_calc_fsb - calculate FSB | ||
| 65 | * @pll: PLL value | ||
| 66 | * | ||
| 67 | * Calculates FSB from PLL value | ||
| 68 | */ | ||
| 69 | static int nforce2_calc_fsb(int pll) | ||
| 70 | { | ||
| 71 | unsigned char mul, div; | ||
| 72 | |||
| 73 | mul = (pll >> 8) & 0xff; | ||
| 74 | div = pll & 0xff; | ||
| 75 | |||
| 76 | if (div > 0) | ||
| 77 | return NFORCE2_XTAL * mul / div; | ||
| 78 | |||
| 79 | return 0; | ||
| 80 | } | ||
| 81 | |||
| 82 | /** | ||
| 83 | * nforce2_calc_pll - calculate PLL value | ||
| 84 | * @fsb: FSB | ||
| 85 | * | ||
| 86 | * Calculate PLL value for given FSB | ||
| 87 | */ | ||
| 88 | static int nforce2_calc_pll(unsigned int fsb) | ||
| 89 | { | ||
| 90 | unsigned char xmul, xdiv; | ||
| 91 | unsigned char mul = 0, div = 0; | ||
| 92 | int tried = 0; | ||
| 93 | |||
| 94 | /* Try to calculate multiplier and divider up to 4 times */ | ||
| 95 | while (((mul == 0) || (div == 0)) && (tried <= 3)) { | ||
| 96 | for (xdiv = 2; xdiv <= 0x80; xdiv++) | ||
| 97 | for (xmul = 1; xmul <= 0xfe; xmul++) | ||
| 98 | if (nforce2_calc_fsb(NFORCE2_PLL(xmul, xdiv)) == | ||
| 99 | fsb + tried) { | ||
| 100 | mul = xmul; | ||
| 101 | div = xdiv; | ||
| 102 | } | ||
| 103 | tried++; | ||
| 104 | } | ||
| 105 | |||
| 106 | if ((mul == 0) || (div == 0)) | ||
| 107 | return -1; | ||
| 108 | |||
| 109 | return NFORCE2_PLL(mul, div); | ||
| 110 | } | ||
| 111 | |||
| 112 | /** | ||
| 113 | * nforce2_write_pll - write PLL value to chipset | ||
| 114 | * @pll: PLL value | ||
| 115 | * | ||
| 116 | * Writes new FSB PLL value to chipset | ||
| 117 | */ | ||
| 118 | static void nforce2_write_pll(int pll) | ||
| 119 | { | ||
| 120 | int temp; | ||
| 121 | |||
| 122 | /* Set the pll addr. to 0x00 */ | ||
| 123 | pci_write_config_dword(nforce2_dev, NFORCE2_PLLADR, 0); | ||
| 124 | |||
| 125 | /* Now write the value in all 64 registers */ | ||
| 126 | for (temp = 0; temp <= 0x3f; temp++) | ||
| 127 | pci_write_config_dword(nforce2_dev, NFORCE2_PLLREG, pll); | ||
| 128 | |||
| 129 | return; | ||
| 130 | } | ||
| 131 | |||
| 132 | /** | ||
| 133 | * nforce2_fsb_read - Read FSB | ||
| 134 | * | ||
| 135 | * Read FSB from chipset | ||
| 136 | * If bootfsb != 0, return FSB at boot-time | ||
| 137 | */ | ||
| 138 | static unsigned int nforce2_fsb_read(int bootfsb) | ||
| 139 | { | ||
| 140 | struct pci_dev *nforce2_sub5; | ||
| 141 | u32 fsb, temp = 0; | ||
| 142 | |||
| 143 | /* Get chipset boot FSB from subdevice 5 (FSB at boot-time) */ | ||
| 144 | nforce2_sub5 = pci_get_subsys(PCI_VENDOR_ID_NVIDIA, 0x01EF, | ||
| 145 | PCI_ANY_ID, PCI_ANY_ID, NULL); | ||
| 146 | if (!nforce2_sub5) | ||
| 147 | return 0; | ||
| 148 | |||
| 149 | pci_read_config_dword(nforce2_sub5, NFORCE2_BOOTFSB, &fsb); | ||
| 150 | fsb /= 1000000; | ||
| 151 | |||
| 152 | /* Check if PLL register is already set */ | ||
| 153 | pci_read_config_byte(nforce2_dev, NFORCE2_PLLENABLE, (u8 *)&temp); | ||
| 154 | |||
| 155 | if (bootfsb || !temp) | ||
| 156 | return fsb; | ||
| 157 | |||
| 158 | /* Use PLL register FSB value */ | ||
| 159 | pci_read_config_dword(nforce2_dev, NFORCE2_PLLREG, &temp); | ||
| 160 | fsb = nforce2_calc_fsb(temp); | ||
| 161 | |||
| 162 | return fsb; | ||
| 163 | } | ||
| 164 | |||
| 165 | /** | ||
| 166 | * nforce2_set_fsb - set new FSB | ||
| 167 | * @fsb: New FSB | ||
| 168 | * | ||
| 169 | * Sets new FSB | ||
| 170 | */ | ||
| 171 | static int nforce2_set_fsb(unsigned int fsb) | ||
| 172 | { | ||
| 173 | u32 temp = 0; | ||
| 174 | unsigned int tfsb; | ||
| 175 | int diff; | ||
| 176 | int pll = 0; | ||
| 177 | |||
| 178 | if ((fsb > max_fsb) || (fsb < NFORCE2_MIN_FSB)) { | ||
| 179 | printk(KERN_ERR PFX "FSB %d is out of range!\n", fsb); | ||
| 180 | return -EINVAL; | ||
| 181 | } | ||
| 182 | |||
| 183 | tfsb = nforce2_fsb_read(0); | ||
| 184 | if (!tfsb) { | ||
| 185 | printk(KERN_ERR PFX "Error while reading the FSB\n"); | ||
| 186 | return -EINVAL; | ||
| 187 | } | ||
| 188 | |||
| 189 | /* First write? Then set actual value */ | ||
| 190 | pci_read_config_byte(nforce2_dev, NFORCE2_PLLENABLE, (u8 *)&temp); | ||
| 191 | if (!temp) { | ||
| 192 | pll = nforce2_calc_pll(tfsb); | ||
| 193 | |||
| 194 | if (pll < 0) | ||
| 195 | return -EINVAL; | ||
| 196 | |||
| 197 | nforce2_write_pll(pll); | ||
| 198 | } | ||
| 199 | |||
| 200 | /* Enable write access */ | ||
| 201 | temp = 0x01; | ||
| 202 | pci_write_config_byte(nforce2_dev, NFORCE2_PLLENABLE, (u8)temp); | ||
| 203 | |||
| 204 | diff = tfsb - fsb; | ||
| 205 | |||
| 206 | if (!diff) | ||
| 207 | return 0; | ||
| 208 | |||
| 209 | while ((tfsb != fsb) && (tfsb <= max_fsb) && (tfsb >= min_fsb)) { | ||
| 210 | if (diff < 0) | ||
| 211 | tfsb++; | ||
| 212 | else | ||
| 213 | tfsb--; | ||
| 214 | |||
| 215 | /* Calculate the PLL reg. value */ | ||
| 216 | pll = nforce2_calc_pll(tfsb); | ||
| 217 | if (pll == -1) | ||
| 218 | return -EINVAL; | ||
| 219 | |||
| 220 | nforce2_write_pll(pll); | ||
| 221 | #ifdef NFORCE2_DELAY | ||
| 222 | mdelay(NFORCE2_DELAY); | ||
| 223 | #endif | ||
| 224 | } | ||
| 225 | |||
| 226 | temp = 0x40; | ||
| 227 | pci_write_config_byte(nforce2_dev, NFORCE2_PLLADR, (u8)temp); | ||
| 228 | |||
| 229 | return 0; | ||
| 230 | } | ||
| 231 | |||
| 232 | /** | ||
| 233 | * nforce2_get - get the CPU frequency | ||
| 234 | * @cpu: CPU number | ||
| 235 | * | ||
| 236 | * Returns the CPU frequency | ||
| 237 | */ | ||
| 238 | static unsigned int nforce2_get(unsigned int cpu) | ||
| 239 | { | ||
| 240 | if (cpu) | ||
| 241 | return 0; | ||
| 242 | return nforce2_fsb_read(0) * fid * 100; | ||
| 243 | } | ||
| 244 | |||
| 245 | /** | ||
| 246 | * nforce2_target - set a new CPUFreq policy | ||
| 247 | * @policy: new policy | ||
| 248 | * @target_freq: the target frequency | ||
| 249 | * @relation: how that frequency relates to achieved frequency | ||
| 250 | * (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H) | ||
| 251 | * | ||
| 252 | * Sets a new CPUFreq policy. | ||
| 253 | */ | ||
| 254 | static int nforce2_target(struct cpufreq_policy *policy, | ||
| 255 | unsigned int target_freq, unsigned int relation) | ||
| 256 | { | ||
| 257 | /* unsigned long flags; */ | ||
| 258 | struct cpufreq_freqs freqs; | ||
| 259 | unsigned int target_fsb; | ||
| 260 | |||
| 261 | if ((target_freq > policy->max) || (target_freq < policy->min)) | ||
| 262 | return -EINVAL; | ||
| 263 | |||
| 264 | target_fsb = target_freq / (fid * 100); | ||
| 265 | |||
| 266 | freqs.old = nforce2_get(policy->cpu); | ||
| 267 | freqs.new = target_fsb * fid * 100; | ||
| 268 | freqs.cpu = 0; /* Only one CPU on nForce2 platforms */ | ||
| 269 | |||
| 270 | if (freqs.old == freqs.new) | ||
| 271 | return 0; | ||
| 272 | |||
| 273 | dprintk("Old CPU frequency %d kHz, new %d kHz\n", | ||
| 274 | freqs.old, freqs.new); | ||
| 275 | |||
| 276 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
| 277 | |||
| 278 | /* Disable IRQs */ | ||
| 279 | /* local_irq_save(flags); */ | ||
| 280 | |||
| 281 | if (nforce2_set_fsb(target_fsb) < 0) | ||
| 282 | printk(KERN_ERR PFX "Changing FSB to %d failed\n", | ||
| 283 | target_fsb); | ||
| 284 | else | ||
| 285 | dprintk("Changed FSB successfully to %d\n", | ||
| 286 | target_fsb); | ||
| 287 | |||
| 288 | /* Enable IRQs */ | ||
| 289 | /* local_irq_restore(flags); */ | ||
| 290 | |||
| 291 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 292 | |||
| 293 | return 0; | ||
| 294 | } | ||
| 295 | |||
| 296 | /** | ||
| 297 | * nforce2_verify - verifies a new CPUFreq policy | ||
| 298 | * @policy: new policy | ||
| 299 | */ | ||
| 300 | static int nforce2_verify(struct cpufreq_policy *policy) | ||
| 301 | { | ||
| 302 | unsigned int fsb_pol_max; | ||
| 303 | |||
| 304 | fsb_pol_max = policy->max / (fid * 100); | ||
| 305 | |||
| 306 | if (policy->min < (fsb_pol_max * fid * 100)) | ||
| 307 | policy->max = (fsb_pol_max + 1) * fid * 100; | ||
| 308 | |||
| 309 | cpufreq_verify_within_limits(policy, | ||
| 310 | policy->cpuinfo.min_freq, | ||
| 311 | policy->cpuinfo.max_freq); | ||
| 312 | return 0; | ||
| 313 | } | ||
| 314 | |||
| 315 | static int nforce2_cpu_init(struct cpufreq_policy *policy) | ||
| 316 | { | ||
| 317 | unsigned int fsb; | ||
| 318 | unsigned int rfid; | ||
| 319 | |||
| 320 | /* capability check */ | ||
| 321 | if (policy->cpu != 0) | ||
| 322 | return -ENODEV; | ||
| 323 | |||
| 324 | /* Get current FSB */ | ||
| 325 | fsb = nforce2_fsb_read(0); | ||
| 326 | |||
| 327 | if (!fsb) | ||
| 328 | return -EIO; | ||
| 329 | |||
| 330 | /* FIX: Get FID from CPU */ | ||
| 331 | if (!fid) { | ||
| 332 | if (!cpu_khz) { | ||
| 333 | printk(KERN_WARNING PFX | ||
| 334 | "cpu_khz not set, can't calculate multiplier!\n"); | ||
| 335 | return -ENODEV; | ||
| 336 | } | ||
| 337 | |||
| 338 | fid = cpu_khz / (fsb * 100); | ||
| 339 | rfid = fid % 5; | ||
| 340 | |||
| 341 | if (rfid) { | ||
| 342 | if (rfid > 2) | ||
| 343 | fid += 5 - rfid; | ||
| 344 | else | ||
| 345 | fid -= rfid; | ||
| 346 | } | ||
| 347 | } | ||
| 348 | |||
| 349 | printk(KERN_INFO PFX "FSB currently at %i MHz, FID %d.%d\n", fsb, | ||
| 350 | fid / 10, fid % 10); | ||
| 351 | |||
| 352 | /* Set maximum FSB to FSB at boot time */ | ||
| 353 | max_fsb = nforce2_fsb_read(1); | ||
| 354 | |||
| 355 | if (!max_fsb) | ||
| 356 | return -EIO; | ||
| 357 | |||
| 358 | if (!min_fsb) | ||
| 359 | min_fsb = max_fsb - NFORCE2_SAFE_DISTANCE; | ||
| 360 | |||
| 361 | if (min_fsb < NFORCE2_MIN_FSB) | ||
| 362 | min_fsb = NFORCE2_MIN_FSB; | ||
| 363 | |||
| 364 | /* cpuinfo and default policy values */ | ||
| 365 | policy->cpuinfo.min_freq = min_fsb * fid * 100; | ||
| 366 | policy->cpuinfo.max_freq = max_fsb * fid * 100; | ||
| 367 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | ||
| 368 | policy->cur = nforce2_get(policy->cpu); | ||
| 369 | policy->min = policy->cpuinfo.min_freq; | ||
| 370 | policy->max = policy->cpuinfo.max_freq; | ||
| 371 | |||
| 372 | return 0; | ||
| 373 | } | ||
| 374 | |||
| 375 | static int nforce2_cpu_exit(struct cpufreq_policy *policy) | ||
| 376 | { | ||
| 377 | return 0; | ||
| 378 | } | ||
| 379 | |||
| 380 | static struct cpufreq_driver nforce2_driver = { | ||
| 381 | .name = "nforce2", | ||
| 382 | .verify = nforce2_verify, | ||
| 383 | .target = nforce2_target, | ||
| 384 | .get = nforce2_get, | ||
| 385 | .init = nforce2_cpu_init, | ||
| 386 | .exit = nforce2_cpu_exit, | ||
| 387 | .owner = THIS_MODULE, | ||
| 388 | }; | ||
| 389 | |||
| 390 | /** | ||
| 391 | * nforce2_detect_chipset - detect the Southbridge which contains FSB PLL logic | ||
| 392 | * | ||
| 393 | * Detects nForce2 A2 and C1 stepping | ||
| 394 | * | ||
| 395 | */ | ||
| 396 | static int nforce2_detect_chipset(void) | ||
| 397 | { | ||
| 398 | nforce2_dev = pci_get_subsys(PCI_VENDOR_ID_NVIDIA, | ||
| 399 | PCI_DEVICE_ID_NVIDIA_NFORCE2, | ||
| 400 | PCI_ANY_ID, PCI_ANY_ID, NULL); | ||
| 401 | |||
| 402 | if (nforce2_dev == NULL) | ||
| 403 | return -ENODEV; | ||
| 404 | |||
| 405 | printk(KERN_INFO PFX "Detected nForce2 chipset revision %X\n", | ||
| 406 | nforce2_dev->revision); | ||
| 407 | printk(KERN_INFO PFX | ||
| 408 | "FSB changing is maybe unstable and can lead to " | ||
| 409 | "crashes and data loss.\n"); | ||
| 410 | |||
| 411 | return 0; | ||
| 412 | } | ||
| 413 | |||
| 414 | /** | ||
| 415 | * nforce2_init - initializes the nForce2 CPUFreq driver | ||
| 416 | * | ||
| 417 | * Initializes the nForce2 FSB support. Returns -ENODEV on unsupported | ||
| 418 | * devices, -EINVAL on problems during initiatization, and zero on | ||
| 419 | * success. | ||
| 420 | */ | ||
| 421 | static int __init nforce2_init(void) | ||
| 422 | { | ||
| 423 | /* TODO: do we need to detect the processor? */ | ||
| 424 | |||
| 425 | /* detect chipset */ | ||
| 426 | if (nforce2_detect_chipset()) { | ||
| 427 | printk(KERN_INFO PFX "No nForce2 chipset.\n"); | ||
| 428 | return -ENODEV; | ||
| 429 | } | ||
| 430 | |||
| 431 | return cpufreq_register_driver(&nforce2_driver); | ||
| 432 | } | ||
| 433 | |||
| 434 | /** | ||
| 435 | * nforce2_exit - unregisters cpufreq module | ||
| 436 | * | ||
| 437 | * Unregisters nForce2 FSB change support. | ||
| 438 | */ | ||
| 439 | static void __exit nforce2_exit(void) | ||
| 440 | { | ||
| 441 | cpufreq_unregister_driver(&nforce2_driver); | ||
| 442 | } | ||
| 443 | |||
| 444 | module_init(nforce2_init); | ||
| 445 | module_exit(nforce2_exit); | ||
| 446 | |||
diff --git a/arch/x86/kernel/cpu/cpufreq/e_powersaver.c b/arch/x86/kernel/cpu/cpufreq/e_powersaver.c deleted file mode 100644 index 35a257dd4bb7..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/e_powersaver.c +++ /dev/null | |||
| @@ -1,367 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Based on documentation provided by Dave Jones. Thanks! | ||
| 3 | * | ||
| 4 | * Licensed under the terms of the GNU GPL License version 2. | ||
| 5 | * | ||
| 6 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <linux/kernel.h> | ||
| 10 | #include <linux/module.h> | ||
| 11 | #include <linux/init.h> | ||
| 12 | #include <linux/cpufreq.h> | ||
| 13 | #include <linux/ioport.h> | ||
| 14 | #include <linux/slab.h> | ||
| 15 | #include <linux/timex.h> | ||
| 16 | #include <linux/io.h> | ||
| 17 | #include <linux/delay.h> | ||
| 18 | |||
| 19 | #include <asm/msr.h> | ||
| 20 | #include <asm/tsc.h> | ||
| 21 | |||
| 22 | #define EPS_BRAND_C7M 0 | ||
| 23 | #define EPS_BRAND_C7 1 | ||
| 24 | #define EPS_BRAND_EDEN 2 | ||
| 25 | #define EPS_BRAND_C3 3 | ||
| 26 | #define EPS_BRAND_C7D 4 | ||
| 27 | |||
| 28 | struct eps_cpu_data { | ||
| 29 | u32 fsb; | ||
| 30 | struct cpufreq_frequency_table freq_table[]; | ||
| 31 | }; | ||
| 32 | |||
| 33 | static struct eps_cpu_data *eps_cpu[NR_CPUS]; | ||
| 34 | |||
| 35 | |||
| 36 | static unsigned int eps_get(unsigned int cpu) | ||
| 37 | { | ||
| 38 | struct eps_cpu_data *centaur; | ||
| 39 | u32 lo, hi; | ||
| 40 | |||
| 41 | if (cpu) | ||
| 42 | return 0; | ||
| 43 | centaur = eps_cpu[cpu]; | ||
| 44 | if (centaur == NULL) | ||
| 45 | return 0; | ||
| 46 | |||
| 47 | /* Return current frequency */ | ||
| 48 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
| 49 | return centaur->fsb * ((lo >> 8) & 0xff); | ||
| 50 | } | ||
| 51 | |||
| 52 | static int eps_set_state(struct eps_cpu_data *centaur, | ||
| 53 | unsigned int cpu, | ||
| 54 | u32 dest_state) | ||
| 55 | { | ||
| 56 | struct cpufreq_freqs freqs; | ||
| 57 | u32 lo, hi; | ||
| 58 | int err = 0; | ||
| 59 | int i; | ||
| 60 | |||
| 61 | freqs.old = eps_get(cpu); | ||
| 62 | freqs.new = centaur->fsb * ((dest_state >> 8) & 0xff); | ||
| 63 | freqs.cpu = cpu; | ||
| 64 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
| 65 | |||
| 66 | /* Wait while CPU is busy */ | ||
| 67 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
| 68 | i = 0; | ||
| 69 | while (lo & ((1 << 16) | (1 << 17))) { | ||
| 70 | udelay(16); | ||
| 71 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
| 72 | i++; | ||
| 73 | if (unlikely(i > 64)) { | ||
| 74 | err = -ENODEV; | ||
| 75 | goto postchange; | ||
| 76 | } | ||
| 77 | } | ||
| 78 | /* Set new multiplier and voltage */ | ||
| 79 | wrmsr(MSR_IA32_PERF_CTL, dest_state & 0xffff, 0); | ||
| 80 | /* Wait until transition end */ | ||
| 81 | i = 0; | ||
| 82 | do { | ||
| 83 | udelay(16); | ||
| 84 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
| 85 | i++; | ||
| 86 | if (unlikely(i > 64)) { | ||
| 87 | err = -ENODEV; | ||
| 88 | goto postchange; | ||
| 89 | } | ||
| 90 | } while (lo & ((1 << 16) | (1 << 17))); | ||
| 91 | |||
| 92 | /* Return current frequency */ | ||
| 93 | postchange: | ||
| 94 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
| 95 | freqs.new = centaur->fsb * ((lo >> 8) & 0xff); | ||
| 96 | |||
| 97 | #ifdef DEBUG | ||
| 98 | { | ||
| 99 | u8 current_multiplier, current_voltage; | ||
| 100 | |||
| 101 | /* Print voltage and multiplier */ | ||
| 102 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
| 103 | current_voltage = lo & 0xff; | ||
| 104 | printk(KERN_INFO "eps: Current voltage = %dmV\n", | ||
| 105 | current_voltage * 16 + 700); | ||
| 106 | current_multiplier = (lo >> 8) & 0xff; | ||
| 107 | printk(KERN_INFO "eps: Current multiplier = %d\n", | ||
| 108 | current_multiplier); | ||
| 109 | } | ||
| 110 | #endif | ||
| 111 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 112 | return err; | ||
| 113 | } | ||
| 114 | |||
| 115 | static int eps_target(struct cpufreq_policy *policy, | ||
| 116 | unsigned int target_freq, | ||
| 117 | unsigned int relation) | ||
| 118 | { | ||
| 119 | struct eps_cpu_data *centaur; | ||
| 120 | unsigned int newstate = 0; | ||
| 121 | unsigned int cpu = policy->cpu; | ||
| 122 | unsigned int dest_state; | ||
| 123 | int ret; | ||
| 124 | |||
| 125 | if (unlikely(eps_cpu[cpu] == NULL)) | ||
| 126 | return -ENODEV; | ||
| 127 | centaur = eps_cpu[cpu]; | ||
| 128 | |||
| 129 | if (unlikely(cpufreq_frequency_table_target(policy, | ||
| 130 | &eps_cpu[cpu]->freq_table[0], | ||
| 131 | target_freq, | ||
| 132 | relation, | ||
| 133 | &newstate))) { | ||
| 134 | return -EINVAL; | ||
| 135 | } | ||
| 136 | |||
| 137 | /* Make frequency transition */ | ||
| 138 | dest_state = centaur->freq_table[newstate].index & 0xffff; | ||
| 139 | ret = eps_set_state(centaur, cpu, dest_state); | ||
| 140 | if (ret) | ||
| 141 | printk(KERN_ERR "eps: Timeout!\n"); | ||
| 142 | return ret; | ||
| 143 | } | ||
| 144 | |||
| 145 | static int eps_verify(struct cpufreq_policy *policy) | ||
| 146 | { | ||
| 147 | return cpufreq_frequency_table_verify(policy, | ||
| 148 | &eps_cpu[policy->cpu]->freq_table[0]); | ||
| 149 | } | ||
| 150 | |||
| 151 | static int eps_cpu_init(struct cpufreq_policy *policy) | ||
| 152 | { | ||
| 153 | unsigned int i; | ||
| 154 | u32 lo, hi; | ||
| 155 | u64 val; | ||
| 156 | u8 current_multiplier, current_voltage; | ||
| 157 | u8 max_multiplier, max_voltage; | ||
| 158 | u8 min_multiplier, min_voltage; | ||
| 159 | u8 brand = 0; | ||
| 160 | u32 fsb; | ||
| 161 | struct eps_cpu_data *centaur; | ||
| 162 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
| 163 | struct cpufreq_frequency_table *f_table; | ||
| 164 | int k, step, voltage; | ||
| 165 | int ret; | ||
| 166 | int states; | ||
| 167 | |||
| 168 | if (policy->cpu != 0) | ||
| 169 | return -ENODEV; | ||
| 170 | |||
| 171 | /* Check brand */ | ||
| 172 | printk(KERN_INFO "eps: Detected VIA "); | ||
| 173 | |||
| 174 | switch (c->x86_model) { | ||
| 175 | case 10: | ||
| 176 | rdmsr(0x1153, lo, hi); | ||
| 177 | brand = (((lo >> 2) ^ lo) >> 18) & 3; | ||
| 178 | printk(KERN_CONT "Model A "); | ||
| 179 | break; | ||
| 180 | case 13: | ||
| 181 | rdmsr(0x1154, lo, hi); | ||
| 182 | brand = (((lo >> 4) ^ (lo >> 2))) & 0x000000ff; | ||
| 183 | printk(KERN_CONT "Model D "); | ||
| 184 | break; | ||
| 185 | } | ||
| 186 | |||
| 187 | switch (brand) { | ||
| 188 | case EPS_BRAND_C7M: | ||
| 189 | printk(KERN_CONT "C7-M\n"); | ||
| 190 | break; | ||
| 191 | case EPS_BRAND_C7: | ||
| 192 | printk(KERN_CONT "C7\n"); | ||
| 193 | break; | ||
| 194 | case EPS_BRAND_EDEN: | ||
| 195 | printk(KERN_CONT "Eden\n"); | ||
| 196 | break; | ||
| 197 | case EPS_BRAND_C7D: | ||
| 198 | printk(KERN_CONT "C7-D\n"); | ||
| 199 | break; | ||
| 200 | case EPS_BRAND_C3: | ||
| 201 | printk(KERN_CONT "C3\n"); | ||
| 202 | return -ENODEV; | ||
| 203 | break; | ||
| 204 | } | ||
| 205 | /* Enable Enhanced PowerSaver */ | ||
| 206 | rdmsrl(MSR_IA32_MISC_ENABLE, val); | ||
| 207 | if (!(val & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) { | ||
| 208 | val |= MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP; | ||
| 209 | wrmsrl(MSR_IA32_MISC_ENABLE, val); | ||
| 210 | /* Can be locked at 0 */ | ||
| 211 | rdmsrl(MSR_IA32_MISC_ENABLE, val); | ||
| 212 | if (!(val & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) { | ||
| 213 | printk(KERN_INFO "eps: Can't enable Enhanced PowerSaver\n"); | ||
| 214 | return -ENODEV; | ||
| 215 | } | ||
| 216 | } | ||
| 217 | |||
| 218 | /* Print voltage and multiplier */ | ||
| 219 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
| 220 | current_voltage = lo & 0xff; | ||
| 221 | printk(KERN_INFO "eps: Current voltage = %dmV\n", | ||
| 222 | current_voltage * 16 + 700); | ||
| 223 | current_multiplier = (lo >> 8) & 0xff; | ||
| 224 | printk(KERN_INFO "eps: Current multiplier = %d\n", current_multiplier); | ||
| 225 | |||
| 226 | /* Print limits */ | ||
| 227 | max_voltage = hi & 0xff; | ||
| 228 | printk(KERN_INFO "eps: Highest voltage = %dmV\n", | ||
| 229 | max_voltage * 16 + 700); | ||
| 230 | max_multiplier = (hi >> 8) & 0xff; | ||
| 231 | printk(KERN_INFO "eps: Highest multiplier = %d\n", max_multiplier); | ||
| 232 | min_voltage = (hi >> 16) & 0xff; | ||
| 233 | printk(KERN_INFO "eps: Lowest voltage = %dmV\n", | ||
| 234 | min_voltage * 16 + 700); | ||
| 235 | min_multiplier = (hi >> 24) & 0xff; | ||
| 236 | printk(KERN_INFO "eps: Lowest multiplier = %d\n", min_multiplier); | ||
| 237 | |||
| 238 | /* Sanity checks */ | ||
| 239 | if (current_multiplier == 0 || max_multiplier == 0 | ||
| 240 | || min_multiplier == 0) | ||
| 241 | return -EINVAL; | ||
| 242 | if (current_multiplier > max_multiplier | ||
| 243 | || max_multiplier <= min_multiplier) | ||
| 244 | return -EINVAL; | ||
| 245 | if (current_voltage > 0x1f || max_voltage > 0x1f) | ||
| 246 | return -EINVAL; | ||
| 247 | if (max_voltage < min_voltage) | ||
| 248 | return -EINVAL; | ||
| 249 | |||
| 250 | /* Calc FSB speed */ | ||
| 251 | fsb = cpu_khz / current_multiplier; | ||
| 252 | /* Calc number of p-states supported */ | ||
| 253 | if (brand == EPS_BRAND_C7M) | ||
| 254 | states = max_multiplier - min_multiplier + 1; | ||
| 255 | else | ||
| 256 | states = 2; | ||
| 257 | |||
| 258 | /* Allocate private data and frequency table for current cpu */ | ||
| 259 | centaur = kzalloc(sizeof(struct eps_cpu_data) | ||
| 260 | + (states + 1) * sizeof(struct cpufreq_frequency_table), | ||
| 261 | GFP_KERNEL); | ||
| 262 | if (!centaur) | ||
| 263 | return -ENOMEM; | ||
| 264 | eps_cpu[0] = centaur; | ||
| 265 | |||
| 266 | /* Copy basic values */ | ||
| 267 | centaur->fsb = fsb; | ||
| 268 | |||
| 269 | /* Fill frequency and MSR value table */ | ||
| 270 | f_table = ¢aur->freq_table[0]; | ||
| 271 | if (brand != EPS_BRAND_C7M) { | ||
| 272 | f_table[0].frequency = fsb * min_multiplier; | ||
| 273 | f_table[0].index = (min_multiplier << 8) | min_voltage; | ||
| 274 | f_table[1].frequency = fsb * max_multiplier; | ||
| 275 | f_table[1].index = (max_multiplier << 8) | max_voltage; | ||
| 276 | f_table[2].frequency = CPUFREQ_TABLE_END; | ||
| 277 | } else { | ||
| 278 | k = 0; | ||
| 279 | step = ((max_voltage - min_voltage) * 256) | ||
| 280 | / (max_multiplier - min_multiplier); | ||
| 281 | for (i = min_multiplier; i <= max_multiplier; i++) { | ||
| 282 | voltage = (k * step) / 256 + min_voltage; | ||
| 283 | f_table[k].frequency = fsb * i; | ||
| 284 | f_table[k].index = (i << 8) | voltage; | ||
| 285 | k++; | ||
| 286 | } | ||
| 287 | f_table[k].frequency = CPUFREQ_TABLE_END; | ||
| 288 | } | ||
| 289 | |||
| 290 | policy->cpuinfo.transition_latency = 140000; /* 844mV -> 700mV in ns */ | ||
| 291 | policy->cur = fsb * current_multiplier; | ||
| 292 | |||
| 293 | ret = cpufreq_frequency_table_cpuinfo(policy, ¢aur->freq_table[0]); | ||
| 294 | if (ret) { | ||
| 295 | kfree(centaur); | ||
| 296 | return ret; | ||
| 297 | } | ||
| 298 | |||
| 299 | cpufreq_frequency_table_get_attr(¢aur->freq_table[0], policy->cpu); | ||
| 300 | return 0; | ||
| 301 | } | ||
| 302 | |||
| 303 | static int eps_cpu_exit(struct cpufreq_policy *policy) | ||
| 304 | { | ||
| 305 | unsigned int cpu = policy->cpu; | ||
| 306 | struct eps_cpu_data *centaur; | ||
| 307 | u32 lo, hi; | ||
| 308 | |||
| 309 | if (eps_cpu[cpu] == NULL) | ||
| 310 | return -ENODEV; | ||
| 311 | centaur = eps_cpu[cpu]; | ||
| 312 | |||
| 313 | /* Get max frequency */ | ||
| 314 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
| 315 | /* Set max frequency */ | ||
| 316 | eps_set_state(centaur, cpu, hi & 0xffff); | ||
| 317 | /* Bye */ | ||
| 318 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
| 319 | kfree(eps_cpu[cpu]); | ||
| 320 | eps_cpu[cpu] = NULL; | ||
| 321 | return 0; | ||
| 322 | } | ||
| 323 | |||
| 324 | static struct freq_attr *eps_attr[] = { | ||
| 325 | &cpufreq_freq_attr_scaling_available_freqs, | ||
| 326 | NULL, | ||
| 327 | }; | ||
| 328 | |||
| 329 | static struct cpufreq_driver eps_driver = { | ||
| 330 | .verify = eps_verify, | ||
| 331 | .target = eps_target, | ||
| 332 | .init = eps_cpu_init, | ||
| 333 | .exit = eps_cpu_exit, | ||
| 334 | .get = eps_get, | ||
| 335 | .name = "e_powersaver", | ||
| 336 | .owner = THIS_MODULE, | ||
| 337 | .attr = eps_attr, | ||
| 338 | }; | ||
| 339 | |||
| 340 | static int __init eps_init(void) | ||
| 341 | { | ||
| 342 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
| 343 | |||
| 344 | /* This driver will work only on Centaur C7 processors with | ||
| 345 | * Enhanced SpeedStep/PowerSaver registers */ | ||
| 346 | if (c->x86_vendor != X86_VENDOR_CENTAUR | ||
| 347 | || c->x86 != 6 || c->x86_model < 10) | ||
| 348 | return -ENODEV; | ||
| 349 | if (!cpu_has(c, X86_FEATURE_EST)) | ||
| 350 | return -ENODEV; | ||
| 351 | |||
| 352 | if (cpufreq_register_driver(&eps_driver)) | ||
| 353 | return -EINVAL; | ||
| 354 | return 0; | ||
| 355 | } | ||
| 356 | |||
| 357 | static void __exit eps_exit(void) | ||
| 358 | { | ||
| 359 | cpufreq_unregister_driver(&eps_driver); | ||
| 360 | } | ||
| 361 | |||
| 362 | MODULE_AUTHOR("Rafal Bilski <rafalbilski@interia.pl>"); | ||
| 363 | MODULE_DESCRIPTION("Enhanced PowerSaver driver for VIA C7 CPU's."); | ||
| 364 | MODULE_LICENSE("GPL"); | ||
| 365 | |||
| 366 | module_init(eps_init); | ||
| 367 | module_exit(eps_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/elanfreq.c b/arch/x86/kernel/cpu/cpufreq/elanfreq.c deleted file mode 100644 index c587db472a75..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/elanfreq.c +++ /dev/null | |||
| @@ -1,309 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * elanfreq: cpufreq driver for the AMD ELAN family | ||
| 3 | * | ||
| 4 | * (c) Copyright 2002 Robert Schwebel <r.schwebel@pengutronix.de> | ||
| 5 | * | ||
| 6 | * Parts of this code are (c) Sven Geggus <sven@geggus.net> | ||
| 7 | * | ||
| 8 | * All Rights Reserved. | ||
| 9 | * | ||
| 10 | * This program is free software; you can redistribute it and/or | ||
| 11 | * modify it under the terms of the GNU General Public License | ||
| 12 | * as published by the Free Software Foundation; either version | ||
| 13 | * 2 of the License, or (at your option) any later version. | ||
| 14 | * | ||
| 15 | * 2002-02-13: - initial revision for 2.4.18-pre9 by Robert Schwebel | ||
| 16 | * | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <linux/kernel.h> | ||
| 20 | #include <linux/module.h> | ||
| 21 | #include <linux/init.h> | ||
| 22 | |||
| 23 | #include <linux/delay.h> | ||
| 24 | #include <linux/cpufreq.h> | ||
| 25 | |||
| 26 | #include <asm/msr.h> | ||
| 27 | #include <linux/timex.h> | ||
| 28 | #include <linux/io.h> | ||
| 29 | |||
| 30 | #define REG_CSCIR 0x22 /* Chip Setup and Control Index Register */ | ||
| 31 | #define REG_CSCDR 0x23 /* Chip Setup and Control Data Register */ | ||
| 32 | |||
| 33 | /* Module parameter */ | ||
| 34 | static int max_freq; | ||
| 35 | |||
| 36 | struct s_elan_multiplier { | ||
| 37 | int clock; /* frequency in kHz */ | ||
| 38 | int val40h; /* PMU Force Mode register */ | ||
| 39 | int val80h; /* CPU Clock Speed Register */ | ||
| 40 | }; | ||
| 41 | |||
| 42 | /* | ||
| 43 | * It is important that the frequencies | ||
| 44 | * are listed in ascending order here! | ||
| 45 | */ | ||
| 46 | static struct s_elan_multiplier elan_multiplier[] = { | ||
| 47 | {1000, 0x02, 0x18}, | ||
| 48 | {2000, 0x02, 0x10}, | ||
| 49 | {4000, 0x02, 0x08}, | ||
| 50 | {8000, 0x00, 0x00}, | ||
| 51 | {16000, 0x00, 0x02}, | ||
| 52 | {33000, 0x00, 0x04}, | ||
| 53 | {66000, 0x01, 0x04}, | ||
| 54 | {99000, 0x01, 0x05} | ||
| 55 | }; | ||
| 56 | |||
| 57 | static struct cpufreq_frequency_table elanfreq_table[] = { | ||
| 58 | {0, 1000}, | ||
| 59 | {1, 2000}, | ||
| 60 | {2, 4000}, | ||
| 61 | {3, 8000}, | ||
| 62 | {4, 16000}, | ||
| 63 | {5, 33000}, | ||
| 64 | {6, 66000}, | ||
| 65 | {7, 99000}, | ||
| 66 | {0, CPUFREQ_TABLE_END}, | ||
| 67 | }; | ||
| 68 | |||
| 69 | |||
| 70 | /** | ||
| 71 | * elanfreq_get_cpu_frequency: determine current cpu speed | ||
| 72 | * | ||
| 73 | * Finds out at which frequency the CPU of the Elan SOC runs | ||
| 74 | * at the moment. Frequencies from 1 to 33 MHz are generated | ||
| 75 | * the normal way, 66 and 99 MHz are called "Hyperspeed Mode" | ||
| 76 | * and have the rest of the chip running with 33 MHz. | ||
| 77 | */ | ||
| 78 | |||
| 79 | static unsigned int elanfreq_get_cpu_frequency(unsigned int cpu) | ||
| 80 | { | ||
| 81 | u8 clockspeed_reg; /* Clock Speed Register */ | ||
| 82 | |||
| 83 | local_irq_disable(); | ||
| 84 | outb_p(0x80, REG_CSCIR); | ||
| 85 | clockspeed_reg = inb_p(REG_CSCDR); | ||
| 86 | local_irq_enable(); | ||
| 87 | |||
| 88 | if ((clockspeed_reg & 0xE0) == 0xE0) | ||
| 89 | return 0; | ||
| 90 | |||
| 91 | /* Are we in CPU clock multiplied mode (66/99 MHz)? */ | ||
| 92 | if ((clockspeed_reg & 0xE0) == 0xC0) { | ||
| 93 | if ((clockspeed_reg & 0x01) == 0) | ||
| 94 | return 66000; | ||
| 95 | else | ||
| 96 | return 99000; | ||
| 97 | } | ||
| 98 | |||
| 99 | /* 33 MHz is not 32 MHz... */ | ||
| 100 | if ((clockspeed_reg & 0xE0) == 0xA0) | ||
| 101 | return 33000; | ||
| 102 | |||
| 103 | return (1<<((clockspeed_reg & 0xE0) >> 5)) * 1000; | ||
| 104 | } | ||
| 105 | |||
| 106 | |||
| 107 | /** | ||
| 108 | * elanfreq_set_cpu_frequency: Change the CPU core frequency | ||
| 109 | * @cpu: cpu number | ||
| 110 | * @freq: frequency in kHz | ||
| 111 | * | ||
| 112 | * This function takes a frequency value and changes the CPU frequency | ||
| 113 | * according to this. Note that the frequency has to be checked by | ||
| 114 | * elanfreq_validatespeed() for correctness! | ||
| 115 | * | ||
| 116 | * There is no return value. | ||
| 117 | */ | ||
| 118 | |||
| 119 | static void elanfreq_set_cpu_state(unsigned int state) | ||
| 120 | { | ||
| 121 | struct cpufreq_freqs freqs; | ||
| 122 | |||
| 123 | freqs.old = elanfreq_get_cpu_frequency(0); | ||
| 124 | freqs.new = elan_multiplier[state].clock; | ||
| 125 | freqs.cpu = 0; /* elanfreq.c is UP only driver */ | ||
| 126 | |||
| 127 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
| 128 | |||
| 129 | printk(KERN_INFO "elanfreq: attempting to set frequency to %i kHz\n", | ||
| 130 | elan_multiplier[state].clock); | ||
| 131 | |||
| 132 | |||
| 133 | /* | ||
| 134 | * Access to the Elan's internal registers is indexed via | ||
| 135 | * 0x22: Chip Setup & Control Register Index Register (CSCI) | ||
| 136 | * 0x23: Chip Setup & Control Register Data Register (CSCD) | ||
| 137 | * | ||
| 138 | */ | ||
| 139 | |||
| 140 | /* | ||
| 141 | * 0x40 is the Power Management Unit's Force Mode Register. | ||
| 142 | * Bit 6 enables Hyperspeed Mode (66/100 MHz core frequency) | ||
| 143 | */ | ||
| 144 | |||
| 145 | local_irq_disable(); | ||
| 146 | outb_p(0x40, REG_CSCIR); /* Disable hyperspeed mode */ | ||
| 147 | outb_p(0x00, REG_CSCDR); | ||
| 148 | local_irq_enable(); /* wait till internal pipelines and */ | ||
| 149 | udelay(1000); /* buffers have cleaned up */ | ||
| 150 | |||
| 151 | local_irq_disable(); | ||
| 152 | |||
| 153 | /* now, set the CPU clock speed register (0x80) */ | ||
| 154 | outb_p(0x80, REG_CSCIR); | ||
| 155 | outb_p(elan_multiplier[state].val80h, REG_CSCDR); | ||
| 156 | |||
| 157 | /* now, the hyperspeed bit in PMU Force Mode Register (0x40) */ | ||
| 158 | outb_p(0x40, REG_CSCIR); | ||
| 159 | outb_p(elan_multiplier[state].val40h, REG_CSCDR); | ||
| 160 | udelay(10000); | ||
| 161 | local_irq_enable(); | ||
| 162 | |||
| 163 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 164 | }; | ||
| 165 | |||
| 166 | |||
| 167 | /** | ||
| 168 | * elanfreq_validatespeed: test if frequency range is valid | ||
| 169 | * @policy: the policy to validate | ||
| 170 | * | ||
| 171 | * This function checks if a given frequency range in kHz is valid | ||
| 172 | * for the hardware supported by the driver. | ||
| 173 | */ | ||
| 174 | |||
| 175 | static int elanfreq_verify(struct cpufreq_policy *policy) | ||
| 176 | { | ||
| 177 | return cpufreq_frequency_table_verify(policy, &elanfreq_table[0]); | ||
| 178 | } | ||
| 179 | |||
| 180 | static int elanfreq_target(struct cpufreq_policy *policy, | ||
| 181 | unsigned int target_freq, | ||
| 182 | unsigned int relation) | ||
| 183 | { | ||
| 184 | unsigned int newstate = 0; | ||
| 185 | |||
| 186 | if (cpufreq_frequency_table_target(policy, &elanfreq_table[0], | ||
| 187 | target_freq, relation, &newstate)) | ||
| 188 | return -EINVAL; | ||
| 189 | |||
| 190 | elanfreq_set_cpu_state(newstate); | ||
| 191 | |||
| 192 | return 0; | ||
| 193 | } | ||
| 194 | |||
| 195 | |||
| 196 | /* | ||
| 197 | * Module init and exit code | ||
| 198 | */ | ||
| 199 | |||
| 200 | static int elanfreq_cpu_init(struct cpufreq_policy *policy) | ||
| 201 | { | ||
| 202 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
| 203 | unsigned int i; | ||
| 204 | int result; | ||
| 205 | |||
| 206 | /* capability check */ | ||
| 207 | if ((c->x86_vendor != X86_VENDOR_AMD) || | ||
| 208 | (c->x86 != 4) || (c->x86_model != 10)) | ||
| 209 | return -ENODEV; | ||
| 210 | |||
| 211 | /* max freq */ | ||
| 212 | if (!max_freq) | ||
| 213 | max_freq = elanfreq_get_cpu_frequency(0); | ||
| 214 | |||
| 215 | /* table init */ | ||
| 216 | for (i = 0; (elanfreq_table[i].frequency != CPUFREQ_TABLE_END); i++) { | ||
| 217 | if (elanfreq_table[i].frequency > max_freq) | ||
| 218 | elanfreq_table[i].frequency = CPUFREQ_ENTRY_INVALID; | ||
| 219 | } | ||
| 220 | |||
| 221 | /* cpuinfo and default policy values */ | ||
| 222 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | ||
| 223 | policy->cur = elanfreq_get_cpu_frequency(0); | ||
| 224 | |||
| 225 | result = cpufreq_frequency_table_cpuinfo(policy, elanfreq_table); | ||
| 226 | if (result) | ||
| 227 | return result; | ||
| 228 | |||
| 229 | cpufreq_frequency_table_get_attr(elanfreq_table, policy->cpu); | ||
| 230 | return 0; | ||
| 231 | } | ||
| 232 | |||
| 233 | |||
| 234 | static int elanfreq_cpu_exit(struct cpufreq_policy *policy) | ||
| 235 | { | ||
| 236 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
| 237 | return 0; | ||
| 238 | } | ||
| 239 | |||
| 240 | |||
| 241 | #ifndef MODULE | ||
| 242 | /** | ||
| 243 | * elanfreq_setup - elanfreq command line parameter parsing | ||
| 244 | * | ||
| 245 | * elanfreq command line parameter. Use: | ||
| 246 | * elanfreq=66000 | ||
| 247 | * to set the maximum CPU frequency to 66 MHz. Note that in | ||
| 248 | * case you do not give this boot parameter, the maximum | ||
| 249 | * frequency will fall back to _current_ CPU frequency which | ||
| 250 | * might be lower. If you build this as a module, use the | ||
| 251 | * max_freq module parameter instead. | ||
| 252 | */ | ||
| 253 | static int __init elanfreq_setup(char *str) | ||
| 254 | { | ||
| 255 | max_freq = simple_strtoul(str, &str, 0); | ||
| 256 | printk(KERN_WARNING "You're using the deprecated elanfreq command line option. Use elanfreq.max_freq instead, please!\n"); | ||
| 257 | return 1; | ||
| 258 | } | ||
| 259 | __setup("elanfreq=", elanfreq_setup); | ||
| 260 | #endif | ||
| 261 | |||
| 262 | |||
| 263 | static struct freq_attr *elanfreq_attr[] = { | ||
| 264 | &cpufreq_freq_attr_scaling_available_freqs, | ||
| 265 | NULL, | ||
| 266 | }; | ||
| 267 | |||
| 268 | |||
| 269 | static struct cpufreq_driver elanfreq_driver = { | ||
| 270 | .get = elanfreq_get_cpu_frequency, | ||
| 271 | .verify = elanfreq_verify, | ||
| 272 | .target = elanfreq_target, | ||
| 273 | .init = elanfreq_cpu_init, | ||
| 274 | .exit = elanfreq_cpu_exit, | ||
| 275 | .name = "elanfreq", | ||
| 276 | .owner = THIS_MODULE, | ||
| 277 | .attr = elanfreq_attr, | ||
| 278 | }; | ||
| 279 | |||
| 280 | |||
| 281 | static int __init elanfreq_init(void) | ||
| 282 | { | ||
| 283 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
| 284 | |||
| 285 | /* Test if we have the right hardware */ | ||
| 286 | if ((c->x86_vendor != X86_VENDOR_AMD) || | ||
| 287 | (c->x86 != 4) || (c->x86_model != 10)) { | ||
| 288 | printk(KERN_INFO "elanfreq: error: no Elan processor found!\n"); | ||
| 289 | return -ENODEV; | ||
| 290 | } | ||
| 291 | return cpufreq_register_driver(&elanfreq_driver); | ||
| 292 | } | ||
| 293 | |||
| 294 | |||
| 295 | static void __exit elanfreq_exit(void) | ||
| 296 | { | ||
| 297 | cpufreq_unregister_driver(&elanfreq_driver); | ||
| 298 | } | ||
| 299 | |||
| 300 | |||
| 301 | module_param(max_freq, int, 0444); | ||
| 302 | |||
| 303 | MODULE_LICENSE("GPL"); | ||
| 304 | MODULE_AUTHOR("Robert Schwebel <r.schwebel@pengutronix.de>, " | ||
| 305 | "Sven Geggus <sven@geggus.net>"); | ||
| 306 | MODULE_DESCRIPTION("cpufreq driver for AMD's Elan CPUs"); | ||
| 307 | |||
| 308 | module_init(elanfreq_init); | ||
| 309 | module_exit(elanfreq_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/gx-suspmod.c b/arch/x86/kernel/cpu/cpufreq/gx-suspmod.c deleted file mode 100644 index 32974cf84232..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/gx-suspmod.c +++ /dev/null | |||
| @@ -1,517 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Cyrix MediaGX and NatSemi Geode Suspend Modulation | ||
| 3 | * (C) 2002 Zwane Mwaikambo <zwane@commfireservices.com> | ||
| 4 | * (C) 2002 Hiroshi Miura <miura@da-cha.org> | ||
| 5 | * All Rights Reserved | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU General Public License | ||
| 9 | * version 2 as published by the Free Software Foundation | ||
| 10 | * | ||
| 11 | * The author(s) of this software shall not be held liable for damages | ||
| 12 | * of any nature resulting due to the use of this software. This | ||
| 13 | * software is provided AS-IS with no warranties. | ||
| 14 | * | ||
| 15 | * Theoretical note: | ||
| 16 | * | ||
| 17 | * (see Geode(tm) CS5530 manual (rev.4.1) page.56) | ||
| 18 | * | ||
| 19 | * CPU frequency control on NatSemi Geode GX1/GXLV processor and CS55x0 | ||
| 20 | * are based on Suspend Modulation. | ||
| 21 | * | ||
| 22 | * Suspend Modulation works by asserting and de-asserting the SUSP# pin | ||
| 23 | * to CPU(GX1/GXLV) for configurable durations. When asserting SUSP# | ||
| 24 | * the CPU enters an idle state. GX1 stops its core clock when SUSP# is | ||
| 25 | * asserted then power consumption is reduced. | ||
| 26 | * | ||
| 27 | * Suspend Modulation's OFF/ON duration are configurable | ||
| 28 | * with 'Suspend Modulation OFF Count Register' | ||
| 29 | * and 'Suspend Modulation ON Count Register'. | ||
| 30 | * These registers are 8bit counters that represent the number of | ||
| 31 | * 32us intervals which the SUSP# pin is asserted(ON)/de-asserted(OFF) | ||
| 32 | * to the processor. | ||
| 33 | * | ||
| 34 | * These counters define a ratio which is the effective frequency | ||
| 35 | * of operation of the system. | ||
| 36 | * | ||
| 37 | * OFF Count | ||
| 38 | * F_eff = Fgx * ---------------------- | ||
| 39 | * OFF Count + ON Count | ||
| 40 | * | ||
| 41 | * 0 <= On Count, Off Count <= 255 | ||
| 42 | * | ||
| 43 | * From these limits, we can get register values | ||
| 44 | * | ||
| 45 | * off_duration + on_duration <= MAX_DURATION | ||
| 46 | * on_duration = off_duration * (stock_freq - freq) / freq | ||
| 47 | * | ||
| 48 | * off_duration = (freq * DURATION) / stock_freq | ||
| 49 | * on_duration = DURATION - off_duration | ||
| 50 | * | ||
| 51 | * | ||
| 52 | *--------------------------------------------------------------------------- | ||
| 53 | * | ||
| 54 | * ChangeLog: | ||
| 55 | * Dec. 12, 2003 Hiroshi Miura <miura@da-cha.org> | ||
| 56 | * - fix on/off register mistake | ||
| 57 | * - fix cpu_khz calc when it stops cpu modulation. | ||
| 58 | * | ||
| 59 | * Dec. 11, 2002 Hiroshi Miura <miura@da-cha.org> | ||
| 60 | * - rewrite for Cyrix MediaGX Cx5510/5520 and | ||
| 61 | * NatSemi Geode Cs5530(A). | ||
| 62 | * | ||
| 63 | * Jul. ??, 2002 Zwane Mwaikambo <zwane@commfireservices.com> | ||
| 64 | * - cs5530_mod patch for 2.4.19-rc1. | ||
| 65 | * | ||
| 66 | *--------------------------------------------------------------------------- | ||
| 67 | * | ||
| 68 | * Todo | ||
| 69 | * Test on machines with 5510, 5530, 5530A | ||
| 70 | */ | ||
| 71 | |||
| 72 | /************************************************************************ | ||
| 73 | * Suspend Modulation - Definitions * | ||
| 74 | ************************************************************************/ | ||
| 75 | |||
| 76 | #include <linux/kernel.h> | ||
| 77 | #include <linux/module.h> | ||
| 78 | #include <linux/init.h> | ||
| 79 | #include <linux/smp.h> | ||
| 80 | #include <linux/cpufreq.h> | ||
| 81 | #include <linux/pci.h> | ||
| 82 | #include <linux/errno.h> | ||
| 83 | #include <linux/slab.h> | ||
| 84 | |||
| 85 | #include <asm/processor-cyrix.h> | ||
| 86 | |||
| 87 | /* PCI config registers, all at F0 */ | ||
| 88 | #define PCI_PMER1 0x80 /* power management enable register 1 */ | ||
| 89 | #define PCI_PMER2 0x81 /* power management enable register 2 */ | ||
| 90 | #define PCI_PMER3 0x82 /* power management enable register 3 */ | ||
| 91 | #define PCI_IRQTC 0x8c /* irq speedup timer counter register:typical 2 to 4ms */ | ||
| 92 | #define PCI_VIDTC 0x8d /* video speedup timer counter register: typical 50 to 100ms */ | ||
| 93 | #define PCI_MODOFF 0x94 /* suspend modulation OFF counter register, 1 = 32us */ | ||
| 94 | #define PCI_MODON 0x95 /* suspend modulation ON counter register */ | ||
| 95 | #define PCI_SUSCFG 0x96 /* suspend configuration register */ | ||
| 96 | |||
| 97 | /* PMER1 bits */ | ||
| 98 | #define GPM (1<<0) /* global power management */ | ||
| 99 | #define GIT (1<<1) /* globally enable PM device idle timers */ | ||
| 100 | #define GTR (1<<2) /* globally enable IO traps */ | ||
| 101 | #define IRQ_SPDUP (1<<3) /* disable clock throttle during interrupt handling */ | ||
| 102 | #define VID_SPDUP (1<<4) /* disable clock throttle during vga video handling */ | ||
| 103 | |||
| 104 | /* SUSCFG bits */ | ||
| 105 | #define SUSMOD (1<<0) /* enable/disable suspend modulation */ | ||
| 106 | /* the below is supported only with cs5530 (after rev.1.2)/cs5530A */ | ||
| 107 | #define SMISPDUP (1<<1) /* select how SMI re-enable suspend modulation: */ | ||
| 108 | /* IRQTC timer or read SMI speedup disable reg.(F1BAR[08-09h]) */ | ||
| 109 | #define SUSCFG (1<<2) /* enable powering down a GXLV processor. "Special 3Volt Suspend" mode */ | ||
| 110 | /* the below is supported only with cs5530A */ | ||
| 111 | #define PWRSVE_ISA (1<<3) /* stop ISA clock */ | ||
| 112 | #define PWRSVE (1<<4) /* active idle */ | ||
| 113 | |||
| 114 | struct gxfreq_params { | ||
| 115 | u8 on_duration; | ||
| 116 | u8 off_duration; | ||
| 117 | u8 pci_suscfg; | ||
| 118 | u8 pci_pmer1; | ||
| 119 | u8 pci_pmer2; | ||
| 120 | struct pci_dev *cs55x0; | ||
| 121 | }; | ||
| 122 | |||
| 123 | static struct gxfreq_params *gx_params; | ||
| 124 | static int stock_freq; | ||
| 125 | |||
| 126 | /* PCI bus clock - defaults to 30.000 if cpu_khz is not available */ | ||
| 127 | static int pci_busclk; | ||
| 128 | module_param(pci_busclk, int, 0444); | ||
| 129 | |||
| 130 | /* maximum duration for which the cpu may be suspended | ||
| 131 | * (32us * MAX_DURATION). If no parameter is given, this defaults | ||
| 132 | * to 255. | ||
| 133 | * Note that this leads to a maximum of 8 ms(!) where the CPU clock | ||
| 134 | * is suspended -- processing power is just 0.39% of what it used to be, | ||
| 135 | * though. 781.25 kHz(!) for a 200 MHz processor -- wow. */ | ||
| 136 | static int max_duration = 255; | ||
| 137 | module_param(max_duration, int, 0444); | ||
| 138 | |||
| 139 | /* For the default policy, we want at least some processing power | ||
| 140 | * - let's say 5%. (min = maxfreq / POLICY_MIN_DIV) | ||
| 141 | */ | ||
| 142 | #define POLICY_MIN_DIV 20 | ||
| 143 | |||
| 144 | |||
| 145 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
| 146 | "gx-suspmod", msg) | ||
| 147 | |||
| 148 | /** | ||
| 149 | * we can detect a core multipiler from dir0_lsb | ||
| 150 | * from GX1 datasheet p.56, | ||
| 151 | * MULT[3:0]: | ||
| 152 | * 0000 = SYSCLK multiplied by 4 (test only) | ||
| 153 | * 0001 = SYSCLK multiplied by 10 | ||
| 154 | * 0010 = SYSCLK multiplied by 4 | ||
| 155 | * 0011 = SYSCLK multiplied by 6 | ||
| 156 | * 0100 = SYSCLK multiplied by 9 | ||
| 157 | * 0101 = SYSCLK multiplied by 5 | ||
| 158 | * 0110 = SYSCLK multiplied by 7 | ||
| 159 | * 0111 = SYSCLK multiplied by 8 | ||
| 160 | * of 33.3MHz | ||
| 161 | **/ | ||
| 162 | static int gx_freq_mult[16] = { | ||
| 163 | 4, 10, 4, 6, 9, 5, 7, 8, | ||
| 164 | 0, 0, 0, 0, 0, 0, 0, 0 | ||
| 165 | }; | ||
| 166 | |||
| 167 | |||
| 168 | /**************************************************************** | ||
| 169 | * Low Level chipset interface * | ||
| 170 | ****************************************************************/ | ||
| 171 | static struct pci_device_id gx_chipset_tbl[] __initdata = { | ||
| 172 | { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5530_LEGACY), }, | ||
| 173 | { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5520), }, | ||
| 174 | { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5510), }, | ||
| 175 | { 0, }, | ||
| 176 | }; | ||
| 177 | |||
| 178 | static void gx_write_byte(int reg, int value) | ||
| 179 | { | ||
| 180 | pci_write_config_byte(gx_params->cs55x0, reg, value); | ||
| 181 | } | ||
| 182 | |||
| 183 | /** | ||
| 184 | * gx_detect_chipset: | ||
| 185 | * | ||
| 186 | **/ | ||
| 187 | static __init struct pci_dev *gx_detect_chipset(void) | ||
| 188 | { | ||
| 189 | struct pci_dev *gx_pci = NULL; | ||
| 190 | |||
| 191 | /* check if CPU is a MediaGX or a Geode. */ | ||
| 192 | if ((boot_cpu_data.x86_vendor != X86_VENDOR_NSC) && | ||
| 193 | (boot_cpu_data.x86_vendor != X86_VENDOR_CYRIX)) { | ||
| 194 | dprintk("error: no MediaGX/Geode processor found!\n"); | ||
| 195 | return NULL; | ||
| 196 | } | ||
| 197 | |||
| 198 | /* detect which companion chip is used */ | ||
| 199 | for_each_pci_dev(gx_pci) { | ||
| 200 | if ((pci_match_id(gx_chipset_tbl, gx_pci)) != NULL) | ||
| 201 | return gx_pci; | ||
| 202 | } | ||
| 203 | |||
| 204 | dprintk("error: no supported chipset found!\n"); | ||
| 205 | return NULL; | ||
| 206 | } | ||
| 207 | |||
| 208 | /** | ||
| 209 | * gx_get_cpuspeed: | ||
| 210 | * | ||
| 211 | * Finds out at which efficient frequency the Cyrix MediaGX/NatSemi | ||
| 212 | * Geode CPU runs. | ||
| 213 | */ | ||
| 214 | static unsigned int gx_get_cpuspeed(unsigned int cpu) | ||
| 215 | { | ||
| 216 | if ((gx_params->pci_suscfg & SUSMOD) == 0) | ||
| 217 | return stock_freq; | ||
| 218 | |||
| 219 | return (stock_freq * gx_params->off_duration) | ||
| 220 | / (gx_params->on_duration + gx_params->off_duration); | ||
| 221 | } | ||
| 222 | |||
| 223 | /** | ||
| 224 | * gx_validate_speed: | ||
| 225 | * determine current cpu speed | ||
| 226 | * | ||
| 227 | **/ | ||
| 228 | |||
| 229 | static unsigned int gx_validate_speed(unsigned int khz, u8 *on_duration, | ||
| 230 | u8 *off_duration) | ||
| 231 | { | ||
| 232 | unsigned int i; | ||
| 233 | u8 tmp_on, tmp_off; | ||
| 234 | int old_tmp_freq = stock_freq; | ||
| 235 | int tmp_freq; | ||
| 236 | |||
| 237 | *off_duration = 1; | ||
| 238 | *on_duration = 0; | ||
| 239 | |||
| 240 | for (i = max_duration; i > 0; i--) { | ||
| 241 | tmp_off = ((khz * i) / stock_freq) & 0xff; | ||
| 242 | tmp_on = i - tmp_off; | ||
| 243 | tmp_freq = (stock_freq * tmp_off) / i; | ||
| 244 | /* if this relation is closer to khz, use this. If it's equal, | ||
| 245 | * prefer it, too - lower latency */ | ||
| 246 | if (abs(tmp_freq - khz) <= abs(old_tmp_freq - khz)) { | ||
| 247 | *on_duration = tmp_on; | ||
| 248 | *off_duration = tmp_off; | ||
| 249 | old_tmp_freq = tmp_freq; | ||
| 250 | } | ||
| 251 | } | ||
| 252 | |||
| 253 | return old_tmp_freq; | ||
| 254 | } | ||
| 255 | |||
| 256 | |||
| 257 | /** | ||
| 258 | * gx_set_cpuspeed: | ||
| 259 | * set cpu speed in khz. | ||
| 260 | **/ | ||
| 261 | |||
| 262 | static void gx_set_cpuspeed(unsigned int khz) | ||
| 263 | { | ||
| 264 | u8 suscfg, pmer1; | ||
| 265 | unsigned int new_khz; | ||
| 266 | unsigned long flags; | ||
| 267 | struct cpufreq_freqs freqs; | ||
| 268 | |||
| 269 | freqs.cpu = 0; | ||
| 270 | freqs.old = gx_get_cpuspeed(0); | ||
| 271 | |||
| 272 | new_khz = gx_validate_speed(khz, &gx_params->on_duration, | ||
| 273 | &gx_params->off_duration); | ||
| 274 | |||
| 275 | freqs.new = new_khz; | ||
| 276 | |||
| 277 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
| 278 | local_irq_save(flags); | ||
| 279 | |||
| 280 | |||
| 281 | |||
| 282 | if (new_khz != stock_freq) { | ||
| 283 | /* if new khz == 100% of CPU speed, it is special case */ | ||
| 284 | switch (gx_params->cs55x0->device) { | ||
| 285 | case PCI_DEVICE_ID_CYRIX_5530_LEGACY: | ||
| 286 | pmer1 = gx_params->pci_pmer1 | IRQ_SPDUP | VID_SPDUP; | ||
| 287 | /* FIXME: need to test other values -- Zwane,Miura */ | ||
| 288 | /* typical 2 to 4ms */ | ||
| 289 | gx_write_byte(PCI_IRQTC, 4); | ||
| 290 | /* typical 50 to 100ms */ | ||
| 291 | gx_write_byte(PCI_VIDTC, 100); | ||
| 292 | gx_write_byte(PCI_PMER1, pmer1); | ||
| 293 | |||
| 294 | if (gx_params->cs55x0->revision < 0x10) { | ||
| 295 | /* CS5530(rev 1.2, 1.3) */ | ||
| 296 | suscfg = gx_params->pci_suscfg|SUSMOD; | ||
| 297 | } else { | ||
| 298 | /* CS5530A,B.. */ | ||
| 299 | suscfg = gx_params->pci_suscfg|SUSMOD|PWRSVE; | ||
| 300 | } | ||
| 301 | break; | ||
| 302 | case PCI_DEVICE_ID_CYRIX_5520: | ||
| 303 | case PCI_DEVICE_ID_CYRIX_5510: | ||
| 304 | suscfg = gx_params->pci_suscfg | SUSMOD; | ||
| 305 | break; | ||
| 306 | default: | ||
| 307 | local_irq_restore(flags); | ||
| 308 | dprintk("fatal: try to set unknown chipset.\n"); | ||
| 309 | return; | ||
| 310 | } | ||
| 311 | } else { | ||
| 312 | suscfg = gx_params->pci_suscfg & ~(SUSMOD); | ||
| 313 | gx_params->off_duration = 0; | ||
| 314 | gx_params->on_duration = 0; | ||
| 315 | dprintk("suspend modulation disabled: cpu runs 100%% speed.\n"); | ||
| 316 | } | ||
| 317 | |||
| 318 | gx_write_byte(PCI_MODOFF, gx_params->off_duration); | ||
| 319 | gx_write_byte(PCI_MODON, gx_params->on_duration); | ||
| 320 | |||
| 321 | gx_write_byte(PCI_SUSCFG, suscfg); | ||
| 322 | pci_read_config_byte(gx_params->cs55x0, PCI_SUSCFG, &suscfg); | ||
| 323 | |||
| 324 | local_irq_restore(flags); | ||
| 325 | |||
| 326 | gx_params->pci_suscfg = suscfg; | ||
| 327 | |||
| 328 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 329 | |||
| 330 | dprintk("suspend modulation w/ duration of ON:%d us, OFF:%d us\n", | ||
| 331 | gx_params->on_duration * 32, gx_params->off_duration * 32); | ||
| 332 | dprintk("suspend modulation w/ clock speed: %d kHz.\n", freqs.new); | ||
| 333 | } | ||
| 334 | |||
| 335 | /**************************************************************** | ||
| 336 | * High level functions * | ||
| 337 | ****************************************************************/ | ||
| 338 | |||
| 339 | /* | ||
| 340 | * cpufreq_gx_verify: test if frequency range is valid | ||
| 341 | * | ||
| 342 | * This function checks if a given frequency range in kHz is valid | ||
| 343 | * for the hardware supported by the driver. | ||
| 344 | */ | ||
| 345 | |||
| 346 | static int cpufreq_gx_verify(struct cpufreq_policy *policy) | ||
| 347 | { | ||
| 348 | unsigned int tmp_freq = 0; | ||
| 349 | u8 tmp1, tmp2; | ||
| 350 | |||
| 351 | if (!stock_freq || !policy) | ||
| 352 | return -EINVAL; | ||
| 353 | |||
| 354 | policy->cpu = 0; | ||
| 355 | cpufreq_verify_within_limits(policy, (stock_freq / max_duration), | ||
| 356 | stock_freq); | ||
| 357 | |||
| 358 | /* it needs to be assured that at least one supported frequency is | ||
| 359 | * within policy->min and policy->max. If it is not, policy->max | ||
| 360 | * needs to be increased until one freuqency is supported. | ||
| 361 | * policy->min may not be decreased, though. This way we guarantee a | ||
| 362 | * specific processing capacity. | ||
| 363 | */ | ||
| 364 | tmp_freq = gx_validate_speed(policy->min, &tmp1, &tmp2); | ||
| 365 | if (tmp_freq < policy->min) | ||
| 366 | tmp_freq += stock_freq / max_duration; | ||
| 367 | policy->min = tmp_freq; | ||
| 368 | if (policy->min > policy->max) | ||
| 369 | policy->max = tmp_freq; | ||
| 370 | tmp_freq = gx_validate_speed(policy->max, &tmp1, &tmp2); | ||
| 371 | if (tmp_freq > policy->max) | ||
| 372 | tmp_freq -= stock_freq / max_duration; | ||
| 373 | policy->max = tmp_freq; | ||
| 374 | if (policy->max < policy->min) | ||
| 375 | policy->max = policy->min; | ||
| 376 | cpufreq_verify_within_limits(policy, (stock_freq / max_duration), | ||
| 377 | stock_freq); | ||
| 378 | |||
| 379 | return 0; | ||
| 380 | } | ||
| 381 | |||
| 382 | /* | ||
| 383 | * cpufreq_gx_target: | ||
| 384 | * | ||
| 385 | */ | ||
| 386 | static int cpufreq_gx_target(struct cpufreq_policy *policy, | ||
| 387 | unsigned int target_freq, | ||
| 388 | unsigned int relation) | ||
| 389 | { | ||
| 390 | u8 tmp1, tmp2; | ||
| 391 | unsigned int tmp_freq; | ||
| 392 | |||
| 393 | if (!stock_freq || !policy) | ||
| 394 | return -EINVAL; | ||
| 395 | |||
| 396 | policy->cpu = 0; | ||
| 397 | |||
| 398 | tmp_freq = gx_validate_speed(target_freq, &tmp1, &tmp2); | ||
| 399 | while (tmp_freq < policy->min) { | ||
| 400 | tmp_freq += stock_freq / max_duration; | ||
| 401 | tmp_freq = gx_validate_speed(tmp_freq, &tmp1, &tmp2); | ||
| 402 | } | ||
| 403 | while (tmp_freq > policy->max) { | ||
| 404 | tmp_freq -= stock_freq / max_duration; | ||
| 405 | tmp_freq = gx_validate_speed(tmp_freq, &tmp1, &tmp2); | ||
| 406 | } | ||
| 407 | |||
| 408 | gx_set_cpuspeed(tmp_freq); | ||
| 409 | |||
| 410 | return 0; | ||
| 411 | } | ||
| 412 | |||
| 413 | static int cpufreq_gx_cpu_init(struct cpufreq_policy *policy) | ||
| 414 | { | ||
| 415 | unsigned int maxfreq, curfreq; | ||
| 416 | |||
| 417 | if (!policy || policy->cpu != 0) | ||
| 418 | return -ENODEV; | ||
| 419 | |||
| 420 | /* determine maximum frequency */ | ||
| 421 | if (pci_busclk) | ||
| 422 | maxfreq = pci_busclk * gx_freq_mult[getCx86(CX86_DIR1) & 0x0f]; | ||
| 423 | else if (cpu_khz) | ||
| 424 | maxfreq = cpu_khz; | ||
| 425 | else | ||
| 426 | maxfreq = 30000 * gx_freq_mult[getCx86(CX86_DIR1) & 0x0f]; | ||
| 427 | |||
| 428 | stock_freq = maxfreq; | ||
| 429 | curfreq = gx_get_cpuspeed(0); | ||
| 430 | |||
| 431 | dprintk("cpu max frequency is %d.\n", maxfreq); | ||
| 432 | dprintk("cpu current frequency is %dkHz.\n", curfreq); | ||
| 433 | |||
| 434 | /* setup basic struct for cpufreq API */ | ||
| 435 | policy->cpu = 0; | ||
| 436 | |||
| 437 | if (max_duration < POLICY_MIN_DIV) | ||
| 438 | policy->min = maxfreq / max_duration; | ||
| 439 | else | ||
| 440 | policy->min = maxfreq / POLICY_MIN_DIV; | ||
| 441 | policy->max = maxfreq; | ||
| 442 | policy->cur = curfreq; | ||
| 443 | policy->cpuinfo.min_freq = maxfreq / max_duration; | ||
| 444 | policy->cpuinfo.max_freq = maxfreq; | ||
| 445 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | ||
| 446 | |||
| 447 | return 0; | ||
| 448 | } | ||
| 449 | |||
| 450 | /* | ||
| 451 | * cpufreq_gx_init: | ||
| 452 | * MediaGX/Geode GX initialize cpufreq driver | ||
| 453 | */ | ||
| 454 | static struct cpufreq_driver gx_suspmod_driver = { | ||
| 455 | .get = gx_get_cpuspeed, | ||
| 456 | .verify = cpufreq_gx_verify, | ||
| 457 | .target = cpufreq_gx_target, | ||
| 458 | .init = cpufreq_gx_cpu_init, | ||
| 459 | .name = "gx-suspmod", | ||
| 460 | .owner = THIS_MODULE, | ||
| 461 | }; | ||
| 462 | |||
| 463 | static int __init cpufreq_gx_init(void) | ||
| 464 | { | ||
| 465 | int ret; | ||
| 466 | struct gxfreq_params *params; | ||
| 467 | struct pci_dev *gx_pci; | ||
| 468 | |||
| 469 | /* Test if we have the right hardware */ | ||
| 470 | gx_pci = gx_detect_chipset(); | ||
| 471 | if (gx_pci == NULL) | ||
| 472 | return -ENODEV; | ||
| 473 | |||
| 474 | /* check whether module parameters are sane */ | ||
| 475 | if (max_duration > 0xff) | ||
| 476 | max_duration = 0xff; | ||
| 477 | |||
| 478 | dprintk("geode suspend modulation available.\n"); | ||
| 479 | |||
| 480 | params = kzalloc(sizeof(struct gxfreq_params), GFP_KERNEL); | ||
| 481 | if (params == NULL) | ||
| 482 | return -ENOMEM; | ||
| 483 | |||
| 484 | params->cs55x0 = gx_pci; | ||
| 485 | gx_params = params; | ||
| 486 | |||
| 487 | /* keep cs55x0 configurations */ | ||
| 488 | pci_read_config_byte(params->cs55x0, PCI_SUSCFG, &(params->pci_suscfg)); | ||
| 489 | pci_read_config_byte(params->cs55x0, PCI_PMER1, &(params->pci_pmer1)); | ||
| 490 | pci_read_config_byte(params->cs55x0, PCI_PMER2, &(params->pci_pmer2)); | ||
| 491 | pci_read_config_byte(params->cs55x0, PCI_MODON, &(params->on_duration)); | ||
| 492 | pci_read_config_byte(params->cs55x0, PCI_MODOFF, | ||
| 493 | &(params->off_duration)); | ||
| 494 | |||
| 495 | ret = cpufreq_register_driver(&gx_suspmod_driver); | ||
| 496 | if (ret) { | ||
| 497 | kfree(params); | ||
| 498 | return ret; /* register error! */ | ||
| 499 | } | ||
| 500 | |||
| 501 | return 0; | ||
| 502 | } | ||
| 503 | |||
| 504 | static void __exit cpufreq_gx_exit(void) | ||
| 505 | { | ||
| 506 | cpufreq_unregister_driver(&gx_suspmod_driver); | ||
| 507 | pci_dev_put(gx_params->cs55x0); | ||
| 508 | kfree(gx_params); | ||
| 509 | } | ||
| 510 | |||
| 511 | MODULE_AUTHOR("Hiroshi Miura <miura@da-cha.org>"); | ||
| 512 | MODULE_DESCRIPTION("Cpufreq driver for Cyrix MediaGX and NatSemi Geode"); | ||
| 513 | MODULE_LICENSE("GPL"); | ||
| 514 | |||
| 515 | module_init(cpufreq_gx_init); | ||
| 516 | module_exit(cpufreq_gx_exit); | ||
| 517 | |||
diff --git a/arch/x86/kernel/cpu/cpufreq/longhaul.c b/arch/x86/kernel/cpu/cpufreq/longhaul.c deleted file mode 100644 index cf48cdd6907d..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/longhaul.c +++ /dev/null | |||
| @@ -1,1029 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * (C) 2001-2004 Dave Jones. <davej@redhat.com> | ||
| 3 | * (C) 2002 Padraig Brady. <padraig@antefacto.com> | ||
| 4 | * | ||
| 5 | * Licensed under the terms of the GNU GPL License version 2. | ||
| 6 | * Based upon datasheets & sample CPUs kindly provided by VIA. | ||
| 7 | * | ||
| 8 | * VIA have currently 3 different versions of Longhaul. | ||
| 9 | * Version 1 (Longhaul) uses the BCR2 MSR at 0x1147. | ||
| 10 | * It is present only in Samuel 1 (C5A), Samuel 2 (C5B) stepping 0. | ||
| 11 | * Version 2 of longhaul is backward compatible with v1, but adds | ||
| 12 | * LONGHAUL MSR for purpose of both frequency and voltage scaling. | ||
| 13 | * Present in Samuel 2 (steppings 1-7 only) (C5B), and Ezra (C5C). | ||
| 14 | * Version 3 of longhaul got renamed to Powersaver and redesigned | ||
| 15 | * to use only the POWERSAVER MSR at 0x110a. | ||
| 16 | * It is present in Ezra-T (C5M), Nehemiah (C5X) and above. | ||
| 17 | * It's pretty much the same feature wise to longhaul v2, though | ||
| 18 | * there is provision for scaling FSB too, but this doesn't work | ||
| 19 | * too well in practice so we don't even try to use this. | ||
| 20 | * | ||
| 21 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
| 22 | */ | ||
| 23 | |||
| 24 | #include <linux/kernel.h> | ||
| 25 | #include <linux/module.h> | ||
| 26 | #include <linux/moduleparam.h> | ||
| 27 | #include <linux/init.h> | ||
| 28 | #include <linux/cpufreq.h> | ||
| 29 | #include <linux/pci.h> | ||
| 30 | #include <linux/slab.h> | ||
| 31 | #include <linux/string.h> | ||
| 32 | #include <linux/delay.h> | ||
| 33 | #include <linux/timex.h> | ||
| 34 | #include <linux/io.h> | ||
| 35 | #include <linux/acpi.h> | ||
| 36 | |||
| 37 | #include <asm/msr.h> | ||
| 38 | #include <acpi/processor.h> | ||
| 39 | |||
| 40 | #include "longhaul.h" | ||
| 41 | |||
| 42 | #define PFX "longhaul: " | ||
| 43 | |||
| 44 | #define TYPE_LONGHAUL_V1 1 | ||
| 45 | #define TYPE_LONGHAUL_V2 2 | ||
| 46 | #define TYPE_POWERSAVER 3 | ||
| 47 | |||
| 48 | #define CPU_SAMUEL 1 | ||
| 49 | #define CPU_SAMUEL2 2 | ||
| 50 | #define CPU_EZRA 3 | ||
| 51 | #define CPU_EZRA_T 4 | ||
| 52 | #define CPU_NEHEMIAH 5 | ||
| 53 | #define CPU_NEHEMIAH_C 6 | ||
| 54 | |||
| 55 | /* Flags */ | ||
| 56 | #define USE_ACPI_C3 (1 << 1) | ||
| 57 | #define USE_NORTHBRIDGE (1 << 2) | ||
| 58 | |||
| 59 | static int cpu_model; | ||
| 60 | static unsigned int numscales = 16; | ||
| 61 | static unsigned int fsb; | ||
| 62 | |||
| 63 | static const struct mV_pos *vrm_mV_table; | ||
| 64 | static const unsigned char *mV_vrm_table; | ||
| 65 | |||
| 66 | static unsigned int highest_speed, lowest_speed; /* kHz */ | ||
| 67 | static unsigned int minmult, maxmult; | ||
| 68 | static int can_scale_voltage; | ||
| 69 | static struct acpi_processor *pr; | ||
| 70 | static struct acpi_processor_cx *cx; | ||
| 71 | static u32 acpi_regs_addr; | ||
| 72 | static u8 longhaul_flags; | ||
| 73 | static unsigned int longhaul_index; | ||
| 74 | |||
| 75 | /* Module parameters */ | ||
| 76 | static int scale_voltage; | ||
| 77 | static int disable_acpi_c3; | ||
| 78 | static int revid_errata; | ||
| 79 | |||
| 80 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
| 81 | "longhaul", msg) | ||
| 82 | |||
| 83 | |||
| 84 | /* Clock ratios multiplied by 10 */ | ||
| 85 | static int mults[32]; | ||
| 86 | static int eblcr[32]; | ||
| 87 | static int longhaul_version; | ||
| 88 | static struct cpufreq_frequency_table *longhaul_table; | ||
| 89 | |||
| 90 | #ifdef CONFIG_CPU_FREQ_DEBUG | ||
| 91 | static char speedbuffer[8]; | ||
| 92 | |||
| 93 | static char *print_speed(int speed) | ||
| 94 | { | ||
| 95 | if (speed < 1000) { | ||
| 96 | snprintf(speedbuffer, sizeof(speedbuffer), "%dMHz", speed); | ||
| 97 | return speedbuffer; | ||
| 98 | } | ||
| 99 | |||
| 100 | if (speed%1000 == 0) | ||
| 101 | snprintf(speedbuffer, sizeof(speedbuffer), | ||
| 102 | "%dGHz", speed/1000); | ||
| 103 | else | ||
| 104 | snprintf(speedbuffer, sizeof(speedbuffer), | ||
| 105 | "%d.%dGHz", speed/1000, (speed%1000)/100); | ||
| 106 | |||
| 107 | return speedbuffer; | ||
| 108 | } | ||
| 109 | #endif | ||
| 110 | |||
| 111 | |||
| 112 | static unsigned int calc_speed(int mult) | ||
| 113 | { | ||
| 114 | int khz; | ||
| 115 | khz = (mult/10)*fsb; | ||
| 116 | if (mult%10) | ||
| 117 | khz += fsb/2; | ||
| 118 | khz *= 1000; | ||
| 119 | return khz; | ||
| 120 | } | ||
| 121 | |||
| 122 | |||
| 123 | static int longhaul_get_cpu_mult(void) | ||
| 124 | { | ||
| 125 | unsigned long invalue = 0, lo, hi; | ||
| 126 | |||
| 127 | rdmsr(MSR_IA32_EBL_CR_POWERON, lo, hi); | ||
| 128 | invalue = (lo & (1<<22|1<<23|1<<24|1<<25))>>22; | ||
| 129 | if (longhaul_version == TYPE_LONGHAUL_V2 || | ||
| 130 | longhaul_version == TYPE_POWERSAVER) { | ||
| 131 | if (lo & (1<<27)) | ||
| 132 | invalue += 16; | ||
| 133 | } | ||
| 134 | return eblcr[invalue]; | ||
| 135 | } | ||
| 136 | |||
| 137 | /* For processor with BCR2 MSR */ | ||
| 138 | |||
| 139 | static void do_longhaul1(unsigned int mults_index) | ||
| 140 | { | ||
| 141 | union msr_bcr2 bcr2; | ||
| 142 | |||
| 143 | rdmsrl(MSR_VIA_BCR2, bcr2.val); | ||
| 144 | /* Enable software clock multiplier */ | ||
| 145 | bcr2.bits.ESOFTBF = 1; | ||
| 146 | bcr2.bits.CLOCKMUL = mults_index & 0xff; | ||
| 147 | |||
| 148 | /* Sync to timer tick */ | ||
| 149 | safe_halt(); | ||
| 150 | /* Change frequency on next halt or sleep */ | ||
| 151 | wrmsrl(MSR_VIA_BCR2, bcr2.val); | ||
| 152 | /* Invoke transition */ | ||
| 153 | ACPI_FLUSH_CPU_CACHE(); | ||
| 154 | halt(); | ||
| 155 | |||
| 156 | /* Disable software clock multiplier */ | ||
| 157 | local_irq_disable(); | ||
| 158 | rdmsrl(MSR_VIA_BCR2, bcr2.val); | ||
| 159 | bcr2.bits.ESOFTBF = 0; | ||
| 160 | wrmsrl(MSR_VIA_BCR2, bcr2.val); | ||
| 161 | } | ||
| 162 | |||
| 163 | /* For processor with Longhaul MSR */ | ||
| 164 | |||
| 165 | static void do_powersaver(int cx_address, unsigned int mults_index, | ||
| 166 | unsigned int dir) | ||
| 167 | { | ||
| 168 | union msr_longhaul longhaul; | ||
| 169 | u32 t; | ||
| 170 | |||
| 171 | rdmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
| 172 | /* Setup new frequency */ | ||
| 173 | if (!revid_errata) | ||
| 174 | longhaul.bits.RevisionKey = longhaul.bits.RevisionID; | ||
| 175 | else | ||
| 176 | longhaul.bits.RevisionKey = 0; | ||
| 177 | longhaul.bits.SoftBusRatio = mults_index & 0xf; | ||
| 178 | longhaul.bits.SoftBusRatio4 = (mults_index & 0x10) >> 4; | ||
| 179 | /* Setup new voltage */ | ||
| 180 | if (can_scale_voltage) | ||
| 181 | longhaul.bits.SoftVID = (mults_index >> 8) & 0x1f; | ||
| 182 | /* Sync to timer tick */ | ||
| 183 | safe_halt(); | ||
| 184 | /* Raise voltage if necessary */ | ||
| 185 | if (can_scale_voltage && dir) { | ||
| 186 | longhaul.bits.EnableSoftVID = 1; | ||
| 187 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
| 188 | /* Change voltage */ | ||
| 189 | if (!cx_address) { | ||
| 190 | ACPI_FLUSH_CPU_CACHE(); | ||
| 191 | halt(); | ||
| 192 | } else { | ||
| 193 | ACPI_FLUSH_CPU_CACHE(); | ||
| 194 | /* Invoke C3 */ | ||
| 195 | inb(cx_address); | ||
| 196 | /* Dummy op - must do something useless after P_LVL3 | ||
| 197 | * read */ | ||
| 198 | t = inl(acpi_gbl_FADT.xpm_timer_block.address); | ||
| 199 | } | ||
| 200 | longhaul.bits.EnableSoftVID = 0; | ||
| 201 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
| 202 | } | ||
| 203 | |||
| 204 | /* Change frequency on next halt or sleep */ | ||
| 205 | longhaul.bits.EnableSoftBusRatio = 1; | ||
| 206 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
| 207 | if (!cx_address) { | ||
| 208 | ACPI_FLUSH_CPU_CACHE(); | ||
| 209 | halt(); | ||
| 210 | } else { | ||
| 211 | ACPI_FLUSH_CPU_CACHE(); | ||
| 212 | /* Invoke C3 */ | ||
| 213 | inb(cx_address); | ||
| 214 | /* Dummy op - must do something useless after P_LVL3 read */ | ||
| 215 | t = inl(acpi_gbl_FADT.xpm_timer_block.address); | ||
| 216 | } | ||
| 217 | /* Disable bus ratio bit */ | ||
| 218 | longhaul.bits.EnableSoftBusRatio = 0; | ||
| 219 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
| 220 | |||
| 221 | /* Reduce voltage if necessary */ | ||
| 222 | if (can_scale_voltage && !dir) { | ||
| 223 | longhaul.bits.EnableSoftVID = 1; | ||
| 224 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
| 225 | /* Change voltage */ | ||
| 226 | if (!cx_address) { | ||
| 227 | ACPI_FLUSH_CPU_CACHE(); | ||
| 228 | halt(); | ||
| 229 | } else { | ||
| 230 | ACPI_FLUSH_CPU_CACHE(); | ||
| 231 | /* Invoke C3 */ | ||
| 232 | inb(cx_address); | ||
| 233 | /* Dummy op - must do something useless after P_LVL3 | ||
| 234 | * read */ | ||
| 235 | t = inl(acpi_gbl_FADT.xpm_timer_block.address); | ||
| 236 | } | ||
| 237 | longhaul.bits.EnableSoftVID = 0; | ||
| 238 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
| 239 | } | ||
| 240 | } | ||
| 241 | |||
| 242 | /** | ||
| 243 | * longhaul_set_cpu_frequency() | ||
| 244 | * @mults_index : bitpattern of the new multiplier. | ||
| 245 | * | ||
| 246 | * Sets a new clock ratio. | ||
| 247 | */ | ||
| 248 | |||
| 249 | static void longhaul_setstate(unsigned int table_index) | ||
| 250 | { | ||
| 251 | unsigned int mults_index; | ||
| 252 | int speed, mult; | ||
| 253 | struct cpufreq_freqs freqs; | ||
| 254 | unsigned long flags; | ||
| 255 | unsigned int pic1_mask, pic2_mask; | ||
| 256 | u16 bm_status = 0; | ||
| 257 | u32 bm_timeout = 1000; | ||
| 258 | unsigned int dir = 0; | ||
| 259 | |||
| 260 | mults_index = longhaul_table[table_index].index; | ||
| 261 | /* Safety precautions */ | ||
| 262 | mult = mults[mults_index & 0x1f]; | ||
| 263 | if (mult == -1) | ||
| 264 | return; | ||
| 265 | speed = calc_speed(mult); | ||
| 266 | if ((speed > highest_speed) || (speed < lowest_speed)) | ||
| 267 | return; | ||
| 268 | /* Voltage transition before frequency transition? */ | ||
| 269 | if (can_scale_voltage && longhaul_index < table_index) | ||
| 270 | dir = 1; | ||
| 271 | |||
| 272 | freqs.old = calc_speed(longhaul_get_cpu_mult()); | ||
| 273 | freqs.new = speed; | ||
| 274 | freqs.cpu = 0; /* longhaul.c is UP only driver */ | ||
| 275 | |||
| 276 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
| 277 | |||
| 278 | dprintk("Setting to FSB:%dMHz Mult:%d.%dx (%s)\n", | ||
| 279 | fsb, mult/10, mult%10, print_speed(speed/1000)); | ||
| 280 | retry_loop: | ||
| 281 | preempt_disable(); | ||
| 282 | local_irq_save(flags); | ||
| 283 | |||
| 284 | pic2_mask = inb(0xA1); | ||
| 285 | pic1_mask = inb(0x21); /* works on C3. save mask. */ | ||
| 286 | outb(0xFF, 0xA1); /* Overkill */ | ||
| 287 | outb(0xFE, 0x21); /* TMR0 only */ | ||
| 288 | |||
| 289 | /* Wait while PCI bus is busy. */ | ||
| 290 | if (acpi_regs_addr && (longhaul_flags & USE_NORTHBRIDGE | ||
| 291 | || ((pr != NULL) && pr->flags.bm_control))) { | ||
| 292 | bm_status = inw(acpi_regs_addr); | ||
| 293 | bm_status &= 1 << 4; | ||
| 294 | while (bm_status && bm_timeout) { | ||
| 295 | outw(1 << 4, acpi_regs_addr); | ||
| 296 | bm_timeout--; | ||
| 297 | bm_status = inw(acpi_regs_addr); | ||
| 298 | bm_status &= 1 << 4; | ||
| 299 | } | ||
| 300 | } | ||
| 301 | |||
| 302 | if (longhaul_flags & USE_NORTHBRIDGE) { | ||
| 303 | /* Disable AGP and PCI arbiters */ | ||
| 304 | outb(3, 0x22); | ||
| 305 | } else if ((pr != NULL) && pr->flags.bm_control) { | ||
| 306 | /* Disable bus master arbitration */ | ||
| 307 | acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE, 1); | ||
| 308 | } | ||
| 309 | switch (longhaul_version) { | ||
| 310 | |||
| 311 | /* | ||
| 312 | * Longhaul v1. (Samuel[C5A] and Samuel2 stepping 0[C5B]) | ||
| 313 | * Software controlled multipliers only. | ||
| 314 | */ | ||
| 315 | case TYPE_LONGHAUL_V1: | ||
| 316 | do_longhaul1(mults_index); | ||
| 317 | break; | ||
| 318 | |||
| 319 | /* | ||
| 320 | * Longhaul v2 appears in Samuel2 Steppings 1->7 [C5B] and Ezra [C5C] | ||
| 321 | * | ||
| 322 | * Longhaul v3 (aka Powersaver). (Ezra-T [C5M] & Nehemiah [C5N]) | ||
| 323 | * Nehemiah can do FSB scaling too, but this has never been proven | ||
| 324 | * to work in practice. | ||
| 325 | */ | ||
| 326 | case TYPE_LONGHAUL_V2: | ||
| 327 | case TYPE_POWERSAVER: | ||
| 328 | if (longhaul_flags & USE_ACPI_C3) { | ||
| 329 | /* Don't allow wakeup */ | ||
| 330 | acpi_write_bit_register(ACPI_BITREG_BUS_MASTER_RLD, 0); | ||
| 331 | do_powersaver(cx->address, mults_index, dir); | ||
| 332 | } else { | ||
| 333 | do_powersaver(0, mults_index, dir); | ||
| 334 | } | ||
| 335 | break; | ||
| 336 | } | ||
| 337 | |||
| 338 | if (longhaul_flags & USE_NORTHBRIDGE) { | ||
| 339 | /* Enable arbiters */ | ||
| 340 | outb(0, 0x22); | ||
| 341 | } else if ((pr != NULL) && pr->flags.bm_control) { | ||
| 342 | /* Enable bus master arbitration */ | ||
| 343 | acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE, 0); | ||
| 344 | } | ||
| 345 | outb(pic2_mask, 0xA1); /* restore mask */ | ||
| 346 | outb(pic1_mask, 0x21); | ||
| 347 | |||
| 348 | local_irq_restore(flags); | ||
| 349 | preempt_enable(); | ||
| 350 | |||
| 351 | freqs.new = calc_speed(longhaul_get_cpu_mult()); | ||
| 352 | /* Check if requested frequency is set. */ | ||
| 353 | if (unlikely(freqs.new != speed)) { | ||
| 354 | printk(KERN_INFO PFX "Failed to set requested frequency!\n"); | ||
| 355 | /* Revision ID = 1 but processor is expecting revision key | ||
| 356 | * equal to 0. Jumpers at the bottom of processor will change | ||
| 357 | * multiplier and FSB, but will not change bits in Longhaul | ||
| 358 | * MSR nor enable voltage scaling. */ | ||
| 359 | if (!revid_errata) { | ||
| 360 | printk(KERN_INFO PFX "Enabling \"Ignore Revision ID\" " | ||
| 361 | "option.\n"); | ||
| 362 | revid_errata = 1; | ||
| 363 | msleep(200); | ||
| 364 | goto retry_loop; | ||
| 365 | } | ||
| 366 | /* Why ACPI C3 sometimes doesn't work is a mystery for me. | ||
| 367 | * But it does happen. Processor is entering ACPI C3 state, | ||
| 368 | * but it doesn't change frequency. I tried poking various | ||
| 369 | * bits in northbridge registers, but without success. */ | ||
| 370 | if (longhaul_flags & USE_ACPI_C3) { | ||
| 371 | printk(KERN_INFO PFX "Disabling ACPI C3 support.\n"); | ||
| 372 | longhaul_flags &= ~USE_ACPI_C3; | ||
| 373 | if (revid_errata) { | ||
| 374 | printk(KERN_INFO PFX "Disabling \"Ignore " | ||
| 375 | "Revision ID\" option.\n"); | ||
| 376 | revid_errata = 0; | ||
| 377 | } | ||
| 378 | msleep(200); | ||
| 379 | goto retry_loop; | ||
| 380 | } | ||
| 381 | /* This shouldn't happen. Longhaul ver. 2 was reported not | ||
| 382 | * working on processors without voltage scaling, but with | ||
| 383 | * RevID = 1. RevID errata will make things right. Just | ||
| 384 | * to be 100% sure. */ | ||
| 385 | if (longhaul_version == TYPE_LONGHAUL_V2) { | ||
| 386 | printk(KERN_INFO PFX "Switching to Longhaul ver. 1\n"); | ||
| 387 | longhaul_version = TYPE_LONGHAUL_V1; | ||
| 388 | msleep(200); | ||
| 389 | goto retry_loop; | ||
| 390 | } | ||
| 391 | } | ||
| 392 | /* Report true CPU frequency */ | ||
| 393 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 394 | |||
| 395 | if (!bm_timeout) | ||
| 396 | printk(KERN_INFO PFX "Warning: Timeout while waiting for " | ||
| 397 | "idle PCI bus.\n"); | ||
| 398 | } | ||
| 399 | |||
| 400 | /* | ||
| 401 | * Centaur decided to make life a little more tricky. | ||
| 402 | * Only longhaul v1 is allowed to read EBLCR BSEL[0:1]. | ||
| 403 | * Samuel2 and above have to try and guess what the FSB is. | ||
| 404 | * We do this by assuming we booted at maximum multiplier, and interpolate | ||
| 405 | * between that value multiplied by possible FSBs and cpu_mhz which | ||
| 406 | * was calculated at boot time. Really ugly, but no other way to do this. | ||
| 407 | */ | ||
| 408 | |||
| 409 | #define ROUNDING 0xf | ||
| 410 | |||
| 411 | static int guess_fsb(int mult) | ||
| 412 | { | ||
| 413 | int speed = cpu_khz / 1000; | ||
| 414 | int i; | ||
| 415 | int speeds[] = { 666, 1000, 1333, 2000 }; | ||
| 416 | int f_max, f_min; | ||
| 417 | |||
| 418 | for (i = 0; i < 4; i++) { | ||
| 419 | f_max = ((speeds[i] * mult) + 50) / 100; | ||
| 420 | f_max += (ROUNDING / 2); | ||
| 421 | f_min = f_max - ROUNDING; | ||
| 422 | if ((speed <= f_max) && (speed >= f_min)) | ||
| 423 | return speeds[i] / 10; | ||
| 424 | } | ||
| 425 | return 0; | ||
| 426 | } | ||
| 427 | |||
| 428 | |||
| 429 | static int __cpuinit longhaul_get_ranges(void) | ||
| 430 | { | ||
| 431 | unsigned int i, j, k = 0; | ||
| 432 | unsigned int ratio; | ||
| 433 | int mult; | ||
| 434 | |||
| 435 | /* Get current frequency */ | ||
| 436 | mult = longhaul_get_cpu_mult(); | ||
| 437 | if (mult == -1) { | ||
| 438 | printk(KERN_INFO PFX "Invalid (reserved) multiplier!\n"); | ||
| 439 | return -EINVAL; | ||
| 440 | } | ||
| 441 | fsb = guess_fsb(mult); | ||
| 442 | if (fsb == 0) { | ||
| 443 | printk(KERN_INFO PFX "Invalid (reserved) FSB!\n"); | ||
| 444 | return -EINVAL; | ||
| 445 | } | ||
| 446 | /* Get max multiplier - as we always did. | ||
| 447 | * Longhaul MSR is useful only when voltage scaling is enabled. | ||
| 448 | * C3 is booting at max anyway. */ | ||
| 449 | maxmult = mult; | ||
| 450 | /* Get min multiplier */ | ||
| 451 | switch (cpu_model) { | ||
| 452 | case CPU_NEHEMIAH: | ||
| 453 | minmult = 50; | ||
| 454 | break; | ||
| 455 | case CPU_NEHEMIAH_C: | ||
| 456 | minmult = 40; | ||
| 457 | break; | ||
| 458 | default: | ||
| 459 | minmult = 30; | ||
| 460 | break; | ||
| 461 | } | ||
| 462 | |||
| 463 | dprintk("MinMult:%d.%dx MaxMult:%d.%dx\n", | ||
| 464 | minmult/10, minmult%10, maxmult/10, maxmult%10); | ||
| 465 | |||
| 466 | highest_speed = calc_speed(maxmult); | ||
| 467 | lowest_speed = calc_speed(minmult); | ||
| 468 | dprintk("FSB:%dMHz Lowest speed: %s Highest speed:%s\n", fsb, | ||
| 469 | print_speed(lowest_speed/1000), | ||
| 470 | print_speed(highest_speed/1000)); | ||
| 471 | |||
| 472 | if (lowest_speed == highest_speed) { | ||
| 473 | printk(KERN_INFO PFX "highestspeed == lowest, aborting.\n"); | ||
| 474 | return -EINVAL; | ||
| 475 | } | ||
| 476 | if (lowest_speed > highest_speed) { | ||
| 477 | printk(KERN_INFO PFX "nonsense! lowest (%d > %d) !\n", | ||
| 478 | lowest_speed, highest_speed); | ||
| 479 | return -EINVAL; | ||
| 480 | } | ||
| 481 | |||
| 482 | longhaul_table = kmalloc((numscales + 1) * sizeof(*longhaul_table), | ||
| 483 | GFP_KERNEL); | ||
| 484 | if (!longhaul_table) | ||
| 485 | return -ENOMEM; | ||
| 486 | |||
| 487 | for (j = 0; j < numscales; j++) { | ||
| 488 | ratio = mults[j]; | ||
| 489 | if (ratio == -1) | ||
| 490 | continue; | ||
| 491 | if (ratio > maxmult || ratio < minmult) | ||
| 492 | continue; | ||
| 493 | longhaul_table[k].frequency = calc_speed(ratio); | ||
| 494 | longhaul_table[k].index = j; | ||
| 495 | k++; | ||
| 496 | } | ||
| 497 | if (k <= 1) { | ||
| 498 | kfree(longhaul_table); | ||
| 499 | return -ENODEV; | ||
| 500 | } | ||
| 501 | /* Sort */ | ||
| 502 | for (j = 0; j < k - 1; j++) { | ||
| 503 | unsigned int min_f, min_i; | ||
| 504 | min_f = longhaul_table[j].frequency; | ||
| 505 | min_i = j; | ||
| 506 | for (i = j + 1; i < k; i++) { | ||
| 507 | if (longhaul_table[i].frequency < min_f) { | ||
| 508 | min_f = longhaul_table[i].frequency; | ||
| 509 | min_i = i; | ||
| 510 | } | ||
| 511 | } | ||
| 512 | if (min_i != j) { | ||
| 513 | swap(longhaul_table[j].frequency, | ||
| 514 | longhaul_table[min_i].frequency); | ||
| 515 | swap(longhaul_table[j].index, | ||
| 516 | longhaul_table[min_i].index); | ||
| 517 | } | ||
| 518 | } | ||
| 519 | |||
| 520 | longhaul_table[k].frequency = CPUFREQ_TABLE_END; | ||
| 521 | |||
| 522 | /* Find index we are running on */ | ||
| 523 | for (j = 0; j < k; j++) { | ||
| 524 | if (mults[longhaul_table[j].index & 0x1f] == mult) { | ||
| 525 | longhaul_index = j; | ||
| 526 | break; | ||
| 527 | } | ||
| 528 | } | ||
| 529 | return 0; | ||
| 530 | } | ||
| 531 | |||
| 532 | |||
| 533 | static void __cpuinit longhaul_setup_voltagescaling(void) | ||
| 534 | { | ||
| 535 | union msr_longhaul longhaul; | ||
| 536 | struct mV_pos minvid, maxvid, vid; | ||
| 537 | unsigned int j, speed, pos, kHz_step, numvscales; | ||
| 538 | int min_vid_speed; | ||
| 539 | |||
| 540 | rdmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
| 541 | if (!(longhaul.bits.RevisionID & 1)) { | ||
| 542 | printk(KERN_INFO PFX "Voltage scaling not supported by CPU.\n"); | ||
| 543 | return; | ||
| 544 | } | ||
| 545 | |||
| 546 | if (!longhaul.bits.VRMRev) { | ||
| 547 | printk(KERN_INFO PFX "VRM 8.5\n"); | ||
| 548 | vrm_mV_table = &vrm85_mV[0]; | ||
| 549 | mV_vrm_table = &mV_vrm85[0]; | ||
| 550 | } else { | ||
| 551 | printk(KERN_INFO PFX "Mobile VRM\n"); | ||
| 552 | if (cpu_model < CPU_NEHEMIAH) | ||
| 553 | return; | ||
| 554 | vrm_mV_table = &mobilevrm_mV[0]; | ||
| 555 | mV_vrm_table = &mV_mobilevrm[0]; | ||
| 556 | } | ||
| 557 | |||
| 558 | minvid = vrm_mV_table[longhaul.bits.MinimumVID]; | ||
| 559 | maxvid = vrm_mV_table[longhaul.bits.MaximumVID]; | ||
| 560 | |||
| 561 | if (minvid.mV == 0 || maxvid.mV == 0 || minvid.mV > maxvid.mV) { | ||
| 562 | printk(KERN_INFO PFX "Bogus values Min:%d.%03d Max:%d.%03d. " | ||
| 563 | "Voltage scaling disabled.\n", | ||
| 564 | minvid.mV/1000, minvid.mV%1000, | ||
| 565 | maxvid.mV/1000, maxvid.mV%1000); | ||
| 566 | return; | ||
| 567 | } | ||
| 568 | |||
| 569 | if (minvid.mV == maxvid.mV) { | ||
| 570 | printk(KERN_INFO PFX "Claims to support voltage scaling but " | ||
| 571 | "min & max are both %d.%03d. " | ||
| 572 | "Voltage scaling disabled\n", | ||
| 573 | maxvid.mV/1000, maxvid.mV%1000); | ||
| 574 | return; | ||
| 575 | } | ||
| 576 | |||
| 577 | /* How many voltage steps*/ | ||
| 578 | numvscales = maxvid.pos - minvid.pos + 1; | ||
| 579 | printk(KERN_INFO PFX | ||
| 580 | "Max VID=%d.%03d " | ||
| 581 | "Min VID=%d.%03d, " | ||
| 582 | "%d possible voltage scales\n", | ||
| 583 | maxvid.mV/1000, maxvid.mV%1000, | ||
| 584 | minvid.mV/1000, minvid.mV%1000, | ||
| 585 | numvscales); | ||
| 586 | |||
| 587 | /* Calculate max frequency at min voltage */ | ||
| 588 | j = longhaul.bits.MinMHzBR; | ||
| 589 | if (longhaul.bits.MinMHzBR4) | ||
| 590 | j += 16; | ||
| 591 | min_vid_speed = eblcr[j]; | ||
| 592 | if (min_vid_speed == -1) | ||
| 593 | return; | ||
| 594 | switch (longhaul.bits.MinMHzFSB) { | ||
| 595 | case 0: | ||
| 596 | min_vid_speed *= 13333; | ||
| 597 | break; | ||
| 598 | case 1: | ||
| 599 | min_vid_speed *= 10000; | ||
| 600 | break; | ||
| 601 | case 3: | ||
| 602 | min_vid_speed *= 6666; | ||
| 603 | break; | ||
| 604 | default: | ||
| 605 | return; | ||
| 606 | break; | ||
| 607 | } | ||
| 608 | if (min_vid_speed >= highest_speed) | ||
| 609 | return; | ||
| 610 | /* Calculate kHz for one voltage step */ | ||
| 611 | kHz_step = (highest_speed - min_vid_speed) / numvscales; | ||
| 612 | |||
| 613 | j = 0; | ||
| 614 | while (longhaul_table[j].frequency != CPUFREQ_TABLE_END) { | ||
| 615 | speed = longhaul_table[j].frequency; | ||
| 616 | if (speed > min_vid_speed) | ||
| 617 | pos = (speed - min_vid_speed) / kHz_step + minvid.pos; | ||
| 618 | else | ||
| 619 | pos = minvid.pos; | ||
| 620 | longhaul_table[j].index |= mV_vrm_table[pos] << 8; | ||
| 621 | vid = vrm_mV_table[mV_vrm_table[pos]]; | ||
| 622 | printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n", | ||
| 623 | speed, j, vid.mV); | ||
| 624 | j++; | ||
| 625 | } | ||
| 626 | |||
| 627 | can_scale_voltage = 1; | ||
| 628 | printk(KERN_INFO PFX "Voltage scaling enabled.\n"); | ||
| 629 | } | ||
| 630 | |||
| 631 | |||
| 632 | static int longhaul_verify(struct cpufreq_policy *policy) | ||
| 633 | { | ||
| 634 | return cpufreq_frequency_table_verify(policy, longhaul_table); | ||
| 635 | } | ||
| 636 | |||
| 637 | |||
| 638 | static int longhaul_target(struct cpufreq_policy *policy, | ||
| 639 | unsigned int target_freq, unsigned int relation) | ||
| 640 | { | ||
| 641 | unsigned int table_index = 0; | ||
| 642 | unsigned int i; | ||
| 643 | unsigned int dir = 0; | ||
| 644 | u8 vid, current_vid; | ||
| 645 | |||
| 646 | if (cpufreq_frequency_table_target(policy, longhaul_table, target_freq, | ||
| 647 | relation, &table_index)) | ||
| 648 | return -EINVAL; | ||
| 649 | |||
| 650 | /* Don't set same frequency again */ | ||
| 651 | if (longhaul_index == table_index) | ||
| 652 | return 0; | ||
| 653 | |||
| 654 | if (!can_scale_voltage) | ||
| 655 | longhaul_setstate(table_index); | ||
| 656 | else { | ||
| 657 | /* On test system voltage transitions exceeding single | ||
| 658 | * step up or down were turning motherboard off. Both | ||
| 659 | * "ondemand" and "userspace" are unsafe. C7 is doing | ||
| 660 | * this in hardware, C3 is old and we need to do this | ||
| 661 | * in software. */ | ||
| 662 | i = longhaul_index; | ||
| 663 | current_vid = (longhaul_table[longhaul_index].index >> 8); | ||
| 664 | current_vid &= 0x1f; | ||
| 665 | if (table_index > longhaul_index) | ||
| 666 | dir = 1; | ||
| 667 | while (i != table_index) { | ||
| 668 | vid = (longhaul_table[i].index >> 8) & 0x1f; | ||
| 669 | if (vid != current_vid) { | ||
| 670 | longhaul_setstate(i); | ||
| 671 | current_vid = vid; | ||
| 672 | msleep(200); | ||
| 673 | } | ||
| 674 | if (dir) | ||
| 675 | i++; | ||
| 676 | else | ||
| 677 | i--; | ||
| 678 | } | ||
| 679 | longhaul_setstate(table_index); | ||
| 680 | } | ||
| 681 | longhaul_index = table_index; | ||
| 682 | return 0; | ||
| 683 | } | ||
| 684 | |||
| 685 | |||
| 686 | static unsigned int longhaul_get(unsigned int cpu) | ||
| 687 | { | ||
| 688 | if (cpu) | ||
| 689 | return 0; | ||
| 690 | return calc_speed(longhaul_get_cpu_mult()); | ||
| 691 | } | ||
| 692 | |||
| 693 | static acpi_status longhaul_walk_callback(acpi_handle obj_handle, | ||
| 694 | u32 nesting_level, | ||
| 695 | void *context, void **return_value) | ||
| 696 | { | ||
| 697 | struct acpi_device *d; | ||
| 698 | |||
| 699 | if (acpi_bus_get_device(obj_handle, &d)) | ||
| 700 | return 0; | ||
| 701 | |||
| 702 | *return_value = acpi_driver_data(d); | ||
| 703 | return 1; | ||
| 704 | } | ||
| 705 | |||
| 706 | /* VIA don't support PM2 reg, but have something similar */ | ||
| 707 | static int enable_arbiter_disable(void) | ||
| 708 | { | ||
| 709 | struct pci_dev *dev; | ||
| 710 | int status = 1; | ||
| 711 | int reg; | ||
| 712 | u8 pci_cmd; | ||
| 713 | |||
| 714 | /* Find PLE133 host bridge */ | ||
| 715 | reg = 0x78; | ||
| 716 | dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8601_0, | ||
| 717 | NULL); | ||
| 718 | /* Find PM133/VT8605 host bridge */ | ||
| 719 | if (dev == NULL) | ||
| 720 | dev = pci_get_device(PCI_VENDOR_ID_VIA, | ||
| 721 | PCI_DEVICE_ID_VIA_8605_0, NULL); | ||
| 722 | /* Find CLE266 host bridge */ | ||
| 723 | if (dev == NULL) { | ||
| 724 | reg = 0x76; | ||
| 725 | dev = pci_get_device(PCI_VENDOR_ID_VIA, | ||
| 726 | PCI_DEVICE_ID_VIA_862X_0, NULL); | ||
| 727 | /* Find CN400 V-Link host bridge */ | ||
| 728 | if (dev == NULL) | ||
| 729 | dev = pci_get_device(PCI_VENDOR_ID_VIA, 0x7259, NULL); | ||
| 730 | } | ||
| 731 | if (dev != NULL) { | ||
| 732 | /* Enable access to port 0x22 */ | ||
| 733 | pci_read_config_byte(dev, reg, &pci_cmd); | ||
| 734 | if (!(pci_cmd & 1<<7)) { | ||
| 735 | pci_cmd |= 1<<7; | ||
| 736 | pci_write_config_byte(dev, reg, pci_cmd); | ||
| 737 | pci_read_config_byte(dev, reg, &pci_cmd); | ||
| 738 | if (!(pci_cmd & 1<<7)) { | ||
| 739 | printk(KERN_ERR PFX | ||
| 740 | "Can't enable access to port 0x22.\n"); | ||
| 741 | status = 0; | ||
| 742 | } | ||
| 743 | } | ||
| 744 | pci_dev_put(dev); | ||
| 745 | return status; | ||
| 746 | } | ||
| 747 | return 0; | ||
| 748 | } | ||
| 749 | |||
| 750 | static int longhaul_setup_southbridge(void) | ||
| 751 | { | ||
| 752 | struct pci_dev *dev; | ||
| 753 | u8 pci_cmd; | ||
| 754 | |||
| 755 | /* Find VT8235 southbridge */ | ||
| 756 | dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, NULL); | ||
| 757 | if (dev == NULL) | ||
| 758 | /* Find VT8237 southbridge */ | ||
| 759 | dev = pci_get_device(PCI_VENDOR_ID_VIA, | ||
| 760 | PCI_DEVICE_ID_VIA_8237, NULL); | ||
| 761 | if (dev != NULL) { | ||
| 762 | /* Set transition time to max */ | ||
| 763 | pci_read_config_byte(dev, 0xec, &pci_cmd); | ||
| 764 | pci_cmd &= ~(1 << 2); | ||
| 765 | pci_write_config_byte(dev, 0xec, pci_cmd); | ||
| 766 | pci_read_config_byte(dev, 0xe4, &pci_cmd); | ||
| 767 | pci_cmd &= ~(1 << 7); | ||
| 768 | pci_write_config_byte(dev, 0xe4, pci_cmd); | ||
| 769 | pci_read_config_byte(dev, 0xe5, &pci_cmd); | ||
| 770 | pci_cmd |= 1 << 7; | ||
| 771 | pci_write_config_byte(dev, 0xe5, pci_cmd); | ||
| 772 | /* Get address of ACPI registers block*/ | ||
| 773 | pci_read_config_byte(dev, 0x81, &pci_cmd); | ||
| 774 | if (pci_cmd & 1 << 7) { | ||
| 775 | pci_read_config_dword(dev, 0x88, &acpi_regs_addr); | ||
| 776 | acpi_regs_addr &= 0xff00; | ||
| 777 | printk(KERN_INFO PFX "ACPI I/O at 0x%x\n", | ||
| 778 | acpi_regs_addr); | ||
| 779 | } | ||
| 780 | |||
| 781 | pci_dev_put(dev); | ||
| 782 | return 1; | ||
| 783 | } | ||
| 784 | return 0; | ||
| 785 | } | ||
| 786 | |||
| 787 | static int __cpuinit longhaul_cpu_init(struct cpufreq_policy *policy) | ||
| 788 | { | ||
| 789 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
| 790 | char *cpuname = NULL; | ||
| 791 | int ret; | ||
| 792 | u32 lo, hi; | ||
| 793 | |||
| 794 | /* Check what we have on this motherboard */ | ||
| 795 | switch (c->x86_model) { | ||
| 796 | case 6: | ||
| 797 | cpu_model = CPU_SAMUEL; | ||
| 798 | cpuname = "C3 'Samuel' [C5A]"; | ||
| 799 | longhaul_version = TYPE_LONGHAUL_V1; | ||
| 800 | memcpy(mults, samuel1_mults, sizeof(samuel1_mults)); | ||
| 801 | memcpy(eblcr, samuel1_eblcr, sizeof(samuel1_eblcr)); | ||
| 802 | break; | ||
| 803 | |||
| 804 | case 7: | ||
| 805 | switch (c->x86_mask) { | ||
| 806 | case 0: | ||
| 807 | longhaul_version = TYPE_LONGHAUL_V1; | ||
| 808 | cpu_model = CPU_SAMUEL2; | ||
| 809 | cpuname = "C3 'Samuel 2' [C5B]"; | ||
| 810 | /* Note, this is not a typo, early Samuel2's had | ||
| 811 | * Samuel1 ratios. */ | ||
| 812 | memcpy(mults, samuel1_mults, sizeof(samuel1_mults)); | ||
| 813 | memcpy(eblcr, samuel2_eblcr, sizeof(samuel2_eblcr)); | ||
| 814 | break; | ||
| 815 | case 1 ... 15: | ||
| 816 | longhaul_version = TYPE_LONGHAUL_V2; | ||
| 817 | if (c->x86_mask < 8) { | ||
| 818 | cpu_model = CPU_SAMUEL2; | ||
| 819 | cpuname = "C3 'Samuel 2' [C5B]"; | ||
| 820 | } else { | ||
| 821 | cpu_model = CPU_EZRA; | ||
| 822 | cpuname = "C3 'Ezra' [C5C]"; | ||
| 823 | } | ||
| 824 | memcpy(mults, ezra_mults, sizeof(ezra_mults)); | ||
| 825 | memcpy(eblcr, ezra_eblcr, sizeof(ezra_eblcr)); | ||
| 826 | break; | ||
| 827 | } | ||
| 828 | break; | ||
| 829 | |||
| 830 | case 8: | ||
| 831 | cpu_model = CPU_EZRA_T; | ||
| 832 | cpuname = "C3 'Ezra-T' [C5M]"; | ||
| 833 | longhaul_version = TYPE_POWERSAVER; | ||
| 834 | numscales = 32; | ||
| 835 | memcpy(mults, ezrat_mults, sizeof(ezrat_mults)); | ||
| 836 | memcpy(eblcr, ezrat_eblcr, sizeof(ezrat_eblcr)); | ||
| 837 | break; | ||
| 838 | |||
| 839 | case 9: | ||
| 840 | longhaul_version = TYPE_POWERSAVER; | ||
| 841 | numscales = 32; | ||
| 842 | memcpy(mults, nehemiah_mults, sizeof(nehemiah_mults)); | ||
| 843 | memcpy(eblcr, nehemiah_eblcr, sizeof(nehemiah_eblcr)); | ||
| 844 | switch (c->x86_mask) { | ||
| 845 | case 0 ... 1: | ||
| 846 | cpu_model = CPU_NEHEMIAH; | ||
| 847 | cpuname = "C3 'Nehemiah A' [C5XLOE]"; | ||
| 848 | break; | ||
| 849 | case 2 ... 4: | ||
| 850 | cpu_model = CPU_NEHEMIAH; | ||
| 851 | cpuname = "C3 'Nehemiah B' [C5XLOH]"; | ||
| 852 | break; | ||
| 853 | case 5 ... 15: | ||
| 854 | cpu_model = CPU_NEHEMIAH_C; | ||
| 855 | cpuname = "C3 'Nehemiah C' [C5P]"; | ||
| 856 | break; | ||
| 857 | } | ||
| 858 | break; | ||
| 859 | |||
| 860 | default: | ||
| 861 | cpuname = "Unknown"; | ||
| 862 | break; | ||
| 863 | } | ||
| 864 | /* Check Longhaul ver. 2 */ | ||
| 865 | if (longhaul_version == TYPE_LONGHAUL_V2) { | ||
| 866 | rdmsr(MSR_VIA_LONGHAUL, lo, hi); | ||
| 867 | if (lo == 0 && hi == 0) | ||
| 868 | /* Looks like MSR isn't present */ | ||
| 869 | longhaul_version = TYPE_LONGHAUL_V1; | ||
| 870 | } | ||
| 871 | |||
| 872 | printk(KERN_INFO PFX "VIA %s CPU detected. ", cpuname); | ||
| 873 | switch (longhaul_version) { | ||
| 874 | case TYPE_LONGHAUL_V1: | ||
| 875 | case TYPE_LONGHAUL_V2: | ||
| 876 | printk(KERN_CONT "Longhaul v%d supported.\n", longhaul_version); | ||
| 877 | break; | ||
| 878 | case TYPE_POWERSAVER: | ||
| 879 | printk(KERN_CONT "Powersaver supported.\n"); | ||
| 880 | break; | ||
| 881 | }; | ||
| 882 | |||
| 883 | /* Doesn't hurt */ | ||
| 884 | longhaul_setup_southbridge(); | ||
| 885 | |||
| 886 | /* Find ACPI data for processor */ | ||
| 887 | acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, | ||
| 888 | ACPI_UINT32_MAX, &longhaul_walk_callback, NULL, | ||
| 889 | NULL, (void *)&pr); | ||
| 890 | |||
| 891 | /* Check ACPI support for C3 state */ | ||
| 892 | if (pr != NULL && longhaul_version == TYPE_POWERSAVER) { | ||
| 893 | cx = &pr->power.states[ACPI_STATE_C3]; | ||
| 894 | if (cx->address > 0 && cx->latency <= 1000) | ||
| 895 | longhaul_flags |= USE_ACPI_C3; | ||
| 896 | } | ||
| 897 | /* Disable if it isn't working */ | ||
| 898 | if (disable_acpi_c3) | ||
| 899 | longhaul_flags &= ~USE_ACPI_C3; | ||
| 900 | /* Check if northbridge is friendly */ | ||
| 901 | if (enable_arbiter_disable()) | ||
| 902 | longhaul_flags |= USE_NORTHBRIDGE; | ||
| 903 | |||
| 904 | /* Check ACPI support for bus master arbiter disable */ | ||
| 905 | if (!(longhaul_flags & USE_ACPI_C3 | ||
| 906 | || longhaul_flags & USE_NORTHBRIDGE) | ||
| 907 | && ((pr == NULL) || !(pr->flags.bm_control))) { | ||
| 908 | printk(KERN_ERR PFX | ||
| 909 | "No ACPI support. Unsupported northbridge.\n"); | ||
| 910 | return -ENODEV; | ||
| 911 | } | ||
| 912 | |||
| 913 | if (longhaul_flags & USE_NORTHBRIDGE) | ||
| 914 | printk(KERN_INFO PFX "Using northbridge support.\n"); | ||
| 915 | if (longhaul_flags & USE_ACPI_C3) | ||
| 916 | printk(KERN_INFO PFX "Using ACPI support.\n"); | ||
| 917 | |||
| 918 | ret = longhaul_get_ranges(); | ||
| 919 | if (ret != 0) | ||
| 920 | return ret; | ||
| 921 | |||
| 922 | if ((longhaul_version != TYPE_LONGHAUL_V1) && (scale_voltage != 0)) | ||
| 923 | longhaul_setup_voltagescaling(); | ||
| 924 | |||
| 925 | policy->cpuinfo.transition_latency = 200000; /* nsec */ | ||
| 926 | policy->cur = calc_speed(longhaul_get_cpu_mult()); | ||
| 927 | |||
| 928 | ret = cpufreq_frequency_table_cpuinfo(policy, longhaul_table); | ||
| 929 | if (ret) | ||
| 930 | return ret; | ||
| 931 | |||
| 932 | cpufreq_frequency_table_get_attr(longhaul_table, policy->cpu); | ||
| 933 | |||
| 934 | return 0; | ||
| 935 | } | ||
| 936 | |||
| 937 | static int __devexit longhaul_cpu_exit(struct cpufreq_policy *policy) | ||
| 938 | { | ||
| 939 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
| 940 | return 0; | ||
| 941 | } | ||
| 942 | |||
| 943 | static struct freq_attr *longhaul_attr[] = { | ||
| 944 | &cpufreq_freq_attr_scaling_available_freqs, | ||
| 945 | NULL, | ||
| 946 | }; | ||
| 947 | |||
| 948 | static struct cpufreq_driver longhaul_driver = { | ||
| 949 | .verify = longhaul_verify, | ||
| 950 | .target = longhaul_target, | ||
| 951 | .get = longhaul_get, | ||
| 952 | .init = longhaul_cpu_init, | ||
| 953 | .exit = __devexit_p(longhaul_cpu_exit), | ||
| 954 | .name = "longhaul", | ||
| 955 | .owner = THIS_MODULE, | ||
| 956 | .attr = longhaul_attr, | ||
| 957 | }; | ||
| 958 | |||
| 959 | |||
| 960 | static int __init longhaul_init(void) | ||
| 961 | { | ||
| 962 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
| 963 | |||
| 964 | if (c->x86_vendor != X86_VENDOR_CENTAUR || c->x86 != 6) | ||
| 965 | return -ENODEV; | ||
| 966 | |||
| 967 | #ifdef CONFIG_SMP | ||
| 968 | if (num_online_cpus() > 1) { | ||
| 969 | printk(KERN_ERR PFX "More than 1 CPU detected, " | ||
| 970 | "longhaul disabled.\n"); | ||
| 971 | return -ENODEV; | ||
| 972 | } | ||
| 973 | #endif | ||
| 974 | #ifdef CONFIG_X86_IO_APIC | ||
| 975 | if (cpu_has_apic) { | ||
| 976 | printk(KERN_ERR PFX "APIC detected. Longhaul is currently " | ||
| 977 | "broken in this configuration.\n"); | ||
| 978 | return -ENODEV; | ||
| 979 | } | ||
| 980 | #endif | ||
| 981 | switch (c->x86_model) { | ||
| 982 | case 6 ... 9: | ||
| 983 | return cpufreq_register_driver(&longhaul_driver); | ||
| 984 | case 10: | ||
| 985 | printk(KERN_ERR PFX "Use acpi-cpufreq driver for VIA C7\n"); | ||
| 986 | default: | ||
| 987 | ; | ||
| 988 | } | ||
| 989 | |||
| 990 | return -ENODEV; | ||
| 991 | } | ||
| 992 | |||
| 993 | |||
| 994 | static void __exit longhaul_exit(void) | ||
| 995 | { | ||
| 996 | int i; | ||
| 997 | |||
| 998 | for (i = 0; i < numscales; i++) { | ||
| 999 | if (mults[i] == maxmult) { | ||
| 1000 | longhaul_setstate(i); | ||
| 1001 | break; | ||
| 1002 | } | ||
| 1003 | } | ||
| 1004 | |||
| 1005 | cpufreq_unregister_driver(&longhaul_driver); | ||
| 1006 | kfree(longhaul_table); | ||
| 1007 | } | ||
| 1008 | |||
| 1009 | /* Even if BIOS is exporting ACPI C3 state, and it is used | ||
| 1010 | * with success when CPU is idle, this state doesn't | ||
| 1011 | * trigger frequency transition in some cases. */ | ||
| 1012 | module_param(disable_acpi_c3, int, 0644); | ||
| 1013 | MODULE_PARM_DESC(disable_acpi_c3, "Don't use ACPI C3 support"); | ||
| 1014 | /* Change CPU voltage with frequency. Very useful to save | ||
| 1015 | * power, but most VIA C3 processors aren't supporting it. */ | ||
| 1016 | module_param(scale_voltage, int, 0644); | ||
| 1017 | MODULE_PARM_DESC(scale_voltage, "Scale voltage of processor"); | ||
| 1018 | /* Force revision key to 0 for processors which doesn't | ||
| 1019 | * support voltage scaling, but are introducing itself as | ||
| 1020 | * such. */ | ||
| 1021 | module_param(revid_errata, int, 0644); | ||
| 1022 | MODULE_PARM_DESC(revid_errata, "Ignore CPU Revision ID"); | ||
| 1023 | |||
| 1024 | MODULE_AUTHOR("Dave Jones <davej@redhat.com>"); | ||
| 1025 | MODULE_DESCRIPTION("Longhaul driver for VIA Cyrix processors."); | ||
| 1026 | MODULE_LICENSE("GPL"); | ||
| 1027 | |||
| 1028 | late_initcall(longhaul_init); | ||
| 1029 | module_exit(longhaul_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/longhaul.h b/arch/x86/kernel/cpu/cpufreq/longhaul.h deleted file mode 100644 index cbf48fbca881..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/longhaul.h +++ /dev/null | |||
| @@ -1,353 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * longhaul.h | ||
| 3 | * (C) 2003 Dave Jones. | ||
| 4 | * | ||
| 5 | * Licensed under the terms of the GNU GPL License version 2. | ||
| 6 | * | ||
| 7 | * VIA-specific information | ||
| 8 | */ | ||
| 9 | |||
| 10 | union msr_bcr2 { | ||
| 11 | struct { | ||
| 12 | unsigned Reseved:19, // 18:0 | ||
| 13 | ESOFTBF:1, // 19 | ||
| 14 | Reserved2:3, // 22:20 | ||
| 15 | CLOCKMUL:4, // 26:23 | ||
| 16 | Reserved3:5; // 31:27 | ||
| 17 | } bits; | ||
| 18 | unsigned long val; | ||
| 19 | }; | ||
| 20 | |||
| 21 | union msr_longhaul { | ||
| 22 | struct { | ||
| 23 | unsigned RevisionID:4, // 3:0 | ||
| 24 | RevisionKey:4, // 7:4 | ||
| 25 | EnableSoftBusRatio:1, // 8 | ||
| 26 | EnableSoftVID:1, // 9 | ||
| 27 | EnableSoftBSEL:1, // 10 | ||
| 28 | Reserved:3, // 11:13 | ||
| 29 | SoftBusRatio4:1, // 14 | ||
| 30 | VRMRev:1, // 15 | ||
| 31 | SoftBusRatio:4, // 19:16 | ||
| 32 | SoftVID:5, // 24:20 | ||
| 33 | Reserved2:3, // 27:25 | ||
| 34 | SoftBSEL:2, // 29:28 | ||
| 35 | Reserved3:2, // 31:30 | ||
| 36 | MaxMHzBR:4, // 35:32 | ||
| 37 | MaximumVID:5, // 40:36 | ||
| 38 | MaxMHzFSB:2, // 42:41 | ||
| 39 | MaxMHzBR4:1, // 43 | ||
| 40 | Reserved4:4, // 47:44 | ||
| 41 | MinMHzBR:4, // 51:48 | ||
| 42 | MinimumVID:5, // 56:52 | ||
| 43 | MinMHzFSB:2, // 58:57 | ||
| 44 | MinMHzBR4:1, // 59 | ||
| 45 | Reserved5:4; // 63:60 | ||
| 46 | } bits; | ||
| 47 | unsigned long long val; | ||
| 48 | }; | ||
| 49 | |||
| 50 | /* | ||
| 51 | * Clock ratio tables. Div/Mod by 10 to get ratio. | ||
| 52 | * The eblcr values specify the ratio read from the CPU. | ||
| 53 | * The mults values specify what to write to the CPU. | ||
| 54 | */ | ||
| 55 | |||
| 56 | /* | ||
| 57 | * VIA C3 Samuel 1 & Samuel 2 (stepping 0) | ||
| 58 | */ | ||
| 59 | static const int __cpuinitdata samuel1_mults[16] = { | ||
| 60 | -1, /* 0000 -> RESERVED */ | ||
| 61 | 30, /* 0001 -> 3.0x */ | ||
| 62 | 40, /* 0010 -> 4.0x */ | ||
| 63 | -1, /* 0011 -> RESERVED */ | ||
| 64 | -1, /* 0100 -> RESERVED */ | ||
| 65 | 35, /* 0101 -> 3.5x */ | ||
| 66 | 45, /* 0110 -> 4.5x */ | ||
| 67 | 55, /* 0111 -> 5.5x */ | ||
| 68 | 60, /* 1000 -> 6.0x */ | ||
| 69 | 70, /* 1001 -> 7.0x */ | ||
| 70 | 80, /* 1010 -> 8.0x */ | ||
| 71 | 50, /* 1011 -> 5.0x */ | ||
| 72 | 65, /* 1100 -> 6.5x */ | ||
| 73 | 75, /* 1101 -> 7.5x */ | ||
| 74 | -1, /* 1110 -> RESERVED */ | ||
| 75 | -1, /* 1111 -> RESERVED */ | ||
| 76 | }; | ||
| 77 | |||
| 78 | static const int __cpuinitdata samuel1_eblcr[16] = { | ||
| 79 | 50, /* 0000 -> RESERVED */ | ||
| 80 | 30, /* 0001 -> 3.0x */ | ||
| 81 | 40, /* 0010 -> 4.0x */ | ||
| 82 | -1, /* 0011 -> RESERVED */ | ||
| 83 | 55, /* 0100 -> 5.5x */ | ||
| 84 | 35, /* 0101 -> 3.5x */ | ||
| 85 | 45, /* 0110 -> 4.5x */ | ||
| 86 | -1, /* 0111 -> RESERVED */ | ||
| 87 | -1, /* 1000 -> RESERVED */ | ||
| 88 | 70, /* 1001 -> 7.0x */ | ||
| 89 | 80, /* 1010 -> 8.0x */ | ||
| 90 | 60, /* 1011 -> 6.0x */ | ||
| 91 | -1, /* 1100 -> RESERVED */ | ||
| 92 | 75, /* 1101 -> 7.5x */ | ||
| 93 | -1, /* 1110 -> RESERVED */ | ||
| 94 | 65, /* 1111 -> 6.5x */ | ||
| 95 | }; | ||
| 96 | |||
| 97 | /* | ||
| 98 | * VIA C3 Samuel2 Stepping 1->15 | ||
| 99 | */ | ||
| 100 | static const int __cpuinitdata samuel2_eblcr[16] = { | ||
| 101 | 50, /* 0000 -> 5.0x */ | ||
| 102 | 30, /* 0001 -> 3.0x */ | ||
| 103 | 40, /* 0010 -> 4.0x */ | ||
| 104 | 100, /* 0011 -> 10.0x */ | ||
| 105 | 55, /* 0100 -> 5.5x */ | ||
| 106 | 35, /* 0101 -> 3.5x */ | ||
| 107 | 45, /* 0110 -> 4.5x */ | ||
| 108 | 110, /* 0111 -> 11.0x */ | ||
| 109 | 90, /* 1000 -> 9.0x */ | ||
| 110 | 70, /* 1001 -> 7.0x */ | ||
| 111 | 80, /* 1010 -> 8.0x */ | ||
| 112 | 60, /* 1011 -> 6.0x */ | ||
| 113 | 120, /* 1100 -> 12.0x */ | ||
| 114 | 75, /* 1101 -> 7.5x */ | ||
| 115 | 130, /* 1110 -> 13.0x */ | ||
| 116 | 65, /* 1111 -> 6.5x */ | ||
| 117 | }; | ||
| 118 | |||
| 119 | /* | ||
| 120 | * VIA C3 Ezra | ||
| 121 | */ | ||
| 122 | static const int __cpuinitdata ezra_mults[16] = { | ||
| 123 | 100, /* 0000 -> 10.0x */ | ||
| 124 | 30, /* 0001 -> 3.0x */ | ||
| 125 | 40, /* 0010 -> 4.0x */ | ||
| 126 | 90, /* 0011 -> 9.0x */ | ||
| 127 | 95, /* 0100 -> 9.5x */ | ||
| 128 | 35, /* 0101 -> 3.5x */ | ||
| 129 | 45, /* 0110 -> 4.5x */ | ||
| 130 | 55, /* 0111 -> 5.5x */ | ||
| 131 | 60, /* 1000 -> 6.0x */ | ||
| 132 | 70, /* 1001 -> 7.0x */ | ||
| 133 | 80, /* 1010 -> 8.0x */ | ||
| 134 | 50, /* 1011 -> 5.0x */ | ||
| 135 | 65, /* 1100 -> 6.5x */ | ||
| 136 | 75, /* 1101 -> 7.5x */ | ||
| 137 | 85, /* 1110 -> 8.5x */ | ||
| 138 | 120, /* 1111 -> 12.0x */ | ||
| 139 | }; | ||
| 140 | |||
| 141 | static const int __cpuinitdata ezra_eblcr[16] = { | ||
| 142 | 50, /* 0000 -> 5.0x */ | ||
| 143 | 30, /* 0001 -> 3.0x */ | ||
| 144 | 40, /* 0010 -> 4.0x */ | ||
| 145 | 100, /* 0011 -> 10.0x */ | ||
| 146 | 55, /* 0100 -> 5.5x */ | ||
| 147 | 35, /* 0101 -> 3.5x */ | ||
| 148 | 45, /* 0110 -> 4.5x */ | ||
| 149 | 95, /* 0111 -> 9.5x */ | ||
| 150 | 90, /* 1000 -> 9.0x */ | ||
| 151 | 70, /* 1001 -> 7.0x */ | ||
| 152 | 80, /* 1010 -> 8.0x */ | ||
| 153 | 60, /* 1011 -> 6.0x */ | ||
| 154 | 120, /* 1100 -> 12.0x */ | ||
| 155 | 75, /* 1101 -> 7.5x */ | ||
| 156 | 85, /* 1110 -> 8.5x */ | ||
| 157 | 65, /* 1111 -> 6.5x */ | ||
| 158 | }; | ||
| 159 | |||
| 160 | /* | ||
| 161 | * VIA C3 (Ezra-T) [C5M]. | ||
| 162 | */ | ||
| 163 | static const int __cpuinitdata ezrat_mults[32] = { | ||
| 164 | 100, /* 0000 -> 10.0x */ | ||
| 165 | 30, /* 0001 -> 3.0x */ | ||
| 166 | 40, /* 0010 -> 4.0x */ | ||
| 167 | 90, /* 0011 -> 9.0x */ | ||
| 168 | 95, /* 0100 -> 9.5x */ | ||
| 169 | 35, /* 0101 -> 3.5x */ | ||
| 170 | 45, /* 0110 -> 4.5x */ | ||
| 171 | 55, /* 0111 -> 5.5x */ | ||
| 172 | 60, /* 1000 -> 6.0x */ | ||
| 173 | 70, /* 1001 -> 7.0x */ | ||
| 174 | 80, /* 1010 -> 8.0x */ | ||
| 175 | 50, /* 1011 -> 5.0x */ | ||
| 176 | 65, /* 1100 -> 6.5x */ | ||
| 177 | 75, /* 1101 -> 7.5x */ | ||
| 178 | 85, /* 1110 -> 8.5x */ | ||
| 179 | 120, /* 1111 -> 12.0x */ | ||
| 180 | |||
| 181 | -1, /* 0000 -> RESERVED (10.0x) */ | ||
| 182 | 110, /* 0001 -> 11.0x */ | ||
| 183 | -1, /* 0010 -> 12.0x */ | ||
| 184 | -1, /* 0011 -> RESERVED (9.0x)*/ | ||
| 185 | 105, /* 0100 -> 10.5x */ | ||
| 186 | 115, /* 0101 -> 11.5x */ | ||
| 187 | 125, /* 0110 -> 12.5x */ | ||
| 188 | 135, /* 0111 -> 13.5x */ | ||
| 189 | 140, /* 1000 -> 14.0x */ | ||
| 190 | 150, /* 1001 -> 15.0x */ | ||
| 191 | 160, /* 1010 -> 16.0x */ | ||
| 192 | 130, /* 1011 -> 13.0x */ | ||
| 193 | 145, /* 1100 -> 14.5x */ | ||
| 194 | 155, /* 1101 -> 15.5x */ | ||
| 195 | -1, /* 1110 -> RESERVED (13.0x) */ | ||
| 196 | -1, /* 1111 -> RESERVED (12.0x) */ | ||
| 197 | }; | ||
| 198 | |||
| 199 | static const int __cpuinitdata ezrat_eblcr[32] = { | ||
| 200 | 50, /* 0000 -> 5.0x */ | ||
| 201 | 30, /* 0001 -> 3.0x */ | ||
| 202 | 40, /* 0010 -> 4.0x */ | ||
| 203 | 100, /* 0011 -> 10.0x */ | ||
| 204 | 55, /* 0100 -> 5.5x */ | ||
| 205 | 35, /* 0101 -> 3.5x */ | ||
| 206 | 45, /* 0110 -> 4.5x */ | ||
| 207 | 95, /* 0111 -> 9.5x */ | ||
| 208 | 90, /* 1000 -> 9.0x */ | ||
| 209 | 70, /* 1001 -> 7.0x */ | ||
| 210 | 80, /* 1010 -> 8.0x */ | ||
| 211 | 60, /* 1011 -> 6.0x */ | ||
| 212 | 120, /* 1100 -> 12.0x */ | ||
| 213 | 75, /* 1101 -> 7.5x */ | ||
| 214 | 85, /* 1110 -> 8.5x */ | ||
| 215 | 65, /* 1111 -> 6.5x */ | ||
| 216 | |||
| 217 | -1, /* 0000 -> RESERVED (9.0x) */ | ||
| 218 | 110, /* 0001 -> 11.0x */ | ||
| 219 | 120, /* 0010 -> 12.0x */ | ||
| 220 | -1, /* 0011 -> RESERVED (10.0x)*/ | ||
| 221 | 135, /* 0100 -> 13.5x */ | ||
| 222 | 115, /* 0101 -> 11.5x */ | ||
| 223 | 125, /* 0110 -> 12.5x */ | ||
| 224 | 105, /* 0111 -> 10.5x */ | ||
| 225 | 130, /* 1000 -> 13.0x */ | ||
| 226 | 150, /* 1001 -> 15.0x */ | ||
| 227 | 160, /* 1010 -> 16.0x */ | ||
| 228 | 140, /* 1011 -> 14.0x */ | ||
| 229 | -1, /* 1100 -> RESERVED (12.0x) */ | ||
| 230 | 155, /* 1101 -> 15.5x */ | ||
| 231 | -1, /* 1110 -> RESERVED (13.0x) */ | ||
| 232 | 145, /* 1111 -> 14.5x */ | ||
| 233 | }; | ||
| 234 | |||
| 235 | /* | ||
| 236 | * VIA C3 Nehemiah */ | ||
| 237 | |||
| 238 | static const int __cpuinitdata nehemiah_mults[32] = { | ||
| 239 | 100, /* 0000 -> 10.0x */ | ||
| 240 | -1, /* 0001 -> 16.0x */ | ||
| 241 | 40, /* 0010 -> 4.0x */ | ||
| 242 | 90, /* 0011 -> 9.0x */ | ||
| 243 | 95, /* 0100 -> 9.5x */ | ||
| 244 | -1, /* 0101 -> RESERVED */ | ||
| 245 | 45, /* 0110 -> 4.5x */ | ||
| 246 | 55, /* 0111 -> 5.5x */ | ||
| 247 | 60, /* 1000 -> 6.0x */ | ||
| 248 | 70, /* 1001 -> 7.0x */ | ||
| 249 | 80, /* 1010 -> 8.0x */ | ||
| 250 | 50, /* 1011 -> 5.0x */ | ||
| 251 | 65, /* 1100 -> 6.5x */ | ||
| 252 | 75, /* 1101 -> 7.5x */ | ||
| 253 | 85, /* 1110 -> 8.5x */ | ||
| 254 | 120, /* 1111 -> 12.0x */ | ||
| 255 | -1, /* 0000 -> 10.0x */ | ||
| 256 | 110, /* 0001 -> 11.0x */ | ||
| 257 | -1, /* 0010 -> 12.0x */ | ||
| 258 | -1, /* 0011 -> 9.0x */ | ||
| 259 | 105, /* 0100 -> 10.5x */ | ||
| 260 | 115, /* 0101 -> 11.5x */ | ||
| 261 | 125, /* 0110 -> 12.5x */ | ||
| 262 | 135, /* 0111 -> 13.5x */ | ||
| 263 | 140, /* 1000 -> 14.0x */ | ||
| 264 | 150, /* 1001 -> 15.0x */ | ||
| 265 | 160, /* 1010 -> 16.0x */ | ||
| 266 | 130, /* 1011 -> 13.0x */ | ||
| 267 | 145, /* 1100 -> 14.5x */ | ||
| 268 | 155, /* 1101 -> 15.5x */ | ||
| 269 | -1, /* 1110 -> RESERVED (13.0x) */ | ||
| 270 | -1, /* 1111 -> 12.0x */ | ||
| 271 | }; | ||
| 272 | |||
| 273 | static const int __cpuinitdata nehemiah_eblcr[32] = { | ||
| 274 | 50, /* 0000 -> 5.0x */ | ||
| 275 | 160, /* 0001 -> 16.0x */ | ||
| 276 | 40, /* 0010 -> 4.0x */ | ||
| 277 | 100, /* 0011 -> 10.0x */ | ||
| 278 | 55, /* 0100 -> 5.5x */ | ||
| 279 | -1, /* 0101 -> RESERVED */ | ||
| 280 | 45, /* 0110 -> 4.5x */ | ||
| 281 | 95, /* 0111 -> 9.5x */ | ||
| 282 | 90, /* 1000 -> 9.0x */ | ||
| 283 | 70, /* 1001 -> 7.0x */ | ||
| 284 | 80, /* 1010 -> 8.0x */ | ||
| 285 | 60, /* 1011 -> 6.0x */ | ||
| 286 | 120, /* 1100 -> 12.0x */ | ||
| 287 | 75, /* 1101 -> 7.5x */ | ||
| 288 | 85, /* 1110 -> 8.5x */ | ||
| 289 | 65, /* 1111 -> 6.5x */ | ||
| 290 | 90, /* 0000 -> 9.0x */ | ||
| 291 | 110, /* 0001 -> 11.0x */ | ||
| 292 | 120, /* 0010 -> 12.0x */ | ||
| 293 | 100, /* 0011 -> 10.0x */ | ||
| 294 | 135, /* 0100 -> 13.5x */ | ||
| 295 | 115, /* 0101 -> 11.5x */ | ||
| 296 | 125, /* 0110 -> 12.5x */ | ||
| 297 | 105, /* 0111 -> 10.5x */ | ||
| 298 | 130, /* 1000 -> 13.0x */ | ||
| 299 | 150, /* 1001 -> 15.0x */ | ||
| 300 | 160, /* 1010 -> 16.0x */ | ||
| 301 | 140, /* 1011 -> 14.0x */ | ||
| 302 | 120, /* 1100 -> 12.0x */ | ||
| 303 | 155, /* 1101 -> 15.5x */ | ||
| 304 | -1, /* 1110 -> RESERVED (13.0x) */ | ||
| 305 | 145 /* 1111 -> 14.5x */ | ||
| 306 | }; | ||
| 307 | |||
| 308 | /* | ||
| 309 | * Voltage scales. Div/Mod by 1000 to get actual voltage. | ||
| 310 | * Which scale to use depends on the VRM type in use. | ||
| 311 | */ | ||
| 312 | |||
| 313 | struct mV_pos { | ||
| 314 | unsigned short mV; | ||
| 315 | unsigned short pos; | ||
| 316 | }; | ||
| 317 | |||
| 318 | static const struct mV_pos __cpuinitdata vrm85_mV[32] = { | ||
| 319 | {1250, 8}, {1200, 6}, {1150, 4}, {1100, 2}, | ||
| 320 | {1050, 0}, {1800, 30}, {1750, 28}, {1700, 26}, | ||
| 321 | {1650, 24}, {1600, 22}, {1550, 20}, {1500, 18}, | ||
| 322 | {1450, 16}, {1400, 14}, {1350, 12}, {1300, 10}, | ||
| 323 | {1275, 9}, {1225, 7}, {1175, 5}, {1125, 3}, | ||
| 324 | {1075, 1}, {1825, 31}, {1775, 29}, {1725, 27}, | ||
| 325 | {1675, 25}, {1625, 23}, {1575, 21}, {1525, 19}, | ||
| 326 | {1475, 17}, {1425, 15}, {1375, 13}, {1325, 11} | ||
| 327 | }; | ||
| 328 | |||
| 329 | static const unsigned char __cpuinitdata mV_vrm85[32] = { | ||
| 330 | 0x04, 0x14, 0x03, 0x13, 0x02, 0x12, 0x01, 0x11, | ||
| 331 | 0x00, 0x10, 0x0f, 0x1f, 0x0e, 0x1e, 0x0d, 0x1d, | ||
| 332 | 0x0c, 0x1c, 0x0b, 0x1b, 0x0a, 0x1a, 0x09, 0x19, | ||
| 333 | 0x08, 0x18, 0x07, 0x17, 0x06, 0x16, 0x05, 0x15 | ||
| 334 | }; | ||
| 335 | |||
| 336 | static const struct mV_pos __cpuinitdata mobilevrm_mV[32] = { | ||
| 337 | {1750, 31}, {1700, 30}, {1650, 29}, {1600, 28}, | ||
| 338 | {1550, 27}, {1500, 26}, {1450, 25}, {1400, 24}, | ||
| 339 | {1350, 23}, {1300, 22}, {1250, 21}, {1200, 20}, | ||
| 340 | {1150, 19}, {1100, 18}, {1050, 17}, {1000, 16}, | ||
| 341 | {975, 15}, {950, 14}, {925, 13}, {900, 12}, | ||
| 342 | {875, 11}, {850, 10}, {825, 9}, {800, 8}, | ||
| 343 | {775, 7}, {750, 6}, {725, 5}, {700, 4}, | ||
| 344 | {675, 3}, {650, 2}, {625, 1}, {600, 0} | ||
| 345 | }; | ||
| 346 | |||
| 347 | static const unsigned char __cpuinitdata mV_mobilevrm[32] = { | ||
| 348 | 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, | ||
| 349 | 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, | ||
| 350 | 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, | ||
| 351 | 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 | ||
| 352 | }; | ||
| 353 | |||
diff --git a/arch/x86/kernel/cpu/cpufreq/longrun.c b/arch/x86/kernel/cpu/cpufreq/longrun.c deleted file mode 100644 index d9f51367666b..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/longrun.c +++ /dev/null | |||
| @@ -1,327 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> | ||
| 3 | * | ||
| 4 | * Licensed under the terms of the GNU GPL License version 2. | ||
| 5 | * | ||
| 6 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <linux/kernel.h> | ||
| 10 | #include <linux/module.h> | ||
| 11 | #include <linux/init.h> | ||
| 12 | #include <linux/cpufreq.h> | ||
| 13 | #include <linux/timex.h> | ||
| 14 | |||
| 15 | #include <asm/msr.h> | ||
| 16 | #include <asm/processor.h> | ||
| 17 | |||
| 18 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
| 19 | "longrun", msg) | ||
| 20 | |||
| 21 | static struct cpufreq_driver longrun_driver; | ||
| 22 | |||
| 23 | /** | ||
| 24 | * longrun_{low,high}_freq is needed for the conversion of cpufreq kHz | ||
| 25 | * values into per cent values. In TMTA microcode, the following is valid: | ||
| 26 | * performance_pctg = (current_freq - low_freq)/(high_freq - low_freq) | ||
| 27 | */ | ||
| 28 | static unsigned int longrun_low_freq, longrun_high_freq; | ||
| 29 | |||
| 30 | |||
| 31 | /** | ||
| 32 | * longrun_get_policy - get the current LongRun policy | ||
| 33 | * @policy: struct cpufreq_policy where current policy is written into | ||
| 34 | * | ||
| 35 | * Reads the current LongRun policy by access to MSR_TMTA_LONGRUN_FLAGS | ||
| 36 | * and MSR_TMTA_LONGRUN_CTRL | ||
| 37 | */ | ||
| 38 | static void __cpuinit longrun_get_policy(struct cpufreq_policy *policy) | ||
| 39 | { | ||
| 40 | u32 msr_lo, msr_hi; | ||
| 41 | |||
| 42 | rdmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi); | ||
| 43 | dprintk("longrun flags are %x - %x\n", msr_lo, msr_hi); | ||
| 44 | if (msr_lo & 0x01) | ||
| 45 | policy->policy = CPUFREQ_POLICY_PERFORMANCE; | ||
| 46 | else | ||
| 47 | policy->policy = CPUFREQ_POLICY_POWERSAVE; | ||
| 48 | |||
| 49 | rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); | ||
| 50 | dprintk("longrun ctrl is %x - %x\n", msr_lo, msr_hi); | ||
| 51 | msr_lo &= 0x0000007F; | ||
| 52 | msr_hi &= 0x0000007F; | ||
| 53 | |||
| 54 | if (longrun_high_freq <= longrun_low_freq) { | ||
| 55 | /* Assume degenerate Longrun table */ | ||
| 56 | policy->min = policy->max = longrun_high_freq; | ||
| 57 | } else { | ||
| 58 | policy->min = longrun_low_freq + msr_lo * | ||
| 59 | ((longrun_high_freq - longrun_low_freq) / 100); | ||
| 60 | policy->max = longrun_low_freq + msr_hi * | ||
| 61 | ((longrun_high_freq - longrun_low_freq) / 100); | ||
| 62 | } | ||
| 63 | policy->cpu = 0; | ||
| 64 | } | ||
| 65 | |||
| 66 | |||
| 67 | /** | ||
| 68 | * longrun_set_policy - sets a new CPUFreq policy | ||
| 69 | * @policy: new policy | ||
| 70 | * | ||
| 71 | * Sets a new CPUFreq policy on LongRun-capable processors. This function | ||
| 72 | * has to be called with cpufreq_driver locked. | ||
| 73 | */ | ||
| 74 | static int longrun_set_policy(struct cpufreq_policy *policy) | ||
| 75 | { | ||
| 76 | u32 msr_lo, msr_hi; | ||
| 77 | u32 pctg_lo, pctg_hi; | ||
| 78 | |||
| 79 | if (!policy) | ||
| 80 | return -EINVAL; | ||
| 81 | |||
| 82 | if (longrun_high_freq <= longrun_low_freq) { | ||
| 83 | /* Assume degenerate Longrun table */ | ||
| 84 | pctg_lo = pctg_hi = 100; | ||
| 85 | } else { | ||
| 86 | pctg_lo = (policy->min - longrun_low_freq) / | ||
| 87 | ((longrun_high_freq - longrun_low_freq) / 100); | ||
| 88 | pctg_hi = (policy->max - longrun_low_freq) / | ||
| 89 | ((longrun_high_freq - longrun_low_freq) / 100); | ||
| 90 | } | ||
| 91 | |||
| 92 | if (pctg_hi > 100) | ||
| 93 | pctg_hi = 100; | ||
| 94 | if (pctg_lo > pctg_hi) | ||
| 95 | pctg_lo = pctg_hi; | ||
| 96 | |||
| 97 | /* performance or economy mode */ | ||
| 98 | rdmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi); | ||
| 99 | msr_lo &= 0xFFFFFFFE; | ||
| 100 | switch (policy->policy) { | ||
| 101 | case CPUFREQ_POLICY_PERFORMANCE: | ||
| 102 | msr_lo |= 0x00000001; | ||
| 103 | break; | ||
| 104 | case CPUFREQ_POLICY_POWERSAVE: | ||
| 105 | break; | ||
| 106 | } | ||
| 107 | wrmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi); | ||
| 108 | |||
| 109 | /* lower and upper boundary */ | ||
| 110 | rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); | ||
| 111 | msr_lo &= 0xFFFFFF80; | ||
| 112 | msr_hi &= 0xFFFFFF80; | ||
| 113 | msr_lo |= pctg_lo; | ||
| 114 | msr_hi |= pctg_hi; | ||
| 115 | wrmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); | ||
| 116 | |||
| 117 | return 0; | ||
| 118 | } | ||
| 119 | |||
| 120 | |||
| 121 | /** | ||
| 122 | * longrun_verify_poliy - verifies a new CPUFreq policy | ||
| 123 | * @policy: the policy to verify | ||
| 124 | * | ||
| 125 | * Validates a new CPUFreq policy. This function has to be called with | ||
| 126 | * cpufreq_driver locked. | ||
| 127 | */ | ||
| 128 | static int longrun_verify_policy(struct cpufreq_policy *policy) | ||
| 129 | { | ||
| 130 | if (!policy) | ||
| 131 | return -EINVAL; | ||
| 132 | |||
| 133 | policy->cpu = 0; | ||
| 134 | cpufreq_verify_within_limits(policy, | ||
| 135 | policy->cpuinfo.min_freq, | ||
| 136 | policy->cpuinfo.max_freq); | ||
| 137 | |||
| 138 | if ((policy->policy != CPUFREQ_POLICY_POWERSAVE) && | ||
| 139 | (policy->policy != CPUFREQ_POLICY_PERFORMANCE)) | ||
| 140 | return -EINVAL; | ||
| 141 | |||
| 142 | return 0; | ||
| 143 | } | ||
| 144 | |||
| 145 | static unsigned int longrun_get(unsigned int cpu) | ||
| 146 | { | ||
| 147 | u32 eax, ebx, ecx, edx; | ||
| 148 | |||
| 149 | if (cpu) | ||
| 150 | return 0; | ||
| 151 | |||
| 152 | cpuid(0x80860007, &eax, &ebx, &ecx, &edx); | ||
| 153 | dprintk("cpuid eax is %u\n", eax); | ||
| 154 | |||
| 155 | return eax * 1000; | ||
| 156 | } | ||
| 157 | |||
| 158 | /** | ||
| 159 | * longrun_determine_freqs - determines the lowest and highest possible core frequency | ||
| 160 | * @low_freq: an int to put the lowest frequency into | ||
| 161 | * @high_freq: an int to put the highest frequency into | ||
| 162 | * | ||
| 163 | * Determines the lowest and highest possible core frequencies on this CPU. | ||
| 164 | * This is necessary to calculate the performance percentage according to | ||
| 165 | * TMTA rules: | ||
| 166 | * performance_pctg = (target_freq - low_freq)/(high_freq - low_freq) | ||
| 167 | */ | ||
| 168 | static int __cpuinit longrun_determine_freqs(unsigned int *low_freq, | ||
| 169 | unsigned int *high_freq) | ||
| 170 | { | ||
| 171 | u32 msr_lo, msr_hi; | ||
| 172 | u32 save_lo, save_hi; | ||
| 173 | u32 eax, ebx, ecx, edx; | ||
| 174 | u32 try_hi; | ||
| 175 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
| 176 | |||
| 177 | if (!low_freq || !high_freq) | ||
| 178 | return -EINVAL; | ||
| 179 | |||
| 180 | if (cpu_has(c, X86_FEATURE_LRTI)) { | ||
| 181 | /* if the LongRun Table Interface is present, the | ||
| 182 | * detection is a bit easier: | ||
| 183 | * For minimum frequency, read out the maximum | ||
| 184 | * level (msr_hi), write that into "currently | ||
| 185 | * selected level", and read out the frequency. | ||
| 186 | * For maximum frequency, read out level zero. | ||
| 187 | */ | ||
| 188 | /* minimum */ | ||
| 189 | rdmsr(MSR_TMTA_LRTI_READOUT, msr_lo, msr_hi); | ||
| 190 | wrmsr(MSR_TMTA_LRTI_READOUT, msr_hi, msr_hi); | ||
| 191 | rdmsr(MSR_TMTA_LRTI_VOLT_MHZ, msr_lo, msr_hi); | ||
| 192 | *low_freq = msr_lo * 1000; /* to kHz */ | ||
| 193 | |||
| 194 | /* maximum */ | ||
| 195 | wrmsr(MSR_TMTA_LRTI_READOUT, 0, msr_hi); | ||
| 196 | rdmsr(MSR_TMTA_LRTI_VOLT_MHZ, msr_lo, msr_hi); | ||
| 197 | *high_freq = msr_lo * 1000; /* to kHz */ | ||
| 198 | |||
| 199 | dprintk("longrun table interface told %u - %u kHz\n", | ||
| 200 | *low_freq, *high_freq); | ||
| 201 | |||
| 202 | if (*low_freq > *high_freq) | ||
| 203 | *low_freq = *high_freq; | ||
| 204 | return 0; | ||
| 205 | } | ||
| 206 | |||
| 207 | /* set the upper border to the value determined during TSC init */ | ||
| 208 | *high_freq = (cpu_khz / 1000); | ||
| 209 | *high_freq = *high_freq * 1000; | ||
| 210 | dprintk("high frequency is %u kHz\n", *high_freq); | ||
| 211 | |||
| 212 | /* get current borders */ | ||
| 213 | rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); | ||
| 214 | save_lo = msr_lo & 0x0000007F; | ||
| 215 | save_hi = msr_hi & 0x0000007F; | ||
| 216 | |||
| 217 | /* if current perf_pctg is larger than 90%, we need to decrease the | ||
| 218 | * upper limit to make the calculation more accurate. | ||
| 219 | */ | ||
| 220 | cpuid(0x80860007, &eax, &ebx, &ecx, &edx); | ||
| 221 | /* try decreasing in 10% steps, some processors react only | ||
| 222 | * on some barrier values */ | ||
| 223 | for (try_hi = 80; try_hi > 0 && ecx > 90; try_hi -= 10) { | ||
| 224 | /* set to 0 to try_hi perf_pctg */ | ||
| 225 | msr_lo &= 0xFFFFFF80; | ||
| 226 | msr_hi &= 0xFFFFFF80; | ||
| 227 | msr_hi |= try_hi; | ||
| 228 | wrmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); | ||
| 229 | |||
| 230 | /* read out current core MHz and current perf_pctg */ | ||
| 231 | cpuid(0x80860007, &eax, &ebx, &ecx, &edx); | ||
| 232 | |||
| 233 | /* restore values */ | ||
| 234 | wrmsr(MSR_TMTA_LONGRUN_CTRL, save_lo, save_hi); | ||
| 235 | } | ||
| 236 | dprintk("percentage is %u %%, freq is %u MHz\n", ecx, eax); | ||
| 237 | |||
| 238 | /* performance_pctg = (current_freq - low_freq)/(high_freq - low_freq) | ||
| 239 | * eqals | ||
| 240 | * low_freq * (1 - perf_pctg) = (cur_freq - high_freq * perf_pctg) | ||
| 241 | * | ||
| 242 | * high_freq * perf_pctg is stored tempoarily into "ebx". | ||
| 243 | */ | ||
| 244 | ebx = (((cpu_khz / 1000) * ecx) / 100); /* to MHz */ | ||
| 245 | |||
| 246 | if ((ecx > 95) || (ecx == 0) || (eax < ebx)) | ||
| 247 | return -EIO; | ||
| 248 | |||
| 249 | edx = ((eax - ebx) * 100) / (100 - ecx); | ||
| 250 | *low_freq = edx * 1000; /* back to kHz */ | ||
| 251 | |||
| 252 | dprintk("low frequency is %u kHz\n", *low_freq); | ||
| 253 | |||
| 254 | if (*low_freq > *high_freq) | ||
| 255 | *low_freq = *high_freq; | ||
| 256 | |||
| 257 | return 0; | ||
| 258 | } | ||
| 259 | |||
| 260 | |||
| 261 | static int __cpuinit longrun_cpu_init(struct cpufreq_policy *policy) | ||
| 262 | { | ||
| 263 | int result = 0; | ||
| 264 | |||
| 265 | /* capability check */ | ||
| 266 | if (policy->cpu != 0) | ||
| 267 | return -ENODEV; | ||
| 268 | |||
| 269 | /* detect low and high frequency */ | ||
| 270 | result = longrun_determine_freqs(&longrun_low_freq, &longrun_high_freq); | ||
| 271 | if (result) | ||
| 272 | return result; | ||
| 273 | |||
| 274 | /* cpuinfo and default policy values */ | ||
| 275 | policy->cpuinfo.min_freq = longrun_low_freq; | ||
| 276 | policy->cpuinfo.max_freq = longrun_high_freq; | ||
| 277 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | ||
| 278 | longrun_get_policy(policy); | ||
| 279 | |||
| 280 | return 0; | ||
| 281 | } | ||
| 282 | |||
| 283 | |||
| 284 | static struct cpufreq_driver longrun_driver = { | ||
| 285 | .flags = CPUFREQ_CONST_LOOPS, | ||
| 286 | .verify = longrun_verify_policy, | ||
| 287 | .setpolicy = longrun_set_policy, | ||
| 288 | .get = longrun_get, | ||
| 289 | .init = longrun_cpu_init, | ||
| 290 | .name = "longrun", | ||
| 291 | .owner = THIS_MODULE, | ||
| 292 | }; | ||
| 293 | |||
| 294 | |||
| 295 | /** | ||
| 296 | * longrun_init - initializes the Transmeta Crusoe LongRun CPUFreq driver | ||
| 297 | * | ||
| 298 | * Initializes the LongRun support. | ||
| 299 | */ | ||
| 300 | static int __init longrun_init(void) | ||
| 301 | { | ||
| 302 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
| 303 | |||
| 304 | if (c->x86_vendor != X86_VENDOR_TRANSMETA || | ||
| 305 | !cpu_has(c, X86_FEATURE_LONGRUN)) | ||
| 306 | return -ENODEV; | ||
| 307 | |||
| 308 | return cpufreq_register_driver(&longrun_driver); | ||
| 309 | } | ||
| 310 | |||
| 311 | |||
| 312 | /** | ||
| 313 | * longrun_exit - unregisters LongRun support | ||
| 314 | */ | ||
| 315 | static void __exit longrun_exit(void) | ||
| 316 | { | ||
| 317 | cpufreq_unregister_driver(&longrun_driver); | ||
| 318 | } | ||
| 319 | |||
| 320 | |||
| 321 | MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>"); | ||
| 322 | MODULE_DESCRIPTION("LongRun driver for Transmeta Crusoe and " | ||
| 323 | "Efficeon processors."); | ||
| 324 | MODULE_LICENSE("GPL"); | ||
| 325 | |||
| 326 | module_init(longrun_init); | ||
| 327 | module_exit(longrun_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/mperf.c b/arch/x86/kernel/cpu/cpufreq/mperf.c deleted file mode 100644 index 911e193018ae..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/mperf.c +++ /dev/null | |||
| @@ -1,51 +0,0 @@ | |||
| 1 | #include <linux/kernel.h> | ||
| 2 | #include <linux/smp.h> | ||
| 3 | #include <linux/module.h> | ||
| 4 | #include <linux/init.h> | ||
| 5 | #include <linux/cpufreq.h> | ||
| 6 | #include <linux/slab.h> | ||
| 7 | |||
| 8 | #include "mperf.h" | ||
| 9 | |||
| 10 | static DEFINE_PER_CPU(struct aperfmperf, acfreq_old_perf); | ||
| 11 | |||
| 12 | /* Called via smp_call_function_single(), on the target CPU */ | ||
| 13 | static void read_measured_perf_ctrs(void *_cur) | ||
| 14 | { | ||
| 15 | struct aperfmperf *am = _cur; | ||
| 16 | |||
| 17 | get_aperfmperf(am); | ||
| 18 | } | ||
| 19 | |||
| 20 | /* | ||
| 21 | * Return the measured active (C0) frequency on this CPU since last call | ||
| 22 | * to this function. | ||
| 23 | * Input: cpu number | ||
| 24 | * Return: Average CPU frequency in terms of max frequency (zero on error) | ||
| 25 | * | ||
| 26 | * We use IA32_MPERF and IA32_APERF MSRs to get the measured performance | ||
| 27 | * over a period of time, while CPU is in C0 state. | ||
| 28 | * IA32_MPERF counts at the rate of max advertised frequency | ||
| 29 | * IA32_APERF counts at the rate of actual CPU frequency | ||
| 30 | * Only IA32_APERF/IA32_MPERF ratio is architecturally defined and | ||
| 31 | * no meaning should be associated with absolute values of these MSRs. | ||
| 32 | */ | ||
| 33 | unsigned int cpufreq_get_measured_perf(struct cpufreq_policy *policy, | ||
| 34 | unsigned int cpu) | ||
| 35 | { | ||
| 36 | struct aperfmperf perf; | ||
| 37 | unsigned long ratio; | ||
| 38 | unsigned int retval; | ||
| 39 | |||
| 40 | if (smp_call_function_single(cpu, read_measured_perf_ctrs, &perf, 1)) | ||
| 41 | return 0; | ||
| 42 | |||
| 43 | ratio = calc_aperfmperf_ratio(&per_cpu(acfreq_old_perf, cpu), &perf); | ||
| 44 | per_cpu(acfreq_old_perf, cpu) = perf; | ||
| 45 | |||
| 46 | retval = (policy->cpuinfo.max_freq * ratio) >> APERFMPERF_SHIFT; | ||
| 47 | |||
| 48 | return retval; | ||
| 49 | } | ||
| 50 | EXPORT_SYMBOL_GPL(cpufreq_get_measured_perf); | ||
| 51 | MODULE_LICENSE("GPL"); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/mperf.h b/arch/x86/kernel/cpu/cpufreq/mperf.h deleted file mode 100644 index 5dbf2950dc22..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/mperf.h +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * (c) 2010 Advanced Micro Devices, Inc. | ||
| 3 | * Your use of this code is subject to the terms and conditions of the | ||
| 4 | * GNU general public license version 2. See "COPYING" or | ||
| 5 | * http://www.gnu.org/licenses/gpl.html | ||
| 6 | */ | ||
| 7 | |||
| 8 | unsigned int cpufreq_get_measured_perf(struct cpufreq_policy *policy, | ||
| 9 | unsigned int cpu); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/p4-clockmod.c b/arch/x86/kernel/cpu/cpufreq/p4-clockmod.c deleted file mode 100644 index 52c93648e492..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/p4-clockmod.c +++ /dev/null | |||
| @@ -1,331 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Pentium 4/Xeon CPU on demand clock modulation/speed scaling | ||
| 3 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> | ||
| 4 | * (C) 2002 Zwane Mwaikambo <zwane@commfireservices.com> | ||
| 5 | * (C) 2002 Arjan van de Ven <arjanv@redhat.com> | ||
| 6 | * (C) 2002 Tora T. Engstad | ||
| 7 | * All Rights Reserved | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU General Public License | ||
| 11 | * as published by the Free Software Foundation; either version | ||
| 12 | * 2 of the License, or (at your option) any later version. | ||
| 13 | * | ||
| 14 | * The author(s) of this software shall not be held liable for damages | ||
| 15 | * of any nature resulting due to the use of this software. This | ||
| 16 | * software is provided AS-IS with no warranties. | ||
| 17 | * | ||
| 18 | * Date Errata Description | ||
| 19 | * 20020525 N44, O17 12.5% or 25% DC causes lockup | ||
| 20 | * | ||
| 21 | */ | ||
| 22 | |||
| 23 | #include <linux/kernel.h> | ||
| 24 | #include <linux/module.h> | ||
| 25 | #include <linux/init.h> | ||
| 26 | #include <linux/smp.h> | ||
| 27 | #include <linux/cpufreq.h> | ||
| 28 | #include <linux/cpumask.h> | ||
| 29 | #include <linux/timex.h> | ||
| 30 | |||
| 31 | #include <asm/processor.h> | ||
| 32 | #include <asm/msr.h> | ||
| 33 | #include <asm/timer.h> | ||
| 34 | |||
| 35 | #include "speedstep-lib.h" | ||
| 36 | |||
| 37 | #define PFX "p4-clockmod: " | ||
| 38 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
| 39 | "p4-clockmod", msg) | ||
| 40 | |||
| 41 | /* | ||
| 42 | * Duty Cycle (3bits), note DC_DISABLE is not specified in | ||
| 43 | * intel docs i just use it to mean disable | ||
| 44 | */ | ||
| 45 | enum { | ||
| 46 | DC_RESV, DC_DFLT, DC_25PT, DC_38PT, DC_50PT, | ||
| 47 | DC_64PT, DC_75PT, DC_88PT, DC_DISABLE | ||
| 48 | }; | ||
| 49 | |||
| 50 | #define DC_ENTRIES 8 | ||
| 51 | |||
| 52 | |||
| 53 | static int has_N44_O17_errata[NR_CPUS]; | ||
| 54 | static unsigned int stock_freq; | ||
| 55 | static struct cpufreq_driver p4clockmod_driver; | ||
| 56 | static unsigned int cpufreq_p4_get(unsigned int cpu); | ||
| 57 | |||
| 58 | static int cpufreq_p4_setdc(unsigned int cpu, unsigned int newstate) | ||
| 59 | { | ||
| 60 | u32 l, h; | ||
| 61 | |||
| 62 | if (!cpu_online(cpu) || | ||
| 63 | (newstate > DC_DISABLE) || (newstate == DC_RESV)) | ||
| 64 | return -EINVAL; | ||
| 65 | |||
| 66 | rdmsr_on_cpu(cpu, MSR_IA32_THERM_STATUS, &l, &h); | ||
| 67 | |||
| 68 | if (l & 0x01) | ||
| 69 | dprintk("CPU#%d currently thermal throttled\n", cpu); | ||
| 70 | |||
| 71 | if (has_N44_O17_errata[cpu] && | ||
| 72 | (newstate == DC_25PT || newstate == DC_DFLT)) | ||
| 73 | newstate = DC_38PT; | ||
| 74 | |||
| 75 | rdmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, &l, &h); | ||
| 76 | if (newstate == DC_DISABLE) { | ||
| 77 | dprintk("CPU#%d disabling modulation\n", cpu); | ||
| 78 | wrmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, l & ~(1<<4), h); | ||
| 79 | } else { | ||
| 80 | dprintk("CPU#%d setting duty cycle to %d%%\n", | ||
| 81 | cpu, ((125 * newstate) / 10)); | ||
| 82 | /* bits 63 - 5 : reserved | ||
| 83 | * bit 4 : enable/disable | ||
| 84 | * bits 3-1 : duty cycle | ||
| 85 | * bit 0 : reserved | ||
| 86 | */ | ||
| 87 | l = (l & ~14); | ||
| 88 | l = l | (1<<4) | ((newstate & 0x7)<<1); | ||
| 89 | wrmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, l, h); | ||
| 90 | } | ||
| 91 | |||
| 92 | return 0; | ||
| 93 | } | ||
| 94 | |||
| 95 | |||
| 96 | static struct cpufreq_frequency_table p4clockmod_table[] = { | ||
| 97 | {DC_RESV, CPUFREQ_ENTRY_INVALID}, | ||
| 98 | {DC_DFLT, 0}, | ||
| 99 | {DC_25PT, 0}, | ||
| 100 | {DC_38PT, 0}, | ||
| 101 | {DC_50PT, 0}, | ||
| 102 | {DC_64PT, 0}, | ||
| 103 | {DC_75PT, 0}, | ||
| 104 | {DC_88PT, 0}, | ||
| 105 | {DC_DISABLE, 0}, | ||
| 106 | {DC_RESV, CPUFREQ_TABLE_END}, | ||
| 107 | }; | ||
| 108 | |||
| 109 | |||
| 110 | static int cpufreq_p4_target(struct cpufreq_policy *policy, | ||
| 111 | unsigned int target_freq, | ||
| 112 | unsigned int relation) | ||
| 113 | { | ||
| 114 | unsigned int newstate = DC_RESV; | ||
| 115 | struct cpufreq_freqs freqs; | ||
| 116 | int i; | ||
| 117 | |||
| 118 | if (cpufreq_frequency_table_target(policy, &p4clockmod_table[0], | ||
| 119 | target_freq, relation, &newstate)) | ||
| 120 | return -EINVAL; | ||
| 121 | |||
| 122 | freqs.old = cpufreq_p4_get(policy->cpu); | ||
| 123 | freqs.new = stock_freq * p4clockmod_table[newstate].index / 8; | ||
| 124 | |||
| 125 | if (freqs.new == freqs.old) | ||
| 126 | return 0; | ||
| 127 | |||
| 128 | /* notifiers */ | ||
| 129 | for_each_cpu(i, policy->cpus) { | ||
| 130 | freqs.cpu = i; | ||
| 131 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
| 132 | } | ||
| 133 | |||
| 134 | /* run on each logical CPU, | ||
| 135 | * see section 13.15.3 of IA32 Intel Architecture Software | ||
| 136 | * Developer's Manual, Volume 3 | ||
| 137 | */ | ||
| 138 | for_each_cpu(i, policy->cpus) | ||
| 139 | cpufreq_p4_setdc(i, p4clockmod_table[newstate].index); | ||
| 140 | |||
| 141 | /* notifiers */ | ||
| 142 | for_each_cpu(i, policy->cpus) { | ||
| 143 | freqs.cpu = i; | ||
| 144 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 145 | } | ||
| 146 | |||
| 147 | return 0; | ||
| 148 | } | ||
| 149 | |||
| 150 | |||
| 151 | static int cpufreq_p4_verify(struct cpufreq_policy *policy) | ||
| 152 | { | ||
| 153 | return cpufreq_frequency_table_verify(policy, &p4clockmod_table[0]); | ||
| 154 | } | ||
| 155 | |||
| 156 | |||
| 157 | static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c) | ||
| 158 | { | ||
| 159 | if (c->x86 == 0x06) { | ||
| 160 | if (cpu_has(c, X86_FEATURE_EST)) | ||
| 161 | printk_once(KERN_WARNING PFX "Warning: EST-capable " | ||
| 162 | "CPU detected. The acpi-cpufreq module offers " | ||
| 163 | "voltage scaling in addition to frequency " | ||
| 164 | "scaling. You should use that instead of " | ||
| 165 | "p4-clockmod, if possible.\n"); | ||
| 166 | switch (c->x86_model) { | ||
| 167 | case 0x0E: /* Core */ | ||
| 168 | case 0x0F: /* Core Duo */ | ||
| 169 | case 0x16: /* Celeron Core */ | ||
| 170 | case 0x1C: /* Atom */ | ||
| 171 | p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS; | ||
| 172 | return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE); | ||
| 173 | case 0x0D: /* Pentium M (Dothan) */ | ||
| 174 | p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS; | ||
| 175 | /* fall through */ | ||
| 176 | case 0x09: /* Pentium M (Banias) */ | ||
| 177 | return speedstep_get_frequency(SPEEDSTEP_CPU_PM); | ||
| 178 | } | ||
| 179 | } | ||
| 180 | |||
| 181 | if (c->x86 != 0xF) | ||
| 182 | return 0; | ||
| 183 | |||
| 184 | /* on P-4s, the TSC runs with constant frequency independent whether | ||
| 185 | * throttling is active or not. */ | ||
| 186 | p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS; | ||
| 187 | |||
| 188 | if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) { | ||
| 189 | printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. " | ||
| 190 | "The speedstep-ich or acpi cpufreq modules offer " | ||
| 191 | "voltage scaling in addition of frequency scaling. " | ||
| 192 | "You should use either one instead of p4-clockmod, " | ||
| 193 | "if possible.\n"); | ||
| 194 | return speedstep_get_frequency(SPEEDSTEP_CPU_P4M); | ||
| 195 | } | ||
| 196 | |||
| 197 | return speedstep_get_frequency(SPEEDSTEP_CPU_P4D); | ||
| 198 | } | ||
| 199 | |||
| 200 | |||
| 201 | |||
| 202 | static int cpufreq_p4_cpu_init(struct cpufreq_policy *policy) | ||
| 203 | { | ||
| 204 | struct cpuinfo_x86 *c = &cpu_data(policy->cpu); | ||
| 205 | int cpuid = 0; | ||
| 206 | unsigned int i; | ||
| 207 | |||
| 208 | #ifdef CONFIG_SMP | ||
| 209 | cpumask_copy(policy->cpus, cpu_sibling_mask(policy->cpu)); | ||
| 210 | #endif | ||
| 211 | |||
| 212 | /* Errata workaround */ | ||
| 213 | cpuid = (c->x86 << 8) | (c->x86_model << 4) | c->x86_mask; | ||
| 214 | switch (cpuid) { | ||
| 215 | case 0x0f07: | ||
| 216 | case 0x0f0a: | ||
| 217 | case 0x0f11: | ||
| 218 | case 0x0f12: | ||
| 219 | has_N44_O17_errata[policy->cpu] = 1; | ||
| 220 | dprintk("has errata -- disabling low frequencies\n"); | ||
| 221 | } | ||
| 222 | |||
| 223 | if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4D && | ||
| 224 | c->x86_model < 2) { | ||
| 225 | /* switch to maximum frequency and measure result */ | ||
| 226 | cpufreq_p4_setdc(policy->cpu, DC_DISABLE); | ||
| 227 | recalibrate_cpu_khz(); | ||
| 228 | } | ||
| 229 | /* get max frequency */ | ||
| 230 | stock_freq = cpufreq_p4_get_frequency(c); | ||
| 231 | if (!stock_freq) | ||
| 232 | return -EINVAL; | ||
| 233 | |||
| 234 | /* table init */ | ||
| 235 | for (i = 1; (p4clockmod_table[i].frequency != CPUFREQ_TABLE_END); i++) { | ||
| 236 | if ((i < 2) && (has_N44_O17_errata[policy->cpu])) | ||
| 237 | p4clockmod_table[i].frequency = CPUFREQ_ENTRY_INVALID; | ||
| 238 | else | ||
| 239 | p4clockmod_table[i].frequency = (stock_freq * i)/8; | ||
| 240 | } | ||
| 241 | cpufreq_frequency_table_get_attr(p4clockmod_table, policy->cpu); | ||
| 242 | |||
| 243 | /* cpuinfo and default policy values */ | ||
| 244 | |||
| 245 | /* the transition latency is set to be 1 higher than the maximum | ||
| 246 | * transition latency of the ondemand governor */ | ||
| 247 | policy->cpuinfo.transition_latency = 10000001; | ||
| 248 | policy->cur = stock_freq; | ||
| 249 | |||
| 250 | return cpufreq_frequency_table_cpuinfo(policy, &p4clockmod_table[0]); | ||
| 251 | } | ||
| 252 | |||
| 253 | |||
| 254 | static int cpufreq_p4_cpu_exit(struct cpufreq_policy *policy) | ||
| 255 | { | ||
| 256 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
| 257 | return 0; | ||
| 258 | } | ||
| 259 | |||
| 260 | static unsigned int cpufreq_p4_get(unsigned int cpu) | ||
| 261 | { | ||
| 262 | u32 l, h; | ||
| 263 | |||
| 264 | rdmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, &l, &h); | ||
| 265 | |||
| 266 | if (l & 0x10) { | ||
| 267 | l = l >> 1; | ||
| 268 | l &= 0x7; | ||
| 269 | } else | ||
| 270 | l = DC_DISABLE; | ||
| 271 | |||
| 272 | if (l != DC_DISABLE) | ||
| 273 | return stock_freq * l / 8; | ||
| 274 | |||
| 275 | return stock_freq; | ||
| 276 | } | ||
| 277 | |||
| 278 | static struct freq_attr *p4clockmod_attr[] = { | ||
| 279 | &cpufreq_freq_attr_scaling_available_freqs, | ||
| 280 | NULL, | ||
| 281 | }; | ||
| 282 | |||
| 283 | static struct cpufreq_driver p4clockmod_driver = { | ||
| 284 | .verify = cpufreq_p4_verify, | ||
| 285 | .target = cpufreq_p4_target, | ||
| 286 | .init = cpufreq_p4_cpu_init, | ||
| 287 | .exit = cpufreq_p4_cpu_exit, | ||
| 288 | .get = cpufreq_p4_get, | ||
| 289 | .name = "p4-clockmod", | ||
| 290 | .owner = THIS_MODULE, | ||
| 291 | .attr = p4clockmod_attr, | ||
| 292 | }; | ||
| 293 | |||
| 294 | |||
| 295 | static int __init cpufreq_p4_init(void) | ||
| 296 | { | ||
| 297 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
| 298 | int ret; | ||
| 299 | |||
| 300 | /* | ||
| 301 | * THERM_CONTROL is architectural for IA32 now, so | ||
| 302 | * we can rely on the capability checks | ||
| 303 | */ | ||
| 304 | if (c->x86_vendor != X86_VENDOR_INTEL) | ||
| 305 | return -ENODEV; | ||
| 306 | |||
| 307 | if (!test_cpu_cap(c, X86_FEATURE_ACPI) || | ||
| 308 | !test_cpu_cap(c, X86_FEATURE_ACC)) | ||
| 309 | return -ENODEV; | ||
| 310 | |||
| 311 | ret = cpufreq_register_driver(&p4clockmod_driver); | ||
| 312 | if (!ret) | ||
| 313 | printk(KERN_INFO PFX "P4/Xeon(TM) CPU On-Demand Clock " | ||
| 314 | "Modulation available\n"); | ||
| 315 | |||
| 316 | return ret; | ||
| 317 | } | ||
| 318 | |||
| 319 | |||
| 320 | static void __exit cpufreq_p4_exit(void) | ||
| 321 | { | ||
| 322 | cpufreq_unregister_driver(&p4clockmod_driver); | ||
| 323 | } | ||
| 324 | |||
| 325 | |||
| 326 | MODULE_AUTHOR("Zwane Mwaikambo <zwane@commfireservices.com>"); | ||
| 327 | MODULE_DESCRIPTION("cpufreq driver for Pentium(TM) 4/Xeon(TM)"); | ||
| 328 | MODULE_LICENSE("GPL"); | ||
| 329 | |||
| 330 | late_initcall(cpufreq_p4_init); | ||
| 331 | module_exit(cpufreq_p4_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/pcc-cpufreq.c b/arch/x86/kernel/cpu/cpufreq/pcc-cpufreq.c deleted file mode 100644 index 755a31e0f5b0..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/pcc-cpufreq.c +++ /dev/null | |||
| @@ -1,624 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * pcc-cpufreq.c - Processor Clocking Control firmware cpufreq interface | ||
| 3 | * | ||
| 4 | * Copyright (C) 2009 Red Hat, Matthew Garrett <mjg@redhat.com> | ||
| 5 | * Copyright (C) 2009 Hewlett-Packard Development Company, L.P. | ||
| 6 | * Nagananda Chumbalkar <nagananda.chumbalkar@hp.com> | ||
| 7 | * | ||
| 8 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 9 | * | ||
| 10 | * This program is free software; you can redistribute it and/or modify | ||
| 11 | * it under the terms of the GNU General Public License as published by | ||
| 12 | * the Free Software Foundation; version 2 of the License. | ||
| 13 | * | ||
| 14 | * This program is distributed in the hope that it will be useful, but | ||
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or NON | ||
| 17 | * INFRINGEMENT. See the GNU General Public License for more details. | ||
| 18 | * | ||
| 19 | * You should have received a copy of the GNU General Public License along | ||
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
| 21 | * 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 22 | * | ||
| 23 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 24 | */ | ||
| 25 | |||
| 26 | #include <linux/kernel.h> | ||
| 27 | #include <linux/module.h> | ||
| 28 | #include <linux/init.h> | ||
| 29 | #include <linux/smp.h> | ||
| 30 | #include <linux/sched.h> | ||
| 31 | #include <linux/cpufreq.h> | ||
| 32 | #include <linux/compiler.h> | ||
| 33 | #include <linux/slab.h> | ||
| 34 | |||
| 35 | #include <linux/acpi.h> | ||
| 36 | #include <linux/io.h> | ||
| 37 | #include <linux/spinlock.h> | ||
| 38 | #include <linux/uaccess.h> | ||
| 39 | |||
| 40 | #include <acpi/processor.h> | ||
| 41 | |||
| 42 | #define PCC_VERSION "1.00.00" | ||
| 43 | #define POLL_LOOPS 300 | ||
| 44 | |||
| 45 | #define CMD_COMPLETE 0x1 | ||
| 46 | #define CMD_GET_FREQ 0x0 | ||
| 47 | #define CMD_SET_FREQ 0x1 | ||
| 48 | |||
| 49 | #define BUF_SZ 4 | ||
| 50 | |||
| 51 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
| 52 | "pcc-cpufreq", msg) | ||
| 53 | |||
| 54 | struct pcc_register_resource { | ||
| 55 | u8 descriptor; | ||
| 56 | u16 length; | ||
| 57 | u8 space_id; | ||
| 58 | u8 bit_width; | ||
| 59 | u8 bit_offset; | ||
| 60 | u8 access_size; | ||
| 61 | u64 address; | ||
| 62 | } __attribute__ ((packed)); | ||
| 63 | |||
| 64 | struct pcc_memory_resource { | ||
| 65 | u8 descriptor; | ||
| 66 | u16 length; | ||
| 67 | u8 space_id; | ||
| 68 | u8 resource_usage; | ||
| 69 | u8 type_specific; | ||
| 70 | u64 granularity; | ||
| 71 | u64 minimum; | ||
| 72 | u64 maximum; | ||
| 73 | u64 translation_offset; | ||
| 74 | u64 address_length; | ||
| 75 | } __attribute__ ((packed)); | ||
| 76 | |||
| 77 | static struct cpufreq_driver pcc_cpufreq_driver; | ||
| 78 | |||
| 79 | struct pcc_header { | ||
| 80 | u32 signature; | ||
| 81 | u16 length; | ||
| 82 | u8 major; | ||
| 83 | u8 minor; | ||
| 84 | u32 features; | ||
| 85 | u16 command; | ||
| 86 | u16 status; | ||
| 87 | u32 latency; | ||
| 88 | u32 minimum_time; | ||
| 89 | u32 maximum_time; | ||
| 90 | u32 nominal; | ||
| 91 | u32 throttled_frequency; | ||
| 92 | u32 minimum_frequency; | ||
| 93 | }; | ||
| 94 | |||
| 95 | static void __iomem *pcch_virt_addr; | ||
| 96 | static struct pcc_header __iomem *pcch_hdr; | ||
| 97 | |||
| 98 | static DEFINE_SPINLOCK(pcc_lock); | ||
| 99 | |||
| 100 | static struct acpi_generic_address doorbell; | ||
| 101 | |||
| 102 | static u64 doorbell_preserve; | ||
| 103 | static u64 doorbell_write; | ||
| 104 | |||
| 105 | static u8 OSC_UUID[16] = {0x63, 0x9B, 0x2C, 0x9F, 0x70, 0x91, 0x49, 0x1f, | ||
| 106 | 0xBB, 0x4F, 0xA5, 0x98, 0x2F, 0xA1, 0xB5, 0x46}; | ||
| 107 | |||
| 108 | struct pcc_cpu { | ||
| 109 | u32 input_offset; | ||
| 110 | u32 output_offset; | ||
| 111 | }; | ||
| 112 | |||
| 113 | static struct pcc_cpu __percpu *pcc_cpu_info; | ||
| 114 | |||
| 115 | static int pcc_cpufreq_verify(struct cpufreq_policy *policy) | ||
| 116 | { | ||
| 117 | cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, | ||
| 118 | policy->cpuinfo.max_freq); | ||
| 119 | return 0; | ||
| 120 | } | ||
| 121 | |||
| 122 | static inline void pcc_cmd(void) | ||
| 123 | { | ||
| 124 | u64 doorbell_value; | ||
| 125 | int i; | ||
| 126 | |||
| 127 | acpi_read(&doorbell_value, &doorbell); | ||
| 128 | acpi_write((doorbell_value & doorbell_preserve) | doorbell_write, | ||
| 129 | &doorbell); | ||
| 130 | |||
| 131 | for (i = 0; i < POLL_LOOPS; i++) { | ||
| 132 | if (ioread16(&pcch_hdr->status) & CMD_COMPLETE) | ||
| 133 | break; | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | static inline void pcc_clear_mapping(void) | ||
| 138 | { | ||
| 139 | if (pcch_virt_addr) | ||
| 140 | iounmap(pcch_virt_addr); | ||
| 141 | pcch_virt_addr = NULL; | ||
| 142 | } | ||
| 143 | |||
| 144 | static unsigned int pcc_get_freq(unsigned int cpu) | ||
| 145 | { | ||
| 146 | struct pcc_cpu *pcc_cpu_data; | ||
| 147 | unsigned int curr_freq; | ||
| 148 | unsigned int freq_limit; | ||
| 149 | u16 status; | ||
| 150 | u32 input_buffer; | ||
| 151 | u32 output_buffer; | ||
| 152 | |||
| 153 | spin_lock(&pcc_lock); | ||
| 154 | |||
| 155 | dprintk("get: get_freq for CPU %d\n", cpu); | ||
| 156 | pcc_cpu_data = per_cpu_ptr(pcc_cpu_info, cpu); | ||
| 157 | |||
| 158 | input_buffer = 0x1; | ||
| 159 | iowrite32(input_buffer, | ||
| 160 | (pcch_virt_addr + pcc_cpu_data->input_offset)); | ||
| 161 | iowrite16(CMD_GET_FREQ, &pcch_hdr->command); | ||
| 162 | |||
| 163 | pcc_cmd(); | ||
| 164 | |||
| 165 | output_buffer = | ||
| 166 | ioread32(pcch_virt_addr + pcc_cpu_data->output_offset); | ||
| 167 | |||
| 168 | /* Clear the input buffer - we are done with the current command */ | ||
| 169 | memset_io((pcch_virt_addr + pcc_cpu_data->input_offset), 0, BUF_SZ); | ||
| 170 | |||
| 171 | status = ioread16(&pcch_hdr->status); | ||
| 172 | if (status != CMD_COMPLETE) { | ||
| 173 | dprintk("get: FAILED: for CPU %d, status is %d\n", | ||
| 174 | cpu, status); | ||
| 175 | goto cmd_incomplete; | ||
| 176 | } | ||
| 177 | iowrite16(0, &pcch_hdr->status); | ||
| 178 | curr_freq = (((ioread32(&pcch_hdr->nominal) * (output_buffer & 0xff)) | ||
| 179 | / 100) * 1000); | ||
| 180 | |||
| 181 | dprintk("get: SUCCESS: (virtual) output_offset for cpu %d is " | ||
| 182 | "0x%x, contains a value of: 0x%x. Speed is: %d MHz\n", | ||
| 183 | cpu, (pcch_virt_addr + pcc_cpu_data->output_offset), | ||
| 184 | output_buffer, curr_freq); | ||
| 185 | |||
| 186 | freq_limit = (output_buffer >> 8) & 0xff; | ||
| 187 | if (freq_limit != 0xff) { | ||
| 188 | dprintk("get: frequency for cpu %d is being temporarily" | ||
| 189 | " capped at %d\n", cpu, curr_freq); | ||
| 190 | } | ||
| 191 | |||
| 192 | spin_unlock(&pcc_lock); | ||
| 193 | return curr_freq; | ||
| 194 | |||
| 195 | cmd_incomplete: | ||
| 196 | iowrite16(0, &pcch_hdr->status); | ||
| 197 | spin_unlock(&pcc_lock); | ||
| 198 | return 0; | ||
| 199 | } | ||
| 200 | |||
| 201 | static int pcc_cpufreq_target(struct cpufreq_policy *policy, | ||
| 202 | unsigned int target_freq, | ||
| 203 | unsigned int relation) | ||
| 204 | { | ||
| 205 | struct pcc_cpu *pcc_cpu_data; | ||
| 206 | struct cpufreq_freqs freqs; | ||
| 207 | u16 status; | ||
| 208 | u32 input_buffer; | ||
| 209 | int cpu; | ||
| 210 | |||
| 211 | spin_lock(&pcc_lock); | ||
| 212 | cpu = policy->cpu; | ||
| 213 | pcc_cpu_data = per_cpu_ptr(pcc_cpu_info, cpu); | ||
| 214 | |||
| 215 | dprintk("target: CPU %d should go to target freq: %d " | ||
| 216 | "(virtual) input_offset is 0x%x\n", | ||
| 217 | cpu, target_freq, | ||
| 218 | (pcch_virt_addr + pcc_cpu_data->input_offset)); | ||
| 219 | |||
| 220 | freqs.new = target_freq; | ||
| 221 | freqs.cpu = cpu; | ||
| 222 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
| 223 | |||
| 224 | input_buffer = 0x1 | (((target_freq * 100) | ||
| 225 | / (ioread32(&pcch_hdr->nominal) * 1000)) << 8); | ||
| 226 | iowrite32(input_buffer, | ||
| 227 | (pcch_virt_addr + pcc_cpu_data->input_offset)); | ||
| 228 | iowrite16(CMD_SET_FREQ, &pcch_hdr->command); | ||
| 229 | |||
| 230 | pcc_cmd(); | ||
| 231 | |||
| 232 | /* Clear the input buffer - we are done with the current command */ | ||
| 233 | memset_io((pcch_virt_addr + pcc_cpu_data->input_offset), 0, BUF_SZ); | ||
| 234 | |||
| 235 | status = ioread16(&pcch_hdr->status); | ||
| 236 | if (status != CMD_COMPLETE) { | ||
| 237 | dprintk("target: FAILED for cpu %d, with status: 0x%x\n", | ||
| 238 | cpu, status); | ||
| 239 | goto cmd_incomplete; | ||
| 240 | } | ||
| 241 | iowrite16(0, &pcch_hdr->status); | ||
| 242 | |||
| 243 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 244 | dprintk("target: was SUCCESSFUL for cpu %d\n", cpu); | ||
| 245 | spin_unlock(&pcc_lock); | ||
| 246 | |||
| 247 | return 0; | ||
| 248 | |||
| 249 | cmd_incomplete: | ||
| 250 | iowrite16(0, &pcch_hdr->status); | ||
| 251 | spin_unlock(&pcc_lock); | ||
| 252 | return -EINVAL; | ||
| 253 | } | ||
| 254 | |||
| 255 | static int pcc_get_offset(int cpu) | ||
| 256 | { | ||
| 257 | acpi_status status; | ||
| 258 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; | ||
| 259 | union acpi_object *pccp, *offset; | ||
| 260 | struct pcc_cpu *pcc_cpu_data; | ||
| 261 | struct acpi_processor *pr; | ||
| 262 | int ret = 0; | ||
| 263 | |||
| 264 | pr = per_cpu(processors, cpu); | ||
| 265 | pcc_cpu_data = per_cpu_ptr(pcc_cpu_info, cpu); | ||
| 266 | |||
| 267 | status = acpi_evaluate_object(pr->handle, "PCCP", NULL, &buffer); | ||
| 268 | if (ACPI_FAILURE(status)) | ||
| 269 | return -ENODEV; | ||
| 270 | |||
| 271 | pccp = buffer.pointer; | ||
| 272 | if (!pccp || pccp->type != ACPI_TYPE_PACKAGE) { | ||
| 273 | ret = -ENODEV; | ||
| 274 | goto out_free; | ||
| 275 | }; | ||
| 276 | |||
| 277 | offset = &(pccp->package.elements[0]); | ||
| 278 | if (!offset || offset->type != ACPI_TYPE_INTEGER) { | ||
| 279 | ret = -ENODEV; | ||
| 280 | goto out_free; | ||
| 281 | } | ||
| 282 | |||
| 283 | pcc_cpu_data->input_offset = offset->integer.value; | ||
| 284 | |||
| 285 | offset = &(pccp->package.elements[1]); | ||
| 286 | if (!offset || offset->type != ACPI_TYPE_INTEGER) { | ||
| 287 | ret = -ENODEV; | ||
| 288 | goto out_free; | ||
| 289 | } | ||
| 290 | |||
| 291 | pcc_cpu_data->output_offset = offset->integer.value; | ||
| 292 | |||
| 293 | memset_io((pcch_virt_addr + pcc_cpu_data->input_offset), 0, BUF_SZ); | ||
| 294 | memset_io((pcch_virt_addr + pcc_cpu_data->output_offset), 0, BUF_SZ); | ||
| 295 | |||
| 296 | dprintk("pcc_get_offset: for CPU %d: pcc_cpu_data " | ||
| 297 | "input_offset: 0x%x, pcc_cpu_data output_offset: 0x%x\n", | ||
| 298 | cpu, pcc_cpu_data->input_offset, pcc_cpu_data->output_offset); | ||
| 299 | out_free: | ||
| 300 | kfree(buffer.pointer); | ||
| 301 | return ret; | ||
| 302 | } | ||
| 303 | |||
| 304 | static int __init pcc_cpufreq_do_osc(acpi_handle *handle) | ||
| 305 | { | ||
| 306 | acpi_status status; | ||
| 307 | struct acpi_object_list input; | ||
| 308 | struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; | ||
| 309 | union acpi_object in_params[4]; | ||
| 310 | union acpi_object *out_obj; | ||
| 311 | u32 capabilities[2]; | ||
| 312 | u32 errors; | ||
| 313 | u32 supported; | ||
| 314 | int ret = 0; | ||
| 315 | |||
| 316 | input.count = 4; | ||
| 317 | input.pointer = in_params; | ||
| 318 | in_params[0].type = ACPI_TYPE_BUFFER; | ||
| 319 | in_params[0].buffer.length = 16; | ||
| 320 | in_params[0].buffer.pointer = OSC_UUID; | ||
| 321 | in_params[1].type = ACPI_TYPE_INTEGER; | ||
| 322 | in_params[1].integer.value = 1; | ||
| 323 | in_params[2].type = ACPI_TYPE_INTEGER; | ||
| 324 | in_params[2].integer.value = 2; | ||
| 325 | in_params[3].type = ACPI_TYPE_BUFFER; | ||
| 326 | in_params[3].buffer.length = 8; | ||
| 327 | in_params[3].buffer.pointer = (u8 *)&capabilities; | ||
| 328 | |||
| 329 | capabilities[0] = OSC_QUERY_ENABLE; | ||
| 330 | capabilities[1] = 0x1; | ||
| 331 | |||
| 332 | status = acpi_evaluate_object(*handle, "_OSC", &input, &output); | ||
| 333 | if (ACPI_FAILURE(status)) | ||
| 334 | return -ENODEV; | ||
| 335 | |||
| 336 | if (!output.length) | ||
| 337 | return -ENODEV; | ||
| 338 | |||
| 339 | out_obj = output.pointer; | ||
| 340 | if (out_obj->type != ACPI_TYPE_BUFFER) { | ||
| 341 | ret = -ENODEV; | ||
| 342 | goto out_free; | ||
| 343 | } | ||
| 344 | |||
| 345 | errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0); | ||
| 346 | if (errors) { | ||
| 347 | ret = -ENODEV; | ||
| 348 | goto out_free; | ||
| 349 | } | ||
| 350 | |||
| 351 | supported = *((u32 *)(out_obj->buffer.pointer + 4)); | ||
| 352 | if (!(supported & 0x1)) { | ||
| 353 | ret = -ENODEV; | ||
| 354 | goto out_free; | ||
| 355 | } | ||
| 356 | |||
| 357 | kfree(output.pointer); | ||
| 358 | capabilities[0] = 0x0; | ||
| 359 | capabilities[1] = 0x1; | ||
| 360 | |||
| 361 | status = acpi_evaluate_object(*handle, "_OSC", &input, &output); | ||
| 362 | if (ACPI_FAILURE(status)) | ||
| 363 | return -ENODEV; | ||
| 364 | |||
| 365 | if (!output.length) | ||
| 366 | return -ENODEV; | ||
| 367 | |||
| 368 | out_obj = output.pointer; | ||
| 369 | if (out_obj->type != ACPI_TYPE_BUFFER) { | ||
| 370 | ret = -ENODEV; | ||
| 371 | goto out_free; | ||
| 372 | } | ||
| 373 | |||
| 374 | errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0); | ||
| 375 | if (errors) { | ||
| 376 | ret = -ENODEV; | ||
| 377 | goto out_free; | ||
| 378 | } | ||
| 379 | |||
| 380 | supported = *((u32 *)(out_obj->buffer.pointer + 4)); | ||
| 381 | if (!(supported & 0x1)) { | ||
| 382 | ret = -ENODEV; | ||
| 383 | goto out_free; | ||
| 384 | } | ||
| 385 | |||
| 386 | out_free: | ||
| 387 | kfree(output.pointer); | ||
| 388 | return ret; | ||
| 389 | } | ||
| 390 | |||
| 391 | static int __init pcc_cpufreq_probe(void) | ||
| 392 | { | ||
| 393 | acpi_status status; | ||
| 394 | struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; | ||
| 395 | struct pcc_memory_resource *mem_resource; | ||
| 396 | struct pcc_register_resource *reg_resource; | ||
| 397 | union acpi_object *out_obj, *member; | ||
| 398 | acpi_handle handle, osc_handle, pcch_handle; | ||
| 399 | int ret = 0; | ||
| 400 | |||
| 401 | status = acpi_get_handle(NULL, "\\_SB", &handle); | ||
| 402 | if (ACPI_FAILURE(status)) | ||
| 403 | return -ENODEV; | ||
| 404 | |||
| 405 | status = acpi_get_handle(handle, "PCCH", &pcch_handle); | ||
| 406 | if (ACPI_FAILURE(status)) | ||
| 407 | return -ENODEV; | ||
| 408 | |||
| 409 | status = acpi_get_handle(handle, "_OSC", &osc_handle); | ||
| 410 | if (ACPI_SUCCESS(status)) { | ||
| 411 | ret = pcc_cpufreq_do_osc(&osc_handle); | ||
| 412 | if (ret) | ||
| 413 | dprintk("probe: _OSC evaluation did not succeed\n"); | ||
| 414 | /* Firmware's use of _OSC is optional */ | ||
| 415 | ret = 0; | ||
| 416 | } | ||
| 417 | |||
| 418 | status = acpi_evaluate_object(handle, "PCCH", NULL, &output); | ||
| 419 | if (ACPI_FAILURE(status)) | ||
| 420 | return -ENODEV; | ||
| 421 | |||
| 422 | out_obj = output.pointer; | ||
| 423 | if (out_obj->type != ACPI_TYPE_PACKAGE) { | ||
| 424 | ret = -ENODEV; | ||
| 425 | goto out_free; | ||
| 426 | } | ||
| 427 | |||
| 428 | member = &out_obj->package.elements[0]; | ||
| 429 | if (member->type != ACPI_TYPE_BUFFER) { | ||
| 430 | ret = -ENODEV; | ||
| 431 | goto out_free; | ||
| 432 | } | ||
| 433 | |||
| 434 | mem_resource = (struct pcc_memory_resource *)member->buffer.pointer; | ||
| 435 | |||
| 436 | dprintk("probe: mem_resource descriptor: 0x%x," | ||
| 437 | " length: %d, space_id: %d, resource_usage: %d," | ||
| 438 | " type_specific: %d, granularity: 0x%llx," | ||
| 439 | " minimum: 0x%llx, maximum: 0x%llx," | ||
| 440 | " translation_offset: 0x%llx, address_length: 0x%llx\n", | ||
| 441 | mem_resource->descriptor, mem_resource->length, | ||
| 442 | mem_resource->space_id, mem_resource->resource_usage, | ||
| 443 | mem_resource->type_specific, mem_resource->granularity, | ||
| 444 | mem_resource->minimum, mem_resource->maximum, | ||
| 445 | mem_resource->translation_offset, | ||
| 446 | mem_resource->address_length); | ||
| 447 | |||
| 448 | if (mem_resource->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) { | ||
| 449 | ret = -ENODEV; | ||
| 450 | goto out_free; | ||
| 451 | } | ||
| 452 | |||
| 453 | pcch_virt_addr = ioremap_nocache(mem_resource->minimum, | ||
| 454 | mem_resource->address_length); | ||
| 455 | if (pcch_virt_addr == NULL) { | ||
| 456 | dprintk("probe: could not map shared mem region\n"); | ||
| 457 | goto out_free; | ||
| 458 | } | ||
| 459 | pcch_hdr = pcch_virt_addr; | ||
| 460 | |||
| 461 | dprintk("probe: PCCH header (virtual) addr: 0x%p\n", pcch_hdr); | ||
| 462 | dprintk("probe: PCCH header is at physical address: 0x%llx," | ||
| 463 | " signature: 0x%x, length: %d bytes, major: %d, minor: %d," | ||
| 464 | " supported features: 0x%x, command field: 0x%x," | ||
| 465 | " status field: 0x%x, nominal latency: %d us\n", | ||
| 466 | mem_resource->minimum, ioread32(&pcch_hdr->signature), | ||
| 467 | ioread16(&pcch_hdr->length), ioread8(&pcch_hdr->major), | ||
| 468 | ioread8(&pcch_hdr->minor), ioread32(&pcch_hdr->features), | ||
| 469 | ioread16(&pcch_hdr->command), ioread16(&pcch_hdr->status), | ||
| 470 | ioread32(&pcch_hdr->latency)); | ||
| 471 | |||
| 472 | dprintk("probe: min time between commands: %d us," | ||
| 473 | " max time between commands: %d us," | ||
| 474 | " nominal CPU frequency: %d MHz," | ||
| 475 | " minimum CPU frequency: %d MHz," | ||
| 476 | " minimum CPU frequency without throttling: %d MHz\n", | ||
| 477 | ioread32(&pcch_hdr->minimum_time), | ||
| 478 | ioread32(&pcch_hdr->maximum_time), | ||
| 479 | ioread32(&pcch_hdr->nominal), | ||
| 480 | ioread32(&pcch_hdr->throttled_frequency), | ||
| 481 | ioread32(&pcch_hdr->minimum_frequency)); | ||
| 482 | |||
| 483 | member = &out_obj->package.elements[1]; | ||
| 484 | if (member->type != ACPI_TYPE_BUFFER) { | ||
| 485 | ret = -ENODEV; | ||
| 486 | goto pcch_free; | ||
| 487 | } | ||
| 488 | |||
| 489 | reg_resource = (struct pcc_register_resource *)member->buffer.pointer; | ||
| 490 | |||
| 491 | doorbell.space_id = reg_resource->space_id; | ||
| 492 | doorbell.bit_width = reg_resource->bit_width; | ||
| 493 | doorbell.bit_offset = reg_resource->bit_offset; | ||
| 494 | doorbell.access_width = 64; | ||
| 495 | doorbell.address = reg_resource->address; | ||
| 496 | |||
| 497 | dprintk("probe: doorbell: space_id is %d, bit_width is %d, " | ||
| 498 | "bit_offset is %d, access_width is %d, address is 0x%llx\n", | ||
| 499 | doorbell.space_id, doorbell.bit_width, doorbell.bit_offset, | ||
| 500 | doorbell.access_width, reg_resource->address); | ||
| 501 | |||
| 502 | member = &out_obj->package.elements[2]; | ||
| 503 | if (member->type != ACPI_TYPE_INTEGER) { | ||
| 504 | ret = -ENODEV; | ||
| 505 | goto pcch_free; | ||
| 506 | } | ||
| 507 | |||
| 508 | doorbell_preserve = member->integer.value; | ||
| 509 | |||
| 510 | member = &out_obj->package.elements[3]; | ||
| 511 | if (member->type != ACPI_TYPE_INTEGER) { | ||
| 512 | ret = -ENODEV; | ||
| 513 | goto pcch_free; | ||
| 514 | } | ||
| 515 | |||
| 516 | doorbell_write = member->integer.value; | ||
| 517 | |||
| 518 | dprintk("probe: doorbell_preserve: 0x%llx," | ||
| 519 | " doorbell_write: 0x%llx\n", | ||
| 520 | doorbell_preserve, doorbell_write); | ||
| 521 | |||
| 522 | pcc_cpu_info = alloc_percpu(struct pcc_cpu); | ||
| 523 | if (!pcc_cpu_info) { | ||
| 524 | ret = -ENOMEM; | ||
| 525 | goto pcch_free; | ||
| 526 | } | ||
| 527 | |||
| 528 | printk(KERN_DEBUG "pcc-cpufreq: (v%s) driver loaded with frequency" | ||
| 529 | " limits: %d MHz, %d MHz\n", PCC_VERSION, | ||
| 530 | ioread32(&pcch_hdr->minimum_frequency), | ||
| 531 | ioread32(&pcch_hdr->nominal)); | ||
| 532 | kfree(output.pointer); | ||
| 533 | return ret; | ||
| 534 | pcch_free: | ||
| 535 | pcc_clear_mapping(); | ||
| 536 | out_free: | ||
| 537 | kfree(output.pointer); | ||
| 538 | return ret; | ||
| 539 | } | ||
| 540 | |||
| 541 | static int pcc_cpufreq_cpu_init(struct cpufreq_policy *policy) | ||
| 542 | { | ||
| 543 | unsigned int cpu = policy->cpu; | ||
| 544 | unsigned int result = 0; | ||
| 545 | |||
| 546 | if (!pcch_virt_addr) { | ||
| 547 | result = -1; | ||
| 548 | goto out; | ||
| 549 | } | ||
| 550 | |||
| 551 | result = pcc_get_offset(cpu); | ||
| 552 | if (result) { | ||
| 553 | dprintk("init: PCCP evaluation failed\n"); | ||
| 554 | goto out; | ||
| 555 | } | ||
| 556 | |||
| 557 | policy->max = policy->cpuinfo.max_freq = | ||
| 558 | ioread32(&pcch_hdr->nominal) * 1000; | ||
| 559 | policy->min = policy->cpuinfo.min_freq = | ||
| 560 | ioread32(&pcch_hdr->minimum_frequency) * 1000; | ||
| 561 | policy->cur = pcc_get_freq(cpu); | ||
| 562 | |||
| 563 | if (!policy->cur) { | ||
| 564 | dprintk("init: Unable to get current CPU frequency\n"); | ||
| 565 | result = -EINVAL; | ||
| 566 | goto out; | ||
| 567 | } | ||
| 568 | |||
| 569 | dprintk("init: policy->max is %d, policy->min is %d\n", | ||
| 570 | policy->max, policy->min); | ||
| 571 | out: | ||
| 572 | return result; | ||
| 573 | } | ||
| 574 | |||
| 575 | static int pcc_cpufreq_cpu_exit(struct cpufreq_policy *policy) | ||
| 576 | { | ||
| 577 | return 0; | ||
| 578 | } | ||
| 579 | |||
| 580 | static struct cpufreq_driver pcc_cpufreq_driver = { | ||
| 581 | .flags = CPUFREQ_CONST_LOOPS, | ||
| 582 | .get = pcc_get_freq, | ||
| 583 | .verify = pcc_cpufreq_verify, | ||
| 584 | .target = pcc_cpufreq_target, | ||
| 585 | .init = pcc_cpufreq_cpu_init, | ||
| 586 | .exit = pcc_cpufreq_cpu_exit, | ||
| 587 | .name = "pcc-cpufreq", | ||
| 588 | .owner = THIS_MODULE, | ||
| 589 | }; | ||
| 590 | |||
| 591 | static int __init pcc_cpufreq_init(void) | ||
| 592 | { | ||
| 593 | int ret; | ||
| 594 | |||
| 595 | if (acpi_disabled) | ||
| 596 | return 0; | ||
| 597 | |||
| 598 | ret = pcc_cpufreq_probe(); | ||
| 599 | if (ret) { | ||
| 600 | dprintk("pcc_cpufreq_init: PCCH evaluation failed\n"); | ||
| 601 | return ret; | ||
| 602 | } | ||
| 603 | |||
| 604 | ret = cpufreq_register_driver(&pcc_cpufreq_driver); | ||
| 605 | |||
| 606 | return ret; | ||
| 607 | } | ||
| 608 | |||
| 609 | static void __exit pcc_cpufreq_exit(void) | ||
| 610 | { | ||
| 611 | cpufreq_unregister_driver(&pcc_cpufreq_driver); | ||
| 612 | |||
| 613 | pcc_clear_mapping(); | ||
| 614 | |||
| 615 | free_percpu(pcc_cpu_info); | ||
| 616 | } | ||
| 617 | |||
| 618 | MODULE_AUTHOR("Matthew Garrett, Naga Chumbalkar"); | ||
| 619 | MODULE_VERSION(PCC_VERSION); | ||
| 620 | MODULE_DESCRIPTION("Processor Clocking Control interface driver"); | ||
| 621 | MODULE_LICENSE("GPL"); | ||
| 622 | |||
| 623 | late_initcall(pcc_cpufreq_init); | ||
| 624 | module_exit(pcc_cpufreq_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k6.c b/arch/x86/kernel/cpu/cpufreq/powernow-k6.c deleted file mode 100644 index b3379d6a5c57..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/powernow-k6.c +++ /dev/null | |||
| @@ -1,261 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * This file was based upon code in Powertweak Linux (http://powertweak.sf.net) | ||
| 3 | * (C) 2000-2003 Dave Jones, Arjan van de Ven, Janne Pänkälä, | ||
| 4 | * Dominik Brodowski. | ||
| 5 | * | ||
| 6 | * Licensed under the terms of the GNU GPL License version 2. | ||
| 7 | * | ||
| 8 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <linux/kernel.h> | ||
| 12 | #include <linux/module.h> | ||
| 13 | #include <linux/init.h> | ||
| 14 | #include <linux/cpufreq.h> | ||
| 15 | #include <linux/ioport.h> | ||
| 16 | #include <linux/timex.h> | ||
| 17 | #include <linux/io.h> | ||
| 18 | |||
| 19 | #include <asm/msr.h> | ||
| 20 | |||
| 21 | #define POWERNOW_IOPORT 0xfff0 /* it doesn't matter where, as long | ||
| 22 | as it is unused */ | ||
| 23 | |||
| 24 | #define PFX "powernow-k6: " | ||
| 25 | static unsigned int busfreq; /* FSB, in 10 kHz */ | ||
| 26 | static unsigned int max_multiplier; | ||
| 27 | |||
| 28 | |||
| 29 | /* Clock ratio multiplied by 10 - see table 27 in AMD#23446 */ | ||
| 30 | static struct cpufreq_frequency_table clock_ratio[] = { | ||
| 31 | {45, /* 000 -> 4.5x */ 0}, | ||
| 32 | {50, /* 001 -> 5.0x */ 0}, | ||
| 33 | {40, /* 010 -> 4.0x */ 0}, | ||
| 34 | {55, /* 011 -> 5.5x */ 0}, | ||
| 35 | {20, /* 100 -> 2.0x */ 0}, | ||
| 36 | {30, /* 101 -> 3.0x */ 0}, | ||
| 37 | {60, /* 110 -> 6.0x */ 0}, | ||
| 38 | {35, /* 111 -> 3.5x */ 0}, | ||
| 39 | {0, CPUFREQ_TABLE_END} | ||
| 40 | }; | ||
| 41 | |||
| 42 | |||
| 43 | /** | ||
| 44 | * powernow_k6_get_cpu_multiplier - returns the current FSB multiplier | ||
| 45 | * | ||
| 46 | * Returns the current setting of the frequency multiplier. Core clock | ||
| 47 | * speed is frequency of the Front-Side Bus multiplied with this value. | ||
| 48 | */ | ||
| 49 | static int powernow_k6_get_cpu_multiplier(void) | ||
| 50 | { | ||
| 51 | u64 invalue = 0; | ||
| 52 | u32 msrval; | ||
| 53 | |||
| 54 | msrval = POWERNOW_IOPORT + 0x1; | ||
| 55 | wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */ | ||
| 56 | invalue = inl(POWERNOW_IOPORT + 0x8); | ||
| 57 | msrval = POWERNOW_IOPORT + 0x0; | ||
| 58 | wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */ | ||
| 59 | |||
| 60 | return clock_ratio[(invalue >> 5)&7].index; | ||
| 61 | } | ||
| 62 | |||
| 63 | |||
| 64 | /** | ||
| 65 | * powernow_k6_set_state - set the PowerNow! multiplier | ||
| 66 | * @best_i: clock_ratio[best_i] is the target multiplier | ||
| 67 | * | ||
| 68 | * Tries to change the PowerNow! multiplier | ||
| 69 | */ | ||
| 70 | static void powernow_k6_set_state(unsigned int best_i) | ||
| 71 | { | ||
| 72 | unsigned long outvalue = 0, invalue = 0; | ||
| 73 | unsigned long msrval; | ||
| 74 | struct cpufreq_freqs freqs; | ||
| 75 | |||
| 76 | if (clock_ratio[best_i].index > max_multiplier) { | ||
| 77 | printk(KERN_ERR PFX "invalid target frequency\n"); | ||
| 78 | return; | ||
| 79 | } | ||
| 80 | |||
| 81 | freqs.old = busfreq * powernow_k6_get_cpu_multiplier(); | ||
| 82 | freqs.new = busfreq * clock_ratio[best_i].index; | ||
| 83 | freqs.cpu = 0; /* powernow-k6.c is UP only driver */ | ||
| 84 | |||
| 85 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
| 86 | |||
| 87 | /* we now need to transform best_i to the BVC format, see AMD#23446 */ | ||
| 88 | |||
| 89 | outvalue = (1<<12) | (1<<10) | (1<<9) | (best_i<<5); | ||
| 90 | |||
| 91 | msrval = POWERNOW_IOPORT + 0x1; | ||
| 92 | wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */ | ||
| 93 | invalue = inl(POWERNOW_IOPORT + 0x8); | ||
| 94 | invalue = invalue & 0xf; | ||
| 95 | outvalue = outvalue | invalue; | ||
| 96 | outl(outvalue , (POWERNOW_IOPORT + 0x8)); | ||
| 97 | msrval = POWERNOW_IOPORT + 0x0; | ||
| 98 | wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */ | ||
| 99 | |||
| 100 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 101 | |||
| 102 | return; | ||
| 103 | } | ||
| 104 | |||
| 105 | |||
| 106 | /** | ||
| 107 | * powernow_k6_verify - verifies a new CPUfreq policy | ||
| 108 | * @policy: new policy | ||
| 109 | * | ||
| 110 | * Policy must be within lowest and highest possible CPU Frequency, | ||
| 111 | * and at least one possible state must be within min and max. | ||
| 112 | */ | ||
| 113 | static int powernow_k6_verify(struct cpufreq_policy *policy) | ||
| 114 | { | ||
| 115 | return cpufreq_frequency_table_verify(policy, &clock_ratio[0]); | ||
| 116 | } | ||
| 117 | |||
| 118 | |||
| 119 | /** | ||
| 120 | * powernow_k6_setpolicy - sets a new CPUFreq policy | ||
| 121 | * @policy: new policy | ||
| 122 | * @target_freq: the target frequency | ||
| 123 | * @relation: how that frequency relates to achieved frequency | ||
| 124 | * (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H) | ||
| 125 | * | ||
| 126 | * sets a new CPUFreq policy | ||
| 127 | */ | ||
| 128 | static int powernow_k6_target(struct cpufreq_policy *policy, | ||
| 129 | unsigned int target_freq, | ||
| 130 | unsigned int relation) | ||
| 131 | { | ||
| 132 | unsigned int newstate = 0; | ||
| 133 | |||
| 134 | if (cpufreq_frequency_table_target(policy, &clock_ratio[0], | ||
| 135 | target_freq, relation, &newstate)) | ||
| 136 | return -EINVAL; | ||
| 137 | |||
| 138 | powernow_k6_set_state(newstate); | ||
| 139 | |||
| 140 | return 0; | ||
| 141 | } | ||
| 142 | |||
| 143 | |||
| 144 | static int powernow_k6_cpu_init(struct cpufreq_policy *policy) | ||
| 145 | { | ||
| 146 | unsigned int i, f; | ||
| 147 | int result; | ||
| 148 | |||
| 149 | if (policy->cpu != 0) | ||
| 150 | return -ENODEV; | ||
| 151 | |||
| 152 | /* get frequencies */ | ||
| 153 | max_multiplier = powernow_k6_get_cpu_multiplier(); | ||
| 154 | busfreq = cpu_khz / max_multiplier; | ||
| 155 | |||
| 156 | /* table init */ | ||
| 157 | for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) { | ||
| 158 | f = clock_ratio[i].index; | ||
| 159 | if (f > max_multiplier) | ||
| 160 | clock_ratio[i].frequency = CPUFREQ_ENTRY_INVALID; | ||
| 161 | else | ||
| 162 | clock_ratio[i].frequency = busfreq * f; | ||
| 163 | } | ||
| 164 | |||
| 165 | /* cpuinfo and default policy values */ | ||
| 166 | policy->cpuinfo.transition_latency = 200000; | ||
| 167 | policy->cur = busfreq * max_multiplier; | ||
| 168 | |||
| 169 | result = cpufreq_frequency_table_cpuinfo(policy, clock_ratio); | ||
| 170 | if (result) | ||
| 171 | return result; | ||
| 172 | |||
| 173 | cpufreq_frequency_table_get_attr(clock_ratio, policy->cpu); | ||
| 174 | |||
| 175 | return 0; | ||
| 176 | } | ||
| 177 | |||
| 178 | |||
| 179 | static int powernow_k6_cpu_exit(struct cpufreq_policy *policy) | ||
| 180 | { | ||
| 181 | unsigned int i; | ||
| 182 | for (i = 0; i < 8; i++) { | ||
| 183 | if (i == max_multiplier) | ||
| 184 | powernow_k6_set_state(i); | ||
| 185 | } | ||
| 186 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
| 187 | return 0; | ||
| 188 | } | ||
| 189 | |||
| 190 | static unsigned int powernow_k6_get(unsigned int cpu) | ||
| 191 | { | ||
| 192 | unsigned int ret; | ||
| 193 | ret = (busfreq * powernow_k6_get_cpu_multiplier()); | ||
| 194 | return ret; | ||
| 195 | } | ||
| 196 | |||
| 197 | static struct freq_attr *powernow_k6_attr[] = { | ||
| 198 | &cpufreq_freq_attr_scaling_available_freqs, | ||
| 199 | NULL, | ||
| 200 | }; | ||
| 201 | |||
| 202 | static struct cpufreq_driver powernow_k6_driver = { | ||
| 203 | .verify = powernow_k6_verify, | ||
| 204 | .target = powernow_k6_target, | ||
| 205 | .init = powernow_k6_cpu_init, | ||
| 206 | .exit = powernow_k6_cpu_exit, | ||
| 207 | .get = powernow_k6_get, | ||
| 208 | .name = "powernow-k6", | ||
| 209 | .owner = THIS_MODULE, | ||
| 210 | .attr = powernow_k6_attr, | ||
| 211 | }; | ||
| 212 | |||
| 213 | |||
| 214 | /** | ||
| 215 | * powernow_k6_init - initializes the k6 PowerNow! CPUFreq driver | ||
| 216 | * | ||
| 217 | * Initializes the K6 PowerNow! support. Returns -ENODEV on unsupported | ||
| 218 | * devices, -EINVAL or -ENOMEM on problems during initiatization, and zero | ||
| 219 | * on success. | ||
| 220 | */ | ||
| 221 | static int __init powernow_k6_init(void) | ||
| 222 | { | ||
| 223 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
| 224 | |||
| 225 | if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 != 5) || | ||
| 226 | ((c->x86_model != 12) && (c->x86_model != 13))) | ||
| 227 | return -ENODEV; | ||
| 228 | |||
| 229 | if (!request_region(POWERNOW_IOPORT, 16, "PowerNow!")) { | ||
| 230 | printk(KERN_INFO PFX "PowerNow IOPORT region already used.\n"); | ||
| 231 | return -EIO; | ||
| 232 | } | ||
| 233 | |||
| 234 | if (cpufreq_register_driver(&powernow_k6_driver)) { | ||
| 235 | release_region(POWERNOW_IOPORT, 16); | ||
| 236 | return -EINVAL; | ||
| 237 | } | ||
| 238 | |||
| 239 | return 0; | ||
| 240 | } | ||
| 241 | |||
| 242 | |||
| 243 | /** | ||
| 244 | * powernow_k6_exit - unregisters AMD K6-2+/3+ PowerNow! support | ||
| 245 | * | ||
| 246 | * Unregisters AMD K6-2+ / K6-3+ PowerNow! support. | ||
| 247 | */ | ||
| 248 | static void __exit powernow_k6_exit(void) | ||
| 249 | { | ||
| 250 | cpufreq_unregister_driver(&powernow_k6_driver); | ||
| 251 | release_region(POWERNOW_IOPORT, 16); | ||
| 252 | } | ||
| 253 | |||
| 254 | |||
| 255 | MODULE_AUTHOR("Arjan van de Ven, Dave Jones <davej@redhat.com>, " | ||
| 256 | "Dominik Brodowski <linux@brodo.de>"); | ||
| 257 | MODULE_DESCRIPTION("PowerNow! driver for AMD K6-2+ / K6-3+ processors."); | ||
| 258 | MODULE_LICENSE("GPL"); | ||
| 259 | |||
| 260 | module_init(powernow_k6_init); | ||
| 261 | module_exit(powernow_k6_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k7.c b/arch/x86/kernel/cpu/cpufreq/powernow-k7.c deleted file mode 100644 index 4a45fd6e41ba..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/powernow-k7.c +++ /dev/null | |||
| @@ -1,752 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * AMD K7 Powernow driver. | ||
| 3 | * (C) 2003 Dave Jones on behalf of SuSE Labs. | ||
| 4 | * (C) 2003-2004 Dave Jones <davej@redhat.com> | ||
| 5 | * | ||
| 6 | * Licensed under the terms of the GNU GPL License version 2. | ||
| 7 | * Based upon datasheets & sample CPUs kindly provided by AMD. | ||
| 8 | * | ||
| 9 | * Errata 5: | ||
| 10 | * CPU may fail to execute a FID/VID change in presence of interrupt. | ||
| 11 | * - We cli/sti on stepping A0 CPUs around the FID/VID transition. | ||
| 12 | * Errata 15: | ||
| 13 | * CPU with half frequency multipliers may hang upon wakeup from disconnect. | ||
| 14 | * - We disable half multipliers if ACPI is used on A0 stepping CPUs. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <linux/kernel.h> | ||
| 18 | #include <linux/module.h> | ||
| 19 | #include <linux/moduleparam.h> | ||
| 20 | #include <linux/init.h> | ||
| 21 | #include <linux/cpufreq.h> | ||
| 22 | #include <linux/slab.h> | ||
| 23 | #include <linux/string.h> | ||
| 24 | #include <linux/dmi.h> | ||
| 25 | #include <linux/timex.h> | ||
| 26 | #include <linux/io.h> | ||
| 27 | |||
| 28 | #include <asm/timer.h> /* Needed for recalibrate_cpu_khz() */ | ||
| 29 | #include <asm/msr.h> | ||
| 30 | #include <asm/system.h> | ||
| 31 | |||
| 32 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
| 33 | #include <linux/acpi.h> | ||
| 34 | #include <acpi/processor.h> | ||
| 35 | #endif | ||
| 36 | |||
| 37 | #include "powernow-k7.h" | ||
| 38 | |||
| 39 | #define PFX "powernow: " | ||
| 40 | |||
| 41 | |||
| 42 | struct psb_s { | ||
| 43 | u8 signature[10]; | ||
| 44 | u8 tableversion; | ||
| 45 | u8 flags; | ||
| 46 | u16 settlingtime; | ||
| 47 | u8 reserved1; | ||
| 48 | u8 numpst; | ||
| 49 | }; | ||
| 50 | |||
| 51 | struct pst_s { | ||
| 52 | u32 cpuid; | ||
| 53 | u8 fsbspeed; | ||
| 54 | u8 maxfid; | ||
| 55 | u8 startvid; | ||
| 56 | u8 numpstates; | ||
| 57 | }; | ||
| 58 | |||
| 59 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
| 60 | union powernow_acpi_control_t { | ||
| 61 | struct { | ||
| 62 | unsigned long fid:5, | ||
| 63 | vid:5, | ||
| 64 | sgtc:20, | ||
| 65 | res1:2; | ||
| 66 | } bits; | ||
| 67 | unsigned long val; | ||
| 68 | }; | ||
| 69 | #endif | ||
| 70 | |||
| 71 | #ifdef CONFIG_CPU_FREQ_DEBUG | ||
| 72 | /* divide by 1000 to get VCore voltage in V. */ | ||
| 73 | static const int mobile_vid_table[32] = { | ||
| 74 | 2000, 1950, 1900, 1850, 1800, 1750, 1700, 1650, | ||
| 75 | 1600, 1550, 1500, 1450, 1400, 1350, 1300, 0, | ||
| 76 | 1275, 1250, 1225, 1200, 1175, 1150, 1125, 1100, | ||
| 77 | 1075, 1050, 1025, 1000, 975, 950, 925, 0, | ||
| 78 | }; | ||
| 79 | #endif | ||
| 80 | |||
| 81 | /* divide by 10 to get FID. */ | ||
| 82 | static const int fid_codes[32] = { | ||
| 83 | 110, 115, 120, 125, 50, 55, 60, 65, | ||
| 84 | 70, 75, 80, 85, 90, 95, 100, 105, | ||
| 85 | 30, 190, 40, 200, 130, 135, 140, 210, | ||
| 86 | 150, 225, 160, 165, 170, 180, -1, -1, | ||
| 87 | }; | ||
| 88 | |||
| 89 | /* This parameter is used in order to force ACPI instead of legacy method for | ||
| 90 | * configuration purpose. | ||
| 91 | */ | ||
| 92 | |||
| 93 | static int acpi_force; | ||
| 94 | |||
| 95 | static struct cpufreq_frequency_table *powernow_table; | ||
| 96 | |||
| 97 | static unsigned int can_scale_bus; | ||
| 98 | static unsigned int can_scale_vid; | ||
| 99 | static unsigned int minimum_speed = -1; | ||
| 100 | static unsigned int maximum_speed; | ||
| 101 | static unsigned int number_scales; | ||
| 102 | static unsigned int fsb; | ||
| 103 | static unsigned int latency; | ||
| 104 | static char have_a0; | ||
| 105 | |||
| 106 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
| 107 | "powernow-k7", msg) | ||
| 108 | |||
| 109 | static int check_fsb(unsigned int fsbspeed) | ||
| 110 | { | ||
| 111 | int delta; | ||
| 112 | unsigned int f = fsb / 1000; | ||
| 113 | |||
| 114 | delta = (fsbspeed > f) ? fsbspeed - f : f - fsbspeed; | ||
| 115 | return delta < 5; | ||
| 116 | } | ||
| 117 | |||
| 118 | static int check_powernow(void) | ||
| 119 | { | ||
| 120 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
| 121 | unsigned int maxei, eax, ebx, ecx, edx; | ||
| 122 | |||
| 123 | if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 != 6)) { | ||
| 124 | #ifdef MODULE | ||
| 125 | printk(KERN_INFO PFX "This module only works with " | ||
| 126 | "AMD K7 CPUs\n"); | ||
| 127 | #endif | ||
| 128 | return 0; | ||
| 129 | } | ||
| 130 | |||
| 131 | /* Get maximum capabilities */ | ||
| 132 | maxei = cpuid_eax(0x80000000); | ||
| 133 | if (maxei < 0x80000007) { /* Any powernow info ? */ | ||
| 134 | #ifdef MODULE | ||
| 135 | printk(KERN_INFO PFX "No powernow capabilities detected\n"); | ||
| 136 | #endif | ||
| 137 | return 0; | ||
| 138 | } | ||
| 139 | |||
| 140 | if ((c->x86_model == 6) && (c->x86_mask == 0)) { | ||
| 141 | printk(KERN_INFO PFX "K7 660[A0] core detected, " | ||
| 142 | "enabling errata workarounds\n"); | ||
| 143 | have_a0 = 1; | ||
| 144 | } | ||
| 145 | |||
| 146 | cpuid(0x80000007, &eax, &ebx, &ecx, &edx); | ||
| 147 | |||
| 148 | /* Check we can actually do something before we say anything.*/ | ||
| 149 | if (!(edx & (1 << 1 | 1 << 2))) | ||
| 150 | return 0; | ||
| 151 | |||
| 152 | printk(KERN_INFO PFX "PowerNOW! Technology present. Can scale: "); | ||
| 153 | |||
| 154 | if (edx & 1 << 1) { | ||
| 155 | printk("frequency"); | ||
| 156 | can_scale_bus = 1; | ||
| 157 | } | ||
| 158 | |||
| 159 | if ((edx & (1 << 1 | 1 << 2)) == 0x6) | ||
| 160 | printk(" and "); | ||
| 161 | |||
| 162 | if (edx & 1 << 2) { | ||
| 163 | printk("voltage"); | ||
| 164 | can_scale_vid = 1; | ||
| 165 | } | ||
| 166 | |||
| 167 | printk(".\n"); | ||
| 168 | return 1; | ||
| 169 | } | ||
| 170 | |||
| 171 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
| 172 | static void invalidate_entry(unsigned int entry) | ||
| 173 | { | ||
| 174 | powernow_table[entry].frequency = CPUFREQ_ENTRY_INVALID; | ||
| 175 | } | ||
| 176 | #endif | ||
| 177 | |||
| 178 | static int get_ranges(unsigned char *pst) | ||
| 179 | { | ||
| 180 | unsigned int j; | ||
| 181 | unsigned int speed; | ||
| 182 | u8 fid, vid; | ||
| 183 | |||
| 184 | powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) * | ||
| 185 | (number_scales + 1)), GFP_KERNEL); | ||
| 186 | if (!powernow_table) | ||
| 187 | return -ENOMEM; | ||
| 188 | |||
| 189 | for (j = 0 ; j < number_scales; j++) { | ||
| 190 | fid = *pst++; | ||
| 191 | |||
| 192 | powernow_table[j].frequency = (fsb * fid_codes[fid]) / 10; | ||
| 193 | powernow_table[j].index = fid; /* lower 8 bits */ | ||
| 194 | |||
| 195 | speed = powernow_table[j].frequency; | ||
| 196 | |||
| 197 | if ((fid_codes[fid] % 10) == 5) { | ||
| 198 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
| 199 | if (have_a0 == 1) | ||
| 200 | invalidate_entry(j); | ||
| 201 | #endif | ||
| 202 | } | ||
| 203 | |||
| 204 | if (speed < minimum_speed) | ||
| 205 | minimum_speed = speed; | ||
| 206 | if (speed > maximum_speed) | ||
| 207 | maximum_speed = speed; | ||
| 208 | |||
| 209 | vid = *pst++; | ||
| 210 | powernow_table[j].index |= (vid << 8); /* upper 8 bits */ | ||
| 211 | |||
| 212 | dprintk(" FID: 0x%x (%d.%dx [%dMHz]) " | ||
| 213 | "VID: 0x%x (%d.%03dV)\n", fid, fid_codes[fid] / 10, | ||
| 214 | fid_codes[fid] % 10, speed/1000, vid, | ||
| 215 | mobile_vid_table[vid]/1000, | ||
| 216 | mobile_vid_table[vid]%1000); | ||
| 217 | } | ||
| 218 | powernow_table[number_scales].frequency = CPUFREQ_TABLE_END; | ||
| 219 | powernow_table[number_scales].index = 0; | ||
| 220 | |||
| 221 | return 0; | ||
| 222 | } | ||
| 223 | |||
| 224 | |||
| 225 | static void change_FID(int fid) | ||
| 226 | { | ||
| 227 | union msr_fidvidctl fidvidctl; | ||
| 228 | |||
| 229 | rdmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val); | ||
| 230 | if (fidvidctl.bits.FID != fid) { | ||
| 231 | fidvidctl.bits.SGTC = latency; | ||
| 232 | fidvidctl.bits.FID = fid; | ||
| 233 | fidvidctl.bits.VIDC = 0; | ||
| 234 | fidvidctl.bits.FIDC = 1; | ||
| 235 | wrmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val); | ||
| 236 | } | ||
| 237 | } | ||
| 238 | |||
| 239 | |||
| 240 | static void change_VID(int vid) | ||
| 241 | { | ||
| 242 | union msr_fidvidctl fidvidctl; | ||
| 243 | |||
| 244 | rdmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val); | ||
| 245 | if (fidvidctl.bits.VID != vid) { | ||
| 246 | fidvidctl.bits.SGTC = latency; | ||
| 247 | fidvidctl.bits.VID = vid; | ||
| 248 | fidvidctl.bits.FIDC = 0; | ||
| 249 | fidvidctl.bits.VIDC = 1; | ||
| 250 | wrmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val); | ||
| 251 | } | ||
| 252 | } | ||
| 253 | |||
| 254 | |||
| 255 | static void change_speed(unsigned int index) | ||
| 256 | { | ||
| 257 | u8 fid, vid; | ||
| 258 | struct cpufreq_freqs freqs; | ||
| 259 | union msr_fidvidstatus fidvidstatus; | ||
| 260 | int cfid; | ||
| 261 | |||
| 262 | /* fid are the lower 8 bits of the index we stored into | ||
| 263 | * the cpufreq frequency table in powernow_decode_bios, | ||
| 264 | * vid are the upper 8 bits. | ||
| 265 | */ | ||
| 266 | |||
| 267 | fid = powernow_table[index].index & 0xFF; | ||
| 268 | vid = (powernow_table[index].index & 0xFF00) >> 8; | ||
| 269 | |||
| 270 | freqs.cpu = 0; | ||
| 271 | |||
| 272 | rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val); | ||
| 273 | cfid = fidvidstatus.bits.CFID; | ||
| 274 | freqs.old = fsb * fid_codes[cfid] / 10; | ||
| 275 | |||
| 276 | freqs.new = powernow_table[index].frequency; | ||
| 277 | |||
| 278 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
| 279 | |||
| 280 | /* Now do the magic poking into the MSRs. */ | ||
| 281 | |||
| 282 | if (have_a0 == 1) /* A0 errata 5 */ | ||
| 283 | local_irq_disable(); | ||
| 284 | |||
| 285 | if (freqs.old > freqs.new) { | ||
| 286 | /* Going down, so change FID first */ | ||
| 287 | change_FID(fid); | ||
| 288 | change_VID(vid); | ||
| 289 | } else { | ||
| 290 | /* Going up, so change VID first */ | ||
| 291 | change_VID(vid); | ||
| 292 | change_FID(fid); | ||
| 293 | } | ||
| 294 | |||
| 295 | |||
| 296 | if (have_a0 == 1) | ||
| 297 | local_irq_enable(); | ||
| 298 | |||
| 299 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 300 | } | ||
| 301 | |||
| 302 | |||
| 303 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
| 304 | |||
| 305 | static struct acpi_processor_performance *acpi_processor_perf; | ||
| 306 | |||
| 307 | static int powernow_acpi_init(void) | ||
| 308 | { | ||
| 309 | int i; | ||
| 310 | int retval = 0; | ||
| 311 | union powernow_acpi_control_t pc; | ||
| 312 | |||
| 313 | if (acpi_processor_perf != NULL && powernow_table != NULL) { | ||
| 314 | retval = -EINVAL; | ||
| 315 | goto err0; | ||
| 316 | } | ||
| 317 | |||
| 318 | acpi_processor_perf = kzalloc(sizeof(struct acpi_processor_performance), | ||
| 319 | GFP_KERNEL); | ||
| 320 | if (!acpi_processor_perf) { | ||
| 321 | retval = -ENOMEM; | ||
| 322 | goto err0; | ||
| 323 | } | ||
| 324 | |||
| 325 | if (!zalloc_cpumask_var(&acpi_processor_perf->shared_cpu_map, | ||
| 326 | GFP_KERNEL)) { | ||
| 327 | retval = -ENOMEM; | ||
| 328 | goto err05; | ||
| 329 | } | ||
| 330 | |||
| 331 | if (acpi_processor_register_performance(acpi_processor_perf, 0)) { | ||
| 332 | retval = -EIO; | ||
| 333 | goto err1; | ||
| 334 | } | ||
| 335 | |||
| 336 | if (acpi_processor_perf->control_register.space_id != | ||
| 337 | ACPI_ADR_SPACE_FIXED_HARDWARE) { | ||
| 338 | retval = -ENODEV; | ||
| 339 | goto err2; | ||
| 340 | } | ||
| 341 | |||
| 342 | if (acpi_processor_perf->status_register.space_id != | ||
| 343 | ACPI_ADR_SPACE_FIXED_HARDWARE) { | ||
| 344 | retval = -ENODEV; | ||
| 345 | goto err2; | ||
| 346 | } | ||
| 347 | |||
| 348 | number_scales = acpi_processor_perf->state_count; | ||
| 349 | |||
| 350 | if (number_scales < 2) { | ||
| 351 | retval = -ENODEV; | ||
| 352 | goto err2; | ||
| 353 | } | ||
| 354 | |||
| 355 | powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) * | ||
| 356 | (number_scales + 1)), GFP_KERNEL); | ||
| 357 | if (!powernow_table) { | ||
| 358 | retval = -ENOMEM; | ||
| 359 | goto err2; | ||
| 360 | } | ||
| 361 | |||
| 362 | pc.val = (unsigned long) acpi_processor_perf->states[0].control; | ||
| 363 | for (i = 0; i < number_scales; i++) { | ||
| 364 | u8 fid, vid; | ||
| 365 | struct acpi_processor_px *state = | ||
| 366 | &acpi_processor_perf->states[i]; | ||
| 367 | unsigned int speed, speed_mhz; | ||
| 368 | |||
| 369 | pc.val = (unsigned long) state->control; | ||
| 370 | dprintk("acpi: P%d: %d MHz %d mW %d uS control %08x SGTC %d\n", | ||
| 371 | i, | ||
| 372 | (u32) state->core_frequency, | ||
| 373 | (u32) state->power, | ||
| 374 | (u32) state->transition_latency, | ||
| 375 | (u32) state->control, | ||
| 376 | pc.bits.sgtc); | ||
| 377 | |||
| 378 | vid = pc.bits.vid; | ||
| 379 | fid = pc.bits.fid; | ||
| 380 | |||
| 381 | powernow_table[i].frequency = fsb * fid_codes[fid] / 10; | ||
| 382 | powernow_table[i].index = fid; /* lower 8 bits */ | ||
| 383 | powernow_table[i].index |= (vid << 8); /* upper 8 bits */ | ||
| 384 | |||
| 385 | speed = powernow_table[i].frequency; | ||
| 386 | speed_mhz = speed / 1000; | ||
| 387 | |||
| 388 | /* processor_perflib will multiply the MHz value by 1000 to | ||
| 389 | * get a KHz value (e.g. 1266000). However, powernow-k7 works | ||
| 390 | * with true KHz values (e.g. 1266768). To ensure that all | ||
| 391 | * powernow frequencies are available, we must ensure that | ||
| 392 | * ACPI doesn't restrict them, so we round up the MHz value | ||
| 393 | * to ensure that perflib's computed KHz value is greater than | ||
| 394 | * or equal to powernow's KHz value. | ||
| 395 | */ | ||
| 396 | if (speed % 1000 > 0) | ||
| 397 | speed_mhz++; | ||
| 398 | |||
| 399 | if ((fid_codes[fid] % 10) == 5) { | ||
| 400 | if (have_a0 == 1) | ||
| 401 | invalidate_entry(i); | ||
| 402 | } | ||
| 403 | |||
| 404 | dprintk(" FID: 0x%x (%d.%dx [%dMHz]) " | ||
| 405 | "VID: 0x%x (%d.%03dV)\n", fid, fid_codes[fid] / 10, | ||
| 406 | fid_codes[fid] % 10, speed_mhz, vid, | ||
| 407 | mobile_vid_table[vid]/1000, | ||
| 408 | mobile_vid_table[vid]%1000); | ||
| 409 | |||
| 410 | if (state->core_frequency != speed_mhz) { | ||
| 411 | state->core_frequency = speed_mhz; | ||
| 412 | dprintk(" Corrected ACPI frequency to %d\n", | ||
| 413 | speed_mhz); | ||
| 414 | } | ||
| 415 | |||
| 416 | if (latency < pc.bits.sgtc) | ||
| 417 | latency = pc.bits.sgtc; | ||
| 418 | |||
| 419 | if (speed < minimum_speed) | ||
| 420 | minimum_speed = speed; | ||
| 421 | if (speed > maximum_speed) | ||
| 422 | maximum_speed = speed; | ||
| 423 | } | ||
| 424 | |||
| 425 | powernow_table[i].frequency = CPUFREQ_TABLE_END; | ||
| 426 | powernow_table[i].index = 0; | ||
| 427 | |||
| 428 | /* notify BIOS that we exist */ | ||
| 429 | acpi_processor_notify_smm(THIS_MODULE); | ||
| 430 | |||
| 431 | return 0; | ||
| 432 | |||
| 433 | err2: | ||
| 434 | acpi_processor_unregister_performance(acpi_processor_perf, 0); | ||
| 435 | err1: | ||
| 436 | free_cpumask_var(acpi_processor_perf->shared_cpu_map); | ||
| 437 | err05: | ||
| 438 | kfree(acpi_processor_perf); | ||
| 439 | err0: | ||
| 440 | printk(KERN_WARNING PFX "ACPI perflib can not be used on " | ||
| 441 | "this platform\n"); | ||
| 442 | acpi_processor_perf = NULL; | ||
| 443 | return retval; | ||
| 444 | } | ||
| 445 | #else | ||
| 446 | static int powernow_acpi_init(void) | ||
| 447 | { | ||
| 448 | printk(KERN_INFO PFX "no support for ACPI processor found." | ||
| 449 | " Please recompile your kernel with ACPI processor\n"); | ||
| 450 | return -EINVAL; | ||
| 451 | } | ||
| 452 | #endif | ||
| 453 | |||
| 454 | static void print_pst_entry(struct pst_s *pst, unsigned int j) | ||
| 455 | { | ||
| 456 | dprintk("PST:%d (@%p)\n", j, pst); | ||
| 457 | dprintk(" cpuid: 0x%x fsb: %d maxFID: 0x%x startvid: 0x%x\n", | ||
| 458 | pst->cpuid, pst->fsbspeed, pst->maxfid, pst->startvid); | ||
| 459 | } | ||
| 460 | |||
| 461 | static int powernow_decode_bios(int maxfid, int startvid) | ||
| 462 | { | ||
| 463 | struct psb_s *psb; | ||
| 464 | struct pst_s *pst; | ||
| 465 | unsigned int i, j; | ||
| 466 | unsigned char *p; | ||
| 467 | unsigned int etuple; | ||
| 468 | unsigned int ret; | ||
| 469 | |||
| 470 | etuple = cpuid_eax(0x80000001); | ||
| 471 | |||
| 472 | for (i = 0xC0000; i < 0xffff0 ; i += 16) { | ||
| 473 | |||
| 474 | p = phys_to_virt(i); | ||
| 475 | |||
| 476 | if (memcmp(p, "AMDK7PNOW!", 10) == 0) { | ||
| 477 | dprintk("Found PSB header at %p\n", p); | ||
| 478 | psb = (struct psb_s *) p; | ||
| 479 | dprintk("Table version: 0x%x\n", psb->tableversion); | ||
| 480 | if (psb->tableversion != 0x12) { | ||
| 481 | printk(KERN_INFO PFX "Sorry, only v1.2 tables" | ||
| 482 | " supported right now\n"); | ||
| 483 | return -ENODEV; | ||
| 484 | } | ||
| 485 | |||
| 486 | dprintk("Flags: 0x%x\n", psb->flags); | ||
| 487 | if ((psb->flags & 1) == 0) | ||
| 488 | dprintk("Mobile voltage regulator\n"); | ||
| 489 | else | ||
| 490 | dprintk("Desktop voltage regulator\n"); | ||
| 491 | |||
| 492 | latency = psb->settlingtime; | ||
| 493 | if (latency < 100) { | ||
| 494 | printk(KERN_INFO PFX "BIOS set settling time " | ||
| 495 | "to %d microseconds. " | ||
| 496 | "Should be at least 100. " | ||
| 497 | "Correcting.\n", latency); | ||
| 498 | latency = 100; | ||
| 499 | } | ||
| 500 | dprintk("Settling Time: %d microseconds.\n", | ||
| 501 | psb->settlingtime); | ||
| 502 | dprintk("Has %d PST tables. (Only dumping ones " | ||
| 503 | "relevant to this CPU).\n", | ||
| 504 | psb->numpst); | ||
| 505 | |||
| 506 | p += sizeof(struct psb_s); | ||
| 507 | |||
| 508 | pst = (struct pst_s *) p; | ||
| 509 | |||
| 510 | for (j = 0; j < psb->numpst; j++) { | ||
| 511 | pst = (struct pst_s *) p; | ||
| 512 | number_scales = pst->numpstates; | ||
| 513 | |||
| 514 | if ((etuple == pst->cpuid) && | ||
| 515 | check_fsb(pst->fsbspeed) && | ||
| 516 | (maxfid == pst->maxfid) && | ||
| 517 | (startvid == pst->startvid)) { | ||
| 518 | print_pst_entry(pst, j); | ||
| 519 | p = (char *)pst + sizeof(struct pst_s); | ||
| 520 | ret = get_ranges(p); | ||
| 521 | return ret; | ||
| 522 | } else { | ||
| 523 | unsigned int k; | ||
| 524 | p = (char *)pst + sizeof(struct pst_s); | ||
| 525 | for (k = 0; k < number_scales; k++) | ||
| 526 | p += 2; | ||
| 527 | } | ||
| 528 | } | ||
| 529 | printk(KERN_INFO PFX "No PST tables match this cpuid " | ||
| 530 | "(0x%x)\n", etuple); | ||
| 531 | printk(KERN_INFO PFX "This is indicative of a broken " | ||
| 532 | "BIOS.\n"); | ||
| 533 | |||
| 534 | return -EINVAL; | ||
| 535 | } | ||
| 536 | p++; | ||
| 537 | } | ||
| 538 | |||
| 539 | return -ENODEV; | ||
| 540 | } | ||
| 541 | |||
| 542 | |||
| 543 | static int powernow_target(struct cpufreq_policy *policy, | ||
| 544 | unsigned int target_freq, | ||
| 545 | unsigned int relation) | ||
| 546 | { | ||
| 547 | unsigned int newstate; | ||
| 548 | |||
| 549 | if (cpufreq_frequency_table_target(policy, powernow_table, target_freq, | ||
| 550 | relation, &newstate)) | ||
| 551 | return -EINVAL; | ||
| 552 | |||
| 553 | change_speed(newstate); | ||
| 554 | |||
| 555 | return 0; | ||
| 556 | } | ||
| 557 | |||
| 558 | |||
| 559 | static int powernow_verify(struct cpufreq_policy *policy) | ||
| 560 | { | ||
| 561 | return cpufreq_frequency_table_verify(policy, powernow_table); | ||
| 562 | } | ||
| 563 | |||
| 564 | /* | ||
| 565 | * We use the fact that the bus frequency is somehow | ||
| 566 | * a multiple of 100000/3 khz, then we compute sgtc according | ||
| 567 | * to this multiple. | ||
| 568 | * That way, we match more how AMD thinks all of that work. | ||
| 569 | * We will then get the same kind of behaviour already tested under | ||
| 570 | * the "well-known" other OS. | ||
| 571 | */ | ||
| 572 | static int __cpuinit fixup_sgtc(void) | ||
| 573 | { | ||
| 574 | unsigned int sgtc; | ||
| 575 | unsigned int m; | ||
| 576 | |||
| 577 | m = fsb / 3333; | ||
| 578 | if ((m % 10) >= 5) | ||
| 579 | m += 5; | ||
| 580 | |||
| 581 | m /= 10; | ||
| 582 | |||
| 583 | sgtc = 100 * m * latency; | ||
| 584 | sgtc = sgtc / 3; | ||
| 585 | if (sgtc > 0xfffff) { | ||
| 586 | printk(KERN_WARNING PFX "SGTC too large %d\n", sgtc); | ||
| 587 | sgtc = 0xfffff; | ||
| 588 | } | ||
| 589 | return sgtc; | ||
| 590 | } | ||
| 591 | |||
| 592 | static unsigned int powernow_get(unsigned int cpu) | ||
| 593 | { | ||
| 594 | union msr_fidvidstatus fidvidstatus; | ||
| 595 | unsigned int cfid; | ||
| 596 | |||
| 597 | if (cpu) | ||
| 598 | return 0; | ||
| 599 | rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val); | ||
| 600 | cfid = fidvidstatus.bits.CFID; | ||
| 601 | |||
| 602 | return fsb * fid_codes[cfid] / 10; | ||
| 603 | } | ||
| 604 | |||
| 605 | |||
| 606 | static int __cpuinit acer_cpufreq_pst(const struct dmi_system_id *d) | ||
| 607 | { | ||
| 608 | printk(KERN_WARNING PFX | ||
| 609 | "%s laptop with broken PST tables in BIOS detected.\n", | ||
| 610 | d->ident); | ||
| 611 | printk(KERN_WARNING PFX | ||
| 612 | "You need to downgrade to 3A21 (09/09/2002), or try a newer " | ||
| 613 | "BIOS than 3A71 (01/20/2003)\n"); | ||
| 614 | printk(KERN_WARNING PFX | ||
| 615 | "cpufreq scaling has been disabled as a result of this.\n"); | ||
| 616 | return 0; | ||
| 617 | } | ||
| 618 | |||
| 619 | /* | ||
| 620 | * Some Athlon laptops have really fucked PST tables. | ||
| 621 | * A BIOS update is all that can save them. | ||
| 622 | * Mention this, and disable cpufreq. | ||
| 623 | */ | ||
| 624 | static struct dmi_system_id __cpuinitdata powernow_dmi_table[] = { | ||
| 625 | { | ||
| 626 | .callback = acer_cpufreq_pst, | ||
| 627 | .ident = "Acer Aspire", | ||
| 628 | .matches = { | ||
| 629 | DMI_MATCH(DMI_SYS_VENDOR, "Insyde Software"), | ||
| 630 | DMI_MATCH(DMI_BIOS_VERSION, "3A71"), | ||
| 631 | }, | ||
| 632 | }, | ||
| 633 | { } | ||
| 634 | }; | ||
| 635 | |||
| 636 | static int __cpuinit powernow_cpu_init(struct cpufreq_policy *policy) | ||
| 637 | { | ||
| 638 | union msr_fidvidstatus fidvidstatus; | ||
| 639 | int result; | ||
| 640 | |||
| 641 | if (policy->cpu != 0) | ||
| 642 | return -ENODEV; | ||
| 643 | |||
| 644 | rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val); | ||
| 645 | |||
| 646 | recalibrate_cpu_khz(); | ||
| 647 | |||
| 648 | fsb = (10 * cpu_khz) / fid_codes[fidvidstatus.bits.CFID]; | ||
| 649 | if (!fsb) { | ||
| 650 | printk(KERN_WARNING PFX "can not determine bus frequency\n"); | ||
| 651 | return -EINVAL; | ||
| 652 | } | ||
| 653 | dprintk("FSB: %3dMHz\n", fsb/1000); | ||
| 654 | |||
| 655 | if (dmi_check_system(powernow_dmi_table) || acpi_force) { | ||
| 656 | printk(KERN_INFO PFX "PSB/PST known to be broken. " | ||
| 657 | "Trying ACPI instead\n"); | ||
| 658 | result = powernow_acpi_init(); | ||
| 659 | } else { | ||
| 660 | result = powernow_decode_bios(fidvidstatus.bits.MFID, | ||
| 661 | fidvidstatus.bits.SVID); | ||
| 662 | if (result) { | ||
| 663 | printk(KERN_INFO PFX "Trying ACPI perflib\n"); | ||
| 664 | maximum_speed = 0; | ||
| 665 | minimum_speed = -1; | ||
| 666 | latency = 0; | ||
| 667 | result = powernow_acpi_init(); | ||
| 668 | if (result) { | ||
| 669 | printk(KERN_INFO PFX | ||
| 670 | "ACPI and legacy methods failed\n"); | ||
| 671 | } | ||
| 672 | } else { | ||
| 673 | /* SGTC use the bus clock as timer */ | ||
| 674 | latency = fixup_sgtc(); | ||
| 675 | printk(KERN_INFO PFX "SGTC: %d\n", latency); | ||
| 676 | } | ||
| 677 | } | ||
| 678 | |||
| 679 | if (result) | ||
| 680 | return result; | ||
| 681 | |||
| 682 | printk(KERN_INFO PFX "Minimum speed %d MHz. Maximum speed %d MHz.\n", | ||
| 683 | minimum_speed/1000, maximum_speed/1000); | ||
| 684 | |||
| 685 | policy->cpuinfo.transition_latency = | ||
| 686 | cpufreq_scale(2000000UL, fsb, latency); | ||
| 687 | |||
| 688 | policy->cur = powernow_get(0); | ||
| 689 | |||
| 690 | cpufreq_frequency_table_get_attr(powernow_table, policy->cpu); | ||
| 691 | |||
| 692 | return cpufreq_frequency_table_cpuinfo(policy, powernow_table); | ||
| 693 | } | ||
| 694 | |||
| 695 | static int powernow_cpu_exit(struct cpufreq_policy *policy) | ||
| 696 | { | ||
| 697 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
| 698 | |||
| 699 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
| 700 | if (acpi_processor_perf) { | ||
| 701 | acpi_processor_unregister_performance(acpi_processor_perf, 0); | ||
| 702 | free_cpumask_var(acpi_processor_perf->shared_cpu_map); | ||
| 703 | kfree(acpi_processor_perf); | ||
| 704 | } | ||
| 705 | #endif | ||
| 706 | |||
| 707 | kfree(powernow_table); | ||
| 708 | return 0; | ||
| 709 | } | ||
| 710 | |||
| 711 | static struct freq_attr *powernow_table_attr[] = { | ||
| 712 | &cpufreq_freq_attr_scaling_available_freqs, | ||
| 713 | NULL, | ||
| 714 | }; | ||
| 715 | |||
| 716 | static struct cpufreq_driver powernow_driver = { | ||
| 717 | .verify = powernow_verify, | ||
| 718 | .target = powernow_target, | ||
| 719 | .get = powernow_get, | ||
| 720 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
| 721 | .bios_limit = acpi_processor_get_bios_limit, | ||
| 722 | #endif | ||
| 723 | .init = powernow_cpu_init, | ||
| 724 | .exit = powernow_cpu_exit, | ||
| 725 | .name = "powernow-k7", | ||
| 726 | .owner = THIS_MODULE, | ||
| 727 | .attr = powernow_table_attr, | ||
| 728 | }; | ||
| 729 | |||
| 730 | static int __init powernow_init(void) | ||
| 731 | { | ||
| 732 | if (check_powernow() == 0) | ||
| 733 | return -ENODEV; | ||
| 734 | return cpufreq_register_driver(&powernow_driver); | ||
| 735 | } | ||
| 736 | |||
| 737 | |||
| 738 | static void __exit powernow_exit(void) | ||
| 739 | { | ||
| 740 | cpufreq_unregister_driver(&powernow_driver); | ||
| 741 | } | ||
| 742 | |||
| 743 | module_param(acpi_force, int, 0444); | ||
| 744 | MODULE_PARM_DESC(acpi_force, "Force ACPI to be used."); | ||
| 745 | |||
| 746 | MODULE_AUTHOR("Dave Jones <davej@redhat.com>"); | ||
| 747 | MODULE_DESCRIPTION("Powernow driver for AMD K7 processors."); | ||
| 748 | MODULE_LICENSE("GPL"); | ||
| 749 | |||
| 750 | late_initcall(powernow_init); | ||
| 751 | module_exit(powernow_exit); | ||
| 752 | |||
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k7.h b/arch/x86/kernel/cpu/cpufreq/powernow-k7.h deleted file mode 100644 index 35fb4eaf6e1c..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/powernow-k7.h +++ /dev/null | |||
| @@ -1,43 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * (C) 2003 Dave Jones. | ||
| 3 | * | ||
| 4 | * Licensed under the terms of the GNU GPL License version 2. | ||
| 5 | * | ||
| 6 | * AMD-specific information | ||
| 7 | * | ||
| 8 | */ | ||
| 9 | |||
| 10 | union msr_fidvidctl { | ||
| 11 | struct { | ||
| 12 | unsigned FID:5, // 4:0 | ||
| 13 | reserved1:3, // 7:5 | ||
| 14 | VID:5, // 12:8 | ||
| 15 | reserved2:3, // 15:13 | ||
| 16 | FIDC:1, // 16 | ||
| 17 | VIDC:1, // 17 | ||
| 18 | reserved3:2, // 19:18 | ||
| 19 | FIDCHGRATIO:1, // 20 | ||
| 20 | reserved4:11, // 31-21 | ||
| 21 | SGTC:20, // 32:51 | ||
| 22 | reserved5:12; // 63:52 | ||
| 23 | } bits; | ||
| 24 | unsigned long long val; | ||
| 25 | }; | ||
| 26 | |||
| 27 | union msr_fidvidstatus { | ||
| 28 | struct { | ||
| 29 | unsigned CFID:5, // 4:0 | ||
| 30 | reserved1:3, // 7:5 | ||
| 31 | SFID:5, // 12:8 | ||
| 32 | reserved2:3, // 15:13 | ||
| 33 | MFID:5, // 20:16 | ||
| 34 | reserved3:11, // 31:21 | ||
| 35 | CVID:5, // 36:32 | ||
| 36 | reserved4:3, // 39:37 | ||
| 37 | SVID:5, // 44:40 | ||
| 38 | reserved5:3, // 47:45 | ||
| 39 | MVID:5, // 52:48 | ||
| 40 | reserved6:11; // 63:53 | ||
| 41 | } bits; | ||
| 42 | unsigned long long val; | ||
| 43 | }; | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k8.c b/arch/x86/kernel/cpu/cpufreq/powernow-k8.c deleted file mode 100644 index 2368e38327b3..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/powernow-k8.c +++ /dev/null | |||
| @@ -1,1607 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * (c) 2003-2010 Advanced Micro Devices, Inc. | ||
| 3 | * Your use of this code is subject to the terms and conditions of the | ||
| 4 | * GNU general public license version 2. See "COPYING" or | ||
| 5 | * http://www.gnu.org/licenses/gpl.html | ||
| 6 | * | ||
| 7 | * Support : mark.langsdorf@amd.com | ||
| 8 | * | ||
| 9 | * Based on the powernow-k7.c module written by Dave Jones. | ||
| 10 | * (C) 2003 Dave Jones on behalf of SuSE Labs | ||
| 11 | * (C) 2004 Dominik Brodowski <linux@brodo.de> | ||
| 12 | * (C) 2004 Pavel Machek <pavel@ucw.cz> | ||
| 13 | * Licensed under the terms of the GNU GPL License version 2. | ||
| 14 | * Based upon datasheets & sample CPUs kindly provided by AMD. | ||
| 15 | * | ||
| 16 | * Valuable input gratefully received from Dave Jones, Pavel Machek, | ||
| 17 | * Dominik Brodowski, Jacob Shin, and others. | ||
| 18 | * Originally developed by Paul Devriendt. | ||
| 19 | * Processor information obtained from Chapter 9 (Power and Thermal Management) | ||
| 20 | * of the "BIOS and Kernel Developer's Guide for the AMD Athlon 64 and AMD | ||
| 21 | * Opteron Processors" available for download from www.amd.com | ||
| 22 | * | ||
| 23 | * Tables for specific CPUs can be inferred from | ||
| 24 | * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/30430.pdf | ||
| 25 | */ | ||
| 26 | |||
| 27 | #include <linux/kernel.h> | ||
| 28 | #include <linux/smp.h> | ||
| 29 | #include <linux/module.h> | ||
| 30 | #include <linux/init.h> | ||
| 31 | #include <linux/cpufreq.h> | ||
| 32 | #include <linux/slab.h> | ||
| 33 | #include <linux/string.h> | ||
| 34 | #include <linux/cpumask.h> | ||
| 35 | #include <linux/sched.h> /* for current / set_cpus_allowed() */ | ||
| 36 | #include <linux/io.h> | ||
| 37 | #include <linux/delay.h> | ||
| 38 | |||
| 39 | #include <asm/msr.h> | ||
| 40 | |||
| 41 | #include <linux/acpi.h> | ||
| 42 | #include <linux/mutex.h> | ||
| 43 | #include <acpi/processor.h> | ||
| 44 | |||
| 45 | #define PFX "powernow-k8: " | ||
| 46 | #define VERSION "version 2.20.00" | ||
| 47 | #include "powernow-k8.h" | ||
| 48 | #include "mperf.h" | ||
| 49 | |||
| 50 | /* serialize freq changes */ | ||
| 51 | static DEFINE_MUTEX(fidvid_mutex); | ||
| 52 | |||
| 53 | static DEFINE_PER_CPU(struct powernow_k8_data *, powernow_data); | ||
| 54 | |||
| 55 | static int cpu_family = CPU_OPTERON; | ||
| 56 | |||
| 57 | /* core performance boost */ | ||
| 58 | static bool cpb_capable, cpb_enabled; | ||
| 59 | static struct msr __percpu *msrs; | ||
| 60 | |||
| 61 | static struct cpufreq_driver cpufreq_amd64_driver; | ||
| 62 | |||
| 63 | #ifndef CONFIG_SMP | ||
| 64 | static inline const struct cpumask *cpu_core_mask(int cpu) | ||
| 65 | { | ||
| 66 | return cpumask_of(0); | ||
| 67 | } | ||
| 68 | #endif | ||
| 69 | |||
| 70 | /* Return a frequency in MHz, given an input fid */ | ||
| 71 | static u32 find_freq_from_fid(u32 fid) | ||
| 72 | { | ||
| 73 | return 800 + (fid * 100); | ||
| 74 | } | ||
| 75 | |||
| 76 | /* Return a frequency in KHz, given an input fid */ | ||
| 77 | static u32 find_khz_freq_from_fid(u32 fid) | ||
| 78 | { | ||
| 79 | return 1000 * find_freq_from_fid(fid); | ||
| 80 | } | ||
| 81 | |||
| 82 | static u32 find_khz_freq_from_pstate(struct cpufreq_frequency_table *data, | ||
| 83 | u32 pstate) | ||
| 84 | { | ||
| 85 | return data[pstate].frequency; | ||
| 86 | } | ||
| 87 | |||
| 88 | /* Return the vco fid for an input fid | ||
| 89 | * | ||
| 90 | * Each "low" fid has corresponding "high" fid, and you can get to "low" fids | ||
| 91 | * only from corresponding high fids. This returns "high" fid corresponding to | ||
| 92 | * "low" one. | ||
| 93 | */ | ||
| 94 | static u32 convert_fid_to_vco_fid(u32 fid) | ||
| 95 | { | ||
| 96 | if (fid < HI_FID_TABLE_BOTTOM) | ||
| 97 | return 8 + (2 * fid); | ||
| 98 | else | ||
| 99 | return fid; | ||
| 100 | } | ||
| 101 | |||
| 102 | /* | ||
| 103 | * Return 1 if the pending bit is set. Unless we just instructed the processor | ||
| 104 | * to transition to a new state, seeing this bit set is really bad news. | ||
| 105 | */ | ||
| 106 | static int pending_bit_stuck(void) | ||
| 107 | { | ||
| 108 | u32 lo, hi; | ||
| 109 | |||
| 110 | if (cpu_family == CPU_HW_PSTATE) | ||
| 111 | return 0; | ||
| 112 | |||
| 113 | rdmsr(MSR_FIDVID_STATUS, lo, hi); | ||
| 114 | return lo & MSR_S_LO_CHANGE_PENDING ? 1 : 0; | ||
| 115 | } | ||
| 116 | |||
| 117 | /* | ||
| 118 | * Update the global current fid / vid values from the status msr. | ||
| 119 | * Returns 1 on error. | ||
| 120 | */ | ||
| 121 | static int query_current_values_with_pending_wait(struct powernow_k8_data *data) | ||
| 122 | { | ||
| 123 | u32 lo, hi; | ||
| 124 | u32 i = 0; | ||
| 125 | |||
| 126 | if (cpu_family == CPU_HW_PSTATE) { | ||
| 127 | rdmsr(MSR_PSTATE_STATUS, lo, hi); | ||
| 128 | i = lo & HW_PSTATE_MASK; | ||
| 129 | data->currpstate = i; | ||
| 130 | |||
| 131 | /* | ||
| 132 | * a workaround for family 11h erratum 311 might cause | ||
| 133 | * an "out-of-range Pstate if the core is in Pstate-0 | ||
| 134 | */ | ||
| 135 | if ((boot_cpu_data.x86 == 0x11) && (i >= data->numps)) | ||
| 136 | data->currpstate = HW_PSTATE_0; | ||
| 137 | |||
| 138 | return 0; | ||
| 139 | } | ||
| 140 | do { | ||
| 141 | if (i++ > 10000) { | ||
| 142 | dprintk("detected change pending stuck\n"); | ||
| 143 | return 1; | ||
| 144 | } | ||
| 145 | rdmsr(MSR_FIDVID_STATUS, lo, hi); | ||
| 146 | } while (lo & MSR_S_LO_CHANGE_PENDING); | ||
| 147 | |||
| 148 | data->currvid = hi & MSR_S_HI_CURRENT_VID; | ||
| 149 | data->currfid = lo & MSR_S_LO_CURRENT_FID; | ||
| 150 | |||
| 151 | return 0; | ||
| 152 | } | ||
| 153 | |||
| 154 | /* the isochronous relief time */ | ||
| 155 | static void count_off_irt(struct powernow_k8_data *data) | ||
| 156 | { | ||
| 157 | udelay((1 << data->irt) * 10); | ||
| 158 | return; | ||
| 159 | } | ||
| 160 | |||
| 161 | /* the voltage stabilization time */ | ||
| 162 | static void count_off_vst(struct powernow_k8_data *data) | ||
| 163 | { | ||
| 164 | udelay(data->vstable * VST_UNITS_20US); | ||
| 165 | return; | ||
| 166 | } | ||
| 167 | |||
| 168 | /* need to init the control msr to a safe value (for each cpu) */ | ||
| 169 | static void fidvid_msr_init(void) | ||
| 170 | { | ||
| 171 | u32 lo, hi; | ||
| 172 | u8 fid, vid; | ||
| 173 | |||
| 174 | rdmsr(MSR_FIDVID_STATUS, lo, hi); | ||
| 175 | vid = hi & MSR_S_HI_CURRENT_VID; | ||
| 176 | fid = lo & MSR_S_LO_CURRENT_FID; | ||
| 177 | lo = fid | (vid << MSR_C_LO_VID_SHIFT); | ||
| 178 | hi = MSR_C_HI_STP_GNT_BENIGN; | ||
| 179 | dprintk("cpu%d, init lo 0x%x, hi 0x%x\n", smp_processor_id(), lo, hi); | ||
| 180 | wrmsr(MSR_FIDVID_CTL, lo, hi); | ||
| 181 | } | ||
| 182 | |||
| 183 | /* write the new fid value along with the other control fields to the msr */ | ||
| 184 | static int write_new_fid(struct powernow_k8_data *data, u32 fid) | ||
| 185 | { | ||
| 186 | u32 lo; | ||
| 187 | u32 savevid = data->currvid; | ||
| 188 | u32 i = 0; | ||
| 189 | |||
| 190 | if ((fid & INVALID_FID_MASK) || (data->currvid & INVALID_VID_MASK)) { | ||
| 191 | printk(KERN_ERR PFX "internal error - overflow on fid write\n"); | ||
| 192 | return 1; | ||
| 193 | } | ||
| 194 | |||
| 195 | lo = fid; | ||
| 196 | lo |= (data->currvid << MSR_C_LO_VID_SHIFT); | ||
| 197 | lo |= MSR_C_LO_INIT_FID_VID; | ||
| 198 | |||
| 199 | dprintk("writing fid 0x%x, lo 0x%x, hi 0x%x\n", | ||
| 200 | fid, lo, data->plllock * PLL_LOCK_CONVERSION); | ||
| 201 | |||
| 202 | do { | ||
| 203 | wrmsr(MSR_FIDVID_CTL, lo, data->plllock * PLL_LOCK_CONVERSION); | ||
| 204 | if (i++ > 100) { | ||
| 205 | printk(KERN_ERR PFX | ||
| 206 | "Hardware error - pending bit very stuck - " | ||
| 207 | "no further pstate changes possible\n"); | ||
| 208 | return 1; | ||
| 209 | } | ||
| 210 | } while (query_current_values_with_pending_wait(data)); | ||
| 211 | |||
| 212 | count_off_irt(data); | ||
| 213 | |||
| 214 | if (savevid != data->currvid) { | ||
| 215 | printk(KERN_ERR PFX | ||
| 216 | "vid change on fid trans, old 0x%x, new 0x%x\n", | ||
| 217 | savevid, data->currvid); | ||
| 218 | return 1; | ||
| 219 | } | ||
| 220 | |||
| 221 | if (fid != data->currfid) { | ||
| 222 | printk(KERN_ERR PFX | ||
| 223 | "fid trans failed, fid 0x%x, curr 0x%x\n", fid, | ||
| 224 | data->currfid); | ||
| 225 | return 1; | ||
| 226 | } | ||
| 227 | |||
| 228 | return 0; | ||
| 229 | } | ||
| 230 | |||
| 231 | /* Write a new vid to the hardware */ | ||
| 232 | static int write_new_vid(struct powernow_k8_data *data, u32 vid) | ||
| 233 | { | ||
| 234 | u32 lo; | ||
| 235 | u32 savefid = data->currfid; | ||
| 236 | int i = 0; | ||
| 237 | |||
| 238 | if ((data->currfid & INVALID_FID_MASK) || (vid & INVALID_VID_MASK)) { | ||
| 239 | printk(KERN_ERR PFX "internal error - overflow on vid write\n"); | ||
| 240 | return 1; | ||
| 241 | } | ||
| 242 | |||
| 243 | lo = data->currfid; | ||
| 244 | lo |= (vid << MSR_C_LO_VID_SHIFT); | ||
| 245 | lo |= MSR_C_LO_INIT_FID_VID; | ||
| 246 | |||
| 247 | dprintk("writing vid 0x%x, lo 0x%x, hi 0x%x\n", | ||
| 248 | vid, lo, STOP_GRANT_5NS); | ||
| 249 | |||
| 250 | do { | ||
| 251 | wrmsr(MSR_FIDVID_CTL, lo, STOP_GRANT_5NS); | ||
| 252 | if (i++ > 100) { | ||
| 253 | printk(KERN_ERR PFX "internal error - pending bit " | ||
| 254 | "very stuck - no further pstate " | ||
| 255 | "changes possible\n"); | ||
| 256 | return 1; | ||
| 257 | } | ||
| 258 | } while (query_current_values_with_pending_wait(data)); | ||
| 259 | |||
| 260 | if (savefid != data->currfid) { | ||
| 261 | printk(KERN_ERR PFX "fid changed on vid trans, old " | ||
| 262 | "0x%x new 0x%x\n", | ||
| 263 | savefid, data->currfid); | ||
| 264 | return 1; | ||
| 265 | } | ||
| 266 | |||
| 267 | if (vid != data->currvid) { | ||
| 268 | printk(KERN_ERR PFX "vid trans failed, vid 0x%x, " | ||
| 269 | "curr 0x%x\n", | ||
| 270 | vid, data->currvid); | ||
| 271 | return 1; | ||
| 272 | } | ||
| 273 | |||
| 274 | return 0; | ||
| 275 | } | ||
| 276 | |||
| 277 | /* | ||
| 278 | * Reduce the vid by the max of step or reqvid. | ||
| 279 | * Decreasing vid codes represent increasing voltages: | ||
| 280 | * vid of 0 is 1.550V, vid of 0x1e is 0.800V, vid of VID_OFF is off. | ||
| 281 | */ | ||
| 282 | static int decrease_vid_code_by_step(struct powernow_k8_data *data, | ||
| 283 | u32 reqvid, u32 step) | ||
| 284 | { | ||
| 285 | if ((data->currvid - reqvid) > step) | ||
| 286 | reqvid = data->currvid - step; | ||
| 287 | |||
| 288 | if (write_new_vid(data, reqvid)) | ||
| 289 | return 1; | ||
| 290 | |||
| 291 | count_off_vst(data); | ||
| 292 | |||
| 293 | return 0; | ||
| 294 | } | ||
| 295 | |||
| 296 | /* Change hardware pstate by single MSR write */ | ||
| 297 | static int transition_pstate(struct powernow_k8_data *data, u32 pstate) | ||
| 298 | { | ||
| 299 | wrmsr(MSR_PSTATE_CTRL, pstate, 0); | ||
| 300 | data->currpstate = pstate; | ||
| 301 | return 0; | ||
| 302 | } | ||
| 303 | |||
| 304 | /* Change Opteron/Athlon64 fid and vid, by the 3 phases. */ | ||
| 305 | static int transition_fid_vid(struct powernow_k8_data *data, | ||
| 306 | u32 reqfid, u32 reqvid) | ||
| 307 | { | ||
| 308 | if (core_voltage_pre_transition(data, reqvid, reqfid)) | ||
| 309 | return 1; | ||
| 310 | |||
| 311 | if (core_frequency_transition(data, reqfid)) | ||
| 312 | return 1; | ||
| 313 | |||
| 314 | if (core_voltage_post_transition(data, reqvid)) | ||
| 315 | return 1; | ||
| 316 | |||
| 317 | if (query_current_values_with_pending_wait(data)) | ||
| 318 | return 1; | ||
| 319 | |||
| 320 | if ((reqfid != data->currfid) || (reqvid != data->currvid)) { | ||
| 321 | printk(KERN_ERR PFX "failed (cpu%d): req 0x%x 0x%x, " | ||
| 322 | "curr 0x%x 0x%x\n", | ||
| 323 | smp_processor_id(), | ||
| 324 | reqfid, reqvid, data->currfid, data->currvid); | ||
| 325 | return 1; | ||
| 326 | } | ||
| 327 | |||
| 328 | dprintk("transitioned (cpu%d): new fid 0x%x, vid 0x%x\n", | ||
| 329 | smp_processor_id(), data->currfid, data->currvid); | ||
| 330 | |||
| 331 | return 0; | ||
| 332 | } | ||
| 333 | |||
| 334 | /* Phase 1 - core voltage transition ... setup voltage */ | ||
| 335 | static int core_voltage_pre_transition(struct powernow_k8_data *data, | ||
| 336 | u32 reqvid, u32 reqfid) | ||
| 337 | { | ||
| 338 | u32 rvosteps = data->rvo; | ||
| 339 | u32 savefid = data->currfid; | ||
| 340 | u32 maxvid, lo, rvomult = 1; | ||
| 341 | |||
| 342 | dprintk("ph1 (cpu%d): start, currfid 0x%x, currvid 0x%x, " | ||
| 343 | "reqvid 0x%x, rvo 0x%x\n", | ||
| 344 | smp_processor_id(), | ||
| 345 | data->currfid, data->currvid, reqvid, data->rvo); | ||
| 346 | |||
| 347 | if ((savefid < LO_FID_TABLE_TOP) && (reqfid < LO_FID_TABLE_TOP)) | ||
| 348 | rvomult = 2; | ||
| 349 | rvosteps *= rvomult; | ||
| 350 | rdmsr(MSR_FIDVID_STATUS, lo, maxvid); | ||
| 351 | maxvid = 0x1f & (maxvid >> 16); | ||
| 352 | dprintk("ph1 maxvid=0x%x\n", maxvid); | ||
| 353 | if (reqvid < maxvid) /* lower numbers are higher voltages */ | ||
| 354 | reqvid = maxvid; | ||
| 355 | |||
| 356 | while (data->currvid > reqvid) { | ||
| 357 | dprintk("ph1: curr 0x%x, req vid 0x%x\n", | ||
| 358 | data->currvid, reqvid); | ||
| 359 | if (decrease_vid_code_by_step(data, reqvid, data->vidmvs)) | ||
| 360 | return 1; | ||
| 361 | } | ||
| 362 | |||
| 363 | while ((rvosteps > 0) && | ||
| 364 | ((rvomult * data->rvo + data->currvid) > reqvid)) { | ||
| 365 | if (data->currvid == maxvid) { | ||
| 366 | rvosteps = 0; | ||
| 367 | } else { | ||
| 368 | dprintk("ph1: changing vid for rvo, req 0x%x\n", | ||
| 369 | data->currvid - 1); | ||
| 370 | if (decrease_vid_code_by_step(data, data->currvid-1, 1)) | ||
| 371 | return 1; | ||
| 372 | rvosteps--; | ||
| 373 | } | ||
| 374 | } | ||
| 375 | |||
| 376 | if (query_current_values_with_pending_wait(data)) | ||
| 377 | return 1; | ||
| 378 | |||
| 379 | if (savefid != data->currfid) { | ||
| 380 | printk(KERN_ERR PFX "ph1 err, currfid changed 0x%x\n", | ||
| 381 | data->currfid); | ||
| 382 | return 1; | ||
| 383 | } | ||
| 384 | |||
| 385 | dprintk("ph1 complete, currfid 0x%x, currvid 0x%x\n", | ||
| 386 | data->currfid, data->currvid); | ||
| 387 | |||
| 388 | return 0; | ||
| 389 | } | ||
| 390 | |||
| 391 | /* Phase 2 - core frequency transition */ | ||
| 392 | static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid) | ||
| 393 | { | ||
| 394 | u32 vcoreqfid, vcocurrfid, vcofiddiff; | ||
| 395 | u32 fid_interval, savevid = data->currvid; | ||
| 396 | |||
| 397 | if (data->currfid == reqfid) { | ||
| 398 | printk(KERN_ERR PFX "ph2 null fid transition 0x%x\n", | ||
| 399 | data->currfid); | ||
| 400 | return 0; | ||
| 401 | } | ||
| 402 | |||
| 403 | dprintk("ph2 (cpu%d): starting, currfid 0x%x, currvid 0x%x, " | ||
| 404 | "reqfid 0x%x\n", | ||
| 405 | smp_processor_id(), | ||
| 406 | data->currfid, data->currvid, reqfid); | ||
| 407 | |||
| 408 | vcoreqfid = convert_fid_to_vco_fid(reqfid); | ||
| 409 | vcocurrfid = convert_fid_to_vco_fid(data->currfid); | ||
| 410 | vcofiddiff = vcocurrfid > vcoreqfid ? vcocurrfid - vcoreqfid | ||
| 411 | : vcoreqfid - vcocurrfid; | ||
| 412 | |||
| 413 | if ((reqfid <= LO_FID_TABLE_TOP) && (data->currfid <= LO_FID_TABLE_TOP)) | ||
| 414 | vcofiddiff = 0; | ||
| 415 | |||
| 416 | while (vcofiddiff > 2) { | ||
| 417 | (data->currfid & 1) ? (fid_interval = 1) : (fid_interval = 2); | ||
| 418 | |||
| 419 | if (reqfid > data->currfid) { | ||
| 420 | if (data->currfid > LO_FID_TABLE_TOP) { | ||
| 421 | if (write_new_fid(data, | ||
| 422 | data->currfid + fid_interval)) | ||
| 423 | return 1; | ||
| 424 | } else { | ||
| 425 | if (write_new_fid | ||
| 426 | (data, | ||
| 427 | 2 + convert_fid_to_vco_fid(data->currfid))) | ||
| 428 | return 1; | ||
| 429 | } | ||
| 430 | } else { | ||
| 431 | if (write_new_fid(data, data->currfid - fid_interval)) | ||
| 432 | return 1; | ||
| 433 | } | ||
| 434 | |||
| 435 | vcocurrfid = convert_fid_to_vco_fid(data->currfid); | ||
| 436 | vcofiddiff = vcocurrfid > vcoreqfid ? vcocurrfid - vcoreqfid | ||
| 437 | : vcoreqfid - vcocurrfid; | ||
| 438 | } | ||
| 439 | |||
| 440 | if (write_new_fid(data, reqfid)) | ||
| 441 | return 1; | ||
| 442 | |||
| 443 | if (query_current_values_with_pending_wait(data)) | ||
| 444 | return 1; | ||
| 445 | |||
| 446 | if (data->currfid != reqfid) { | ||
| 447 | printk(KERN_ERR PFX | ||
| 448 | "ph2: mismatch, failed fid transition, " | ||
| 449 | "curr 0x%x, req 0x%x\n", | ||
| 450 | data->currfid, reqfid); | ||
| 451 | return 1; | ||
| 452 | } | ||
| 453 | |||
| 454 | if (savevid != data->currvid) { | ||
| 455 | printk(KERN_ERR PFX "ph2: vid changed, save 0x%x, curr 0x%x\n", | ||
| 456 | savevid, data->currvid); | ||
| 457 | return 1; | ||
| 458 | } | ||
| 459 | |||
| 460 | dprintk("ph2 complete, currfid 0x%x, currvid 0x%x\n", | ||
| 461 | data->currfid, data->currvid); | ||
| 462 | |||
| 463 | return 0; | ||
| 464 | } | ||
| 465 | |||
| 466 | /* Phase 3 - core voltage transition flow ... jump to the final vid. */ | ||
| 467 | static int core_voltage_post_transition(struct powernow_k8_data *data, | ||
| 468 | u32 reqvid) | ||
| 469 | { | ||
| 470 | u32 savefid = data->currfid; | ||
| 471 | u32 savereqvid = reqvid; | ||
| 472 | |||
| 473 | dprintk("ph3 (cpu%d): starting, currfid 0x%x, currvid 0x%x\n", | ||
| 474 | smp_processor_id(), | ||
| 475 | data->currfid, data->currvid); | ||
| 476 | |||
| 477 | if (reqvid != data->currvid) { | ||
| 478 | if (write_new_vid(data, reqvid)) | ||
| 479 | return 1; | ||
| 480 | |||
| 481 | if (savefid != data->currfid) { | ||
| 482 | printk(KERN_ERR PFX | ||
| 483 | "ph3: bad fid change, save 0x%x, curr 0x%x\n", | ||
| 484 | savefid, data->currfid); | ||
| 485 | return 1; | ||
| 486 | } | ||
| 487 | |||
| 488 | if (data->currvid != reqvid) { | ||
| 489 | printk(KERN_ERR PFX | ||
| 490 | "ph3: failed vid transition\n, " | ||
| 491 | "req 0x%x, curr 0x%x", | ||
| 492 | reqvid, data->currvid); | ||
| 493 | return 1; | ||
| 494 | } | ||
| 495 | } | ||
| 496 | |||
| 497 | if (query_current_values_with_pending_wait(data)) | ||
| 498 | return 1; | ||
| 499 | |||
| 500 | if (savereqvid != data->currvid) { | ||
| 501 | dprintk("ph3 failed, currvid 0x%x\n", data->currvid); | ||
| 502 | return 1; | ||
| 503 | } | ||
| 504 | |||
| 505 | if (savefid != data->currfid) { | ||
| 506 | dprintk("ph3 failed, currfid changed 0x%x\n", | ||
| 507 | data->currfid); | ||
| 508 | return 1; | ||
| 509 | } | ||
| 510 | |||
| 511 | dprintk("ph3 complete, currfid 0x%x, currvid 0x%x\n", | ||
| 512 | data->currfid, data->currvid); | ||
| 513 | |||
| 514 | return 0; | ||
| 515 | } | ||
| 516 | |||
| 517 | static void check_supported_cpu(void *_rc) | ||
| 518 | { | ||
| 519 | u32 eax, ebx, ecx, edx; | ||
| 520 | int *rc = _rc; | ||
| 521 | |||
| 522 | *rc = -ENODEV; | ||
| 523 | |||
| 524 | if (__this_cpu_read(cpu_info.x86_vendor) != X86_VENDOR_AMD) | ||
| 525 | return; | ||
| 526 | |||
| 527 | eax = cpuid_eax(CPUID_PROCESSOR_SIGNATURE); | ||
| 528 | if (((eax & CPUID_XFAM) != CPUID_XFAM_K8) && | ||
| 529 | ((eax & CPUID_XFAM) < CPUID_XFAM_10H)) | ||
| 530 | return; | ||
| 531 | |||
| 532 | if ((eax & CPUID_XFAM) == CPUID_XFAM_K8) { | ||
| 533 | if (((eax & CPUID_USE_XFAM_XMOD) != CPUID_USE_XFAM_XMOD) || | ||
| 534 | ((eax & CPUID_XMOD) > CPUID_XMOD_REV_MASK)) { | ||
| 535 | printk(KERN_INFO PFX | ||
| 536 | "Processor cpuid %x not supported\n", eax); | ||
| 537 | return; | ||
| 538 | } | ||
| 539 | |||
| 540 | eax = cpuid_eax(CPUID_GET_MAX_CAPABILITIES); | ||
| 541 | if (eax < CPUID_FREQ_VOLT_CAPABILITIES) { | ||
| 542 | printk(KERN_INFO PFX | ||
| 543 | "No frequency change capabilities detected\n"); | ||
| 544 | return; | ||
| 545 | } | ||
| 546 | |||
| 547 | cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx); | ||
| 548 | if ((edx & P_STATE_TRANSITION_CAPABLE) | ||
| 549 | != P_STATE_TRANSITION_CAPABLE) { | ||
| 550 | printk(KERN_INFO PFX | ||
| 551 | "Power state transitions not supported\n"); | ||
| 552 | return; | ||
| 553 | } | ||
| 554 | } else { /* must be a HW Pstate capable processor */ | ||
| 555 | cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx); | ||
| 556 | if ((edx & USE_HW_PSTATE) == USE_HW_PSTATE) | ||
| 557 | cpu_family = CPU_HW_PSTATE; | ||
| 558 | else | ||
| 559 | return; | ||
| 560 | } | ||
| 561 | |||
| 562 | *rc = 0; | ||
| 563 | } | ||
| 564 | |||
| 565 | static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst, | ||
| 566 | u8 maxvid) | ||
| 567 | { | ||
| 568 | unsigned int j; | ||
| 569 | u8 lastfid = 0xff; | ||
| 570 | |||
| 571 | for (j = 0; j < data->numps; j++) { | ||
| 572 | if (pst[j].vid > LEAST_VID) { | ||
| 573 | printk(KERN_ERR FW_BUG PFX "vid %d invalid : 0x%x\n", | ||
| 574 | j, pst[j].vid); | ||
| 575 | return -EINVAL; | ||
| 576 | } | ||
| 577 | if (pst[j].vid < data->rvo) { | ||
| 578 | /* vid + rvo >= 0 */ | ||
| 579 | printk(KERN_ERR FW_BUG PFX "0 vid exceeded with pstate" | ||
| 580 | " %d\n", j); | ||
| 581 | return -ENODEV; | ||
| 582 | } | ||
| 583 | if (pst[j].vid < maxvid + data->rvo) { | ||
| 584 | /* vid + rvo >= maxvid */ | ||
| 585 | printk(KERN_ERR FW_BUG PFX "maxvid exceeded with pstate" | ||
| 586 | " %d\n", j); | ||
| 587 | return -ENODEV; | ||
| 588 | } | ||
| 589 | if (pst[j].fid > MAX_FID) { | ||
| 590 | printk(KERN_ERR FW_BUG PFX "maxfid exceeded with pstate" | ||
| 591 | " %d\n", j); | ||
| 592 | return -ENODEV; | ||
| 593 | } | ||
| 594 | if (j && (pst[j].fid < HI_FID_TABLE_BOTTOM)) { | ||
| 595 | /* Only first fid is allowed to be in "low" range */ | ||
| 596 | printk(KERN_ERR FW_BUG PFX "two low fids - %d : " | ||
| 597 | "0x%x\n", j, pst[j].fid); | ||
| 598 | return -EINVAL; | ||
| 599 | } | ||
| 600 | if (pst[j].fid < lastfid) | ||
| 601 | lastfid = pst[j].fid; | ||
| 602 | } | ||
| 603 | if (lastfid & 1) { | ||
| 604 | printk(KERN_ERR FW_BUG PFX "lastfid invalid\n"); | ||
| 605 | return -EINVAL; | ||
| 606 | } | ||
| 607 | if (lastfid > LO_FID_TABLE_TOP) | ||
| 608 | printk(KERN_INFO FW_BUG PFX | ||
| 609 | "first fid not from lo freq table\n"); | ||
| 610 | |||
| 611 | return 0; | ||
| 612 | } | ||
| 613 | |||
| 614 | static void invalidate_entry(struct cpufreq_frequency_table *powernow_table, | ||
| 615 | unsigned int entry) | ||
| 616 | { | ||
| 617 | powernow_table[entry].frequency = CPUFREQ_ENTRY_INVALID; | ||
| 618 | } | ||
| 619 | |||
| 620 | static void print_basics(struct powernow_k8_data *data) | ||
| 621 | { | ||
| 622 | int j; | ||
| 623 | for (j = 0; j < data->numps; j++) { | ||
| 624 | if (data->powernow_table[j].frequency != | ||
| 625 | CPUFREQ_ENTRY_INVALID) { | ||
| 626 | if (cpu_family == CPU_HW_PSTATE) { | ||
| 627 | printk(KERN_INFO PFX | ||
| 628 | " %d : pstate %d (%d MHz)\n", j, | ||
| 629 | data->powernow_table[j].index, | ||
| 630 | data->powernow_table[j].frequency/1000); | ||
| 631 | } else { | ||
| 632 | printk(KERN_INFO PFX | ||
| 633 | "fid 0x%x (%d MHz), vid 0x%x\n", | ||
| 634 | data->powernow_table[j].index & 0xff, | ||
| 635 | data->powernow_table[j].frequency/1000, | ||
| 636 | data->powernow_table[j].index >> 8); | ||
| 637 | } | ||
| 638 | } | ||
| 639 | } | ||
| 640 | if (data->batps) | ||
| 641 | printk(KERN_INFO PFX "Only %d pstates on battery\n", | ||
| 642 | data->batps); | ||
| 643 | } | ||
| 644 | |||
| 645 | static u32 freq_from_fid_did(u32 fid, u32 did) | ||
| 646 | { | ||
| 647 | u32 mhz = 0; | ||
| 648 | |||
| 649 | if (boot_cpu_data.x86 == 0x10) | ||
| 650 | mhz = (100 * (fid + 0x10)) >> did; | ||
| 651 | else if (boot_cpu_data.x86 == 0x11) | ||
| 652 | mhz = (100 * (fid + 8)) >> did; | ||
| 653 | else | ||
| 654 | BUG(); | ||
| 655 | |||
| 656 | return mhz * 1000; | ||
| 657 | } | ||
| 658 | |||
| 659 | static int fill_powernow_table(struct powernow_k8_data *data, | ||
| 660 | struct pst_s *pst, u8 maxvid) | ||
| 661 | { | ||
| 662 | struct cpufreq_frequency_table *powernow_table; | ||
| 663 | unsigned int j; | ||
| 664 | |||
| 665 | if (data->batps) { | ||
| 666 | /* use ACPI support to get full speed on mains power */ | ||
| 667 | printk(KERN_WARNING PFX | ||
| 668 | "Only %d pstates usable (use ACPI driver for full " | ||
| 669 | "range\n", data->batps); | ||
| 670 | data->numps = data->batps; | ||
| 671 | } | ||
| 672 | |||
| 673 | for (j = 1; j < data->numps; j++) { | ||
| 674 | if (pst[j-1].fid >= pst[j].fid) { | ||
| 675 | printk(KERN_ERR PFX "PST out of sequence\n"); | ||
| 676 | return -EINVAL; | ||
| 677 | } | ||
| 678 | } | ||
| 679 | |||
| 680 | if (data->numps < 2) { | ||
| 681 | printk(KERN_ERR PFX "no p states to transition\n"); | ||
| 682 | return -ENODEV; | ||
| 683 | } | ||
| 684 | |||
| 685 | if (check_pst_table(data, pst, maxvid)) | ||
| 686 | return -EINVAL; | ||
| 687 | |||
| 688 | powernow_table = kmalloc((sizeof(struct cpufreq_frequency_table) | ||
| 689 | * (data->numps + 1)), GFP_KERNEL); | ||
| 690 | if (!powernow_table) { | ||
| 691 | printk(KERN_ERR PFX "powernow_table memory alloc failure\n"); | ||
| 692 | return -ENOMEM; | ||
| 693 | } | ||
| 694 | |||
| 695 | for (j = 0; j < data->numps; j++) { | ||
| 696 | int freq; | ||
| 697 | powernow_table[j].index = pst[j].fid; /* lower 8 bits */ | ||
| 698 | powernow_table[j].index |= (pst[j].vid << 8); /* upper 8 bits */ | ||
| 699 | freq = find_khz_freq_from_fid(pst[j].fid); | ||
| 700 | powernow_table[j].frequency = freq; | ||
| 701 | } | ||
| 702 | powernow_table[data->numps].frequency = CPUFREQ_TABLE_END; | ||
| 703 | powernow_table[data->numps].index = 0; | ||
| 704 | |||
| 705 | if (query_current_values_with_pending_wait(data)) { | ||
| 706 | kfree(powernow_table); | ||
| 707 | return -EIO; | ||
| 708 | } | ||
| 709 | |||
| 710 | dprintk("cfid 0x%x, cvid 0x%x\n", data->currfid, data->currvid); | ||
| 711 | data->powernow_table = powernow_table; | ||
| 712 | if (cpumask_first(cpu_core_mask(data->cpu)) == data->cpu) | ||
| 713 | print_basics(data); | ||
| 714 | |||
| 715 | for (j = 0; j < data->numps; j++) | ||
| 716 | if ((pst[j].fid == data->currfid) && | ||
| 717 | (pst[j].vid == data->currvid)) | ||
| 718 | return 0; | ||
| 719 | |||
| 720 | dprintk("currfid/vid do not match PST, ignoring\n"); | ||
| 721 | return 0; | ||
| 722 | } | ||
| 723 | |||
| 724 | /* Find and validate the PSB/PST table in BIOS. */ | ||
| 725 | static int find_psb_table(struct powernow_k8_data *data) | ||
| 726 | { | ||
| 727 | struct psb_s *psb; | ||
| 728 | unsigned int i; | ||
| 729 | u32 mvs; | ||
| 730 | u8 maxvid; | ||
| 731 | u32 cpst = 0; | ||
| 732 | u32 thiscpuid; | ||
| 733 | |||
| 734 | for (i = 0xc0000; i < 0xffff0; i += 0x10) { | ||
| 735 | /* Scan BIOS looking for the signature. */ | ||
| 736 | /* It can not be at ffff0 - it is too big. */ | ||
| 737 | |||
| 738 | psb = phys_to_virt(i); | ||
| 739 | if (memcmp(psb, PSB_ID_STRING, PSB_ID_STRING_LEN) != 0) | ||
| 740 | continue; | ||
| 741 | |||
| 742 | dprintk("found PSB header at 0x%p\n", psb); | ||
| 743 | |||
| 744 | dprintk("table vers: 0x%x\n", psb->tableversion); | ||
| 745 | if (psb->tableversion != PSB_VERSION_1_4) { | ||
| 746 | printk(KERN_ERR FW_BUG PFX "PSB table is not v1.4\n"); | ||
| 747 | return -ENODEV; | ||
| 748 | } | ||
| 749 | |||
| 750 | dprintk("flags: 0x%x\n", psb->flags1); | ||
| 751 | if (psb->flags1) { | ||
| 752 | printk(KERN_ERR FW_BUG PFX "unknown flags\n"); | ||
| 753 | return -ENODEV; | ||
| 754 | } | ||
| 755 | |||
| 756 | data->vstable = psb->vstable; | ||
| 757 | dprintk("voltage stabilization time: %d(*20us)\n", | ||
| 758 | data->vstable); | ||
| 759 | |||
| 760 | dprintk("flags2: 0x%x\n", psb->flags2); | ||
| 761 | data->rvo = psb->flags2 & 3; | ||
| 762 | data->irt = ((psb->flags2) >> 2) & 3; | ||
| 763 | mvs = ((psb->flags2) >> 4) & 3; | ||
| 764 | data->vidmvs = 1 << mvs; | ||
| 765 | data->batps = ((psb->flags2) >> 6) & 3; | ||
| 766 | |||
| 767 | dprintk("ramp voltage offset: %d\n", data->rvo); | ||
| 768 | dprintk("isochronous relief time: %d\n", data->irt); | ||
| 769 | dprintk("maximum voltage step: %d - 0x%x\n", mvs, data->vidmvs); | ||
| 770 | |||
| 771 | dprintk("numpst: 0x%x\n", psb->num_tables); | ||
| 772 | cpst = psb->num_tables; | ||
| 773 | if ((psb->cpuid == 0x00000fc0) || | ||
| 774 | (psb->cpuid == 0x00000fe0)) { | ||
| 775 | thiscpuid = cpuid_eax(CPUID_PROCESSOR_SIGNATURE); | ||
| 776 | if ((thiscpuid == 0x00000fc0) || | ||
| 777 | (thiscpuid == 0x00000fe0)) | ||
| 778 | cpst = 1; | ||
| 779 | } | ||
| 780 | if (cpst != 1) { | ||
| 781 | printk(KERN_ERR FW_BUG PFX "numpst must be 1\n"); | ||
| 782 | return -ENODEV; | ||
| 783 | } | ||
| 784 | |||
| 785 | data->plllock = psb->plllocktime; | ||
| 786 | dprintk("plllocktime: 0x%x (units 1us)\n", psb->plllocktime); | ||
| 787 | dprintk("maxfid: 0x%x\n", psb->maxfid); | ||
| 788 | dprintk("maxvid: 0x%x\n", psb->maxvid); | ||
| 789 | maxvid = psb->maxvid; | ||
| 790 | |||
| 791 | data->numps = psb->numps; | ||
| 792 | dprintk("numpstates: 0x%x\n", data->numps); | ||
| 793 | return fill_powernow_table(data, | ||
| 794 | (struct pst_s *)(psb+1), maxvid); | ||
| 795 | } | ||
| 796 | /* | ||
| 797 | * If you see this message, complain to BIOS manufacturer. If | ||
| 798 | * he tells you "we do not support Linux" or some similar | ||
| 799 | * nonsense, remember that Windows 2000 uses the same legacy | ||
| 800 | * mechanism that the old Linux PSB driver uses. Tell them it | ||
| 801 | * is broken with Windows 2000. | ||
| 802 | * | ||
| 803 | * The reference to the AMD documentation is chapter 9 in the | ||
| 804 | * BIOS and Kernel Developer's Guide, which is available on | ||
| 805 | * www.amd.com | ||
| 806 | */ | ||
| 807 | printk(KERN_ERR FW_BUG PFX "No PSB or ACPI _PSS objects\n"); | ||
| 808 | printk(KERN_ERR PFX "Make sure that your BIOS is up to date" | ||
| 809 | " and Cool'N'Quiet support is enabled in BIOS setup\n"); | ||
| 810 | return -ENODEV; | ||
| 811 | } | ||
| 812 | |||
| 813 | static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, | ||
| 814 | unsigned int index) | ||
| 815 | { | ||
| 816 | u64 control; | ||
| 817 | |||
| 818 | if (!data->acpi_data.state_count || (cpu_family == CPU_HW_PSTATE)) | ||
| 819 | return; | ||
| 820 | |||
| 821 | control = data->acpi_data.states[index].control; | ||
| 822 | data->irt = (control >> IRT_SHIFT) & IRT_MASK; | ||
| 823 | data->rvo = (control >> RVO_SHIFT) & RVO_MASK; | ||
| 824 | data->exttype = (control >> EXT_TYPE_SHIFT) & EXT_TYPE_MASK; | ||
| 825 | data->plllock = (control >> PLL_L_SHIFT) & PLL_L_MASK; | ||
| 826 | data->vidmvs = 1 << ((control >> MVS_SHIFT) & MVS_MASK); | ||
| 827 | data->vstable = (control >> VST_SHIFT) & VST_MASK; | ||
| 828 | } | ||
| 829 | |||
| 830 | static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) | ||
| 831 | { | ||
| 832 | struct cpufreq_frequency_table *powernow_table; | ||
| 833 | int ret_val = -ENODEV; | ||
| 834 | u64 control, status; | ||
| 835 | |||
| 836 | if (acpi_processor_register_performance(&data->acpi_data, data->cpu)) { | ||
| 837 | dprintk("register performance failed: bad ACPI data\n"); | ||
| 838 | return -EIO; | ||
| 839 | } | ||
| 840 | |||
| 841 | /* verify the data contained in the ACPI structures */ | ||
| 842 | if (data->acpi_data.state_count <= 1) { | ||
| 843 | dprintk("No ACPI P-States\n"); | ||
| 844 | goto err_out; | ||
| 845 | } | ||
| 846 | |||
| 847 | control = data->acpi_data.control_register.space_id; | ||
| 848 | status = data->acpi_data.status_register.space_id; | ||
| 849 | |||
| 850 | if ((control != ACPI_ADR_SPACE_FIXED_HARDWARE) || | ||
| 851 | (status != ACPI_ADR_SPACE_FIXED_HARDWARE)) { | ||
| 852 | dprintk("Invalid control/status registers (%x - %x)\n", | ||
| 853 | control, status); | ||
| 854 | goto err_out; | ||
| 855 | } | ||
| 856 | |||
| 857 | /* fill in data->powernow_table */ | ||
| 858 | powernow_table = kmalloc((sizeof(struct cpufreq_frequency_table) | ||
| 859 | * (data->acpi_data.state_count + 1)), GFP_KERNEL); | ||
| 860 | if (!powernow_table) { | ||
| 861 | dprintk("powernow_table memory alloc failure\n"); | ||
| 862 | goto err_out; | ||
| 863 | } | ||
| 864 | |||
| 865 | /* fill in data */ | ||
| 866 | data->numps = data->acpi_data.state_count; | ||
| 867 | powernow_k8_acpi_pst_values(data, 0); | ||
| 868 | |||
| 869 | if (cpu_family == CPU_HW_PSTATE) | ||
| 870 | ret_val = fill_powernow_table_pstate(data, powernow_table); | ||
| 871 | else | ||
| 872 | ret_val = fill_powernow_table_fidvid(data, powernow_table); | ||
| 873 | if (ret_val) | ||
| 874 | goto err_out_mem; | ||
| 875 | |||
| 876 | powernow_table[data->acpi_data.state_count].frequency = | ||
| 877 | CPUFREQ_TABLE_END; | ||
| 878 | powernow_table[data->acpi_data.state_count].index = 0; | ||
| 879 | data->powernow_table = powernow_table; | ||
| 880 | |||
| 881 | if (cpumask_first(cpu_core_mask(data->cpu)) == data->cpu) | ||
| 882 | print_basics(data); | ||
| 883 | |||
| 884 | /* notify BIOS that we exist */ | ||
| 885 | acpi_processor_notify_smm(THIS_MODULE); | ||
| 886 | |||
| 887 | if (!zalloc_cpumask_var(&data->acpi_data.shared_cpu_map, GFP_KERNEL)) { | ||
| 888 | printk(KERN_ERR PFX | ||
| 889 | "unable to alloc powernow_k8_data cpumask\n"); | ||
| 890 | ret_val = -ENOMEM; | ||
| 891 | goto err_out_mem; | ||
| 892 | } | ||
| 893 | |||
| 894 | return 0; | ||
| 895 | |||
| 896 | err_out_mem: | ||
| 897 | kfree(powernow_table); | ||
| 898 | |||
| 899 | err_out: | ||
| 900 | acpi_processor_unregister_performance(&data->acpi_data, data->cpu); | ||
| 901 | |||
| 902 | /* data->acpi_data.state_count informs us at ->exit() | ||
| 903 | * whether ACPI was used */ | ||
| 904 | data->acpi_data.state_count = 0; | ||
| 905 | |||
| 906 | return ret_val; | ||
| 907 | } | ||
| 908 | |||
| 909 | static int fill_powernow_table_pstate(struct powernow_k8_data *data, | ||
| 910 | struct cpufreq_frequency_table *powernow_table) | ||
| 911 | { | ||
| 912 | int i; | ||
| 913 | u32 hi = 0, lo = 0; | ||
| 914 | rdmsr(MSR_PSTATE_CUR_LIMIT, lo, hi); | ||
| 915 | data->max_hw_pstate = (lo & HW_PSTATE_MAX_MASK) >> HW_PSTATE_MAX_SHIFT; | ||
| 916 | |||
| 917 | for (i = 0; i < data->acpi_data.state_count; i++) { | ||
| 918 | u32 index; | ||
| 919 | |||
| 920 | index = data->acpi_data.states[i].control & HW_PSTATE_MASK; | ||
| 921 | if (index > data->max_hw_pstate) { | ||
| 922 | printk(KERN_ERR PFX "invalid pstate %d - " | ||
| 923 | "bad value %d.\n", i, index); | ||
| 924 | printk(KERN_ERR PFX "Please report to BIOS " | ||
| 925 | "manufacturer\n"); | ||
| 926 | invalidate_entry(powernow_table, i); | ||
| 927 | continue; | ||
| 928 | } | ||
| 929 | rdmsr(MSR_PSTATE_DEF_BASE + index, lo, hi); | ||
| 930 | if (!(hi & HW_PSTATE_VALID_MASK)) { | ||
| 931 | dprintk("invalid pstate %d, ignoring\n", index); | ||
| 932 | invalidate_entry(powernow_table, i); | ||
| 933 | continue; | ||
| 934 | } | ||
| 935 | |||
| 936 | powernow_table[i].index = index; | ||
| 937 | |||
| 938 | /* Frequency may be rounded for these */ | ||
| 939 | if ((boot_cpu_data.x86 == 0x10 && boot_cpu_data.x86_model < 10) | ||
| 940 | || boot_cpu_data.x86 == 0x11) { | ||
| 941 | powernow_table[i].frequency = | ||
| 942 | freq_from_fid_did(lo & 0x3f, (lo >> 6) & 7); | ||
| 943 | } else | ||
| 944 | powernow_table[i].frequency = | ||
| 945 | data->acpi_data.states[i].core_frequency * 1000; | ||
| 946 | } | ||
| 947 | return 0; | ||
| 948 | } | ||
| 949 | |||
| 950 | static int fill_powernow_table_fidvid(struct powernow_k8_data *data, | ||
| 951 | struct cpufreq_frequency_table *powernow_table) | ||
| 952 | { | ||
| 953 | int i; | ||
| 954 | |||
| 955 | for (i = 0; i < data->acpi_data.state_count; i++) { | ||
| 956 | u32 fid; | ||
| 957 | u32 vid; | ||
| 958 | u32 freq, index; | ||
| 959 | u64 status, control; | ||
| 960 | |||
| 961 | if (data->exttype) { | ||
| 962 | status = data->acpi_data.states[i].status; | ||
| 963 | fid = status & EXT_FID_MASK; | ||
| 964 | vid = (status >> VID_SHIFT) & EXT_VID_MASK; | ||
| 965 | } else { | ||
| 966 | control = data->acpi_data.states[i].control; | ||
| 967 | fid = control & FID_MASK; | ||
| 968 | vid = (control >> VID_SHIFT) & VID_MASK; | ||
| 969 | } | ||
| 970 | |||
| 971 | dprintk(" %d : fid 0x%x, vid 0x%x\n", i, fid, vid); | ||
| 972 | |||
| 973 | index = fid | (vid<<8); | ||
| 974 | powernow_table[i].index = index; | ||
| 975 | |||
| 976 | freq = find_khz_freq_from_fid(fid); | ||
| 977 | powernow_table[i].frequency = freq; | ||
| 978 | |||
| 979 | /* verify frequency is OK */ | ||
| 980 | if ((freq > (MAX_FREQ * 1000)) || (freq < (MIN_FREQ * 1000))) { | ||
| 981 | dprintk("invalid freq %u kHz, ignoring\n", freq); | ||
| 982 | invalidate_entry(powernow_table, i); | ||
| 983 | continue; | ||
| 984 | } | ||
| 985 | |||
| 986 | /* verify voltage is OK - | ||
| 987 | * BIOSs are using "off" to indicate invalid */ | ||
| 988 | if (vid == VID_OFF) { | ||
| 989 | dprintk("invalid vid %u, ignoring\n", vid); | ||
| 990 | invalidate_entry(powernow_table, i); | ||
| 991 | continue; | ||
| 992 | } | ||
| 993 | |||
| 994 | if (freq != (data->acpi_data.states[i].core_frequency * 1000)) { | ||
| 995 | printk(KERN_INFO PFX "invalid freq entries " | ||
| 996 | "%u kHz vs. %u kHz\n", freq, | ||
| 997 | (unsigned int) | ||
| 998 | (data->acpi_data.states[i].core_frequency | ||
| 999 | * 1000)); | ||
| 1000 | invalidate_entry(powernow_table, i); | ||
| 1001 | continue; | ||
| 1002 | } | ||
| 1003 | } | ||
| 1004 | return 0; | ||
| 1005 | } | ||
| 1006 | |||
| 1007 | static void powernow_k8_cpu_exit_acpi(struct powernow_k8_data *data) | ||
| 1008 | { | ||
| 1009 | if (data->acpi_data.state_count) | ||
| 1010 | acpi_processor_unregister_performance(&data->acpi_data, | ||
| 1011 | data->cpu); | ||
| 1012 | free_cpumask_var(data->acpi_data.shared_cpu_map); | ||
| 1013 | } | ||
| 1014 | |||
| 1015 | static int get_transition_latency(struct powernow_k8_data *data) | ||
| 1016 | { | ||
| 1017 | int max_latency = 0; | ||
| 1018 | int i; | ||
| 1019 | for (i = 0; i < data->acpi_data.state_count; i++) { | ||
| 1020 | int cur_latency = data->acpi_data.states[i].transition_latency | ||
| 1021 | + data->acpi_data.states[i].bus_master_latency; | ||
| 1022 | if (cur_latency > max_latency) | ||
| 1023 | max_latency = cur_latency; | ||
| 1024 | } | ||
| 1025 | if (max_latency == 0) { | ||
| 1026 | /* | ||
| 1027 | * Fam 11h and later may return 0 as transition latency. This | ||
| 1028 | * is intended and means "very fast". While cpufreq core and | ||
| 1029 | * governors currently can handle that gracefully, better set it | ||
| 1030 | * to 1 to avoid problems in the future. | ||
| 1031 | */ | ||
| 1032 | if (boot_cpu_data.x86 < 0x11) | ||
| 1033 | printk(KERN_ERR FW_WARN PFX "Invalid zero transition " | ||
| 1034 | "latency\n"); | ||
| 1035 | max_latency = 1; | ||
| 1036 | } | ||
| 1037 | /* value in usecs, needs to be in nanoseconds */ | ||
| 1038 | return 1000 * max_latency; | ||
| 1039 | } | ||
| 1040 | |||
| 1041 | /* Take a frequency, and issue the fid/vid transition command */ | ||
| 1042 | static int transition_frequency_fidvid(struct powernow_k8_data *data, | ||
| 1043 | unsigned int index) | ||
| 1044 | { | ||
| 1045 | u32 fid = 0; | ||
| 1046 | u32 vid = 0; | ||
| 1047 | int res, i; | ||
| 1048 | struct cpufreq_freqs freqs; | ||
| 1049 | |||
| 1050 | dprintk("cpu %d transition to index %u\n", smp_processor_id(), index); | ||
| 1051 | |||
| 1052 | /* fid/vid correctness check for k8 */ | ||
| 1053 | /* fid are the lower 8 bits of the index we stored into | ||
| 1054 | * the cpufreq frequency table in find_psb_table, vid | ||
| 1055 | * are the upper 8 bits. | ||
| 1056 | */ | ||
| 1057 | fid = data->powernow_table[index].index & 0xFF; | ||
| 1058 | vid = (data->powernow_table[index].index & 0xFF00) >> 8; | ||
| 1059 | |||
| 1060 | dprintk("table matched fid 0x%x, giving vid 0x%x\n", fid, vid); | ||
| 1061 | |||
| 1062 | if (query_current_values_with_pending_wait(data)) | ||
| 1063 | return 1; | ||
| 1064 | |||
| 1065 | if ((data->currvid == vid) && (data->currfid == fid)) { | ||
| 1066 | dprintk("target matches current values (fid 0x%x, vid 0x%x)\n", | ||
| 1067 | fid, vid); | ||
| 1068 | return 0; | ||
| 1069 | } | ||
| 1070 | |||
| 1071 | dprintk("cpu %d, changing to fid 0x%x, vid 0x%x\n", | ||
| 1072 | smp_processor_id(), fid, vid); | ||
| 1073 | freqs.old = find_khz_freq_from_fid(data->currfid); | ||
| 1074 | freqs.new = find_khz_freq_from_fid(fid); | ||
| 1075 | |||
| 1076 | for_each_cpu(i, data->available_cores) { | ||
| 1077 | freqs.cpu = i; | ||
| 1078 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
| 1079 | } | ||
| 1080 | |||
| 1081 | res = transition_fid_vid(data, fid, vid); | ||
| 1082 | freqs.new = find_khz_freq_from_fid(data->currfid); | ||
| 1083 | |||
| 1084 | for_each_cpu(i, data->available_cores) { | ||
| 1085 | freqs.cpu = i; | ||
| 1086 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 1087 | } | ||
| 1088 | return res; | ||
| 1089 | } | ||
| 1090 | |||
| 1091 | /* Take a frequency, and issue the hardware pstate transition command */ | ||
| 1092 | static int transition_frequency_pstate(struct powernow_k8_data *data, | ||
| 1093 | unsigned int index) | ||
| 1094 | { | ||
| 1095 | u32 pstate = 0; | ||
| 1096 | int res, i; | ||
| 1097 | struct cpufreq_freqs freqs; | ||
| 1098 | |||
| 1099 | dprintk("cpu %d transition to index %u\n", smp_processor_id(), index); | ||
| 1100 | |||
| 1101 | /* get MSR index for hardware pstate transition */ | ||
| 1102 | pstate = index & HW_PSTATE_MASK; | ||
| 1103 | if (pstate > data->max_hw_pstate) | ||
| 1104 | return 0; | ||
| 1105 | freqs.old = find_khz_freq_from_pstate(data->powernow_table, | ||
| 1106 | data->currpstate); | ||
| 1107 | freqs.new = find_khz_freq_from_pstate(data->powernow_table, pstate); | ||
| 1108 | |||
| 1109 | for_each_cpu(i, data->available_cores) { | ||
| 1110 | freqs.cpu = i; | ||
| 1111 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
| 1112 | } | ||
| 1113 | |||
| 1114 | res = transition_pstate(data, pstate); | ||
| 1115 | freqs.new = find_khz_freq_from_pstate(data->powernow_table, pstate); | ||
| 1116 | |||
| 1117 | for_each_cpu(i, data->available_cores) { | ||
| 1118 | freqs.cpu = i; | ||
| 1119 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 1120 | } | ||
| 1121 | return res; | ||
| 1122 | } | ||
| 1123 | |||
| 1124 | /* Driver entry point to switch to the target frequency */ | ||
| 1125 | static int powernowk8_target(struct cpufreq_policy *pol, | ||
| 1126 | unsigned targfreq, unsigned relation) | ||
| 1127 | { | ||
| 1128 | cpumask_var_t oldmask; | ||
| 1129 | struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); | ||
| 1130 | u32 checkfid; | ||
| 1131 | u32 checkvid; | ||
| 1132 | unsigned int newstate; | ||
| 1133 | int ret = -EIO; | ||
| 1134 | |||
| 1135 | if (!data) | ||
| 1136 | return -EINVAL; | ||
| 1137 | |||
| 1138 | checkfid = data->currfid; | ||
| 1139 | checkvid = data->currvid; | ||
| 1140 | |||
| 1141 | /* only run on specific CPU from here on. */ | ||
| 1142 | /* This is poor form: use a workqueue or smp_call_function_single */ | ||
| 1143 | if (!alloc_cpumask_var(&oldmask, GFP_KERNEL)) | ||
| 1144 | return -ENOMEM; | ||
| 1145 | |||
| 1146 | cpumask_copy(oldmask, tsk_cpus_allowed(current)); | ||
| 1147 | set_cpus_allowed_ptr(current, cpumask_of(pol->cpu)); | ||
| 1148 | |||
| 1149 | if (smp_processor_id() != pol->cpu) { | ||
| 1150 | printk(KERN_ERR PFX "limiting to cpu %u failed\n", pol->cpu); | ||
| 1151 | goto err_out; | ||
| 1152 | } | ||
| 1153 | |||
| 1154 | if (pending_bit_stuck()) { | ||
| 1155 | printk(KERN_ERR PFX "failing targ, change pending bit set\n"); | ||
| 1156 | goto err_out; | ||
| 1157 | } | ||
| 1158 | |||
| 1159 | dprintk("targ: cpu %d, %d kHz, min %d, max %d, relation %d\n", | ||
| 1160 | pol->cpu, targfreq, pol->min, pol->max, relation); | ||
| 1161 | |||
| 1162 | if (query_current_values_with_pending_wait(data)) | ||
| 1163 | goto err_out; | ||
| 1164 | |||
| 1165 | if (cpu_family != CPU_HW_PSTATE) { | ||
| 1166 | dprintk("targ: curr fid 0x%x, vid 0x%x\n", | ||
| 1167 | data->currfid, data->currvid); | ||
| 1168 | |||
| 1169 | if ((checkvid != data->currvid) || | ||
| 1170 | (checkfid != data->currfid)) { | ||
| 1171 | printk(KERN_INFO PFX | ||
| 1172 | "error - out of sync, fix 0x%x 0x%x, " | ||
| 1173 | "vid 0x%x 0x%x\n", | ||
| 1174 | checkfid, data->currfid, | ||
| 1175 | checkvid, data->currvid); | ||
| 1176 | } | ||
| 1177 | } | ||
| 1178 | |||
| 1179 | if (cpufreq_frequency_table_target(pol, data->powernow_table, | ||
| 1180 | targfreq, relation, &newstate)) | ||
| 1181 | goto err_out; | ||
| 1182 | |||
| 1183 | mutex_lock(&fidvid_mutex); | ||
| 1184 | |||
| 1185 | powernow_k8_acpi_pst_values(data, newstate); | ||
| 1186 | |||
| 1187 | if (cpu_family == CPU_HW_PSTATE) | ||
| 1188 | ret = transition_frequency_pstate(data, newstate); | ||
| 1189 | else | ||
| 1190 | ret = transition_frequency_fidvid(data, newstate); | ||
| 1191 | if (ret) { | ||
| 1192 | printk(KERN_ERR PFX "transition frequency failed\n"); | ||
| 1193 | ret = 1; | ||
| 1194 | mutex_unlock(&fidvid_mutex); | ||
| 1195 | goto err_out; | ||
| 1196 | } | ||
| 1197 | mutex_unlock(&fidvid_mutex); | ||
| 1198 | |||
| 1199 | if (cpu_family == CPU_HW_PSTATE) | ||
| 1200 | pol->cur = find_khz_freq_from_pstate(data->powernow_table, | ||
| 1201 | newstate); | ||
| 1202 | else | ||
| 1203 | pol->cur = find_khz_freq_from_fid(data->currfid); | ||
| 1204 | ret = 0; | ||
| 1205 | |||
| 1206 | err_out: | ||
| 1207 | set_cpus_allowed_ptr(current, oldmask); | ||
| 1208 | free_cpumask_var(oldmask); | ||
| 1209 | return ret; | ||
| 1210 | } | ||
| 1211 | |||
| 1212 | /* Driver entry point to verify the policy and range of frequencies */ | ||
| 1213 | static int powernowk8_verify(struct cpufreq_policy *pol) | ||
| 1214 | { | ||
| 1215 | struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); | ||
| 1216 | |||
| 1217 | if (!data) | ||
| 1218 | return -EINVAL; | ||
| 1219 | |||
| 1220 | return cpufreq_frequency_table_verify(pol, data->powernow_table); | ||
| 1221 | } | ||
| 1222 | |||
| 1223 | struct init_on_cpu { | ||
| 1224 | struct powernow_k8_data *data; | ||
| 1225 | int rc; | ||
| 1226 | }; | ||
| 1227 | |||
| 1228 | static void __cpuinit powernowk8_cpu_init_on_cpu(void *_init_on_cpu) | ||
| 1229 | { | ||
| 1230 | struct init_on_cpu *init_on_cpu = _init_on_cpu; | ||
| 1231 | |||
| 1232 | if (pending_bit_stuck()) { | ||
| 1233 | printk(KERN_ERR PFX "failing init, change pending bit set\n"); | ||
| 1234 | init_on_cpu->rc = -ENODEV; | ||
| 1235 | return; | ||
| 1236 | } | ||
| 1237 | |||
| 1238 | if (query_current_values_with_pending_wait(init_on_cpu->data)) { | ||
| 1239 | init_on_cpu->rc = -ENODEV; | ||
| 1240 | return; | ||
| 1241 | } | ||
| 1242 | |||
| 1243 | if (cpu_family == CPU_OPTERON) | ||
| 1244 | fidvid_msr_init(); | ||
| 1245 | |||
| 1246 | init_on_cpu->rc = 0; | ||
| 1247 | } | ||
| 1248 | |||
| 1249 | /* per CPU init entry point to the driver */ | ||
| 1250 | static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol) | ||
| 1251 | { | ||
| 1252 | static const char ACPI_PSS_BIOS_BUG_MSG[] = | ||
| 1253 | KERN_ERR FW_BUG PFX "No compatible ACPI _PSS objects found.\n" | ||
| 1254 | FW_BUG PFX "Try again with latest BIOS.\n"; | ||
| 1255 | struct powernow_k8_data *data; | ||
| 1256 | struct init_on_cpu init_on_cpu; | ||
| 1257 | int rc; | ||
| 1258 | struct cpuinfo_x86 *c = &cpu_data(pol->cpu); | ||
| 1259 | |||
| 1260 | if (!cpu_online(pol->cpu)) | ||
| 1261 | return -ENODEV; | ||
| 1262 | |||
| 1263 | smp_call_function_single(pol->cpu, check_supported_cpu, &rc, 1); | ||
| 1264 | if (rc) | ||
| 1265 | return -ENODEV; | ||
| 1266 | |||
| 1267 | data = kzalloc(sizeof(struct powernow_k8_data), GFP_KERNEL); | ||
| 1268 | if (!data) { | ||
| 1269 | printk(KERN_ERR PFX "unable to alloc powernow_k8_data"); | ||
| 1270 | return -ENOMEM; | ||
| 1271 | } | ||
| 1272 | |||
| 1273 | data->cpu = pol->cpu; | ||
| 1274 | data->currpstate = HW_PSTATE_INVALID; | ||
| 1275 | |||
| 1276 | if (powernow_k8_cpu_init_acpi(data)) { | ||
| 1277 | /* | ||
| 1278 | * Use the PSB BIOS structure. This is only available on | ||
| 1279 | * an UP version, and is deprecated by AMD. | ||
| 1280 | */ | ||
| 1281 | if (num_online_cpus() != 1) { | ||
| 1282 | printk_once(ACPI_PSS_BIOS_BUG_MSG); | ||
| 1283 | goto err_out; | ||
| 1284 | } | ||
| 1285 | if (pol->cpu != 0) { | ||
| 1286 | printk(KERN_ERR FW_BUG PFX "No ACPI _PSS objects for " | ||
| 1287 | "CPU other than CPU0. Complain to your BIOS " | ||
| 1288 | "vendor.\n"); | ||
| 1289 | goto err_out; | ||
| 1290 | } | ||
| 1291 | rc = find_psb_table(data); | ||
| 1292 | if (rc) | ||
| 1293 | goto err_out; | ||
| 1294 | |||
| 1295 | /* Take a crude guess here. | ||
| 1296 | * That guess was in microseconds, so multiply with 1000 */ | ||
| 1297 | pol->cpuinfo.transition_latency = ( | ||
| 1298 | ((data->rvo + 8) * data->vstable * VST_UNITS_20US) + | ||
| 1299 | ((1 << data->irt) * 30)) * 1000; | ||
| 1300 | } else /* ACPI _PSS objects available */ | ||
| 1301 | pol->cpuinfo.transition_latency = get_transition_latency(data); | ||
| 1302 | |||
| 1303 | /* only run on specific CPU from here on */ | ||
| 1304 | init_on_cpu.data = data; | ||
| 1305 | smp_call_function_single(data->cpu, powernowk8_cpu_init_on_cpu, | ||
| 1306 | &init_on_cpu, 1); | ||
| 1307 | rc = init_on_cpu.rc; | ||
| 1308 | if (rc != 0) | ||
| 1309 | goto err_out_exit_acpi; | ||
| 1310 | |||
| 1311 | if (cpu_family == CPU_HW_PSTATE) | ||
| 1312 | cpumask_copy(pol->cpus, cpumask_of(pol->cpu)); | ||
| 1313 | else | ||
| 1314 | cpumask_copy(pol->cpus, cpu_core_mask(pol->cpu)); | ||
| 1315 | data->available_cores = pol->cpus; | ||
| 1316 | |||
| 1317 | if (cpu_family == CPU_HW_PSTATE) | ||
| 1318 | pol->cur = find_khz_freq_from_pstate(data->powernow_table, | ||
| 1319 | data->currpstate); | ||
| 1320 | else | ||
| 1321 | pol->cur = find_khz_freq_from_fid(data->currfid); | ||
| 1322 | dprintk("policy current frequency %d kHz\n", pol->cur); | ||
| 1323 | |||
| 1324 | /* min/max the cpu is capable of */ | ||
| 1325 | if (cpufreq_frequency_table_cpuinfo(pol, data->powernow_table)) { | ||
| 1326 | printk(KERN_ERR FW_BUG PFX "invalid powernow_table\n"); | ||
| 1327 | powernow_k8_cpu_exit_acpi(data); | ||
| 1328 | kfree(data->powernow_table); | ||
| 1329 | kfree(data); | ||
| 1330 | return -EINVAL; | ||
| 1331 | } | ||
| 1332 | |||
| 1333 | /* Check for APERF/MPERF support in hardware */ | ||
| 1334 | if (cpu_has(c, X86_FEATURE_APERFMPERF)) | ||
| 1335 | cpufreq_amd64_driver.getavg = cpufreq_get_measured_perf; | ||
| 1336 | |||
| 1337 | cpufreq_frequency_table_get_attr(data->powernow_table, pol->cpu); | ||
| 1338 | |||
| 1339 | if (cpu_family == CPU_HW_PSTATE) | ||
| 1340 | dprintk("cpu_init done, current pstate 0x%x\n", | ||
| 1341 | data->currpstate); | ||
| 1342 | else | ||
| 1343 | dprintk("cpu_init done, current fid 0x%x, vid 0x%x\n", | ||
| 1344 | data->currfid, data->currvid); | ||
| 1345 | |||
| 1346 | per_cpu(powernow_data, pol->cpu) = data; | ||
| 1347 | |||
| 1348 | return 0; | ||
| 1349 | |||
| 1350 | err_out_exit_acpi: | ||
| 1351 | powernow_k8_cpu_exit_acpi(data); | ||
| 1352 | |||
| 1353 | err_out: | ||
| 1354 | kfree(data); | ||
| 1355 | return -ENODEV; | ||
| 1356 | } | ||
| 1357 | |||
| 1358 | static int __devexit powernowk8_cpu_exit(struct cpufreq_policy *pol) | ||
| 1359 | { | ||
| 1360 | struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); | ||
| 1361 | |||
| 1362 | if (!data) | ||
| 1363 | return -EINVAL; | ||
| 1364 | |||
| 1365 | powernow_k8_cpu_exit_acpi(data); | ||
| 1366 | |||
| 1367 | cpufreq_frequency_table_put_attr(pol->cpu); | ||
| 1368 | |||
| 1369 | kfree(data->powernow_table); | ||
| 1370 | kfree(data); | ||
| 1371 | per_cpu(powernow_data, pol->cpu) = NULL; | ||
| 1372 | |||
| 1373 | return 0; | ||
| 1374 | } | ||
| 1375 | |||
| 1376 | static void query_values_on_cpu(void *_err) | ||
| 1377 | { | ||
| 1378 | int *err = _err; | ||
| 1379 | struct powernow_k8_data *data = __this_cpu_read(powernow_data); | ||
| 1380 | |||
| 1381 | *err = query_current_values_with_pending_wait(data); | ||
| 1382 | } | ||
| 1383 | |||
| 1384 | static unsigned int powernowk8_get(unsigned int cpu) | ||
| 1385 | { | ||
| 1386 | struct powernow_k8_data *data = per_cpu(powernow_data, cpu); | ||
| 1387 | unsigned int khz = 0; | ||
| 1388 | int err; | ||
| 1389 | |||
| 1390 | if (!data) | ||
| 1391 | return 0; | ||
| 1392 | |||
| 1393 | smp_call_function_single(cpu, query_values_on_cpu, &err, true); | ||
| 1394 | if (err) | ||
| 1395 | goto out; | ||
| 1396 | |||
| 1397 | if (cpu_family == CPU_HW_PSTATE) | ||
| 1398 | khz = find_khz_freq_from_pstate(data->powernow_table, | ||
| 1399 | data->currpstate); | ||
| 1400 | else | ||
| 1401 | khz = find_khz_freq_from_fid(data->currfid); | ||
| 1402 | |||
| 1403 | |||
| 1404 | out: | ||
| 1405 | return khz; | ||
| 1406 | } | ||
| 1407 | |||
| 1408 | static void _cpb_toggle_msrs(bool t) | ||
| 1409 | { | ||
| 1410 | int cpu; | ||
| 1411 | |||
| 1412 | get_online_cpus(); | ||
| 1413 | |||
| 1414 | rdmsr_on_cpus(cpu_online_mask, MSR_K7_HWCR, msrs); | ||
| 1415 | |||
| 1416 | for_each_cpu(cpu, cpu_online_mask) { | ||
| 1417 | struct msr *reg = per_cpu_ptr(msrs, cpu); | ||
| 1418 | if (t) | ||
| 1419 | reg->l &= ~BIT(25); | ||
| 1420 | else | ||
| 1421 | reg->l |= BIT(25); | ||
| 1422 | } | ||
| 1423 | wrmsr_on_cpus(cpu_online_mask, MSR_K7_HWCR, msrs); | ||
| 1424 | |||
| 1425 | put_online_cpus(); | ||
| 1426 | } | ||
| 1427 | |||
| 1428 | /* | ||
| 1429 | * Switch on/off core performance boosting. | ||
| 1430 | * | ||
| 1431 | * 0=disable | ||
| 1432 | * 1=enable. | ||
| 1433 | */ | ||
| 1434 | static void cpb_toggle(bool t) | ||
| 1435 | { | ||
| 1436 | if (!cpb_capable) | ||
| 1437 | return; | ||
| 1438 | |||
| 1439 | if (t && !cpb_enabled) { | ||
| 1440 | cpb_enabled = true; | ||
| 1441 | _cpb_toggle_msrs(t); | ||
| 1442 | printk(KERN_INFO PFX "Core Boosting enabled.\n"); | ||
| 1443 | } else if (!t && cpb_enabled) { | ||
| 1444 | cpb_enabled = false; | ||
| 1445 | _cpb_toggle_msrs(t); | ||
| 1446 | printk(KERN_INFO PFX "Core Boosting disabled.\n"); | ||
| 1447 | } | ||
| 1448 | } | ||
| 1449 | |||
| 1450 | static ssize_t store_cpb(struct cpufreq_policy *policy, const char *buf, | ||
| 1451 | size_t count) | ||
| 1452 | { | ||
| 1453 | int ret = -EINVAL; | ||
| 1454 | unsigned long val = 0; | ||
| 1455 | |||
| 1456 | ret = strict_strtoul(buf, 10, &val); | ||
| 1457 | if (!ret && (val == 0 || val == 1) && cpb_capable) | ||
| 1458 | cpb_toggle(val); | ||
| 1459 | else | ||
| 1460 | return -EINVAL; | ||
| 1461 | |||
| 1462 | return count; | ||
| 1463 | } | ||
| 1464 | |||
| 1465 | static ssize_t show_cpb(struct cpufreq_policy *policy, char *buf) | ||
| 1466 | { | ||
| 1467 | return sprintf(buf, "%u\n", cpb_enabled); | ||
| 1468 | } | ||
| 1469 | |||
| 1470 | #define define_one_rw(_name) \ | ||
| 1471 | static struct freq_attr _name = \ | ||
| 1472 | __ATTR(_name, 0644, show_##_name, store_##_name) | ||
| 1473 | |||
| 1474 | define_one_rw(cpb); | ||
| 1475 | |||
| 1476 | static struct freq_attr *powernow_k8_attr[] = { | ||
| 1477 | &cpufreq_freq_attr_scaling_available_freqs, | ||
| 1478 | &cpb, | ||
| 1479 | NULL, | ||
| 1480 | }; | ||
| 1481 | |||
| 1482 | static struct cpufreq_driver cpufreq_amd64_driver = { | ||
| 1483 | .verify = powernowk8_verify, | ||
| 1484 | .target = powernowk8_target, | ||
| 1485 | .bios_limit = acpi_processor_get_bios_limit, | ||
| 1486 | .init = powernowk8_cpu_init, | ||
| 1487 | .exit = __devexit_p(powernowk8_cpu_exit), | ||
| 1488 | .get = powernowk8_get, | ||
| 1489 | .name = "powernow-k8", | ||
| 1490 | .owner = THIS_MODULE, | ||
| 1491 | .attr = powernow_k8_attr, | ||
| 1492 | }; | ||
| 1493 | |||
| 1494 | /* | ||
| 1495 | * Clear the boost-disable flag on the CPU_DOWN path so that this cpu | ||
| 1496 | * cannot block the remaining ones from boosting. On the CPU_UP path we | ||
| 1497 | * simply keep the boost-disable flag in sync with the current global | ||
| 1498 | * state. | ||
| 1499 | */ | ||
| 1500 | static int cpb_notify(struct notifier_block *nb, unsigned long action, | ||
| 1501 | void *hcpu) | ||
| 1502 | { | ||
| 1503 | unsigned cpu = (long)hcpu; | ||
| 1504 | u32 lo, hi; | ||
| 1505 | |||
| 1506 | switch (action) { | ||
| 1507 | case CPU_UP_PREPARE: | ||
| 1508 | case CPU_UP_PREPARE_FROZEN: | ||
| 1509 | |||
| 1510 | if (!cpb_enabled) { | ||
| 1511 | rdmsr_on_cpu(cpu, MSR_K7_HWCR, &lo, &hi); | ||
| 1512 | lo |= BIT(25); | ||
| 1513 | wrmsr_on_cpu(cpu, MSR_K7_HWCR, lo, hi); | ||
| 1514 | } | ||
| 1515 | break; | ||
| 1516 | |||
| 1517 | case CPU_DOWN_PREPARE: | ||
| 1518 | case CPU_DOWN_PREPARE_FROZEN: | ||
| 1519 | rdmsr_on_cpu(cpu, MSR_K7_HWCR, &lo, &hi); | ||
| 1520 | lo &= ~BIT(25); | ||
| 1521 | wrmsr_on_cpu(cpu, MSR_K7_HWCR, lo, hi); | ||
| 1522 | break; | ||
| 1523 | |||
| 1524 | default: | ||
| 1525 | break; | ||
| 1526 | } | ||
| 1527 | |||
| 1528 | return NOTIFY_OK; | ||
| 1529 | } | ||
| 1530 | |||
| 1531 | static struct notifier_block cpb_nb = { | ||
| 1532 | .notifier_call = cpb_notify, | ||
| 1533 | }; | ||
| 1534 | |||
| 1535 | /* driver entry point for init */ | ||
| 1536 | static int __cpuinit powernowk8_init(void) | ||
| 1537 | { | ||
| 1538 | unsigned int i, supported_cpus = 0, cpu; | ||
| 1539 | int rv; | ||
| 1540 | |||
| 1541 | for_each_online_cpu(i) { | ||
| 1542 | int rc; | ||
| 1543 | smp_call_function_single(i, check_supported_cpu, &rc, 1); | ||
| 1544 | if (rc == 0) | ||
| 1545 | supported_cpus++; | ||
| 1546 | } | ||
| 1547 | |||
| 1548 | if (supported_cpus != num_online_cpus()) | ||
| 1549 | return -ENODEV; | ||
| 1550 | |||
| 1551 | printk(KERN_INFO PFX "Found %d %s (%d cpu cores) (" VERSION ")\n", | ||
| 1552 | num_online_nodes(), boot_cpu_data.x86_model_id, supported_cpus); | ||
| 1553 | |||
| 1554 | if (boot_cpu_has(X86_FEATURE_CPB)) { | ||
| 1555 | |||
| 1556 | cpb_capable = true; | ||
| 1557 | |||
| 1558 | msrs = msrs_alloc(); | ||
| 1559 | if (!msrs) { | ||
| 1560 | printk(KERN_ERR "%s: Error allocating msrs!\n", __func__); | ||
| 1561 | return -ENOMEM; | ||
| 1562 | } | ||
| 1563 | |||
| 1564 | register_cpu_notifier(&cpb_nb); | ||
| 1565 | |||
| 1566 | rdmsr_on_cpus(cpu_online_mask, MSR_K7_HWCR, msrs); | ||
| 1567 | |||
| 1568 | for_each_cpu(cpu, cpu_online_mask) { | ||
| 1569 | struct msr *reg = per_cpu_ptr(msrs, cpu); | ||
| 1570 | cpb_enabled |= !(!!(reg->l & BIT(25))); | ||
| 1571 | } | ||
| 1572 | |||
| 1573 | printk(KERN_INFO PFX "Core Performance Boosting: %s.\n", | ||
| 1574 | (cpb_enabled ? "on" : "off")); | ||
| 1575 | } | ||
| 1576 | |||
| 1577 | rv = cpufreq_register_driver(&cpufreq_amd64_driver); | ||
| 1578 | if (rv < 0 && boot_cpu_has(X86_FEATURE_CPB)) { | ||
| 1579 | unregister_cpu_notifier(&cpb_nb); | ||
| 1580 | msrs_free(msrs); | ||
| 1581 | msrs = NULL; | ||
| 1582 | } | ||
| 1583 | return rv; | ||
| 1584 | } | ||
| 1585 | |||
| 1586 | /* driver entry point for term */ | ||
| 1587 | static void __exit powernowk8_exit(void) | ||
| 1588 | { | ||
| 1589 | dprintk("exit\n"); | ||
| 1590 | |||
| 1591 | if (boot_cpu_has(X86_FEATURE_CPB)) { | ||
| 1592 | msrs_free(msrs); | ||
| 1593 | msrs = NULL; | ||
| 1594 | |||
| 1595 | unregister_cpu_notifier(&cpb_nb); | ||
| 1596 | } | ||
| 1597 | |||
| 1598 | cpufreq_unregister_driver(&cpufreq_amd64_driver); | ||
| 1599 | } | ||
| 1600 | |||
| 1601 | MODULE_AUTHOR("Paul Devriendt <paul.devriendt@amd.com> and " | ||
| 1602 | "Mark Langsdorf <mark.langsdorf@amd.com>"); | ||
| 1603 | MODULE_DESCRIPTION("AMD Athlon 64 and Opteron processor frequency driver."); | ||
| 1604 | MODULE_LICENSE("GPL"); | ||
| 1605 | |||
| 1606 | late_initcall(powernowk8_init); | ||
| 1607 | module_exit(powernowk8_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k8.h b/arch/x86/kernel/cpu/cpufreq/powernow-k8.h deleted file mode 100644 index df3529b1c02d..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/powernow-k8.h +++ /dev/null | |||
| @@ -1,224 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * (c) 2003-2006 Advanced Micro Devices, Inc. | ||
| 3 | * Your use of this code is subject to the terms and conditions of the | ||
| 4 | * GNU general public license version 2. See "COPYING" or | ||
| 5 | * http://www.gnu.org/licenses/gpl.html | ||
| 6 | */ | ||
| 7 | |||
| 8 | enum pstate { | ||
| 9 | HW_PSTATE_INVALID = 0xff, | ||
| 10 | HW_PSTATE_0 = 0, | ||
| 11 | HW_PSTATE_1 = 1, | ||
| 12 | HW_PSTATE_2 = 2, | ||
| 13 | HW_PSTATE_3 = 3, | ||
| 14 | HW_PSTATE_4 = 4, | ||
| 15 | HW_PSTATE_5 = 5, | ||
| 16 | HW_PSTATE_6 = 6, | ||
| 17 | HW_PSTATE_7 = 7, | ||
| 18 | }; | ||
| 19 | |||
| 20 | struct powernow_k8_data { | ||
| 21 | unsigned int cpu; | ||
| 22 | |||
| 23 | u32 numps; /* number of p-states */ | ||
| 24 | u32 batps; /* number of p-states supported on battery */ | ||
| 25 | u32 max_hw_pstate; /* maximum legal hardware pstate */ | ||
| 26 | |||
| 27 | /* these values are constant when the PSB is used to determine | ||
| 28 | * vid/fid pairings, but are modified during the ->target() call | ||
| 29 | * when ACPI is used */ | ||
| 30 | u32 rvo; /* ramp voltage offset */ | ||
| 31 | u32 irt; /* isochronous relief time */ | ||
| 32 | u32 vidmvs; /* usable value calculated from mvs */ | ||
| 33 | u32 vstable; /* voltage stabilization time, units 20 us */ | ||
| 34 | u32 plllock; /* pll lock time, units 1 us */ | ||
| 35 | u32 exttype; /* extended interface = 1 */ | ||
| 36 | |||
| 37 | /* keep track of the current fid / vid or pstate */ | ||
| 38 | u32 currvid; | ||
| 39 | u32 currfid; | ||
| 40 | enum pstate currpstate; | ||
| 41 | |||
| 42 | /* the powernow_table includes all frequency and vid/fid pairings: | ||
| 43 | * fid are the lower 8 bits of the index, vid are the upper 8 bits. | ||
| 44 | * frequency is in kHz */ | ||
| 45 | struct cpufreq_frequency_table *powernow_table; | ||
| 46 | |||
| 47 | /* the acpi table needs to be kept. it's only available if ACPI was | ||
| 48 | * used to determine valid frequency/vid/fid states */ | ||
| 49 | struct acpi_processor_performance acpi_data; | ||
| 50 | |||
| 51 | /* we need to keep track of associated cores, but let cpufreq | ||
| 52 | * handle hotplug events - so just point at cpufreq pol->cpus | ||
| 53 | * structure */ | ||
| 54 | struct cpumask *available_cores; | ||
| 55 | }; | ||
| 56 | |||
| 57 | /* processor's cpuid instruction support */ | ||
| 58 | #define CPUID_PROCESSOR_SIGNATURE 1 /* function 1 */ | ||
| 59 | #define CPUID_XFAM 0x0ff00000 /* extended family */ | ||
| 60 | #define CPUID_XFAM_K8 0 | ||
| 61 | #define CPUID_XMOD 0x000f0000 /* extended model */ | ||
| 62 | #define CPUID_XMOD_REV_MASK 0x000c0000 | ||
| 63 | #define CPUID_XFAM_10H 0x00100000 /* family 0x10 */ | ||
| 64 | #define CPUID_USE_XFAM_XMOD 0x00000f00 | ||
| 65 | #define CPUID_GET_MAX_CAPABILITIES 0x80000000 | ||
| 66 | #define CPUID_FREQ_VOLT_CAPABILITIES 0x80000007 | ||
| 67 | #define P_STATE_TRANSITION_CAPABLE 6 | ||
| 68 | |||
| 69 | /* Model Specific Registers for p-state transitions. MSRs are 64-bit. For */ | ||
| 70 | /* writes (wrmsr - opcode 0f 30), the register number is placed in ecx, and */ | ||
| 71 | /* the value to write is placed in edx:eax. For reads (rdmsr - opcode 0f 32), */ | ||
| 72 | /* the register number is placed in ecx, and the data is returned in edx:eax. */ | ||
| 73 | |||
| 74 | #define MSR_FIDVID_CTL 0xc0010041 | ||
| 75 | #define MSR_FIDVID_STATUS 0xc0010042 | ||
| 76 | |||
| 77 | /* Field definitions within the FID VID Low Control MSR : */ | ||
| 78 | #define MSR_C_LO_INIT_FID_VID 0x00010000 | ||
| 79 | #define MSR_C_LO_NEW_VID 0x00003f00 | ||
| 80 | #define MSR_C_LO_NEW_FID 0x0000003f | ||
| 81 | #define MSR_C_LO_VID_SHIFT 8 | ||
| 82 | |||
| 83 | /* Field definitions within the FID VID High Control MSR : */ | ||
| 84 | #define MSR_C_HI_STP_GNT_TO 0x000fffff | ||
| 85 | |||
| 86 | /* Field definitions within the FID VID Low Status MSR : */ | ||
| 87 | #define MSR_S_LO_CHANGE_PENDING 0x80000000 /* cleared when completed */ | ||
| 88 | #define MSR_S_LO_MAX_RAMP_VID 0x3f000000 | ||
| 89 | #define MSR_S_LO_MAX_FID 0x003f0000 | ||
| 90 | #define MSR_S_LO_START_FID 0x00003f00 | ||
| 91 | #define MSR_S_LO_CURRENT_FID 0x0000003f | ||
| 92 | |||
| 93 | /* Field definitions within the FID VID High Status MSR : */ | ||
| 94 | #define MSR_S_HI_MIN_WORKING_VID 0x3f000000 | ||
| 95 | #define MSR_S_HI_MAX_WORKING_VID 0x003f0000 | ||
| 96 | #define MSR_S_HI_START_VID 0x00003f00 | ||
| 97 | #define MSR_S_HI_CURRENT_VID 0x0000003f | ||
| 98 | #define MSR_C_HI_STP_GNT_BENIGN 0x00000001 | ||
| 99 | |||
| 100 | |||
| 101 | /* Hardware Pstate _PSS and MSR definitions */ | ||
| 102 | #define USE_HW_PSTATE 0x00000080 | ||
| 103 | #define HW_PSTATE_MASK 0x00000007 | ||
| 104 | #define HW_PSTATE_VALID_MASK 0x80000000 | ||
| 105 | #define HW_PSTATE_MAX_MASK 0x000000f0 | ||
| 106 | #define HW_PSTATE_MAX_SHIFT 4 | ||
| 107 | #define MSR_PSTATE_DEF_BASE 0xc0010064 /* base of Pstate MSRs */ | ||
| 108 | #define MSR_PSTATE_STATUS 0xc0010063 /* Pstate Status MSR */ | ||
| 109 | #define MSR_PSTATE_CTRL 0xc0010062 /* Pstate control MSR */ | ||
| 110 | #define MSR_PSTATE_CUR_LIMIT 0xc0010061 /* pstate current limit MSR */ | ||
| 111 | |||
| 112 | /* define the two driver architectures */ | ||
| 113 | #define CPU_OPTERON 0 | ||
| 114 | #define CPU_HW_PSTATE 1 | ||
| 115 | |||
| 116 | |||
| 117 | /* | ||
| 118 | * There are restrictions frequencies have to follow: | ||
| 119 | * - only 1 entry in the low fid table ( <=1.4GHz ) | ||
| 120 | * - lowest entry in the high fid table must be >= 2 * the entry in the | ||
| 121 | * low fid table | ||
| 122 | * - lowest entry in the high fid table must be a <= 200MHz + 2 * the entry | ||
| 123 | * in the low fid table | ||
| 124 | * - the parts can only step at <= 200 MHz intervals, odd fid values are | ||
| 125 | * supported in revision G and later revisions. | ||
| 126 | * - lowest frequency must be >= interprocessor hypertransport link speed | ||
| 127 | * (only applies to MP systems obviously) | ||
| 128 | */ | ||
| 129 | |||
| 130 | /* fids (frequency identifiers) are arranged in 2 tables - lo and hi */ | ||
| 131 | #define LO_FID_TABLE_TOP 7 /* fid values marking the boundary */ | ||
| 132 | #define HI_FID_TABLE_BOTTOM 8 /* between the low and high tables */ | ||
| 133 | |||
| 134 | #define LO_VCOFREQ_TABLE_TOP 1400 /* corresponding vco frequency values */ | ||
| 135 | #define HI_VCOFREQ_TABLE_BOTTOM 1600 | ||
| 136 | |||
| 137 | #define MIN_FREQ_RESOLUTION 200 /* fids jump by 2 matching freq jumps by 200 */ | ||
| 138 | |||
| 139 | #define MAX_FID 0x2a /* Spec only gives FID values as far as 5 GHz */ | ||
| 140 | #define LEAST_VID 0x3e /* Lowest (numerically highest) useful vid value */ | ||
| 141 | |||
| 142 | #define MIN_FREQ 800 /* Min and max freqs, per spec */ | ||
| 143 | #define MAX_FREQ 5000 | ||
| 144 | |||
| 145 | #define INVALID_FID_MASK 0xffffffc0 /* not a valid fid if these bits are set */ | ||
| 146 | #define INVALID_VID_MASK 0xffffffc0 /* not a valid vid if these bits are set */ | ||
| 147 | |||
| 148 | #define VID_OFF 0x3f | ||
| 149 | |||
| 150 | #define STOP_GRANT_5NS 1 /* min poss memory access latency for voltage change */ | ||
| 151 | |||
| 152 | #define PLL_LOCK_CONVERSION (1000/5) /* ms to ns, then divide by clock period */ | ||
| 153 | |||
| 154 | #define MAXIMUM_VID_STEPS 1 /* Current cpus only allow a single step of 25mV */ | ||
| 155 | #define VST_UNITS_20US 20 /* Voltage Stabilization Time is in units of 20us */ | ||
| 156 | |||
| 157 | /* | ||
| 158 | * Most values of interest are encoded in a single field of the _PSS | ||
| 159 | * entries: the "control" value. | ||
| 160 | */ | ||
| 161 | |||
| 162 | #define IRT_SHIFT 30 | ||
| 163 | #define RVO_SHIFT 28 | ||
| 164 | #define EXT_TYPE_SHIFT 27 | ||
| 165 | #define PLL_L_SHIFT 20 | ||
| 166 | #define MVS_SHIFT 18 | ||
| 167 | #define VST_SHIFT 11 | ||
| 168 | #define VID_SHIFT 6 | ||
| 169 | #define IRT_MASK 3 | ||
| 170 | #define RVO_MASK 3 | ||
| 171 | #define EXT_TYPE_MASK 1 | ||
| 172 | #define PLL_L_MASK 0x7f | ||
| 173 | #define MVS_MASK 3 | ||
| 174 | #define VST_MASK 0x7f | ||
| 175 | #define VID_MASK 0x1f | ||
| 176 | #define FID_MASK 0x1f | ||
| 177 | #define EXT_VID_MASK 0x3f | ||
| 178 | #define EXT_FID_MASK 0x3f | ||
| 179 | |||
| 180 | |||
| 181 | /* | ||
| 182 | * Version 1.4 of the PSB table. This table is constructed by BIOS and is | ||
| 183 | * to tell the OS's power management driver which VIDs and FIDs are | ||
| 184 | * supported by this particular processor. | ||
| 185 | * If the data in the PSB / PST is wrong, then this driver will program the | ||
| 186 | * wrong values into hardware, which is very likely to lead to a crash. | ||
| 187 | */ | ||
| 188 | |||
| 189 | #define PSB_ID_STRING "AMDK7PNOW!" | ||
| 190 | #define PSB_ID_STRING_LEN 10 | ||
| 191 | |||
| 192 | #define PSB_VERSION_1_4 0x14 | ||
| 193 | |||
| 194 | struct psb_s { | ||
| 195 | u8 signature[10]; | ||
| 196 | u8 tableversion; | ||
| 197 | u8 flags1; | ||
| 198 | u16 vstable; | ||
| 199 | u8 flags2; | ||
| 200 | u8 num_tables; | ||
| 201 | u32 cpuid; | ||
| 202 | u8 plllocktime; | ||
| 203 | u8 maxfid; | ||
| 204 | u8 maxvid; | ||
| 205 | u8 numps; | ||
| 206 | }; | ||
| 207 | |||
| 208 | /* Pairs of fid/vid values are appended to the version 1.4 PSB table. */ | ||
| 209 | struct pst_s { | ||
| 210 | u8 fid; | ||
| 211 | u8 vid; | ||
| 212 | }; | ||
| 213 | |||
| 214 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "powernow-k8", msg) | ||
| 215 | |||
| 216 | static int core_voltage_pre_transition(struct powernow_k8_data *data, | ||
| 217 | u32 reqvid, u32 regfid); | ||
| 218 | static int core_voltage_post_transition(struct powernow_k8_data *data, u32 reqvid); | ||
| 219 | static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid); | ||
| 220 | |||
| 221 | static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index); | ||
| 222 | |||
| 223 | static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table); | ||
| 224 | static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/sc520_freq.c b/arch/x86/kernel/cpu/cpufreq/sc520_freq.c deleted file mode 100644 index 435a996a613a..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/sc520_freq.c +++ /dev/null | |||
| @@ -1,194 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * sc520_freq.c: cpufreq driver for the AMD Elan sc520 | ||
| 3 | * | ||
| 4 | * Copyright (C) 2005 Sean Young <sean@mess.org> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU General Public License | ||
| 8 | * as published by the Free Software Foundation; either version | ||
| 9 | * 2 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * Based on elanfreq.c | ||
| 12 | * | ||
| 13 | * 2005-03-30: - initial revision | ||
| 14 | */ | ||
| 15 | |||
| 16 | #include <linux/kernel.h> | ||
| 17 | #include <linux/module.h> | ||
| 18 | #include <linux/init.h> | ||
| 19 | |||
| 20 | #include <linux/delay.h> | ||
| 21 | #include <linux/cpufreq.h> | ||
| 22 | #include <linux/timex.h> | ||
| 23 | #include <linux/io.h> | ||
| 24 | |||
| 25 | #include <asm/msr.h> | ||
| 26 | |||
| 27 | #define MMCR_BASE 0xfffef000 /* The default base address */ | ||
| 28 | #define OFFS_CPUCTL 0x2 /* CPU Control Register */ | ||
| 29 | |||
| 30 | static __u8 __iomem *cpuctl; | ||
| 31 | |||
| 32 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
| 33 | "sc520_freq", msg) | ||
| 34 | #define PFX "sc520_freq: " | ||
| 35 | |||
| 36 | static struct cpufreq_frequency_table sc520_freq_table[] = { | ||
| 37 | {0x01, 100000}, | ||
| 38 | {0x02, 133000}, | ||
| 39 | {0, CPUFREQ_TABLE_END}, | ||
| 40 | }; | ||
| 41 | |||
| 42 | static unsigned int sc520_freq_get_cpu_frequency(unsigned int cpu) | ||
| 43 | { | ||
| 44 | u8 clockspeed_reg = *cpuctl; | ||
| 45 | |||
| 46 | switch (clockspeed_reg & 0x03) { | ||
| 47 | default: | ||
| 48 | printk(KERN_ERR PFX "error: cpuctl register has unexpected " | ||
| 49 | "value %02x\n", clockspeed_reg); | ||
| 50 | case 0x01: | ||
| 51 | return 100000; | ||
| 52 | case 0x02: | ||
| 53 | return 133000; | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | static void sc520_freq_set_cpu_state(unsigned int state) | ||
| 58 | { | ||
| 59 | |||
| 60 | struct cpufreq_freqs freqs; | ||
| 61 | u8 clockspeed_reg; | ||
| 62 | |||
| 63 | freqs.old = sc520_freq_get_cpu_frequency(0); | ||
| 64 | freqs.new = sc520_freq_table[state].frequency; | ||
| 65 | freqs.cpu = 0; /* AMD Elan is UP */ | ||
| 66 | |||
| 67 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
| 68 | |||
| 69 | dprintk("attempting to set frequency to %i kHz\n", | ||
| 70 | sc520_freq_table[state].frequency); | ||
| 71 | |||
| 72 | local_irq_disable(); | ||
| 73 | |||
| 74 | clockspeed_reg = *cpuctl & ~0x03; | ||
| 75 | *cpuctl = clockspeed_reg | sc520_freq_table[state].index; | ||
| 76 | |||
| 77 | local_irq_enable(); | ||
| 78 | |||
| 79 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 80 | }; | ||
| 81 | |||
| 82 | static int sc520_freq_verify(struct cpufreq_policy *policy) | ||
| 83 | { | ||
| 84 | return cpufreq_frequency_table_verify(policy, &sc520_freq_table[0]); | ||
| 85 | } | ||
| 86 | |||
| 87 | static int sc520_freq_target(struct cpufreq_policy *policy, | ||
| 88 | unsigned int target_freq, | ||
| 89 | unsigned int relation) | ||
| 90 | { | ||
| 91 | unsigned int newstate = 0; | ||
| 92 | |||
| 93 | if (cpufreq_frequency_table_target(policy, sc520_freq_table, | ||
| 94 | target_freq, relation, &newstate)) | ||
| 95 | return -EINVAL; | ||
| 96 | |||
| 97 | sc520_freq_set_cpu_state(newstate); | ||
| 98 | |||
| 99 | return 0; | ||
| 100 | } | ||
| 101 | |||
| 102 | |||
| 103 | /* | ||
| 104 | * Module init and exit code | ||
| 105 | */ | ||
| 106 | |||
| 107 | static int sc520_freq_cpu_init(struct cpufreq_policy *policy) | ||
| 108 | { | ||
| 109 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
| 110 | int result; | ||
| 111 | |||
| 112 | /* capability check */ | ||
| 113 | if (c->x86_vendor != X86_VENDOR_AMD || | ||
| 114 | c->x86 != 4 || c->x86_model != 9) | ||
| 115 | return -ENODEV; | ||
| 116 | |||
| 117 | /* cpuinfo and default policy values */ | ||
| 118 | policy->cpuinfo.transition_latency = 1000000; /* 1ms */ | ||
| 119 | policy->cur = sc520_freq_get_cpu_frequency(0); | ||
| 120 | |||
| 121 | result = cpufreq_frequency_table_cpuinfo(policy, sc520_freq_table); | ||
| 122 | if (result) | ||
| 123 | return result; | ||
| 124 | |||
| 125 | cpufreq_frequency_table_get_attr(sc520_freq_table, policy->cpu); | ||
| 126 | |||
| 127 | return 0; | ||
| 128 | } | ||
| 129 | |||
| 130 | |||
| 131 | static int sc520_freq_cpu_exit(struct cpufreq_policy *policy) | ||
| 132 | { | ||
| 133 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
| 134 | return 0; | ||
| 135 | } | ||
| 136 | |||
| 137 | |||
| 138 | static struct freq_attr *sc520_freq_attr[] = { | ||
| 139 | &cpufreq_freq_attr_scaling_available_freqs, | ||
| 140 | NULL, | ||
| 141 | }; | ||
| 142 | |||
| 143 | |||
| 144 | static struct cpufreq_driver sc520_freq_driver = { | ||
| 145 | .get = sc520_freq_get_cpu_frequency, | ||
| 146 | .verify = sc520_freq_verify, | ||
| 147 | .target = sc520_freq_target, | ||
| 148 | .init = sc520_freq_cpu_init, | ||
| 149 | .exit = sc520_freq_cpu_exit, | ||
| 150 | .name = "sc520_freq", | ||
| 151 | .owner = THIS_MODULE, | ||
| 152 | .attr = sc520_freq_attr, | ||
| 153 | }; | ||
| 154 | |||
| 155 | |||
| 156 | static int __init sc520_freq_init(void) | ||
| 157 | { | ||
| 158 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
| 159 | int err; | ||
| 160 | |||
| 161 | /* Test if we have the right hardware */ | ||
| 162 | if (c->x86_vendor != X86_VENDOR_AMD || | ||
| 163 | c->x86 != 4 || c->x86_model != 9) { | ||
| 164 | dprintk("no Elan SC520 processor found!\n"); | ||
| 165 | return -ENODEV; | ||
| 166 | } | ||
| 167 | cpuctl = ioremap((unsigned long)(MMCR_BASE + OFFS_CPUCTL), 1); | ||
| 168 | if (!cpuctl) { | ||
| 169 | printk(KERN_ERR "sc520_freq: error: failed to remap memory\n"); | ||
| 170 | return -ENOMEM; | ||
| 171 | } | ||
| 172 | |||
| 173 | err = cpufreq_register_driver(&sc520_freq_driver); | ||
| 174 | if (err) | ||
| 175 | iounmap(cpuctl); | ||
| 176 | |||
| 177 | return err; | ||
| 178 | } | ||
| 179 | |||
| 180 | |||
| 181 | static void __exit sc520_freq_exit(void) | ||
| 182 | { | ||
| 183 | cpufreq_unregister_driver(&sc520_freq_driver); | ||
| 184 | iounmap(cpuctl); | ||
| 185 | } | ||
| 186 | |||
| 187 | |||
| 188 | MODULE_LICENSE("GPL"); | ||
| 189 | MODULE_AUTHOR("Sean Young <sean@mess.org>"); | ||
| 190 | MODULE_DESCRIPTION("cpufreq driver for AMD's Elan sc520 CPU"); | ||
| 191 | |||
| 192 | module_init(sc520_freq_init); | ||
| 193 | module_exit(sc520_freq_exit); | ||
| 194 | |||
diff --git a/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c b/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c deleted file mode 100644 index 9b1ff37de46a..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c +++ /dev/null | |||
| @@ -1,636 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * cpufreq driver for Enhanced SpeedStep, as found in Intel's Pentium | ||
| 3 | * M (part of the Centrino chipset). | ||
| 4 | * | ||
| 5 | * Since the original Pentium M, most new Intel CPUs support Enhanced | ||
| 6 | * SpeedStep. | ||
| 7 | * | ||
| 8 | * Despite the "SpeedStep" in the name, this is almost entirely unlike | ||
| 9 | * traditional SpeedStep. | ||
| 10 | * | ||
| 11 | * Modelled on speedstep.c | ||
| 12 | * | ||
| 13 | * Copyright (C) 2003 Jeremy Fitzhardinge <jeremy@goop.org> | ||
| 14 | */ | ||
| 15 | |||
| 16 | #include <linux/kernel.h> | ||
| 17 | #include <linux/module.h> | ||
| 18 | #include <linux/init.h> | ||
| 19 | #include <linux/cpufreq.h> | ||
| 20 | #include <linux/sched.h> /* current */ | ||
| 21 | #include <linux/delay.h> | ||
| 22 | #include <linux/compiler.h> | ||
| 23 | #include <linux/gfp.h> | ||
| 24 | |||
| 25 | #include <asm/msr.h> | ||
| 26 | #include <asm/processor.h> | ||
| 27 | #include <asm/cpufeature.h> | ||
| 28 | |||
| 29 | #define PFX "speedstep-centrino: " | ||
| 30 | #define MAINTAINER "cpufreq@vger.kernel.org" | ||
| 31 | |||
| 32 | #define dprintk(msg...) \ | ||
| 33 | cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "speedstep-centrino", msg) | ||
| 34 | |||
| 35 | #define INTEL_MSR_RANGE (0xffff) | ||
| 36 | |||
| 37 | struct cpu_id | ||
| 38 | { | ||
| 39 | __u8 x86; /* CPU family */ | ||
| 40 | __u8 x86_model; /* model */ | ||
| 41 | __u8 x86_mask; /* stepping */ | ||
| 42 | }; | ||
| 43 | |||
| 44 | enum { | ||
| 45 | CPU_BANIAS, | ||
| 46 | CPU_DOTHAN_A1, | ||
| 47 | CPU_DOTHAN_A2, | ||
| 48 | CPU_DOTHAN_B0, | ||
| 49 | CPU_MP4HT_D0, | ||
| 50 | CPU_MP4HT_E0, | ||
| 51 | }; | ||
| 52 | |||
| 53 | static const struct cpu_id cpu_ids[] = { | ||
| 54 | [CPU_BANIAS] = { 6, 9, 5 }, | ||
| 55 | [CPU_DOTHAN_A1] = { 6, 13, 1 }, | ||
| 56 | [CPU_DOTHAN_A2] = { 6, 13, 2 }, | ||
| 57 | [CPU_DOTHAN_B0] = { 6, 13, 6 }, | ||
| 58 | [CPU_MP4HT_D0] = {15, 3, 4 }, | ||
| 59 | [CPU_MP4HT_E0] = {15, 4, 1 }, | ||
| 60 | }; | ||
| 61 | #define N_IDS ARRAY_SIZE(cpu_ids) | ||
| 62 | |||
| 63 | struct cpu_model | ||
| 64 | { | ||
| 65 | const struct cpu_id *cpu_id; | ||
| 66 | const char *model_name; | ||
| 67 | unsigned max_freq; /* max clock in kHz */ | ||
| 68 | |||
| 69 | struct cpufreq_frequency_table *op_points; /* clock/voltage pairs */ | ||
| 70 | }; | ||
| 71 | static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c, | ||
| 72 | const struct cpu_id *x); | ||
| 73 | |||
| 74 | /* Operating points for current CPU */ | ||
| 75 | static DEFINE_PER_CPU(struct cpu_model *, centrino_model); | ||
| 76 | static DEFINE_PER_CPU(const struct cpu_id *, centrino_cpu); | ||
| 77 | |||
| 78 | static struct cpufreq_driver centrino_driver; | ||
| 79 | |||
| 80 | #ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_TABLE | ||
| 81 | |||
| 82 | /* Computes the correct form for IA32_PERF_CTL MSR for a particular | ||
| 83 | frequency/voltage operating point; frequency in MHz, volts in mV. | ||
| 84 | This is stored as "index" in the structure. */ | ||
| 85 | #define OP(mhz, mv) \ | ||
| 86 | { \ | ||
| 87 | .frequency = (mhz) * 1000, \ | ||
| 88 | .index = (((mhz)/100) << 8) | ((mv - 700) / 16) \ | ||
| 89 | } | ||
| 90 | |||
| 91 | /* | ||
| 92 | * These voltage tables were derived from the Intel Pentium M | ||
| 93 | * datasheet, document 25261202.pdf, Table 5. I have verified they | ||
| 94 | * are consistent with my IBM ThinkPad X31, which has a 1.3GHz Pentium | ||
| 95 | * M. | ||
| 96 | */ | ||
| 97 | |||
| 98 | /* Ultra Low Voltage Intel Pentium M processor 900MHz (Banias) */ | ||
| 99 | static struct cpufreq_frequency_table banias_900[] = | ||
| 100 | { | ||
| 101 | OP(600, 844), | ||
| 102 | OP(800, 988), | ||
| 103 | OP(900, 1004), | ||
| 104 | { .frequency = CPUFREQ_TABLE_END } | ||
| 105 | }; | ||
| 106 | |||
| 107 | /* Ultra Low Voltage Intel Pentium M processor 1000MHz (Banias) */ | ||
| 108 | static struct cpufreq_frequency_table banias_1000[] = | ||
| 109 | { | ||
| 110 | OP(600, 844), | ||
| 111 | OP(800, 972), | ||
| 112 | OP(900, 988), | ||
| 113 | OP(1000, 1004), | ||
| 114 | { .frequency = CPUFREQ_TABLE_END } | ||
| 115 | }; | ||
| 116 | |||
| 117 | /* Low Voltage Intel Pentium M processor 1.10GHz (Banias) */ | ||
| 118 | static struct cpufreq_frequency_table banias_1100[] = | ||
| 119 | { | ||
| 120 | OP( 600, 956), | ||
| 121 | OP( 800, 1020), | ||
| 122 | OP( 900, 1100), | ||
| 123 | OP(1000, 1164), | ||
| 124 | OP(1100, 1180), | ||
| 125 | { .frequency = CPUFREQ_TABLE_END } | ||
| 126 | }; | ||
| 127 | |||
| 128 | |||
| 129 | /* Low Voltage Intel Pentium M processor 1.20GHz (Banias) */ | ||
| 130 | static struct cpufreq_frequency_table banias_1200[] = | ||
| 131 | { | ||
| 132 | OP( 600, 956), | ||
| 133 | OP( 800, 1004), | ||
| 134 | OP( 900, 1020), | ||
| 135 | OP(1000, 1100), | ||
| 136 | OP(1100, 1164), | ||
| 137 | OP(1200, 1180), | ||
| 138 | { .frequency = CPUFREQ_TABLE_END } | ||
| 139 | }; | ||
| 140 | |||
| 141 | /* Intel Pentium M processor 1.30GHz (Banias) */ | ||
| 142 | static struct cpufreq_frequency_table banias_1300[] = | ||
| 143 | { | ||
| 144 | OP( 600, 956), | ||
| 145 | OP( 800, 1260), | ||
| 146 | OP(1000, 1292), | ||
| 147 | OP(1200, 1356), | ||
| 148 | OP(1300, 1388), | ||
| 149 | { .frequency = CPUFREQ_TABLE_END } | ||
| 150 | }; | ||
| 151 | |||
| 152 | /* Intel Pentium M processor 1.40GHz (Banias) */ | ||
| 153 | static struct cpufreq_frequency_table banias_1400[] = | ||
| 154 | { | ||
| 155 | OP( 600, 956), | ||
| 156 | OP( 800, 1180), | ||
| 157 | OP(1000, 1308), | ||
| 158 | OP(1200, 1436), | ||
| 159 | OP(1400, 1484), | ||
| 160 | { .frequency = CPUFREQ_TABLE_END } | ||
| 161 | }; | ||
| 162 | |||
| 163 | /* Intel Pentium M processor 1.50GHz (Banias) */ | ||
| 164 | static struct cpufreq_frequency_table banias_1500[] = | ||
| 165 | { | ||
| 166 | OP( 600, 956), | ||
| 167 | OP( 800, 1116), | ||
| 168 | OP(1000, 1228), | ||
| 169 | OP(1200, 1356), | ||
| 170 | OP(1400, 1452), | ||
| 171 | OP(1500, 1484), | ||
| 172 | { .frequency = CPUFREQ_TABLE_END } | ||
| 173 | }; | ||
| 174 | |||
| 175 | /* Intel Pentium M processor 1.60GHz (Banias) */ | ||
| 176 | static struct cpufreq_frequency_table banias_1600[] = | ||
| 177 | { | ||
| 178 | OP( 600, 956), | ||
| 179 | OP( 800, 1036), | ||
| 180 | OP(1000, 1164), | ||
| 181 | OP(1200, 1276), | ||
| 182 | OP(1400, 1420), | ||
| 183 | OP(1600, 1484), | ||
| 184 | { .frequency = CPUFREQ_TABLE_END } | ||
| 185 | }; | ||
| 186 | |||
| 187 | /* Intel Pentium M processor 1.70GHz (Banias) */ | ||
| 188 | static struct cpufreq_frequency_table banias_1700[] = | ||
| 189 | { | ||
| 190 | OP( 600, 956), | ||
| 191 | OP( 800, 1004), | ||
| 192 | OP(1000, 1116), | ||
| 193 | OP(1200, 1228), | ||
| 194 | OP(1400, 1308), | ||
| 195 | OP(1700, 1484), | ||
| 196 | { .frequency = CPUFREQ_TABLE_END } | ||
| 197 | }; | ||
| 198 | #undef OP | ||
| 199 | |||
| 200 | #define _BANIAS(cpuid, max, name) \ | ||
| 201 | { .cpu_id = cpuid, \ | ||
| 202 | .model_name = "Intel(R) Pentium(R) M processor " name "MHz", \ | ||
| 203 | .max_freq = (max)*1000, \ | ||
| 204 | .op_points = banias_##max, \ | ||
| 205 | } | ||
| 206 | #define BANIAS(max) _BANIAS(&cpu_ids[CPU_BANIAS], max, #max) | ||
| 207 | |||
| 208 | /* CPU models, their operating frequency range, and freq/voltage | ||
| 209 | operating points */ | ||
| 210 | static struct cpu_model models[] = | ||
| 211 | { | ||
| 212 | _BANIAS(&cpu_ids[CPU_BANIAS], 900, " 900"), | ||
| 213 | BANIAS(1000), | ||
| 214 | BANIAS(1100), | ||
| 215 | BANIAS(1200), | ||
| 216 | BANIAS(1300), | ||
| 217 | BANIAS(1400), | ||
| 218 | BANIAS(1500), | ||
| 219 | BANIAS(1600), | ||
| 220 | BANIAS(1700), | ||
| 221 | |||
| 222 | /* NULL model_name is a wildcard */ | ||
| 223 | { &cpu_ids[CPU_DOTHAN_A1], NULL, 0, NULL }, | ||
| 224 | { &cpu_ids[CPU_DOTHAN_A2], NULL, 0, NULL }, | ||
| 225 | { &cpu_ids[CPU_DOTHAN_B0], NULL, 0, NULL }, | ||
| 226 | { &cpu_ids[CPU_MP4HT_D0], NULL, 0, NULL }, | ||
| 227 | { &cpu_ids[CPU_MP4HT_E0], NULL, 0, NULL }, | ||
| 228 | |||
| 229 | { NULL, } | ||
| 230 | }; | ||
| 231 | #undef _BANIAS | ||
| 232 | #undef BANIAS | ||
| 233 | |||
| 234 | static int centrino_cpu_init_table(struct cpufreq_policy *policy) | ||
| 235 | { | ||
| 236 | struct cpuinfo_x86 *cpu = &cpu_data(policy->cpu); | ||
| 237 | struct cpu_model *model; | ||
| 238 | |||
| 239 | for(model = models; model->cpu_id != NULL; model++) | ||
| 240 | if (centrino_verify_cpu_id(cpu, model->cpu_id) && | ||
| 241 | (model->model_name == NULL || | ||
| 242 | strcmp(cpu->x86_model_id, model->model_name) == 0)) | ||
| 243 | break; | ||
| 244 | |||
| 245 | if (model->cpu_id == NULL) { | ||
| 246 | /* No match at all */ | ||
| 247 | dprintk("no support for CPU model \"%s\": " | ||
| 248 | "send /proc/cpuinfo to " MAINTAINER "\n", | ||
| 249 | cpu->x86_model_id); | ||
| 250 | return -ENOENT; | ||
| 251 | } | ||
| 252 | |||
| 253 | if (model->op_points == NULL) { | ||
| 254 | /* Matched a non-match */ | ||
| 255 | dprintk("no table support for CPU model \"%s\"\n", | ||
| 256 | cpu->x86_model_id); | ||
| 257 | dprintk("try using the acpi-cpufreq driver\n"); | ||
| 258 | return -ENOENT; | ||
| 259 | } | ||
| 260 | |||
| 261 | per_cpu(centrino_model, policy->cpu) = model; | ||
| 262 | |||
| 263 | dprintk("found \"%s\": max frequency: %dkHz\n", | ||
| 264 | model->model_name, model->max_freq); | ||
| 265 | |||
| 266 | return 0; | ||
| 267 | } | ||
| 268 | |||
| 269 | #else | ||
| 270 | static inline int centrino_cpu_init_table(struct cpufreq_policy *policy) | ||
| 271 | { | ||
| 272 | return -ENODEV; | ||
| 273 | } | ||
| 274 | #endif /* CONFIG_X86_SPEEDSTEP_CENTRINO_TABLE */ | ||
| 275 | |||
| 276 | static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c, | ||
| 277 | const struct cpu_id *x) | ||
| 278 | { | ||
| 279 | if ((c->x86 == x->x86) && | ||
| 280 | (c->x86_model == x->x86_model) && | ||
| 281 | (c->x86_mask == x->x86_mask)) | ||
| 282 | return 1; | ||
| 283 | return 0; | ||
| 284 | } | ||
| 285 | |||
| 286 | /* To be called only after centrino_model is initialized */ | ||
| 287 | static unsigned extract_clock(unsigned msr, unsigned int cpu, int failsafe) | ||
| 288 | { | ||
| 289 | int i; | ||
| 290 | |||
| 291 | /* | ||
| 292 | * Extract clock in kHz from PERF_CTL value | ||
| 293 | * for centrino, as some DSDTs are buggy. | ||
| 294 | * Ideally, this can be done using the acpi_data structure. | ||
| 295 | */ | ||
| 296 | if ((per_cpu(centrino_cpu, cpu) == &cpu_ids[CPU_BANIAS]) || | ||
| 297 | (per_cpu(centrino_cpu, cpu) == &cpu_ids[CPU_DOTHAN_A1]) || | ||
| 298 | (per_cpu(centrino_cpu, cpu) == &cpu_ids[CPU_DOTHAN_B0])) { | ||
| 299 | msr = (msr >> 8) & 0xff; | ||
| 300 | return msr * 100000; | ||
| 301 | } | ||
| 302 | |||
| 303 | if ((!per_cpu(centrino_model, cpu)) || | ||
| 304 | (!per_cpu(centrino_model, cpu)->op_points)) | ||
| 305 | return 0; | ||
| 306 | |||
| 307 | msr &= 0xffff; | ||
| 308 | for (i = 0; | ||
| 309 | per_cpu(centrino_model, cpu)->op_points[i].frequency | ||
| 310 | != CPUFREQ_TABLE_END; | ||
| 311 | i++) { | ||
| 312 | if (msr == per_cpu(centrino_model, cpu)->op_points[i].index) | ||
| 313 | return per_cpu(centrino_model, cpu)-> | ||
| 314 | op_points[i].frequency; | ||
| 315 | } | ||
| 316 | if (failsafe) | ||
| 317 | return per_cpu(centrino_model, cpu)->op_points[i-1].frequency; | ||
| 318 | else | ||
| 319 | return 0; | ||
| 320 | } | ||
| 321 | |||
| 322 | /* Return the current CPU frequency in kHz */ | ||
| 323 | static unsigned int get_cur_freq(unsigned int cpu) | ||
| 324 | { | ||
| 325 | unsigned l, h; | ||
| 326 | unsigned clock_freq; | ||
| 327 | |||
| 328 | rdmsr_on_cpu(cpu, MSR_IA32_PERF_STATUS, &l, &h); | ||
| 329 | clock_freq = extract_clock(l, cpu, 0); | ||
| 330 | |||
| 331 | if (unlikely(clock_freq == 0)) { | ||
| 332 | /* | ||
| 333 | * On some CPUs, we can see transient MSR values (which are | ||
| 334 | * not present in _PSS), while CPU is doing some automatic | ||
| 335 | * P-state transition (like TM2). Get the last freq set | ||
| 336 | * in PERF_CTL. | ||
| 337 | */ | ||
| 338 | rdmsr_on_cpu(cpu, MSR_IA32_PERF_CTL, &l, &h); | ||
| 339 | clock_freq = extract_clock(l, cpu, 1); | ||
| 340 | } | ||
| 341 | return clock_freq; | ||
| 342 | } | ||
| 343 | |||
| 344 | |||
| 345 | static int centrino_cpu_init(struct cpufreq_policy *policy) | ||
| 346 | { | ||
| 347 | struct cpuinfo_x86 *cpu = &cpu_data(policy->cpu); | ||
| 348 | unsigned freq; | ||
| 349 | unsigned l, h; | ||
| 350 | int ret; | ||
| 351 | int i; | ||
| 352 | |||
| 353 | /* Only Intel makes Enhanced Speedstep-capable CPUs */ | ||
| 354 | if (cpu->x86_vendor != X86_VENDOR_INTEL || | ||
| 355 | !cpu_has(cpu, X86_FEATURE_EST)) | ||
| 356 | return -ENODEV; | ||
| 357 | |||
| 358 | if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) | ||
| 359 | centrino_driver.flags |= CPUFREQ_CONST_LOOPS; | ||
| 360 | |||
| 361 | if (policy->cpu != 0) | ||
| 362 | return -ENODEV; | ||
| 363 | |||
| 364 | for (i = 0; i < N_IDS; i++) | ||
| 365 | if (centrino_verify_cpu_id(cpu, &cpu_ids[i])) | ||
| 366 | break; | ||
| 367 | |||
| 368 | if (i != N_IDS) | ||
| 369 | per_cpu(centrino_cpu, policy->cpu) = &cpu_ids[i]; | ||
| 370 | |||
| 371 | if (!per_cpu(centrino_cpu, policy->cpu)) { | ||
| 372 | dprintk("found unsupported CPU with " | ||
| 373 | "Enhanced SpeedStep: send /proc/cpuinfo to " | ||
| 374 | MAINTAINER "\n"); | ||
| 375 | return -ENODEV; | ||
| 376 | } | ||
| 377 | |||
| 378 | if (centrino_cpu_init_table(policy)) { | ||
| 379 | return -ENODEV; | ||
| 380 | } | ||
| 381 | |||
| 382 | /* Check to see if Enhanced SpeedStep is enabled, and try to | ||
| 383 | enable it if not. */ | ||
| 384 | rdmsr(MSR_IA32_MISC_ENABLE, l, h); | ||
| 385 | |||
| 386 | if (!(l & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) { | ||
| 387 | l |= MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP; | ||
| 388 | dprintk("trying to enable Enhanced SpeedStep (%x)\n", l); | ||
| 389 | wrmsr(MSR_IA32_MISC_ENABLE, l, h); | ||
| 390 | |||
| 391 | /* check to see if it stuck */ | ||
| 392 | rdmsr(MSR_IA32_MISC_ENABLE, l, h); | ||
| 393 | if (!(l & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) { | ||
| 394 | printk(KERN_INFO PFX | ||
| 395 | "couldn't enable Enhanced SpeedStep\n"); | ||
| 396 | return -ENODEV; | ||
| 397 | } | ||
| 398 | } | ||
| 399 | |||
| 400 | freq = get_cur_freq(policy->cpu); | ||
| 401 | policy->cpuinfo.transition_latency = 10000; | ||
| 402 | /* 10uS transition latency */ | ||
| 403 | policy->cur = freq; | ||
| 404 | |||
| 405 | dprintk("centrino_cpu_init: cur=%dkHz\n", policy->cur); | ||
| 406 | |||
| 407 | ret = cpufreq_frequency_table_cpuinfo(policy, | ||
| 408 | per_cpu(centrino_model, policy->cpu)->op_points); | ||
| 409 | if (ret) | ||
| 410 | return (ret); | ||
| 411 | |||
| 412 | cpufreq_frequency_table_get_attr( | ||
| 413 | per_cpu(centrino_model, policy->cpu)->op_points, policy->cpu); | ||
| 414 | |||
| 415 | return 0; | ||
| 416 | } | ||
| 417 | |||
| 418 | static int centrino_cpu_exit(struct cpufreq_policy *policy) | ||
| 419 | { | ||
| 420 | unsigned int cpu = policy->cpu; | ||
| 421 | |||
| 422 | if (!per_cpu(centrino_model, cpu)) | ||
| 423 | return -ENODEV; | ||
| 424 | |||
| 425 | cpufreq_frequency_table_put_attr(cpu); | ||
| 426 | |||
| 427 | per_cpu(centrino_model, cpu) = NULL; | ||
| 428 | |||
| 429 | return 0; | ||
| 430 | } | ||
| 431 | |||
| 432 | /** | ||
| 433 | * centrino_verify - verifies a new CPUFreq policy | ||
| 434 | * @policy: new policy | ||
| 435 | * | ||
| 436 | * Limit must be within this model's frequency range at least one | ||
| 437 | * border included. | ||
| 438 | */ | ||
| 439 | static int centrino_verify (struct cpufreq_policy *policy) | ||
| 440 | { | ||
| 441 | return cpufreq_frequency_table_verify(policy, | ||
| 442 | per_cpu(centrino_model, policy->cpu)->op_points); | ||
| 443 | } | ||
| 444 | |||
| 445 | /** | ||
| 446 | * centrino_setpolicy - set a new CPUFreq policy | ||
| 447 | * @policy: new policy | ||
| 448 | * @target_freq: the target frequency | ||
| 449 | * @relation: how that frequency relates to achieved frequency | ||
| 450 | * (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H) | ||
| 451 | * | ||
| 452 | * Sets a new CPUFreq policy. | ||
| 453 | */ | ||
| 454 | static int centrino_target (struct cpufreq_policy *policy, | ||
| 455 | unsigned int target_freq, | ||
| 456 | unsigned int relation) | ||
| 457 | { | ||
| 458 | unsigned int newstate = 0; | ||
| 459 | unsigned int msr, oldmsr = 0, h = 0, cpu = policy->cpu; | ||
| 460 | struct cpufreq_freqs freqs; | ||
| 461 | int retval = 0; | ||
| 462 | unsigned int j, k, first_cpu, tmp; | ||
| 463 | cpumask_var_t covered_cpus; | ||
| 464 | |||
| 465 | if (unlikely(!zalloc_cpumask_var(&covered_cpus, GFP_KERNEL))) | ||
| 466 | return -ENOMEM; | ||
| 467 | |||
| 468 | if (unlikely(per_cpu(centrino_model, cpu) == NULL)) { | ||
| 469 | retval = -ENODEV; | ||
| 470 | goto out; | ||
| 471 | } | ||
| 472 | |||
| 473 | if (unlikely(cpufreq_frequency_table_target(policy, | ||
| 474 | per_cpu(centrino_model, cpu)->op_points, | ||
| 475 | target_freq, | ||
| 476 | relation, | ||
| 477 | &newstate))) { | ||
| 478 | retval = -EINVAL; | ||
| 479 | goto out; | ||
| 480 | } | ||
| 481 | |||
| 482 | first_cpu = 1; | ||
| 483 | for_each_cpu(j, policy->cpus) { | ||
| 484 | int good_cpu; | ||
| 485 | |||
| 486 | /* cpufreq holds the hotplug lock, so we are safe here */ | ||
| 487 | if (!cpu_online(j)) | ||
| 488 | continue; | ||
| 489 | |||
| 490 | /* | ||
| 491 | * Support for SMP systems. | ||
| 492 | * Make sure we are running on CPU that wants to change freq | ||
| 493 | */ | ||
| 494 | if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) | ||
| 495 | good_cpu = cpumask_any_and(policy->cpus, | ||
| 496 | cpu_online_mask); | ||
| 497 | else | ||
| 498 | good_cpu = j; | ||
| 499 | |||
| 500 | if (good_cpu >= nr_cpu_ids) { | ||
| 501 | dprintk("couldn't limit to CPUs in this domain\n"); | ||
| 502 | retval = -EAGAIN; | ||
| 503 | if (first_cpu) { | ||
| 504 | /* We haven't started the transition yet. */ | ||
| 505 | goto out; | ||
| 506 | } | ||
| 507 | break; | ||
| 508 | } | ||
| 509 | |||
| 510 | msr = per_cpu(centrino_model, cpu)->op_points[newstate].index; | ||
| 511 | |||
| 512 | if (first_cpu) { | ||
| 513 | rdmsr_on_cpu(good_cpu, MSR_IA32_PERF_CTL, &oldmsr, &h); | ||
| 514 | if (msr == (oldmsr & 0xffff)) { | ||
| 515 | dprintk("no change needed - msr was and needs " | ||
| 516 | "to be %x\n", oldmsr); | ||
| 517 | retval = 0; | ||
| 518 | goto out; | ||
| 519 | } | ||
| 520 | |||
| 521 | freqs.old = extract_clock(oldmsr, cpu, 0); | ||
| 522 | freqs.new = extract_clock(msr, cpu, 0); | ||
| 523 | |||
| 524 | dprintk("target=%dkHz old=%d new=%d msr=%04x\n", | ||
| 525 | target_freq, freqs.old, freqs.new, msr); | ||
| 526 | |||
| 527 | for_each_cpu(k, policy->cpus) { | ||
| 528 | if (!cpu_online(k)) | ||
| 529 | continue; | ||
| 530 | freqs.cpu = k; | ||
| 531 | cpufreq_notify_transition(&freqs, | ||
| 532 | CPUFREQ_PRECHANGE); | ||
| 533 | } | ||
| 534 | |||
| 535 | first_cpu = 0; | ||
| 536 | /* all but 16 LSB are reserved, treat them with care */ | ||
| 537 | oldmsr &= ~0xffff; | ||
| 538 | msr &= 0xffff; | ||
| 539 | oldmsr |= msr; | ||
| 540 | } | ||
| 541 | |||
| 542 | wrmsr_on_cpu(good_cpu, MSR_IA32_PERF_CTL, oldmsr, h); | ||
| 543 | if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) | ||
| 544 | break; | ||
| 545 | |||
| 546 | cpumask_set_cpu(j, covered_cpus); | ||
| 547 | } | ||
| 548 | |||
| 549 | for_each_cpu(k, policy->cpus) { | ||
| 550 | if (!cpu_online(k)) | ||
| 551 | continue; | ||
| 552 | freqs.cpu = k; | ||
| 553 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 554 | } | ||
| 555 | |||
| 556 | if (unlikely(retval)) { | ||
| 557 | /* | ||
| 558 | * We have failed halfway through the frequency change. | ||
| 559 | * We have sent callbacks to policy->cpus and | ||
| 560 | * MSRs have already been written on coverd_cpus. | ||
| 561 | * Best effort undo.. | ||
| 562 | */ | ||
| 563 | |||
| 564 | for_each_cpu(j, covered_cpus) | ||
| 565 | wrmsr_on_cpu(j, MSR_IA32_PERF_CTL, oldmsr, h); | ||
| 566 | |||
| 567 | tmp = freqs.new; | ||
| 568 | freqs.new = freqs.old; | ||
| 569 | freqs.old = tmp; | ||
| 570 | for_each_cpu(j, policy->cpus) { | ||
| 571 | if (!cpu_online(j)) | ||
| 572 | continue; | ||
| 573 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
| 574 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 575 | } | ||
| 576 | } | ||
| 577 | retval = 0; | ||
| 578 | |||
| 579 | out: | ||
| 580 | free_cpumask_var(covered_cpus); | ||
| 581 | return retval; | ||
| 582 | } | ||
| 583 | |||
| 584 | static struct freq_attr* centrino_attr[] = { | ||
| 585 | &cpufreq_freq_attr_scaling_available_freqs, | ||
| 586 | NULL, | ||
| 587 | }; | ||
| 588 | |||
| 589 | static struct cpufreq_driver centrino_driver = { | ||
| 590 | .name = "centrino", /* should be speedstep-centrino, | ||
| 591 | but there's a 16 char limit */ | ||
| 592 | .init = centrino_cpu_init, | ||
| 593 | .exit = centrino_cpu_exit, | ||
| 594 | .verify = centrino_verify, | ||
| 595 | .target = centrino_target, | ||
| 596 | .get = get_cur_freq, | ||
| 597 | .attr = centrino_attr, | ||
| 598 | .owner = THIS_MODULE, | ||
| 599 | }; | ||
| 600 | |||
| 601 | |||
| 602 | /** | ||
| 603 | * centrino_init - initializes the Enhanced SpeedStep CPUFreq driver | ||
| 604 | * | ||
| 605 | * Initializes the Enhanced SpeedStep support. Returns -ENODEV on | ||
| 606 | * unsupported devices, -ENOENT if there's no voltage table for this | ||
| 607 | * particular CPU model, -EINVAL on problems during initiatization, | ||
| 608 | * and zero on success. | ||
| 609 | * | ||
| 610 | * This is quite picky. Not only does the CPU have to advertise the | ||
| 611 | * "est" flag in the cpuid capability flags, we look for a specific | ||
| 612 | * CPU model and stepping, and we need to have the exact model name in | ||
| 613 | * our voltage tables. That is, be paranoid about not releasing | ||
| 614 | * someone's valuable magic smoke. | ||
| 615 | */ | ||
| 616 | static int __init centrino_init(void) | ||
| 617 | { | ||
| 618 | struct cpuinfo_x86 *cpu = &cpu_data(0); | ||
| 619 | |||
| 620 | if (!cpu_has(cpu, X86_FEATURE_EST)) | ||
| 621 | return -ENODEV; | ||
| 622 | |||
| 623 | return cpufreq_register_driver(¢rino_driver); | ||
| 624 | } | ||
| 625 | |||
| 626 | static void __exit centrino_exit(void) | ||
| 627 | { | ||
| 628 | cpufreq_unregister_driver(¢rino_driver); | ||
| 629 | } | ||
| 630 | |||
| 631 | MODULE_AUTHOR ("Jeremy Fitzhardinge <jeremy@goop.org>"); | ||
| 632 | MODULE_DESCRIPTION ("Enhanced SpeedStep driver for Intel Pentium M processors."); | ||
| 633 | MODULE_LICENSE ("GPL"); | ||
| 634 | |||
| 635 | late_initcall(centrino_init); | ||
| 636 | module_exit(centrino_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/speedstep-ich.c b/arch/x86/kernel/cpu/cpufreq/speedstep-ich.c deleted file mode 100644 index 561758e95180..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/speedstep-ich.c +++ /dev/null | |||
| @@ -1,452 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * (C) 2001 Dave Jones, Arjan van de ven. | ||
| 3 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> | ||
| 4 | * | ||
| 5 | * Licensed under the terms of the GNU GPL License version 2. | ||
| 6 | * Based upon reverse engineered information, and on Intel documentation | ||
| 7 | * for chipsets ICH2-M and ICH3-M. | ||
| 8 | * | ||
| 9 | * Many thanks to Ducrot Bruno for finding and fixing the last | ||
| 10 | * "missing link" for ICH2-M/ICH3-M support, and to Thomas Winkler | ||
| 11 | * for extensive testing. | ||
| 12 | * | ||
| 13 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
| 14 | */ | ||
| 15 | |||
| 16 | |||
| 17 | /********************************************************************* | ||
| 18 | * SPEEDSTEP - DEFINITIONS * | ||
| 19 | *********************************************************************/ | ||
| 20 | |||
| 21 | #include <linux/kernel.h> | ||
| 22 | #include <linux/module.h> | ||
| 23 | #include <linux/init.h> | ||
| 24 | #include <linux/cpufreq.h> | ||
| 25 | #include <linux/pci.h> | ||
| 26 | #include <linux/sched.h> | ||
| 27 | |||
| 28 | #include "speedstep-lib.h" | ||
| 29 | |||
| 30 | |||
| 31 | /* speedstep_chipset: | ||
| 32 | * It is necessary to know which chipset is used. As accesses to | ||
| 33 | * this device occur at various places in this module, we need a | ||
| 34 | * static struct pci_dev * pointing to that device. | ||
| 35 | */ | ||
| 36 | static struct pci_dev *speedstep_chipset_dev; | ||
| 37 | |||
| 38 | |||
| 39 | /* speedstep_processor | ||
| 40 | */ | ||
| 41 | static enum speedstep_processor speedstep_processor; | ||
| 42 | |||
| 43 | static u32 pmbase; | ||
| 44 | |||
| 45 | /* | ||
| 46 | * There are only two frequency states for each processor. Values | ||
| 47 | * are in kHz for the time being. | ||
| 48 | */ | ||
| 49 | static struct cpufreq_frequency_table speedstep_freqs[] = { | ||
| 50 | {SPEEDSTEP_HIGH, 0}, | ||
| 51 | {SPEEDSTEP_LOW, 0}, | ||
| 52 | {0, CPUFREQ_TABLE_END}, | ||
| 53 | }; | ||
| 54 | |||
| 55 | |||
| 56 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
| 57 | "speedstep-ich", msg) | ||
| 58 | |||
| 59 | |||
| 60 | /** | ||
| 61 | * speedstep_find_register - read the PMBASE address | ||
| 62 | * | ||
| 63 | * Returns: -ENODEV if no register could be found | ||
| 64 | */ | ||
| 65 | static int speedstep_find_register(void) | ||
| 66 | { | ||
| 67 | if (!speedstep_chipset_dev) | ||
| 68 | return -ENODEV; | ||
| 69 | |||
| 70 | /* get PMBASE */ | ||
| 71 | pci_read_config_dword(speedstep_chipset_dev, 0x40, &pmbase); | ||
| 72 | if (!(pmbase & 0x01)) { | ||
| 73 | printk(KERN_ERR "speedstep-ich: could not find speedstep register\n"); | ||
| 74 | return -ENODEV; | ||
| 75 | } | ||
| 76 | |||
| 77 | pmbase &= 0xFFFFFFFE; | ||
| 78 | if (!pmbase) { | ||
| 79 | printk(KERN_ERR "speedstep-ich: could not find speedstep register\n"); | ||
| 80 | return -ENODEV; | ||
| 81 | } | ||
| 82 | |||
| 83 | dprintk("pmbase is 0x%x\n", pmbase); | ||
| 84 | return 0; | ||
| 85 | } | ||
| 86 | |||
| 87 | /** | ||
| 88 | * speedstep_set_state - set the SpeedStep state | ||
| 89 | * @state: new processor frequency state (SPEEDSTEP_LOW or SPEEDSTEP_HIGH) | ||
| 90 | * | ||
| 91 | * Tries to change the SpeedStep state. Can be called from | ||
| 92 | * smp_call_function_single. | ||
| 93 | */ | ||
| 94 | static void speedstep_set_state(unsigned int state) | ||
| 95 | { | ||
| 96 | u8 pm2_blk; | ||
| 97 | u8 value; | ||
| 98 | unsigned long flags; | ||
| 99 | |||
| 100 | if (state > 0x1) | ||
| 101 | return; | ||
| 102 | |||
| 103 | /* Disable IRQs */ | ||
| 104 | local_irq_save(flags); | ||
| 105 | |||
| 106 | /* read state */ | ||
| 107 | value = inb(pmbase + 0x50); | ||
| 108 | |||
| 109 | dprintk("read at pmbase 0x%x + 0x50 returned 0x%x\n", pmbase, value); | ||
| 110 | |||
| 111 | /* write new state */ | ||
| 112 | value &= 0xFE; | ||
| 113 | value |= state; | ||
| 114 | |||
| 115 | dprintk("writing 0x%x to pmbase 0x%x + 0x50\n", value, pmbase); | ||
| 116 | |||
| 117 | /* Disable bus master arbitration */ | ||
| 118 | pm2_blk = inb(pmbase + 0x20); | ||
| 119 | pm2_blk |= 0x01; | ||
| 120 | outb(pm2_blk, (pmbase + 0x20)); | ||
| 121 | |||
| 122 | /* Actual transition */ | ||
| 123 | outb(value, (pmbase + 0x50)); | ||
| 124 | |||
| 125 | /* Restore bus master arbitration */ | ||
| 126 | pm2_blk &= 0xfe; | ||
| 127 | outb(pm2_blk, (pmbase + 0x20)); | ||
| 128 | |||
| 129 | /* check if transition was successful */ | ||
| 130 | value = inb(pmbase + 0x50); | ||
| 131 | |||
| 132 | /* Enable IRQs */ | ||
| 133 | local_irq_restore(flags); | ||
| 134 | |||
| 135 | dprintk("read at pmbase 0x%x + 0x50 returned 0x%x\n", pmbase, value); | ||
| 136 | |||
| 137 | if (state == (value & 0x1)) | ||
| 138 | dprintk("change to %u MHz succeeded\n", | ||
| 139 | speedstep_get_frequency(speedstep_processor) / 1000); | ||
| 140 | else | ||
| 141 | printk(KERN_ERR "cpufreq: change failed - I/O error\n"); | ||
| 142 | |||
| 143 | return; | ||
| 144 | } | ||
| 145 | |||
| 146 | /* Wrapper for smp_call_function_single. */ | ||
| 147 | static void _speedstep_set_state(void *_state) | ||
| 148 | { | ||
| 149 | speedstep_set_state(*(unsigned int *)_state); | ||
| 150 | } | ||
| 151 | |||
| 152 | /** | ||
| 153 | * speedstep_activate - activate SpeedStep control in the chipset | ||
| 154 | * | ||
| 155 | * Tries to activate the SpeedStep status and control registers. | ||
| 156 | * Returns -EINVAL on an unsupported chipset, and zero on success. | ||
| 157 | */ | ||
| 158 | static int speedstep_activate(void) | ||
| 159 | { | ||
| 160 | u16 value = 0; | ||
| 161 | |||
| 162 | if (!speedstep_chipset_dev) | ||
| 163 | return -EINVAL; | ||
| 164 | |||
| 165 | pci_read_config_word(speedstep_chipset_dev, 0x00A0, &value); | ||
| 166 | if (!(value & 0x08)) { | ||
| 167 | value |= 0x08; | ||
| 168 | dprintk("activating SpeedStep (TM) registers\n"); | ||
| 169 | pci_write_config_word(speedstep_chipset_dev, 0x00A0, value); | ||
| 170 | } | ||
| 171 | |||
| 172 | return 0; | ||
| 173 | } | ||
| 174 | |||
| 175 | |||
| 176 | /** | ||
| 177 | * speedstep_detect_chipset - detect the Southbridge which contains SpeedStep logic | ||
| 178 | * | ||
| 179 | * Detects ICH2-M, ICH3-M and ICH4-M so far. The pci_dev points to | ||
| 180 | * the LPC bridge / PM module which contains all power-management | ||
| 181 | * functions. Returns the SPEEDSTEP_CHIPSET_-number for the detected | ||
| 182 | * chipset, or zero on failure. | ||
| 183 | */ | ||
| 184 | static unsigned int speedstep_detect_chipset(void) | ||
| 185 | { | ||
| 186 | speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | ||
| 187 | PCI_DEVICE_ID_INTEL_82801DB_12, | ||
| 188 | PCI_ANY_ID, PCI_ANY_ID, | ||
| 189 | NULL); | ||
| 190 | if (speedstep_chipset_dev) | ||
| 191 | return 4; /* 4-M */ | ||
| 192 | |||
| 193 | speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | ||
| 194 | PCI_DEVICE_ID_INTEL_82801CA_12, | ||
| 195 | PCI_ANY_ID, PCI_ANY_ID, | ||
| 196 | NULL); | ||
| 197 | if (speedstep_chipset_dev) | ||
| 198 | return 3; /* 3-M */ | ||
| 199 | |||
| 200 | |||
| 201 | speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | ||
| 202 | PCI_DEVICE_ID_INTEL_82801BA_10, | ||
| 203 | PCI_ANY_ID, PCI_ANY_ID, | ||
| 204 | NULL); | ||
| 205 | if (speedstep_chipset_dev) { | ||
| 206 | /* speedstep.c causes lockups on Dell Inspirons 8000 and | ||
| 207 | * 8100 which use a pretty old revision of the 82815 | ||
| 208 | * host brige. Abort on these systems. | ||
| 209 | */ | ||
| 210 | static struct pci_dev *hostbridge; | ||
| 211 | |||
| 212 | hostbridge = pci_get_subsys(PCI_VENDOR_ID_INTEL, | ||
| 213 | PCI_DEVICE_ID_INTEL_82815_MC, | ||
| 214 | PCI_ANY_ID, PCI_ANY_ID, | ||
| 215 | NULL); | ||
| 216 | |||
| 217 | if (!hostbridge) | ||
| 218 | return 2; /* 2-M */ | ||
| 219 | |||
| 220 | if (hostbridge->revision < 5) { | ||
| 221 | dprintk("hostbridge does not support speedstep\n"); | ||
| 222 | speedstep_chipset_dev = NULL; | ||
| 223 | pci_dev_put(hostbridge); | ||
| 224 | return 0; | ||
| 225 | } | ||
| 226 | |||
| 227 | pci_dev_put(hostbridge); | ||
| 228 | return 2; /* 2-M */ | ||
| 229 | } | ||
| 230 | |||
| 231 | return 0; | ||
| 232 | } | ||
| 233 | |||
| 234 | static void get_freq_data(void *_speed) | ||
| 235 | { | ||
| 236 | unsigned int *speed = _speed; | ||
| 237 | |||
| 238 | *speed = speedstep_get_frequency(speedstep_processor); | ||
| 239 | } | ||
| 240 | |||
| 241 | static unsigned int speedstep_get(unsigned int cpu) | ||
| 242 | { | ||
| 243 | unsigned int speed; | ||
| 244 | |||
| 245 | /* You're supposed to ensure CPU is online. */ | ||
| 246 | if (smp_call_function_single(cpu, get_freq_data, &speed, 1) != 0) | ||
| 247 | BUG(); | ||
| 248 | |||
| 249 | dprintk("detected %u kHz as current frequency\n", speed); | ||
| 250 | return speed; | ||
| 251 | } | ||
| 252 | |||
| 253 | /** | ||
| 254 | * speedstep_target - set a new CPUFreq policy | ||
| 255 | * @policy: new policy | ||
| 256 | * @target_freq: the target frequency | ||
| 257 | * @relation: how that frequency relates to achieved frequency | ||
| 258 | * (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H) | ||
| 259 | * | ||
| 260 | * Sets a new CPUFreq policy. | ||
| 261 | */ | ||
| 262 | static int speedstep_target(struct cpufreq_policy *policy, | ||
| 263 | unsigned int target_freq, | ||
| 264 | unsigned int relation) | ||
| 265 | { | ||
| 266 | unsigned int newstate = 0, policy_cpu; | ||
| 267 | struct cpufreq_freqs freqs; | ||
| 268 | int i; | ||
| 269 | |||
| 270 | if (cpufreq_frequency_table_target(policy, &speedstep_freqs[0], | ||
| 271 | target_freq, relation, &newstate)) | ||
| 272 | return -EINVAL; | ||
| 273 | |||
| 274 | policy_cpu = cpumask_any_and(policy->cpus, cpu_online_mask); | ||
| 275 | freqs.old = speedstep_get(policy_cpu); | ||
| 276 | freqs.new = speedstep_freqs[newstate].frequency; | ||
| 277 | freqs.cpu = policy->cpu; | ||
| 278 | |||
| 279 | dprintk("transiting from %u to %u kHz\n", freqs.old, freqs.new); | ||
| 280 | |||
| 281 | /* no transition necessary */ | ||
| 282 | if (freqs.old == freqs.new) | ||
| 283 | return 0; | ||
| 284 | |||
| 285 | for_each_cpu(i, policy->cpus) { | ||
| 286 | freqs.cpu = i; | ||
| 287 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
| 288 | } | ||
| 289 | |||
| 290 | smp_call_function_single(policy_cpu, _speedstep_set_state, &newstate, | ||
| 291 | true); | ||
| 292 | |||
| 293 | for_each_cpu(i, policy->cpus) { | ||
| 294 | freqs.cpu = i; | ||
| 295 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 296 | } | ||
| 297 | |||
| 298 | return 0; | ||
| 299 | } | ||
| 300 | |||
| 301 | |||
| 302 | /** | ||
| 303 | * speedstep_verify - verifies a new CPUFreq policy | ||
| 304 | * @policy: new policy | ||
| 305 | * | ||
| 306 | * Limit must be within speedstep_low_freq and speedstep_high_freq, with | ||
| 307 | * at least one border included. | ||
| 308 | */ | ||
| 309 | static int speedstep_verify(struct cpufreq_policy *policy) | ||
| 310 | { | ||
| 311 | return cpufreq_frequency_table_verify(policy, &speedstep_freqs[0]); | ||
| 312 | } | ||
| 313 | |||
| 314 | struct get_freqs { | ||
| 315 | struct cpufreq_policy *policy; | ||
| 316 | int ret; | ||
| 317 | }; | ||
| 318 | |||
| 319 | static void get_freqs_on_cpu(void *_get_freqs) | ||
| 320 | { | ||
| 321 | struct get_freqs *get_freqs = _get_freqs; | ||
| 322 | |||
| 323 | get_freqs->ret = | ||
| 324 | speedstep_get_freqs(speedstep_processor, | ||
| 325 | &speedstep_freqs[SPEEDSTEP_LOW].frequency, | ||
| 326 | &speedstep_freqs[SPEEDSTEP_HIGH].frequency, | ||
| 327 | &get_freqs->policy->cpuinfo.transition_latency, | ||
| 328 | &speedstep_set_state); | ||
| 329 | } | ||
| 330 | |||
| 331 | static int speedstep_cpu_init(struct cpufreq_policy *policy) | ||
| 332 | { | ||
| 333 | int result; | ||
| 334 | unsigned int policy_cpu, speed; | ||
| 335 | struct get_freqs gf; | ||
| 336 | |||
| 337 | /* only run on CPU to be set, or on its sibling */ | ||
| 338 | #ifdef CONFIG_SMP | ||
| 339 | cpumask_copy(policy->cpus, cpu_sibling_mask(policy->cpu)); | ||
| 340 | #endif | ||
| 341 | policy_cpu = cpumask_any_and(policy->cpus, cpu_online_mask); | ||
| 342 | |||
| 343 | /* detect low and high frequency and transition latency */ | ||
| 344 | gf.policy = policy; | ||
| 345 | smp_call_function_single(policy_cpu, get_freqs_on_cpu, &gf, 1); | ||
| 346 | if (gf.ret) | ||
| 347 | return gf.ret; | ||
| 348 | |||
| 349 | /* get current speed setting */ | ||
| 350 | speed = speedstep_get(policy_cpu); | ||
| 351 | if (!speed) | ||
| 352 | return -EIO; | ||
| 353 | |||
| 354 | dprintk("currently at %s speed setting - %i MHz\n", | ||
| 355 | (speed == speedstep_freqs[SPEEDSTEP_LOW].frequency) | ||
| 356 | ? "low" : "high", | ||
| 357 | (speed / 1000)); | ||
| 358 | |||
| 359 | /* cpuinfo and default policy values */ | ||
| 360 | policy->cur = speed; | ||
| 361 | |||
| 362 | result = cpufreq_frequency_table_cpuinfo(policy, speedstep_freqs); | ||
| 363 | if (result) | ||
| 364 | return result; | ||
| 365 | |||
| 366 | cpufreq_frequency_table_get_attr(speedstep_freqs, policy->cpu); | ||
| 367 | |||
| 368 | return 0; | ||
| 369 | } | ||
| 370 | |||
| 371 | |||
| 372 | static int speedstep_cpu_exit(struct cpufreq_policy *policy) | ||
| 373 | { | ||
| 374 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
| 375 | return 0; | ||
| 376 | } | ||
| 377 | |||
| 378 | static struct freq_attr *speedstep_attr[] = { | ||
| 379 | &cpufreq_freq_attr_scaling_available_freqs, | ||
| 380 | NULL, | ||
| 381 | }; | ||
| 382 | |||
| 383 | |||
| 384 | static struct cpufreq_driver speedstep_driver = { | ||
| 385 | .name = "speedstep-ich", | ||
| 386 | .verify = speedstep_verify, | ||
| 387 | .target = speedstep_target, | ||
| 388 | .init = speedstep_cpu_init, | ||
| 389 | .exit = speedstep_cpu_exit, | ||
| 390 | .get = speedstep_get, | ||
| 391 | .owner = THIS_MODULE, | ||
| 392 | .attr = speedstep_attr, | ||
| 393 | }; | ||
| 394 | |||
| 395 | |||
| 396 | /** | ||
| 397 | * speedstep_init - initializes the SpeedStep CPUFreq driver | ||
| 398 | * | ||
| 399 | * Initializes the SpeedStep support. Returns -ENODEV on unsupported | ||
| 400 | * devices, -EINVAL on problems during initiatization, and zero on | ||
| 401 | * success. | ||
| 402 | */ | ||
| 403 | static int __init speedstep_init(void) | ||
| 404 | { | ||
| 405 | /* detect processor */ | ||
| 406 | speedstep_processor = speedstep_detect_processor(); | ||
| 407 | if (!speedstep_processor) { | ||
| 408 | dprintk("Intel(R) SpeedStep(TM) capable processor " | ||
| 409 | "not found\n"); | ||
| 410 | return -ENODEV; | ||
| 411 | } | ||
| 412 | |||
| 413 | /* detect chipset */ | ||
| 414 | if (!speedstep_detect_chipset()) { | ||
| 415 | dprintk("Intel(R) SpeedStep(TM) for this chipset not " | ||
| 416 | "(yet) available.\n"); | ||
| 417 | return -ENODEV; | ||
| 418 | } | ||
| 419 | |||
| 420 | /* activate speedstep support */ | ||
| 421 | if (speedstep_activate()) { | ||
| 422 | pci_dev_put(speedstep_chipset_dev); | ||
| 423 | return -EINVAL; | ||
| 424 | } | ||
| 425 | |||
| 426 | if (speedstep_find_register()) | ||
| 427 | return -ENODEV; | ||
| 428 | |||
| 429 | return cpufreq_register_driver(&speedstep_driver); | ||
| 430 | } | ||
| 431 | |||
| 432 | |||
| 433 | /** | ||
| 434 | * speedstep_exit - unregisters SpeedStep support | ||
| 435 | * | ||
| 436 | * Unregisters SpeedStep support. | ||
| 437 | */ | ||
| 438 | static void __exit speedstep_exit(void) | ||
| 439 | { | ||
| 440 | pci_dev_put(speedstep_chipset_dev); | ||
| 441 | cpufreq_unregister_driver(&speedstep_driver); | ||
| 442 | } | ||
| 443 | |||
| 444 | |||
| 445 | MODULE_AUTHOR("Dave Jones <davej@redhat.com>, " | ||
| 446 | "Dominik Brodowski <linux@brodo.de>"); | ||
| 447 | MODULE_DESCRIPTION("Speedstep driver for Intel mobile processors on chipsets " | ||
| 448 | "with ICH-M southbridges."); | ||
| 449 | MODULE_LICENSE("GPL"); | ||
| 450 | |||
| 451 | module_init(speedstep_init); | ||
| 452 | module_exit(speedstep_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/speedstep-lib.c b/arch/x86/kernel/cpu/cpufreq/speedstep-lib.c deleted file mode 100644 index a94ec6be69fa..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/speedstep-lib.c +++ /dev/null | |||
| @@ -1,481 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> | ||
| 3 | * | ||
| 4 | * Licensed under the terms of the GNU GPL License version 2. | ||
| 5 | * | ||
| 6 | * Library for common functions for Intel SpeedStep v.1 and v.2 support | ||
| 7 | * | ||
| 8 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <linux/kernel.h> | ||
| 12 | #include <linux/module.h> | ||
| 13 | #include <linux/moduleparam.h> | ||
| 14 | #include <linux/init.h> | ||
| 15 | #include <linux/cpufreq.h> | ||
| 16 | |||
| 17 | #include <asm/msr.h> | ||
| 18 | #include <asm/tsc.h> | ||
| 19 | #include "speedstep-lib.h" | ||
| 20 | |||
| 21 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
| 22 | "speedstep-lib", msg) | ||
| 23 | |||
| 24 | #define PFX "speedstep-lib: " | ||
| 25 | |||
| 26 | #ifdef CONFIG_X86_SPEEDSTEP_RELAXED_CAP_CHECK | ||
| 27 | static int relaxed_check; | ||
| 28 | #else | ||
| 29 | #define relaxed_check 0 | ||
| 30 | #endif | ||
| 31 | |||
| 32 | /********************************************************************* | ||
| 33 | * GET PROCESSOR CORE SPEED IN KHZ * | ||
| 34 | *********************************************************************/ | ||
| 35 | |||
| 36 | static unsigned int pentium3_get_frequency(enum speedstep_processor processor) | ||
| 37 | { | ||
| 38 | /* See table 14 of p3_ds.pdf and table 22 of 29834003.pdf */ | ||
| 39 | struct { | ||
| 40 | unsigned int ratio; /* Frequency Multiplier (x10) */ | ||
| 41 | u8 bitmap; /* power on configuration bits | ||
| 42 | [27, 25:22] (in MSR 0x2a) */ | ||
| 43 | } msr_decode_mult[] = { | ||
| 44 | { 30, 0x01 }, | ||
| 45 | { 35, 0x05 }, | ||
| 46 | { 40, 0x02 }, | ||
| 47 | { 45, 0x06 }, | ||
| 48 | { 50, 0x00 }, | ||
| 49 | { 55, 0x04 }, | ||
| 50 | { 60, 0x0b }, | ||
| 51 | { 65, 0x0f }, | ||
| 52 | { 70, 0x09 }, | ||
| 53 | { 75, 0x0d }, | ||
| 54 | { 80, 0x0a }, | ||
| 55 | { 85, 0x26 }, | ||
| 56 | { 90, 0x20 }, | ||
| 57 | { 100, 0x2b }, | ||
| 58 | { 0, 0xff } /* error or unknown value */ | ||
| 59 | }; | ||
| 60 | |||
| 61 | /* PIII(-M) FSB settings: see table b1-b of 24547206.pdf */ | ||
| 62 | struct { | ||
| 63 | unsigned int value; /* Front Side Bus speed in MHz */ | ||
| 64 | u8 bitmap; /* power on configuration bits [18: 19] | ||
| 65 | (in MSR 0x2a) */ | ||
| 66 | } msr_decode_fsb[] = { | ||
| 67 | { 66, 0x0 }, | ||
| 68 | { 100, 0x2 }, | ||
| 69 | { 133, 0x1 }, | ||
| 70 | { 0, 0xff} | ||
| 71 | }; | ||
| 72 | |||
| 73 | u32 msr_lo, msr_tmp; | ||
| 74 | int i = 0, j = 0; | ||
| 75 | |||
| 76 | /* read MSR 0x2a - we only need the low 32 bits */ | ||
| 77 | rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_tmp); | ||
| 78 | dprintk("P3 - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n", msr_lo, msr_tmp); | ||
| 79 | msr_tmp = msr_lo; | ||
| 80 | |||
| 81 | /* decode the FSB */ | ||
| 82 | msr_tmp &= 0x00c0000; | ||
| 83 | msr_tmp >>= 18; | ||
| 84 | while (msr_tmp != msr_decode_fsb[i].bitmap) { | ||
| 85 | if (msr_decode_fsb[i].bitmap == 0xff) | ||
| 86 | return 0; | ||
| 87 | i++; | ||
| 88 | } | ||
| 89 | |||
| 90 | /* decode the multiplier */ | ||
| 91 | if (processor == SPEEDSTEP_CPU_PIII_C_EARLY) { | ||
| 92 | dprintk("workaround for early PIIIs\n"); | ||
| 93 | msr_lo &= 0x03c00000; | ||
| 94 | } else | ||
| 95 | msr_lo &= 0x0bc00000; | ||
| 96 | msr_lo >>= 22; | ||
| 97 | while (msr_lo != msr_decode_mult[j].bitmap) { | ||
| 98 | if (msr_decode_mult[j].bitmap == 0xff) | ||
| 99 | return 0; | ||
| 100 | j++; | ||
| 101 | } | ||
| 102 | |||
| 103 | dprintk("speed is %u\n", | ||
| 104 | (msr_decode_mult[j].ratio * msr_decode_fsb[i].value * 100)); | ||
| 105 | |||
| 106 | return msr_decode_mult[j].ratio * msr_decode_fsb[i].value * 100; | ||
| 107 | } | ||
| 108 | |||
| 109 | |||
| 110 | static unsigned int pentiumM_get_frequency(void) | ||
| 111 | { | ||
| 112 | u32 msr_lo, msr_tmp; | ||
| 113 | |||
| 114 | rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_tmp); | ||
| 115 | dprintk("PM - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n", msr_lo, msr_tmp); | ||
| 116 | |||
| 117 | /* see table B-2 of 24547212.pdf */ | ||
| 118 | if (msr_lo & 0x00040000) { | ||
| 119 | printk(KERN_DEBUG PFX "PM - invalid FSB: 0x%x 0x%x\n", | ||
| 120 | msr_lo, msr_tmp); | ||
| 121 | return 0; | ||
| 122 | } | ||
| 123 | |||
| 124 | msr_tmp = (msr_lo >> 22) & 0x1f; | ||
| 125 | dprintk("bits 22-26 are 0x%x, speed is %u\n", | ||
| 126 | msr_tmp, (msr_tmp * 100 * 1000)); | ||
| 127 | |||
| 128 | return msr_tmp * 100 * 1000; | ||
| 129 | } | ||
| 130 | |||
| 131 | static unsigned int pentium_core_get_frequency(void) | ||
| 132 | { | ||
| 133 | u32 fsb = 0; | ||
| 134 | u32 msr_lo, msr_tmp; | ||
| 135 | int ret; | ||
| 136 | |||
| 137 | rdmsr(MSR_FSB_FREQ, msr_lo, msr_tmp); | ||
| 138 | /* see table B-2 of 25366920.pdf */ | ||
| 139 | switch (msr_lo & 0x07) { | ||
| 140 | case 5: | ||
| 141 | fsb = 100000; | ||
| 142 | break; | ||
| 143 | case 1: | ||
| 144 | fsb = 133333; | ||
| 145 | break; | ||
| 146 | case 3: | ||
| 147 | fsb = 166667; | ||
| 148 | break; | ||
| 149 | case 2: | ||
| 150 | fsb = 200000; | ||
| 151 | break; | ||
| 152 | case 0: | ||
| 153 | fsb = 266667; | ||
| 154 | break; | ||
| 155 | case 4: | ||
| 156 | fsb = 333333; | ||
| 157 | break; | ||
| 158 | default: | ||
| 159 | printk(KERN_ERR "PCORE - MSR_FSB_FREQ undefined value"); | ||
| 160 | } | ||
| 161 | |||
| 162 | rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_tmp); | ||
| 163 | dprintk("PCORE - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n", | ||
| 164 | msr_lo, msr_tmp); | ||
| 165 | |||
| 166 | msr_tmp = (msr_lo >> 22) & 0x1f; | ||
| 167 | dprintk("bits 22-26 are 0x%x, speed is %u\n", | ||
| 168 | msr_tmp, (msr_tmp * fsb)); | ||
| 169 | |||
| 170 | ret = (msr_tmp * fsb); | ||
| 171 | return ret; | ||
| 172 | } | ||
| 173 | |||
| 174 | |||
| 175 | static unsigned int pentium4_get_frequency(void) | ||
| 176 | { | ||
| 177 | struct cpuinfo_x86 *c = &boot_cpu_data; | ||
| 178 | u32 msr_lo, msr_hi, mult; | ||
| 179 | unsigned int fsb = 0; | ||
| 180 | unsigned int ret; | ||
| 181 | u8 fsb_code; | ||
| 182 | |||
| 183 | /* Pentium 4 Model 0 and 1 do not have the Core Clock Frequency | ||
| 184 | * to System Bus Frequency Ratio Field in the Processor Frequency | ||
| 185 | * Configuration Register of the MSR. Therefore the current | ||
| 186 | * frequency cannot be calculated and has to be measured. | ||
| 187 | */ | ||
| 188 | if (c->x86_model < 2) | ||
| 189 | return cpu_khz; | ||
| 190 | |||
| 191 | rdmsr(0x2c, msr_lo, msr_hi); | ||
| 192 | |||
| 193 | dprintk("P4 - MSR_EBC_FREQUENCY_ID: 0x%x 0x%x\n", msr_lo, msr_hi); | ||
| 194 | |||
| 195 | /* decode the FSB: see IA-32 Intel (C) Architecture Software | ||
| 196 | * Developer's Manual, Volume 3: System Prgramming Guide, | ||
| 197 | * revision #12 in Table B-1: MSRs in the Pentium 4 and | ||
| 198 | * Intel Xeon Processors, on page B-4 and B-5. | ||
| 199 | */ | ||
| 200 | fsb_code = (msr_lo >> 16) & 0x7; | ||
| 201 | switch (fsb_code) { | ||
| 202 | case 0: | ||
| 203 | fsb = 100 * 1000; | ||
| 204 | break; | ||
| 205 | case 1: | ||
| 206 | fsb = 13333 * 10; | ||
| 207 | break; | ||
| 208 | case 2: | ||
| 209 | fsb = 200 * 1000; | ||
| 210 | break; | ||
| 211 | } | ||
| 212 | |||
| 213 | if (!fsb) | ||
| 214 | printk(KERN_DEBUG PFX "couldn't detect FSB speed. " | ||
| 215 | "Please send an e-mail to <linux@brodo.de>\n"); | ||
| 216 | |||
| 217 | /* Multiplier. */ | ||
| 218 | mult = msr_lo >> 24; | ||
| 219 | |||
| 220 | dprintk("P4 - FSB %u kHz; Multiplier %u; Speed %u kHz\n", | ||
| 221 | fsb, mult, (fsb * mult)); | ||
| 222 | |||
| 223 | ret = (fsb * mult); | ||
| 224 | return ret; | ||
| 225 | } | ||
| 226 | |||
| 227 | |||
| 228 | /* Warning: may get called from smp_call_function_single. */ | ||
| 229 | unsigned int speedstep_get_frequency(enum speedstep_processor processor) | ||
| 230 | { | ||
| 231 | switch (processor) { | ||
| 232 | case SPEEDSTEP_CPU_PCORE: | ||
| 233 | return pentium_core_get_frequency(); | ||
| 234 | case SPEEDSTEP_CPU_PM: | ||
| 235 | return pentiumM_get_frequency(); | ||
| 236 | case SPEEDSTEP_CPU_P4D: | ||
| 237 | case SPEEDSTEP_CPU_P4M: | ||
| 238 | return pentium4_get_frequency(); | ||
| 239 | case SPEEDSTEP_CPU_PIII_T: | ||
| 240 | case SPEEDSTEP_CPU_PIII_C: | ||
| 241 | case SPEEDSTEP_CPU_PIII_C_EARLY: | ||
| 242 | return pentium3_get_frequency(processor); | ||
| 243 | default: | ||
| 244 | return 0; | ||
| 245 | }; | ||
| 246 | return 0; | ||
| 247 | } | ||
| 248 | EXPORT_SYMBOL_GPL(speedstep_get_frequency); | ||
| 249 | |||
| 250 | |||
| 251 | /********************************************************************* | ||
| 252 | * DETECT SPEEDSTEP-CAPABLE PROCESSOR * | ||
| 253 | *********************************************************************/ | ||
| 254 | |||
| 255 | unsigned int speedstep_detect_processor(void) | ||
| 256 | { | ||
| 257 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
| 258 | u32 ebx, msr_lo, msr_hi; | ||
| 259 | |||
| 260 | dprintk("x86: %x, model: %x\n", c->x86, c->x86_model); | ||
| 261 | |||
| 262 | if ((c->x86_vendor != X86_VENDOR_INTEL) || | ||
| 263 | ((c->x86 != 6) && (c->x86 != 0xF))) | ||
| 264 | return 0; | ||
| 265 | |||
| 266 | if (c->x86 == 0xF) { | ||
| 267 | /* Intel Mobile Pentium 4-M | ||
| 268 | * or Intel Mobile Pentium 4 with 533 MHz FSB */ | ||
| 269 | if (c->x86_model != 2) | ||
| 270 | return 0; | ||
| 271 | |||
| 272 | ebx = cpuid_ebx(0x00000001); | ||
| 273 | ebx &= 0x000000FF; | ||
| 274 | |||
| 275 | dprintk("ebx value is %x, x86_mask is %x\n", ebx, c->x86_mask); | ||
| 276 | |||
| 277 | switch (c->x86_mask) { | ||
| 278 | case 4: | ||
| 279 | /* | ||
| 280 | * B-stepping [M-P4-M] | ||
| 281 | * sample has ebx = 0x0f, production has 0x0e. | ||
| 282 | */ | ||
| 283 | if ((ebx == 0x0e) || (ebx == 0x0f)) | ||
| 284 | return SPEEDSTEP_CPU_P4M; | ||
| 285 | break; | ||
| 286 | case 7: | ||
| 287 | /* | ||
| 288 | * C-stepping [M-P4-M] | ||
| 289 | * needs to have ebx=0x0e, else it's a celeron: | ||
| 290 | * cf. 25130917.pdf / page 7, footnote 5 even | ||
| 291 | * though 25072120.pdf / page 7 doesn't say | ||
| 292 | * samples are only of B-stepping... | ||
| 293 | */ | ||
| 294 | if (ebx == 0x0e) | ||
| 295 | return SPEEDSTEP_CPU_P4M; | ||
| 296 | break; | ||
| 297 | case 9: | ||
| 298 | /* | ||
| 299 | * D-stepping [M-P4-M or M-P4/533] | ||
| 300 | * | ||
| 301 | * this is totally strange: CPUID 0x0F29 is | ||
| 302 | * used by M-P4-M, M-P4/533 and(!) Celeron CPUs. | ||
| 303 | * The latter need to be sorted out as they don't | ||
| 304 | * support speedstep. | ||
| 305 | * Celerons with CPUID 0x0F29 may have either | ||
| 306 | * ebx=0x8 or 0xf -- 25130917.pdf doesn't say anything | ||
| 307 | * specific. | ||
| 308 | * M-P4-Ms may have either ebx=0xe or 0xf [see above] | ||
| 309 | * M-P4/533 have either ebx=0xe or 0xf. [25317607.pdf] | ||
| 310 | * also, M-P4M HTs have ebx=0x8, too | ||
| 311 | * For now, they are distinguished by the model_id | ||
| 312 | * string | ||
| 313 | */ | ||
| 314 | if ((ebx == 0x0e) || | ||
| 315 | (strstr(c->x86_model_id, | ||
| 316 | "Mobile Intel(R) Pentium(R) 4") != NULL)) | ||
| 317 | return SPEEDSTEP_CPU_P4M; | ||
| 318 | break; | ||
| 319 | default: | ||
| 320 | break; | ||
| 321 | } | ||
| 322 | return 0; | ||
| 323 | } | ||
| 324 | |||
| 325 | switch (c->x86_model) { | ||
| 326 | case 0x0B: /* Intel PIII [Tualatin] */ | ||
| 327 | /* cpuid_ebx(1) is 0x04 for desktop PIII, | ||
| 328 | * 0x06 for mobile PIII-M */ | ||
| 329 | ebx = cpuid_ebx(0x00000001); | ||
| 330 | dprintk("ebx is %x\n", ebx); | ||
| 331 | |||
| 332 | ebx &= 0x000000FF; | ||
| 333 | |||
| 334 | if (ebx != 0x06) | ||
| 335 | return 0; | ||
| 336 | |||
| 337 | /* So far all PIII-M processors support SpeedStep. See | ||
| 338 | * Intel's 24540640.pdf of June 2003 | ||
| 339 | */ | ||
| 340 | return SPEEDSTEP_CPU_PIII_T; | ||
| 341 | |||
| 342 | case 0x08: /* Intel PIII [Coppermine] */ | ||
| 343 | |||
| 344 | /* all mobile PIII Coppermines have FSB 100 MHz | ||
| 345 | * ==> sort out a few desktop PIIIs. */ | ||
| 346 | rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_hi); | ||
| 347 | dprintk("Coppermine: MSR_IA32_EBL_CR_POWERON is 0x%x, 0x%x\n", | ||
| 348 | msr_lo, msr_hi); | ||
| 349 | msr_lo &= 0x00c0000; | ||
| 350 | if (msr_lo != 0x0080000) | ||
| 351 | return 0; | ||
| 352 | |||
| 353 | /* | ||
| 354 | * If the processor is a mobile version, | ||
| 355 | * platform ID has bit 50 set | ||
| 356 | * it has SpeedStep technology if either | ||
| 357 | * bit 56 or 57 is set | ||
| 358 | */ | ||
| 359 | rdmsr(MSR_IA32_PLATFORM_ID, msr_lo, msr_hi); | ||
| 360 | dprintk("Coppermine: MSR_IA32_PLATFORM ID is 0x%x, 0x%x\n", | ||
| 361 | msr_lo, msr_hi); | ||
| 362 | if ((msr_hi & (1<<18)) && | ||
| 363 | (relaxed_check ? 1 : (msr_hi & (3<<24)))) { | ||
| 364 | if (c->x86_mask == 0x01) { | ||
| 365 | dprintk("early PIII version\n"); | ||
| 366 | return SPEEDSTEP_CPU_PIII_C_EARLY; | ||
| 367 | } else | ||
| 368 | return SPEEDSTEP_CPU_PIII_C; | ||
| 369 | } | ||
| 370 | |||
| 371 | default: | ||
| 372 | return 0; | ||
| 373 | } | ||
| 374 | } | ||
| 375 | EXPORT_SYMBOL_GPL(speedstep_detect_processor); | ||
| 376 | |||
| 377 | |||
| 378 | /********************************************************************* | ||
| 379 | * DETECT SPEEDSTEP SPEEDS * | ||
| 380 | *********************************************************************/ | ||
| 381 | |||
| 382 | unsigned int speedstep_get_freqs(enum speedstep_processor processor, | ||
| 383 | unsigned int *low_speed, | ||
| 384 | unsigned int *high_speed, | ||
| 385 | unsigned int *transition_latency, | ||
| 386 | void (*set_state) (unsigned int state)) | ||
| 387 | { | ||
| 388 | unsigned int prev_speed; | ||
| 389 | unsigned int ret = 0; | ||
| 390 | unsigned long flags; | ||
| 391 | struct timeval tv1, tv2; | ||
| 392 | |||
| 393 | if ((!processor) || (!low_speed) || (!high_speed) || (!set_state)) | ||
| 394 | return -EINVAL; | ||
| 395 | |||
| 396 | dprintk("trying to determine both speeds\n"); | ||
| 397 | |||
| 398 | /* get current speed */ | ||
| 399 | prev_speed = speedstep_get_frequency(processor); | ||
| 400 | if (!prev_speed) | ||
| 401 | return -EIO; | ||
| 402 | |||
| 403 | dprintk("previous speed is %u\n", prev_speed); | ||
| 404 | |||
| 405 | local_irq_save(flags); | ||
| 406 | |||
| 407 | /* switch to low state */ | ||
| 408 | set_state(SPEEDSTEP_LOW); | ||
| 409 | *low_speed = speedstep_get_frequency(processor); | ||
| 410 | if (!*low_speed) { | ||
| 411 | ret = -EIO; | ||
| 412 | goto out; | ||
| 413 | } | ||
| 414 | |||
| 415 | dprintk("low speed is %u\n", *low_speed); | ||
| 416 | |||
| 417 | /* start latency measurement */ | ||
| 418 | if (transition_latency) | ||
| 419 | do_gettimeofday(&tv1); | ||
| 420 | |||
| 421 | /* switch to high state */ | ||
| 422 | set_state(SPEEDSTEP_HIGH); | ||
| 423 | |||
| 424 | /* end latency measurement */ | ||
| 425 | if (transition_latency) | ||
| 426 | do_gettimeofday(&tv2); | ||
| 427 | |||
| 428 | *high_speed = speedstep_get_frequency(processor); | ||
| 429 | if (!*high_speed) { | ||
| 430 | ret = -EIO; | ||
| 431 | goto out; | ||
| 432 | } | ||
| 433 | |||
| 434 | dprintk("high speed is %u\n", *high_speed); | ||
| 435 | |||
| 436 | if (*low_speed == *high_speed) { | ||
| 437 | ret = -ENODEV; | ||
| 438 | goto out; | ||
| 439 | } | ||
| 440 | |||
| 441 | /* switch to previous state, if necessary */ | ||
| 442 | if (*high_speed != prev_speed) | ||
| 443 | set_state(SPEEDSTEP_LOW); | ||
| 444 | |||
| 445 | if (transition_latency) { | ||
| 446 | *transition_latency = (tv2.tv_sec - tv1.tv_sec) * USEC_PER_SEC + | ||
| 447 | tv2.tv_usec - tv1.tv_usec; | ||
| 448 | dprintk("transition latency is %u uSec\n", *transition_latency); | ||
| 449 | |||
| 450 | /* convert uSec to nSec and add 20% for safety reasons */ | ||
| 451 | *transition_latency *= 1200; | ||
| 452 | |||
| 453 | /* check if the latency measurement is too high or too low | ||
| 454 | * and set it to a safe value (500uSec) in that case | ||
| 455 | */ | ||
| 456 | if (*transition_latency > 10000000 || | ||
| 457 | *transition_latency < 50000) { | ||
| 458 | printk(KERN_WARNING PFX "frequency transition " | ||
| 459 | "measured seems out of range (%u " | ||
| 460 | "nSec), falling back to a safe one of" | ||
| 461 | "%u nSec.\n", | ||
| 462 | *transition_latency, 500000); | ||
| 463 | *transition_latency = 500000; | ||
| 464 | } | ||
| 465 | } | ||
| 466 | |||
| 467 | out: | ||
| 468 | local_irq_restore(flags); | ||
| 469 | return ret; | ||
| 470 | } | ||
| 471 | EXPORT_SYMBOL_GPL(speedstep_get_freqs); | ||
| 472 | |||
| 473 | #ifdef CONFIG_X86_SPEEDSTEP_RELAXED_CAP_CHECK | ||
| 474 | module_param(relaxed_check, int, 0444); | ||
| 475 | MODULE_PARM_DESC(relaxed_check, | ||
| 476 | "Don't do all checks for speedstep capability."); | ||
| 477 | #endif | ||
| 478 | |||
| 479 | MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>"); | ||
| 480 | MODULE_DESCRIPTION("Library for Intel SpeedStep 1 or 2 cpufreq drivers."); | ||
| 481 | MODULE_LICENSE("GPL"); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/speedstep-lib.h b/arch/x86/kernel/cpu/cpufreq/speedstep-lib.h deleted file mode 100644 index 70d9cea1219d..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/speedstep-lib.h +++ /dev/null | |||
| @@ -1,49 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> | ||
| 3 | * | ||
| 4 | * Licensed under the terms of the GNU GPL License version 2. | ||
| 5 | * | ||
| 6 | * Library for common functions for Intel SpeedStep v.1 and v.2 support | ||
| 7 | * | ||
| 8 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
| 9 | */ | ||
| 10 | |||
| 11 | |||
| 12 | |||
| 13 | /* processors */ | ||
| 14 | enum speedstep_processor { | ||
| 15 | SPEEDSTEP_CPU_PIII_C_EARLY = 0x00000001, /* Coppermine core */ | ||
| 16 | SPEEDSTEP_CPU_PIII_C = 0x00000002, /* Coppermine core */ | ||
| 17 | SPEEDSTEP_CPU_PIII_T = 0x00000003, /* Tualatin core */ | ||
| 18 | SPEEDSTEP_CPU_P4M = 0x00000004, /* P4-M */ | ||
| 19 | /* the following processors are not speedstep-capable and are not auto-detected | ||
| 20 | * in speedstep_detect_processor(). However, their speed can be detected using | ||
| 21 | * the speedstep_get_frequency() call. */ | ||
| 22 | SPEEDSTEP_CPU_PM = 0xFFFFFF03, /* Pentium M */ | ||
| 23 | SPEEDSTEP_CPU_P4D = 0xFFFFFF04, /* desktop P4 */ | ||
| 24 | SPEEDSTEP_CPU_PCORE = 0xFFFFFF05, /* Core */ | ||
| 25 | }; | ||
| 26 | |||
| 27 | /* speedstep states -- only two of them */ | ||
| 28 | |||
| 29 | #define SPEEDSTEP_HIGH 0x00000000 | ||
| 30 | #define SPEEDSTEP_LOW 0x00000001 | ||
| 31 | |||
| 32 | |||
| 33 | /* detect a speedstep-capable processor */ | ||
| 34 | extern enum speedstep_processor speedstep_detect_processor(void); | ||
| 35 | |||
| 36 | /* detect the current speed (in khz) of the processor */ | ||
| 37 | extern unsigned int speedstep_get_frequency(enum speedstep_processor processor); | ||
| 38 | |||
| 39 | |||
| 40 | /* detect the low and high speeds of the processor. The callback | ||
| 41 | * set_state"'s first argument is either SPEEDSTEP_HIGH or | ||
| 42 | * SPEEDSTEP_LOW; the second argument is zero so that no | ||
| 43 | * cpufreq_notify_transition calls are initiated. | ||
| 44 | */ | ||
| 45 | extern unsigned int speedstep_get_freqs(enum speedstep_processor processor, | ||
| 46 | unsigned int *low_speed, | ||
| 47 | unsigned int *high_speed, | ||
| 48 | unsigned int *transition_latency, | ||
| 49 | void (*set_state) (unsigned int state)); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/speedstep-smi.c b/arch/x86/kernel/cpu/cpufreq/speedstep-smi.c deleted file mode 100644 index 91bc25b67bc1..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/speedstep-smi.c +++ /dev/null | |||
| @@ -1,467 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Intel SpeedStep SMI driver. | ||
| 3 | * | ||
| 4 | * (C) 2003 Hiroshi Miura <miura@da-cha.org> | ||
| 5 | * | ||
| 6 | * Licensed under the terms of the GNU GPL License version 2. | ||
| 7 | * | ||
| 8 | */ | ||
| 9 | |||
| 10 | |||
| 11 | /********************************************************************* | ||
| 12 | * SPEEDSTEP - DEFINITIONS * | ||
| 13 | *********************************************************************/ | ||
| 14 | |||
| 15 | #include <linux/kernel.h> | ||
| 16 | #include <linux/module.h> | ||
| 17 | #include <linux/moduleparam.h> | ||
| 18 | #include <linux/init.h> | ||
| 19 | #include <linux/cpufreq.h> | ||
| 20 | #include <linux/delay.h> | ||
| 21 | #include <linux/io.h> | ||
| 22 | #include <asm/ist.h> | ||
| 23 | |||
| 24 | #include "speedstep-lib.h" | ||
| 25 | |||
| 26 | /* speedstep system management interface port/command. | ||
| 27 | * | ||
| 28 | * These parameters are got from IST-SMI BIOS call. | ||
| 29 | * If user gives it, these are used. | ||
| 30 | * | ||
| 31 | */ | ||
| 32 | static int smi_port; | ||
| 33 | static int smi_cmd; | ||
| 34 | static unsigned int smi_sig; | ||
| 35 | |||
| 36 | /* info about the processor */ | ||
| 37 | static enum speedstep_processor speedstep_processor; | ||
| 38 | |||
| 39 | /* | ||
| 40 | * There are only two frequency states for each processor. Values | ||
| 41 | * are in kHz for the time being. | ||
| 42 | */ | ||
| 43 | static struct cpufreq_frequency_table speedstep_freqs[] = { | ||
| 44 | {SPEEDSTEP_HIGH, 0}, | ||
| 45 | {SPEEDSTEP_LOW, 0}, | ||
| 46 | {0, CPUFREQ_TABLE_END}, | ||
| 47 | }; | ||
| 48 | |||
| 49 | #define GET_SPEEDSTEP_OWNER 0 | ||
| 50 | #define GET_SPEEDSTEP_STATE 1 | ||
| 51 | #define SET_SPEEDSTEP_STATE 2 | ||
| 52 | #define GET_SPEEDSTEP_FREQS 4 | ||
| 53 | |||
| 54 | /* how often shall the SMI call be tried if it failed, e.g. because | ||
| 55 | * of DMA activity going on? */ | ||
| 56 | #define SMI_TRIES 5 | ||
| 57 | |||
| 58 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
| 59 | "speedstep-smi", msg) | ||
| 60 | |||
| 61 | /** | ||
| 62 | * speedstep_smi_ownership | ||
| 63 | */ | ||
| 64 | static int speedstep_smi_ownership(void) | ||
| 65 | { | ||
| 66 | u32 command, result, magic, dummy; | ||
| 67 | u32 function = GET_SPEEDSTEP_OWNER; | ||
| 68 | unsigned char magic_data[] = "Copyright (c) 1999 Intel Corporation"; | ||
| 69 | |||
| 70 | command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff); | ||
| 71 | magic = virt_to_phys(magic_data); | ||
| 72 | |||
| 73 | dprintk("trying to obtain ownership with command %x at port %x\n", | ||
| 74 | command, smi_port); | ||
| 75 | |||
| 76 | __asm__ __volatile__( | ||
| 77 | "push %%ebp\n" | ||
| 78 | "out %%al, (%%dx)\n" | ||
| 79 | "pop %%ebp\n" | ||
| 80 | : "=D" (result), | ||
| 81 | "=a" (dummy), "=b" (dummy), "=c" (dummy), "=d" (dummy), | ||
| 82 | "=S" (dummy) | ||
| 83 | : "a" (command), "b" (function), "c" (0), "d" (smi_port), | ||
| 84 | "D" (0), "S" (magic) | ||
| 85 | : "memory" | ||
| 86 | ); | ||
| 87 | |||
| 88 | dprintk("result is %x\n", result); | ||
| 89 | |||
| 90 | return result; | ||
| 91 | } | ||
| 92 | |||
| 93 | /** | ||
| 94 | * speedstep_smi_get_freqs - get SpeedStep preferred & current freq. | ||
| 95 | * @low: the low frequency value is placed here | ||
| 96 | * @high: the high frequency value is placed here | ||
| 97 | * | ||
| 98 | * Only available on later SpeedStep-enabled systems, returns false results or | ||
| 99 | * even hangs [cf. bugme.osdl.org # 1422] on earlier systems. Empirical testing | ||
| 100 | * shows that the latter occurs if !(ist_info.event & 0xFFFF). | ||
| 101 | */ | ||
| 102 | static int speedstep_smi_get_freqs(unsigned int *low, unsigned int *high) | ||
| 103 | { | ||
| 104 | u32 command, result = 0, edi, high_mhz, low_mhz, dummy; | ||
| 105 | u32 state = 0; | ||
| 106 | u32 function = GET_SPEEDSTEP_FREQS; | ||
| 107 | |||
| 108 | if (!(ist_info.event & 0xFFFF)) { | ||
| 109 | dprintk("bug #1422 -- can't read freqs from BIOS\n"); | ||
| 110 | return -ENODEV; | ||
| 111 | } | ||
| 112 | |||
| 113 | command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff); | ||
| 114 | |||
| 115 | dprintk("trying to determine frequencies with command %x at port %x\n", | ||
| 116 | command, smi_port); | ||
| 117 | |||
| 118 | __asm__ __volatile__( | ||
| 119 | "push %%ebp\n" | ||
| 120 | "out %%al, (%%dx)\n" | ||
| 121 | "pop %%ebp" | ||
| 122 | : "=a" (result), | ||
| 123 | "=b" (high_mhz), | ||
| 124 | "=c" (low_mhz), | ||
| 125 | "=d" (state), "=D" (edi), "=S" (dummy) | ||
| 126 | : "a" (command), | ||
| 127 | "b" (function), | ||
| 128 | "c" (state), | ||
| 129 | "d" (smi_port), "S" (0), "D" (0) | ||
| 130 | ); | ||
| 131 | |||
| 132 | dprintk("result %x, low_freq %u, high_freq %u\n", | ||
| 133 | result, low_mhz, high_mhz); | ||
| 134 | |||
| 135 | /* abort if results are obviously incorrect... */ | ||
| 136 | if ((high_mhz + low_mhz) < 600) | ||
| 137 | return -EINVAL; | ||
| 138 | |||
| 139 | *high = high_mhz * 1000; | ||
| 140 | *low = low_mhz * 1000; | ||
| 141 | |||
| 142 | return result; | ||
| 143 | } | ||
| 144 | |||
| 145 | /** | ||
| 146 | * speedstep_get_state - set the SpeedStep state | ||
| 147 | * @state: processor frequency state (SPEEDSTEP_LOW or SPEEDSTEP_HIGH) | ||
| 148 | * | ||
| 149 | */ | ||
| 150 | static int speedstep_get_state(void) | ||
| 151 | { | ||
| 152 | u32 function = GET_SPEEDSTEP_STATE; | ||
| 153 | u32 result, state, edi, command, dummy; | ||
| 154 | |||
| 155 | command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff); | ||
| 156 | |||
| 157 | dprintk("trying to determine current setting with command %x " | ||
| 158 | "at port %x\n", command, smi_port); | ||
| 159 | |||
| 160 | __asm__ __volatile__( | ||
| 161 | "push %%ebp\n" | ||
| 162 | "out %%al, (%%dx)\n" | ||
| 163 | "pop %%ebp\n" | ||
| 164 | : "=a" (result), | ||
| 165 | "=b" (state), "=D" (edi), | ||
| 166 | "=c" (dummy), "=d" (dummy), "=S" (dummy) | ||
| 167 | : "a" (command), "b" (function), "c" (0), | ||
| 168 | "d" (smi_port), "S" (0), "D" (0) | ||
| 169 | ); | ||
| 170 | |||
| 171 | dprintk("state is %x, result is %x\n", state, result); | ||
| 172 | |||
| 173 | return state & 1; | ||
| 174 | } | ||
| 175 | |||
| 176 | |||
| 177 | /** | ||
| 178 | * speedstep_set_state - set the SpeedStep state | ||
| 179 | * @state: new processor frequency state (SPEEDSTEP_LOW or SPEEDSTEP_HIGH) | ||
| 180 | * | ||
| 181 | */ | ||
| 182 | static void speedstep_set_state(unsigned int state) | ||
| 183 | { | ||
| 184 | unsigned int result = 0, command, new_state, dummy; | ||
| 185 | unsigned long flags; | ||
| 186 | unsigned int function = SET_SPEEDSTEP_STATE; | ||
| 187 | unsigned int retry = 0; | ||
| 188 | |||
| 189 | if (state > 0x1) | ||
| 190 | return; | ||
| 191 | |||
| 192 | /* Disable IRQs */ | ||
| 193 | local_irq_save(flags); | ||
| 194 | |||
| 195 | command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff); | ||
| 196 | |||
| 197 | dprintk("trying to set frequency to state %u " | ||
| 198 | "with command %x at port %x\n", | ||
| 199 | state, command, smi_port); | ||
| 200 | |||
| 201 | do { | ||
| 202 | if (retry) { | ||
| 203 | dprintk("retry %u, previous result %u, waiting...\n", | ||
| 204 | retry, result); | ||
| 205 | mdelay(retry * 50); | ||
| 206 | } | ||
| 207 | retry++; | ||
| 208 | __asm__ __volatile__( | ||
| 209 | "push %%ebp\n" | ||
| 210 | "out %%al, (%%dx)\n" | ||
| 211 | "pop %%ebp" | ||
| 212 | : "=b" (new_state), "=D" (result), | ||
| 213 | "=c" (dummy), "=a" (dummy), | ||
| 214 | "=d" (dummy), "=S" (dummy) | ||
| 215 | : "a" (command), "b" (function), "c" (state), | ||
| 216 | "d" (smi_port), "S" (0), "D" (0) | ||
| 217 | ); | ||
| 218 | } while ((new_state != state) && (retry <= SMI_TRIES)); | ||
| 219 | |||
| 220 | /* enable IRQs */ | ||
| 221 | local_irq_restore(flags); | ||
| 222 | |||
| 223 | if (new_state == state) | ||
| 224 | dprintk("change to %u MHz succeeded after %u tries " | ||
| 225 | "with result %u\n", | ||
| 226 | (speedstep_freqs[new_state].frequency / 1000), | ||
| 227 | retry, result); | ||
| 228 | else | ||
| 229 | printk(KERN_ERR "cpufreq: change to state %u " | ||
| 230 | "failed with new_state %u and result %u\n", | ||
| 231 | state, new_state, result); | ||
| 232 | |||
| 233 | return; | ||
| 234 | } | ||
| 235 | |||
| 236 | |||
| 237 | /** | ||
| 238 | * speedstep_target - set a new CPUFreq policy | ||
| 239 | * @policy: new policy | ||
| 240 | * @target_freq: new freq | ||
| 241 | * @relation: | ||
| 242 | * | ||
| 243 | * Sets a new CPUFreq policy/freq. | ||
| 244 | */ | ||
| 245 | static int speedstep_target(struct cpufreq_policy *policy, | ||
| 246 | unsigned int target_freq, unsigned int relation) | ||
| 247 | { | ||
| 248 | unsigned int newstate = 0; | ||
| 249 | struct cpufreq_freqs freqs; | ||
| 250 | |||
| 251 | if (cpufreq_frequency_table_target(policy, &speedstep_freqs[0], | ||
| 252 | target_freq, relation, &newstate)) | ||
| 253 | return -EINVAL; | ||
| 254 | |||
| 255 | freqs.old = speedstep_freqs[speedstep_get_state()].frequency; | ||
| 256 | freqs.new = speedstep_freqs[newstate].frequency; | ||
| 257 | freqs.cpu = 0; /* speedstep.c is UP only driver */ | ||
| 258 | |||
| 259 | if (freqs.old == freqs.new) | ||
| 260 | return 0; | ||
| 261 | |||
| 262 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
| 263 | speedstep_set_state(newstate); | ||
| 264 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
| 265 | |||
| 266 | return 0; | ||
| 267 | } | ||
| 268 | |||
| 269 | |||
| 270 | /** | ||
| 271 | * speedstep_verify - verifies a new CPUFreq policy | ||
| 272 | * @policy: new policy | ||
| 273 | * | ||
| 274 | * Limit must be within speedstep_low_freq and speedstep_high_freq, with | ||
| 275 | * at least one border included. | ||
| 276 | */ | ||
| 277 | static int speedstep_verify(struct cpufreq_policy *policy) | ||
| 278 | { | ||
| 279 | return cpufreq_frequency_table_verify(policy, &speedstep_freqs[0]); | ||
| 280 | } | ||
| 281 | |||
| 282 | |||
| 283 | static int speedstep_cpu_init(struct cpufreq_policy *policy) | ||
| 284 | { | ||
| 285 | int result; | ||
| 286 | unsigned int speed, state; | ||
| 287 | unsigned int *low, *high; | ||
| 288 | |||
| 289 | /* capability check */ | ||
| 290 | if (policy->cpu != 0) | ||
| 291 | return -ENODEV; | ||
| 292 | |||
| 293 | result = speedstep_smi_ownership(); | ||
| 294 | if (result) { | ||
| 295 | dprintk("fails in acquiring ownership of a SMI interface.\n"); | ||
| 296 | return -EINVAL; | ||
| 297 | } | ||
| 298 | |||
| 299 | /* detect low and high frequency */ | ||
| 300 | low = &speedstep_freqs[SPEEDSTEP_LOW].frequency; | ||
| 301 | high = &speedstep_freqs[SPEEDSTEP_HIGH].frequency; | ||
| 302 | |||
| 303 | result = speedstep_smi_get_freqs(low, high); | ||
| 304 | if (result) { | ||
| 305 | /* fall back to speedstep_lib.c dection mechanism: | ||
| 306 | * try both states out */ | ||
| 307 | dprintk("could not detect low and high frequencies " | ||
| 308 | "by SMI call.\n"); | ||
| 309 | result = speedstep_get_freqs(speedstep_processor, | ||
| 310 | low, high, | ||
| 311 | NULL, | ||
| 312 | &speedstep_set_state); | ||
| 313 | |||
| 314 | if (result) { | ||
| 315 | dprintk("could not detect two different speeds" | ||
| 316 | " -- aborting.\n"); | ||
| 317 | return result; | ||
| 318 | } else | ||
| 319 | dprintk("workaround worked.\n"); | ||
| 320 | } | ||
| 321 | |||
| 322 | /* get current speed setting */ | ||
| 323 | state = speedstep_get_state(); | ||
| 324 | speed = speedstep_freqs[state].frequency; | ||
| 325 | |||
| 326 | dprintk("currently at %s speed setting - %i MHz\n", | ||
| 327 | (speed == speedstep_freqs[SPEEDSTEP_LOW].frequency) | ||
| 328 | ? "low" : "high", | ||
| 329 | (speed / 1000)); | ||
| 330 | |||
| 331 | /* cpuinfo and default policy values */ | ||
| 332 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | ||
| 333 | policy->cur = speed; | ||
| 334 | |||
| 335 | result = cpufreq_frequency_table_cpuinfo(policy, speedstep_freqs); | ||
| 336 | if (result) | ||
| 337 | return result; | ||
| 338 | |||
| 339 | cpufreq_frequency_table_get_attr(speedstep_freqs, policy->cpu); | ||
| 340 | |||
| 341 | return 0; | ||
| 342 | } | ||
| 343 | |||
| 344 | static int speedstep_cpu_exit(struct cpufreq_policy *policy) | ||
| 345 | { | ||
| 346 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
| 347 | return 0; | ||
| 348 | } | ||
| 349 | |||
| 350 | static unsigned int speedstep_get(unsigned int cpu) | ||
| 351 | { | ||
| 352 | if (cpu) | ||
| 353 | return -ENODEV; | ||
| 354 | return speedstep_get_frequency(speedstep_processor); | ||
| 355 | } | ||
| 356 | |||
| 357 | |||
| 358 | static int speedstep_resume(struct cpufreq_policy *policy) | ||
| 359 | { | ||
| 360 | int result = speedstep_smi_ownership(); | ||
| 361 | |||
| 362 | if (result) | ||
| 363 | dprintk("fails in re-acquiring ownership of a SMI interface.\n"); | ||
| 364 | |||
| 365 | return result; | ||
| 366 | } | ||
| 367 | |||
| 368 | static struct freq_attr *speedstep_attr[] = { | ||
| 369 | &cpufreq_freq_attr_scaling_available_freqs, | ||
| 370 | NULL, | ||
| 371 | }; | ||
| 372 | |||
| 373 | static struct cpufreq_driver speedstep_driver = { | ||
| 374 | .name = "speedstep-smi", | ||
| 375 | .verify = speedstep_verify, | ||
| 376 | .target = speedstep_target, | ||
| 377 | .init = speedstep_cpu_init, | ||
| 378 | .exit = speedstep_cpu_exit, | ||
| 379 | .get = speedstep_get, | ||
| 380 | .resume = speedstep_resume, | ||
| 381 | .owner = THIS_MODULE, | ||
| 382 | .attr = speedstep_attr, | ||
| 383 | }; | ||
| 384 | |||
| 385 | /** | ||
| 386 | * speedstep_init - initializes the SpeedStep CPUFreq driver | ||
| 387 | * | ||
| 388 | * Initializes the SpeedStep support. Returns -ENODEV on unsupported | ||
| 389 | * BIOS, -EINVAL on problems during initiatization, and zero on | ||
| 390 | * success. | ||
| 391 | */ | ||
| 392 | static int __init speedstep_init(void) | ||
| 393 | { | ||
| 394 | speedstep_processor = speedstep_detect_processor(); | ||
| 395 | |||
| 396 | switch (speedstep_processor) { | ||
| 397 | case SPEEDSTEP_CPU_PIII_T: | ||
| 398 | case SPEEDSTEP_CPU_PIII_C: | ||
| 399 | case SPEEDSTEP_CPU_PIII_C_EARLY: | ||
| 400 | break; | ||
| 401 | default: | ||
| 402 | speedstep_processor = 0; | ||
| 403 | } | ||
| 404 | |||
| 405 | if (!speedstep_processor) { | ||
| 406 | dprintk("No supported Intel CPU detected.\n"); | ||
| 407 | return -ENODEV; | ||
| 408 | } | ||
| 409 | |||
| 410 | dprintk("signature:0x%.8lx, command:0x%.8lx, " | ||
| 411 | "event:0x%.8lx, perf_level:0x%.8lx.\n", | ||
| 412 | ist_info.signature, ist_info.command, | ||
| 413 | ist_info.event, ist_info.perf_level); | ||
| 414 | |||
| 415 | /* Error if no IST-SMI BIOS or no PARM | ||
| 416 | sig= 'ISGE' aka 'Intel Speedstep Gate E' */ | ||
| 417 | if ((ist_info.signature != 0x47534943) && ( | ||
| 418 | (smi_port == 0) || (smi_cmd == 0))) | ||
| 419 | return -ENODEV; | ||
| 420 | |||
| 421 | if (smi_sig == 1) | ||
| 422 | smi_sig = 0x47534943; | ||
| 423 | else | ||
| 424 | smi_sig = ist_info.signature; | ||
| 425 | |||
| 426 | /* setup smi_port from MODLULE_PARM or BIOS */ | ||
| 427 | if ((smi_port > 0xff) || (smi_port < 0)) | ||
| 428 | return -EINVAL; | ||
| 429 | else if (smi_port == 0) | ||
| 430 | smi_port = ist_info.command & 0xff; | ||
| 431 | |||
| 432 | if ((smi_cmd > 0xff) || (smi_cmd < 0)) | ||
| 433 | return -EINVAL; | ||
| 434 | else if (smi_cmd == 0) | ||
| 435 | smi_cmd = (ist_info.command >> 16) & 0xff; | ||
| 436 | |||
| 437 | return cpufreq_register_driver(&speedstep_driver); | ||
| 438 | } | ||
| 439 | |||
| 440 | |||
| 441 | /** | ||
| 442 | * speedstep_exit - unregisters SpeedStep support | ||
| 443 | * | ||
| 444 | * Unregisters SpeedStep support. | ||
| 445 | */ | ||
| 446 | static void __exit speedstep_exit(void) | ||
| 447 | { | ||
| 448 | cpufreq_unregister_driver(&speedstep_driver); | ||
| 449 | } | ||
| 450 | |||
| 451 | module_param(smi_port, int, 0444); | ||
| 452 | module_param(smi_cmd, int, 0444); | ||
| 453 | module_param(smi_sig, uint, 0444); | ||
| 454 | |||
| 455 | MODULE_PARM_DESC(smi_port, "Override the BIOS-given IST port with this value " | ||
| 456 | "-- Intel's default setting is 0xb2"); | ||
| 457 | MODULE_PARM_DESC(smi_cmd, "Override the BIOS-given IST command with this value " | ||
| 458 | "-- Intel's default setting is 0x82"); | ||
| 459 | MODULE_PARM_DESC(smi_sig, "Set to 1 to fake the IST signature when using the " | ||
| 460 | "SMI interface."); | ||
| 461 | |||
| 462 | MODULE_AUTHOR("Hiroshi Miura"); | ||
| 463 | MODULE_DESCRIPTION("Speedstep driver for IST applet SMI interface."); | ||
| 464 | MODULE_LICENSE("GPL"); | ||
| 465 | |||
| 466 | module_init(speedstep_init); | ||
| 467 | module_exit(speedstep_exit); | ||
diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c index 167f97b5596e..bb0adad35143 100644 --- a/arch/x86/kernel/cpu/mcheck/mce_amd.c +++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c | |||
| @@ -509,6 +509,7 @@ recurse: | |||
| 509 | out_free: | 509 | out_free: |
| 510 | if (b) { | 510 | if (b) { |
| 511 | kobject_put(&b->kobj); | 511 | kobject_put(&b->kobj); |
| 512 | list_del(&b->miscj); | ||
| 512 | kfree(b); | 513 | kfree(b); |
| 513 | } | 514 | } |
| 514 | return err; | 515 | return err; |
diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c index 6f8c5e9da97f..0f034460260d 100644 --- a/arch/x86/kernel/cpu/mcheck/therm_throt.c +++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c | |||
| @@ -446,18 +446,20 @@ void intel_init_thermal(struct cpuinfo_x86 *c) | |||
| 446 | */ | 446 | */ |
| 447 | rdmsr(MSR_IA32_MISC_ENABLE, l, h); | 447 | rdmsr(MSR_IA32_MISC_ENABLE, l, h); |
| 448 | 448 | ||
| 449 | h = lvtthmr_init; | ||
| 449 | /* | 450 | /* |
| 450 | * The initial value of thermal LVT entries on all APs always reads | 451 | * The initial value of thermal LVT entries on all APs always reads |
| 451 | * 0x10000 because APs are woken up by BSP issuing INIT-SIPI-SIPI | 452 | * 0x10000 because APs are woken up by BSP issuing INIT-SIPI-SIPI |
| 452 | * sequence to them and LVT registers are reset to 0s except for | 453 | * sequence to them and LVT registers are reset to 0s except for |
| 453 | * the mask bits which are set to 1s when APs receive INIT IPI. | 454 | * the mask bits which are set to 1s when APs receive INIT IPI. |
| 454 | * Always restore the value that BIOS has programmed on AP based on | 455 | * If BIOS takes over the thermal interrupt and sets its interrupt |
| 455 | * BSP's info we saved since BIOS is always setting the same value | 456 | * delivery mode to SMI (not fixed), it restores the value that the |
| 456 | * for all threads/cores | 457 | * BIOS has programmed on AP based on BSP's info we saved since BIOS |
| 458 | * is always setting the same value for all threads/cores. | ||
| 457 | */ | 459 | */ |
| 458 | apic_write(APIC_LVTTHMR, lvtthmr_init); | 460 | if ((h & APIC_DM_FIXED_MASK) != APIC_DM_FIXED) |
| 461 | apic_write(APIC_LVTTHMR, lvtthmr_init); | ||
| 459 | 462 | ||
| 460 | h = lvtthmr_init; | ||
| 461 | 463 | ||
| 462 | if ((l & MSR_IA32_MISC_ENABLE_TM1) && (h & APIC_DM_SMI)) { | 464 | if ((l & MSR_IA32_MISC_ENABLE_TM1) && (h & APIC_DM_SMI)) { |
| 463 | printk(KERN_DEBUG | 465 | printk(KERN_DEBUG |
diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c index c969fd9d1566..f1a6244d7d93 100644 --- a/arch/x86/kernel/kprobes.c +++ b/arch/x86/kernel/kprobes.c | |||
| @@ -1183,12 +1183,13 @@ static void __kprobes optimized_callback(struct optimized_kprobe *op, | |||
| 1183 | struct pt_regs *regs) | 1183 | struct pt_regs *regs) |
| 1184 | { | 1184 | { |
| 1185 | struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); | 1185 | struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); |
| 1186 | unsigned long flags; | ||
| 1186 | 1187 | ||
| 1187 | /* This is possible if op is under delayed unoptimizing */ | 1188 | /* This is possible if op is under delayed unoptimizing */ |
| 1188 | if (kprobe_disabled(&op->kp)) | 1189 | if (kprobe_disabled(&op->kp)) |
| 1189 | return; | 1190 | return; |
| 1190 | 1191 | ||
| 1191 | preempt_disable(); | 1192 | local_irq_save(flags); |
| 1192 | if (kprobe_running()) { | 1193 | if (kprobe_running()) { |
| 1193 | kprobes_inc_nmissed_count(&op->kp); | 1194 | kprobes_inc_nmissed_count(&op->kp); |
| 1194 | } else { | 1195 | } else { |
| @@ -1207,7 +1208,7 @@ static void __kprobes optimized_callback(struct optimized_kprobe *op, | |||
| 1207 | opt_pre_handler(&op->kp, regs); | 1208 | opt_pre_handler(&op->kp, regs); |
| 1208 | __this_cpu_write(current_kprobe, NULL); | 1209 | __this_cpu_write(current_kprobe, NULL); |
| 1209 | } | 1210 | } |
| 1210 | preempt_enable_no_resched(); | 1211 | local_irq_restore(flags); |
| 1211 | } | 1212 | } |
| 1212 | 1213 | ||
| 1213 | static int __kprobes copy_optimized_instructions(u8 *dest, u8 *src) | 1214 | static int __kprobes copy_optimized_instructions(u8 *dest, u8 *src) |
diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c index 55d745ec1181..35ccf75696eb 100644 --- a/arch/x86/kernel/pci-iommu_table.c +++ b/arch/x86/kernel/pci-iommu_table.c | |||
| @@ -50,20 +50,14 @@ void __init check_iommu_entries(struct iommu_table_entry *start, | |||
| 50 | struct iommu_table_entry *finish) | 50 | struct iommu_table_entry *finish) |
| 51 | { | 51 | { |
| 52 | struct iommu_table_entry *p, *q, *x; | 52 | struct iommu_table_entry *p, *q, *x; |
| 53 | char sym_p[KSYM_SYMBOL_LEN]; | ||
| 54 | char sym_q[KSYM_SYMBOL_LEN]; | ||
| 55 | 53 | ||
| 56 | /* Simple cyclic dependency checker. */ | 54 | /* Simple cyclic dependency checker. */ |
| 57 | for (p = start; p < finish; p++) { | 55 | for (p = start; p < finish; p++) { |
| 58 | q = find_dependents_of(start, finish, p); | 56 | q = find_dependents_of(start, finish, p); |
| 59 | x = find_dependents_of(start, finish, q); | 57 | x = find_dependents_of(start, finish, q); |
| 60 | if (p == x) { | 58 | if (p == x) { |
| 61 | sprint_symbol(sym_p, (unsigned long)p->detect); | 59 | printk(KERN_ERR "CYCLIC DEPENDENCY FOUND! %pS depends on %pS and vice-versa. BREAKING IT.\n", |
| 62 | sprint_symbol(sym_q, (unsigned long)q->detect); | 60 | p->detect, q->detect); |
| 63 | |||
| 64 | printk(KERN_ERR "CYCLIC DEPENDENCY FOUND! %s depends" \ | ||
| 65 | " on %s and vice-versa. BREAKING IT.\n", | ||
| 66 | sym_p, sym_q); | ||
| 67 | /* Heavy handed way..*/ | 61 | /* Heavy handed way..*/ |
| 68 | x->depend = 0; | 62 | x->depend = 0; |
| 69 | } | 63 | } |
| @@ -72,12 +66,8 @@ void __init check_iommu_entries(struct iommu_table_entry *start, | |||
| 72 | for (p = start; p < finish; p++) { | 66 | for (p = start; p < finish; p++) { |
| 73 | q = find_dependents_of(p, finish, p); | 67 | q = find_dependents_of(p, finish, p); |
| 74 | if (q && q > p) { | 68 | if (q && q > p) { |
| 75 | sprint_symbol(sym_p, (unsigned long)p->detect); | 69 | printk(KERN_ERR "EXECUTION ORDER INVALID! %pS should be called before %pS!\n", |
| 76 | sprint_symbol(sym_q, (unsigned long)q->detect); | 70 | p->detect, q->detect); |
| 77 | |||
| 78 | printk(KERN_ERR "EXECUTION ORDER INVALID! %s "\ | ||
| 79 | "should be called before %s!\n", | ||
| 80 | sym_p, sym_q); | ||
| 81 | } | 71 | } |
| 82 | } | 72 | } |
| 83 | } | 73 | } |
diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c index c11514e9128b..75ef4b18e9b7 100644 --- a/arch/x86/kernel/x86_init.c +++ b/arch/x86/kernel/x86_init.c | |||
| @@ -61,6 +61,10 @@ struct x86_init_ops x86_init __initdata = { | |||
| 61 | .banner = default_banner, | 61 | .banner = default_banner, |
| 62 | }, | 62 | }, |
| 63 | 63 | ||
| 64 | .mapping = { | ||
| 65 | .pagetable_reserve = native_pagetable_reserve, | ||
| 66 | }, | ||
| 67 | |||
| 64 | .paging = { | 68 | .paging = { |
| 65 | .pagetable_setup_start = native_pagetable_setup_start, | 69 | .pagetable_setup_start = native_pagetable_setup_start, |
| 66 | .pagetable_setup_done = native_pagetable_setup_done, | 70 | .pagetable_setup_done = native_pagetable_setup_done, |
