Changeset 679 for GPL/trunk/alsa-kernel/pci/emu10k1/emufx.c
- Timestamp:
- Mar 18, 2021, 8:57:36 PM (4 years ago)
- Location:
- GPL/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GPL/trunk
- Property svn:mergeinfo changed
/GPL/branches/uniaud32-linux-3.2.102 (added) merged: 611-614 /GPL/branches/uniaud32-next (added) merged: 615-678
- Property svn:mergeinfo changed
-
GPL/trunk/alsa-kernel/pci/emu10k1/emufx.c
r598 r679 1 // SPDX-License-Identifier: GPL-2.0-or-later 1 2 /* 2 3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz> … … 12 13 * TODO: 13 14 * -- 14 *15 * This program is free software; you can redistribute it and/or modify16 * it under the terms of the GNU General Public License as published by17 * the Free Software Foundation; either version 2 of the License, or18 * (at your option) any later version.19 *20 * This program is distributed in the hope that it will be useful,21 * but WITHOUT ANY WARRANTY; without even the implied warranty of22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the23 * GNU General Public License for more details.24 *25 * You should have received a copy of the GNU General Public License26 * along with this program; if not, write to the Free Software27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA28 *29 15 */ 30 16 … … 37 23 #include <linux/mutex.h> 38 24 #include <linux/moduleparam.h> 25 #include <linux/nospec.h> 39 26 40 27 #include <sound/core.h> … … 59 46 /* 60 47 * Tables 61 */ 62 63 static c har *fxbuses[16] = {48 */ 49 50 static const char * const fxbuses[16] = { 64 51 /* 0x00 */ "PCM Left", 65 52 /* 0x01 */ "PCM Right", … … 80 67 }; 81 68 82 static c har *creative_ins[16] = {69 static const char * const creative_ins[16] = { 83 70 /* 0x00 */ "AC97 Left", 84 71 /* 0x01 */ "AC97 Right", … … 99 86 }; 100 87 101 static c har *audigy_ins[16] = {88 static const char * const audigy_ins[16] = { 102 89 /* 0x00 */ "AC97 Left", 103 90 /* 0x01 */ "AC97 Right", … … 118 105 }; 119 106 120 static c har *creative_outs[32] = {107 static const char * const creative_outs[32] = { 121 108 /* 0x00 */ "AC97 Left", 122 109 /* 0x01 */ "AC97 Right", … … 153 140 }; 154 141 155 static c har *audigy_outs[32] = {142 static const char * const audigy_outs[32] = { 156 143 /* 0x00 */ "Digital Front Left", 157 144 /* 0x01 */ "Digital Front Right", … … 172 159 /* 0x10 */ "AC97 Front Left", 173 160 /* 0x11 */ "AC97 Front Right", 174 /* 0x12 */ "ADC Cap utre Left",161 /* 0x12 */ "ADC Capture Left", 175 162 /* 0x13 */ "ADC Capture Right", 176 163 /* 0x14 */ NULL, … … 305 292 static const DECLARE_TLV_DB_LINEAR(snd_emu10k1_db_linear, TLV_DB_GAIN_MUTE, 0); 306 293 294 /* EMU10K1 bass/treble db gain */ 295 static const DECLARE_TLV_DB_SCALE(snd_emu10k1_bass_treble_db_scale, -1200, 60, 0); 296 307 297 static const u32 onoff_table[2] = { 308 298 0x00000000, 0x00000001 309 299 }; 310 311 /*312 */313 314 static inline mm_segment_t snd_enter_user(void)315 {316 mm_segment_t fs = get_fs();317 set_fs(get_ds());318 return fs;319 }320 321 static inline void snd_leave_user(mm_segment_t fs)322 {323 set_fs(fs);324 }325 300 326 301 /* … … 435 410 unsigned char gpr_running, 436 411 void *private_data, 437 struct snd_emu10k1_fx8010_irq **r_irq) 438 { 439 struct snd_emu10k1_fx8010_irq *irq; 412 struct snd_emu10k1_fx8010_irq *irq) 413 { 440 414 unsigned long flags; 441 415 442 irq = kmalloc(sizeof(*irq), GFP_ATOMIC);443 if (irq == NULL)444 return -ENOMEM;445 416 irq->handler = handler; 446 417 irq->gpr_running = gpr_running; … … 457 428 } 458 429 spin_unlock_irqrestore(&emu->fx8010.irq_lock, flags); 459 if (r_irq)460 *r_irq = irq;461 430 return 0; 462 431 } … … 482 451 } 483 452 spin_unlock_irqrestore(&emu->fx8010.irq_lock, flags); 484 kfree(irq);485 453 return 0; 486 454 } … … 497 465 if (snd_BUG_ON(*ptr >= 512)) 498 466 return; 499 code = (u_int32_t __force *)icode->code + (*ptr) * 2;467 code = icode->code + (*ptr) * 2; 500 468 set_bit(*ptr, icode->code_valid); 501 469 code[0] = ((x & 0x3ff) << 10) | (y & 0x3ff); … … 514 482 if (snd_BUG_ON(*ptr >= 1024)) 515 483 return; 516 code = (u_int32_t __force *)icode->code + (*ptr) * 2;484 code = icode->code + (*ptr) * 2; 517 485 set_bit(*ptr, icode->code_valid); 518 486 code[0] = ((x & 0x7ff) << 12) | (y & 0x7ff); … … 537 505 538 506 static int snd_emu10k1_gpr_poke(struct snd_emu10k1 *emu, 539 struct snd_emu10k1_fx8010_code *icode) 507 struct snd_emu10k1_fx8010_code *icode, 508 bool in_kernel) 540 509 { 541 510 int gpr; … … 545 514 if (!test_bit(gpr, icode->gpr_valid)) 546 515 continue; 547 if (get_user(val, &icode->gpr_map[gpr])) 516 if (in_kernel) 517 val = icode->gpr_map[gpr]; 518 else if (get_user(val, (__user u32 *)&icode->gpr_map[gpr])) 548 519 return -EFAULT; 549 520 snd_emu10k1_ptr_write(emu, emu->gpr_base + gpr, 0, val); … … 561 532 set_bit(gpr, icode->gpr_valid); 562 533 val = snd_emu10k1_ptr_read(emu, emu->gpr_base + gpr, 0); 563 if (put_user(val, &icode->gpr_map[gpr]))534 if (put_user(val, (__user u32 *)&icode->gpr_map[gpr])) 564 535 return -EFAULT; 565 536 } … … 568 539 569 540 static int snd_emu10k1_tram_poke(struct snd_emu10k1 *emu, 570 struct snd_emu10k1_fx8010_code *icode) 541 struct snd_emu10k1_fx8010_code *icode, 542 bool in_kernel) 571 543 { 572 544 int tram; … … 576 548 if (!test_bit(tram, icode->tram_valid)) 577 549 continue; 578 if (get_user(val, &icode->tram_data_map[tram]) || 579 get_user(addr, &icode->tram_addr_map[tram])) 580 return -EFAULT; 550 if (in_kernel) { 551 val = icode->tram_data_map[tram]; 552 addr = icode->tram_addr_map[tram]; 553 } else { 554 if (get_user(val, (__user __u32 *)&icode->tram_data_map[tram]) || 555 get_user(addr, (__user __u32 *)&icode->tram_addr_map[tram])) 556 return -EFAULT; 557 } 581 558 snd_emu10k1_ptr_write(emu, TANKMEMDATAREGBASE + tram, 0, val); 582 559 if (!emu->audigy) { … … 606 583 addr |= snd_emu10k1_ptr_read(emu, A_TANKMEMCTLREGBASE + tram, 0) << 20; 607 584 } 608 if (put_user(val, &icode->tram_data_map[tram]) ||609 put_user(addr, &icode->tram_addr_map[tram]))585 if (put_user(val, (__user u32 *)&icode->tram_data_map[tram]) || 586 put_user(addr, (__user u32 *)&icode->tram_addr_map[tram])) 610 587 return -EFAULT; 611 588 } … … 614 591 615 592 static int snd_emu10k1_code_poke(struct snd_emu10k1 *emu, 616 struct snd_emu10k1_fx8010_code *icode) 593 struct snd_emu10k1_fx8010_code *icode, 594 bool in_kernel) 617 595 { 618 596 u32 pc, lo, hi; … … 621 599 if (!test_bit(pc / 2, icode->code_valid)) 622 600 continue; 623 if (get_user(lo, &icode->code[pc + 0]) || 624 get_user(hi, &icode->code[pc + 1])) 625 return -EFAULT; 601 if (in_kernel) { 602 lo = icode->code[pc + 0]; 603 hi = icode->code[pc + 1]; 604 } else { 605 if (get_user(lo, (__user u32 *)&icode->code[pc + 0]) || 606 get_user(hi, (__user u32 *)&icode->code[pc + 1])) 607 return -EFAULT; 608 } 626 609 snd_emu10k1_efx_write(emu, pc + 0, lo); 627 610 snd_emu10k1_efx_write(emu, pc + 1, hi); … … 638 621 for (pc = 0; pc < (emu->audigy ? 2*1024 : 2*512); pc += 2) { 639 622 set_bit(pc / 2, icode->code_valid); 640 if (put_user(snd_emu10k1_efx_read(emu, pc + 0), &icode->code[pc + 0])) 623 if (put_user(snd_emu10k1_efx_read(emu, pc + 0), 624 (__user u32 *)&icode->code[pc + 0])) 641 625 return -EFAULT; 642 if (put_user(snd_emu10k1_efx_read(emu, pc + 1), &icode->code[pc + 1])) 626 if (put_user(snd_emu10k1_efx_read(emu, pc + 1), 627 (__user u32 *)&icode->code[pc + 1])) 643 628 return -EFAULT; 644 629 } … … 647 632 648 633 static struct snd_emu10k1_fx8010_ctl * 649 snd_emu10k1_look_for_ctl(struct snd_emu10k1 *emu, struct snd_ctl_elem_id *id) 650 { 634 snd_emu10k1_look_for_ctl(struct snd_emu10k1 *emu, 635 struct emu10k1_ctl_elem_id *_id) 636 { 637 struct snd_ctl_elem_id *id = (struct snd_ctl_elem_id *)_id; 651 638 struct snd_emu10k1_fx8010_ctl *ctl; 652 639 struct snd_kcontrol *kcontrol; … … 664 651 #define MAX_TLV_SIZE 256 665 652 666 static unsigned int *copy_tlv(const unsigned int __user *_tlv )653 static unsigned int *copy_tlv(const unsigned int __user *_tlv, bool in_kernel) 667 654 { 668 655 unsigned int data[2]; … … 671 658 if (!_tlv) 672 659 return NULL; 673 if (copy_from_user(data, _tlv, sizeof(data))) 660 if (in_kernel) 661 memcpy(data, (__force void *)_tlv, sizeof(data)); 662 else if (copy_from_user(data, _tlv, sizeof(data))) 674 663 return NULL; 675 664 if (data[1] >= MAX_TLV_SIZE) … … 679 668 return NULL; 680 669 memcpy(tlv, data, sizeof(data)); 681 if (copy_from_user(tlv + 2, _tlv + 2, data[1])) { 670 if (in_kernel) { 671 memcpy(tlv + 2, (__force void *)(_tlv + 2), data[1]); 672 } else if (copy_from_user(tlv + 2, _tlv + 2, data[1])) { 682 673 kfree(tlv); 683 674 return NULL; … … 687 678 688 679 static int copy_gctl(struct snd_emu10k1 *emu, 689 struct snd_emu10k1_fx8010_control_gpr *gctl, 690 struct snd_emu10k1_fx8010_control_gpr __user *_gctl, 680 struct snd_emu10k1_fx8010_control_gpr *dst, 681 struct snd_emu10k1_fx8010_control_gpr *src, 682 int idx, bool in_kernel) 683 { 684 struct snd_emu10k1_fx8010_control_gpr __user *_src; 685 struct snd_emu10k1_fx8010_control_old_gpr *octl; 686 struct snd_emu10k1_fx8010_control_old_gpr __user *_octl; 687 688 _src = (struct snd_emu10k1_fx8010_control_gpr __user *)src; 689 if (emu->support_tlv) { 690 if (in_kernel) 691 *dst = src[idx]; 692 else if (copy_from_user(dst, &_src[idx], sizeof(*src))) 693 return -EFAULT; 694 return 0; 695 } 696 697 octl = (struct snd_emu10k1_fx8010_control_old_gpr *)src; 698 _octl = (struct snd_emu10k1_fx8010_control_old_gpr __user *)octl; 699 if (in_kernel) 700 memcpy(dst, &octl[idx], sizeof(*octl)); 701 else if (copy_from_user(dst, &_octl[idx], sizeof(*octl))) 702 return -EFAULT; 703 dst->tlv = NULL; 704 return 0; 705 } 706 707 static int copy_gctl_to_user(struct snd_emu10k1 *emu, 708 struct snd_emu10k1_fx8010_control_gpr *dst, 709 struct snd_emu10k1_fx8010_control_gpr *src, 691 710 int idx) 692 711 { 712 struct snd_emu10k1_fx8010_control_gpr __user *_dst; 693 713 struct snd_emu10k1_fx8010_control_old_gpr __user *octl; 694 714 715 _dst = (struct snd_emu10k1_fx8010_control_gpr __user *)dst; 695 716 if (emu->support_tlv) 696 return copy_from_user(gctl, &_gctl[idx], sizeof(*gctl)); 697 octl = (struct snd_emu10k1_fx8010_control_old_gpr __user *)_gctl; 698 if (copy_from_user(gctl, &octl[idx], sizeof(*octl))) 717 return copy_to_user(&_dst[idx], src, sizeof(*src)); 718 719 octl = (struct snd_emu10k1_fx8010_control_old_gpr __user *)dst; 720 return copy_to_user(&octl[idx], src, sizeof(*octl)); 721 } 722 723 static int copy_ctl_elem_id(const struct emu10k1_ctl_elem_id *list, int i, 724 struct emu10k1_ctl_elem_id *ret, bool in_kernel) 725 { 726 struct emu10k1_ctl_elem_id __user *_id = 727 (struct emu10k1_ctl_elem_id __user *)&list[i]; 728 729 if (in_kernel) 730 *ret = list[i]; 731 else if (copy_from_user(ret, _id, sizeof(*ret))) 699 732 return -EFAULT; 700 gctl->tlv = NULL;701 733 return 0; 702 734 } 703 735 704 static int copy_gctl_to_user(struct snd_emu10k1 *emu,705 struct snd_emu10k1_fx8010_control_gpr __user *_gctl,706 struct snd_emu10k1_fx8010_control_gpr *gctl,707 int idx)708 {709 struct snd_emu10k1_fx8010_control_old_gpr __user *octl;710 711 if (emu->support_tlv)712 return copy_to_user(&_gctl[idx], gctl, sizeof(*gctl));713 714 octl = (struct snd_emu10k1_fx8010_control_old_gpr __user *)_gctl;715 return copy_to_user(&octl[idx], gctl, sizeof(*octl));716 }717 718 736 static int snd_emu10k1_verify_controls(struct snd_emu10k1 *emu, 719 struct snd_emu10k1_fx8010_code *icode) 737 struct snd_emu10k1_fx8010_code *icode, 738 bool in_kernel) 720 739 { 721 740 unsigned int i; 722 struct snd_ctl_elem_id __user *_id; 723 struct snd_ctl_elem_id id; 741 struct emu10k1_ctl_elem_id id; 724 742 struct snd_emu10k1_fx8010_control_gpr *gctl; 743 struct snd_ctl_elem_id *gctl_id; 725 744 int err; 726 745 727 for (i = 0, _id = icode->gpr_del_controls; 728 i < icode->gpr_del_control_count; i++, _id++) { 729 if (copy_from_user(&id, _id, sizeof(id))) 730 return -EFAULT; 746 for (i = 0; i < icode->gpr_del_control_count; i++) { 747 err = copy_ctl_elem_id(icode->gpr_del_controls, i, &id, 748 in_kernel); 749 if (err < 0) 750 return err; 731 751 if (snd_emu10k1_look_for_ctl(emu, &id) == NULL) 732 752 return -ENOENT; … … 737 757 err = 0; 738 758 for (i = 0; i < icode->gpr_add_control_count; i++) { 739 if (copy_gctl(emu, gctl, icode->gpr_add_controls, i)) { 759 if (copy_gctl(emu, gctl, icode->gpr_add_controls, i, 760 in_kernel)) { 740 761 err = -EFAULT; 741 762 goto __error; … … 743 764 if (snd_emu10k1_look_for_ctl(emu, &gctl->id)) 744 765 continue; 766 gctl_id = (struct snd_ctl_elem_id *)&gctl->id; 745 767 down_read(&emu->card->controls_rwsem); 746 if (snd_ctl_find_id(emu->card, &gctl->id) != NULL) {768 if (snd_ctl_find_id(emu->card, gctl_id)) { 747 769 up_read(&emu->card->controls_rwsem); 748 770 err = -EEXIST; … … 750 772 } 751 773 up_read(&emu->card->controls_rwsem); 752 if (gctl ->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER &&753 gctl ->id.iface != SNDRV_CTL_ELEM_IFACE_PCM) {774 if (gctl_id->iface != SNDRV_CTL_ELEM_IFACE_MIXER && 775 gctl_id->iface != SNDRV_CTL_ELEM_IFACE_PCM) { 754 776 err = -EINVAL; 755 777 goto __error; … … 758 780 for (i = 0; i < icode->gpr_list_control_count; i++) { 759 781 /* FIXME: we need to check the WRITE access */ 760 if (copy_gctl(emu, gctl, icode->gpr_list_controls, i)) { 782 if (copy_gctl(emu, gctl, icode->gpr_list_controls, i, 783 in_kernel)) { 761 784 err = -EFAULT; 762 785 goto __error; … … 776 799 list_del(&ctl->list); 777 800 kfree(ctl); 778 if (kctl->tlv.p) 779 kfree(kctl->tlv.p); 801 kfree(kctl->tlv.p); 780 802 } 781 803 782 804 static int snd_emu10k1_add_controls(struct snd_emu10k1 *emu, 783 struct snd_emu10k1_fx8010_code *icode) 805 struct snd_emu10k1_fx8010_code *icode, 806 bool in_kernel) 784 807 { 785 808 unsigned int i, j; 786 809 struct snd_emu10k1_fx8010_control_gpr *gctl; 810 struct snd_ctl_elem_id *gctl_id; 787 811 struct snd_emu10k1_fx8010_ctl *ctl, *nctl; 788 812 struct snd_kcontrol_new knew; … … 800 824 801 825 for (i = 0; i < icode->gpr_add_control_count; i++) { 802 if (copy_gctl(emu, gctl, icode->gpr_add_controls, i)) { 826 if (copy_gctl(emu, gctl, icode->gpr_add_controls, i, 827 in_kernel)) { 803 828 err = -EFAULT; 804 829 goto __error; 805 830 } 806 if (gctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER && 807 gctl->id.iface != SNDRV_CTL_ELEM_IFACE_PCM) { 831 gctl_id = (struct snd_ctl_elem_id *)&gctl->id; 832 if (gctl_id->iface != SNDRV_CTL_ELEM_IFACE_MIXER && 833 gctl_id->iface != SNDRV_CTL_ELEM_IFACE_PCM) { 808 834 err = -EINVAL; 809 835 goto __error; 810 836 } 811 if (! gctl->id.name[0]) {837 if (!*gctl_id->name) { 812 838 err = -EINVAL; 813 839 goto __error; … … 815 841 ctl = snd_emu10k1_look_for_ctl(emu, &gctl->id); 816 842 memset(&knew, 0, sizeof(knew)); 817 knew.iface = gctl ->id.iface;818 knew.name = gctl ->id.name;819 knew.index = gctl ->id.index;820 knew.device = gctl ->id.device;821 knew.subdevice = gctl ->id.subdevice;843 knew.iface = gctl_id->iface; 844 knew.name = gctl_id->name; 845 knew.index = gctl_id->index; 846 knew.device = gctl_id->device; 847 knew.subdevice = gctl_id->subdevice; 822 848 knew.info = snd_emu10k1_gpr_ctl_info; 823 knew.tlv.p = copy_tlv( gctl->tlv);849 knew.tlv.p = copy_tlv((const unsigned int __user *)gctl->tlv, in_kernel); 824 850 if (knew.tlv.p) 825 851 knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | … … 873 899 874 900 static int snd_emu10k1_del_controls(struct snd_emu10k1 *emu, 875 struct snd_emu10k1_fx8010_code *icode) 901 struct snd_emu10k1_fx8010_code *icode, 902 bool in_kernel) 876 903 { 877 904 unsigned int i; 878 struct snd_ctl_elem_id id; 879 struct snd_ctl_elem_id __user *_id; 905 struct emu10k1_ctl_elem_id id; 880 906 struct snd_emu10k1_fx8010_ctl *ctl; 881 907 struct snd_card *card = emu->card; 882 883 for (i = 0, _id = icode->gpr_del_controls; 884 i < icode->gpr_del_control_count; i++, _id++) { 885 if (copy_from_user(&id, _id, sizeof(id))) 886 return -EFAULT; 908 int err; 909 910 for (i = 0; i < icode->gpr_del_control_count; i++) { 911 err = copy_ctl_elem_id(icode->gpr_del_controls, i, &id, 912 in_kernel); 913 if (err < 0) 914 return err; 887 915 down_write(&card->controls_rwsem); 888 916 ctl = snd_emu10k1_look_for_ctl(emu, &id); … … 913 941 memset(gctl, 0, sizeof(*gctl)); 914 942 id = &ctl->kcontrol->id; 915 gctl->id.iface = id->iface;943 gctl->id.iface = (__force int)id->iface; 916 944 strlcpy(gctl->id.name, id->name, sizeof(gctl->id.name)); 917 945 gctl->id.index = id->index; … … 941 969 942 970 static int snd_emu10k1_icode_poke(struct snd_emu10k1 *emu, 943 struct snd_emu10k1_fx8010_code *icode) 971 struct snd_emu10k1_fx8010_code *icode, 972 bool in_kernel) 944 973 { 945 974 int err = 0; 946 975 947 976 mutex_lock(&emu->fx8010.lock); 948 if ((err = snd_emu10k1_verify_controls(emu, icode)) < 0) 977 err = snd_emu10k1_verify_controls(emu, icode, in_kernel); 978 if (err < 0) 949 979 goto __error; 950 980 strlcpy(emu->fx8010.name, icode->name, sizeof(emu->fx8010.name)); … … 956 986 snd_emu10k1_ptr_write(emu, DBG, 0, emu->fx8010.dbg | EMU10K1_DBG_SINGLE_STEP); 957 987 /* ok, do the main job */ 958 if ((err = snd_emu10k1_del_controls(emu, icode)) < 0 || 959 (err = snd_emu10k1_gpr_poke(emu, icode)) < 0 || 960 (err = snd_emu10k1_tram_poke(emu, icode)) < 0 || 961 (err = snd_emu10k1_code_poke(emu, icode)) < 0 || 962 (err = snd_emu10k1_add_controls(emu, icode)) < 0) 988 err = snd_emu10k1_del_controls(emu, icode, in_kernel); 989 if (err < 0) 990 goto __error; 991 err = snd_emu10k1_gpr_poke(emu, icode, in_kernel); 992 if (err < 0) 993 goto __error; 994 err = snd_emu10k1_tram_poke(emu, icode, in_kernel); 995 if (err < 0) 996 goto __error; 997 err = snd_emu10k1_code_poke(emu, icode, in_kernel); 998 if (err < 0) 999 goto __error; 1000 err = snd_emu10k1_add_controls(emu, icode, in_kernel); 1001 if (err < 0) 963 1002 goto __error; 964 1003 /* start FX processor when the DSP code is updated */ … … 1000 1039 if (ipcm->substream >= EMU10K1_FX8010_PCM_COUNT) 1001 1040 return -EINVAL; 1041 ipcm->substream = array_index_nospec(ipcm->substream, 1042 EMU10K1_FX8010_PCM_COUNT); 1002 1043 if (ipcm->channels > 32) 1003 1044 return -EINVAL; … … 1046 1087 if (ipcm->substream >= EMU10K1_FX8010_PCM_COUNT) 1047 1088 return -EINVAL; 1089 ipcm->substream = array_index_nospec(ipcm->substream, 1090 EMU10K1_FX8010_PCM_COUNT); 1048 1091 pcm = &emu->fx8010.pcm[ipcm->substream]; 1049 1092 mutex_lock(&emu->fx8010.lock); … … 1072 1115 #define SND_EMU10K1_CAPTURE_CHANNELS 4 1073 1116 1074 static void __devinit1117 static void 1075 1118 snd_emu10k1_init_mono_control(struct snd_emu10k1_fx8010_control_gpr *ctl, 1076 1119 const char *name, int gpr, int defval) 1077 1120 { 1078 ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;1121 ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER; 1079 1122 strcpy(ctl->id.name, name); 1080 1123 ctl->vcount = ctl->count = 1; … … 1093 1136 } 1094 1137 1095 static void __devinit1138 static void 1096 1139 snd_emu10k1_init_stereo_control(struct snd_emu10k1_fx8010_control_gpr *ctl, 1097 1140 const char *name, int gpr, int defval) 1098 1141 { 1099 ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;1142 ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER; 1100 1143 strcpy(ctl->id.name, name); 1101 1144 ctl->vcount = ctl->count = 2; … … 1115 1158 } 1116 1159 1117 static void __devinit1160 static void 1118 1161 snd_emu10k1_init_mono_onoff_control(struct snd_emu10k1_fx8010_control_gpr *ctl, 1119 1162 const char *name, int gpr, int defval) 1120 1163 { 1121 ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;1164 ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER; 1122 1165 strcpy(ctl->id.name, name); 1123 1166 ctl->vcount = ctl->count = 1; … … 1128 1171 } 1129 1172 1130 static void __devinit1173 static void 1131 1174 snd_emu10k1_init_stereo_onoff_control(struct snd_emu10k1_fx8010_control_gpr *ctl, 1132 1175 const char *name, int gpr, int defval) 1133 1176 { 1134 ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;1177 ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER; 1135 1178 strcpy(ctl->id.name, name); 1136 1179 ctl->vcount = ctl->count = 2; … … 1167 1210 */ 1168 1211 1169 static int _ _devinit _snd_emu10k1_audigy_init_efx(struct snd_emu10k1 *emu)1212 static int _snd_emu10k1_audigy_init_efx(struct snd_emu10k1 *emu) 1170 1213 { 1171 1214 int err, i, z, gpr, nctl; … … 1179 1222 struct snd_emu10k1_fx8010_control_gpr *controls = NULL, *ctl; 1180 1223 u32 *gpr_map; 1181 mm_segment_t seg; 1182 1183 if ((icode = kzalloc(sizeof(*icode), GFP_KERNEL)) == NULL || 1184 (icode->gpr_map = (u_int32_t __user *) 1185 kcalloc(512 + 256 + 256 + 2 * 1024, sizeof(u_int32_t), 1186 GFP_KERNEL)) == NULL || 1187 (controls = kcalloc(SND_EMU10K1_GPR_CONTROLS, 1188 sizeof(*controls), GFP_KERNEL)) == NULL) { 1189 err = -ENOMEM; 1190 goto __err; 1191 } 1192 gpr_map = (u32 __force *)icode->gpr_map; 1224 1225 err = -ENOMEM; 1226 icode = kzalloc(sizeof(*icode), GFP_KERNEL); 1227 if (!icode) 1228 return err; 1229 1230 icode->gpr_map = kcalloc(512 + 256 + 256 + 2 * 1024, 1231 sizeof(u_int32_t), GFP_KERNEL); 1232 if (!icode->gpr_map) 1233 goto __err_gpr; 1234 controls = kcalloc(SND_EMU10K1_GPR_CONTROLS, 1235 sizeof(*controls), GFP_KERNEL); 1236 if (!controls) 1237 goto __err_ctrls; 1238 1239 gpr_map = icode->gpr_map; 1193 1240 1194 1241 icode->tram_data_map = icode->gpr_map + 512; … … 1277 1324 snd_emu10k1_init_stereo_control(&controls[nctl++], "Synth Capture Volume", gpr, 0); 1278 1325 gpr += 2; 1279 1326 1280 1327 /* 1281 1328 * inputs … … 1353 1400 gpr, 0); 1354 1401 gpr += 2; 1355 1402 1356 1403 /* Philips ADC Playback Volume */ 1357 1404 A_ADD_VOLUME_IN(stereo_mix, gpr, A_EXTIN_ADC_L); … … 1445 1492 1446 1493 ctl = &controls[nctl + 0]; 1447 ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;1494 ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER; 1448 1495 strcpy(ctl->id.name, "Tone Control - Bass"); 1449 1496 ctl->vcount = 2; … … 1454 1501 ctl->translation = EMU10K1_GPR_TRANSLATION_BASS; 1455 1502 ctl = &controls[nctl + 1]; 1456 ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;1503 ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER; 1457 1504 strcpy(ctl->id.name, "Tone Control - Treble"); 1458 1505 ctl->vcount = 2; … … 1541 1588 if (emu->card_capabilities->emu_model) { 1542 1589 /* EMU1010 Outputs from PCM Front, Rear, Center, LFE, Side */ 1543 snd_printk(KERN_INFO"EMU outputs on\n");1590 dev_info(emu->card->dev, "EMU outputs on\n"); 1544 1591 for (z = 0; z < 8; z++) { 1545 1592 if (emu->card_capabilities->ca0108_chip) { … … 1551 1598 } 1552 1599 1553 /* IEC958 Optical Raw Playback Switch */ 1600 /* IEC958 Optical Raw Playback Switch */ 1554 1601 gpr_map[gpr++] = 0; 1555 1602 gpr_map[gpr++] = 0x1008; … … 1565 1612 if ((z==1) && (emu->card_capabilities->spdif_bug)) { 1566 1613 /* Due to a SPDIF output bug on some Audigy cards, this code delays the Right channel by 1 sample */ 1567 snd_printk(KERN_INFO "Installing spdif_bug patch: %s\n", emu->card_capabilities->name); 1614 dev_info(emu->card->dev, 1615 "Installing spdif_bug patch: %s\n", 1616 emu->card_capabilities->name); 1568 1617 A_OP(icode, &ptr, iACC3, A_EXTOUT(A_EXTOUT_FRONT_L + z), A_GPR(gpr - 3), A_C_00000000, A_C_00000000); 1569 1618 A_OP(icode, &ptr, iACC3, A_GPR(gpr - 3), A_GPR(tmp + 0), A_GPR(tmp + 1), A_C_00000000); … … 1589 1638 if (emu->card_capabilities->emu_model) { 1590 1639 if (emu->card_capabilities->ca0108_chip) { 1591 snd_printk(KERN_INFO"EMU2 inputs on\n");1640 dev_info(emu->card->dev, "EMU2 inputs on\n"); 1592 1641 for (z = 0; z < 0x10; z++) { 1593 snd_emu10k1_audigy_dsp_convert_32_to_2x16( icode, &ptr, tmp, 1642 snd_emu10k1_audigy_dsp_convert_32_to_2x16( icode, &ptr, tmp, 1594 1643 bit_shifter16, 1595 1644 A3_EMU32IN(z), … … 1597 1646 } 1598 1647 } else { 1599 snd_printk(KERN_INFO"EMU inputs on\n");1648 dev_info(emu->card->dev, "EMU inputs on\n"); 1600 1649 /* Capture 16 (originally 8) channels of S32_LE sound */ 1601 1650 1602 1651 /* 1603 printk(KERN_DEBUG"emufx.c: gpr=0x%x, tmp=0x%x\n",1652 dev_dbg(emu->card->dev, "emufx.c: gpr=0x%x, tmp=0x%x\n", 1604 1653 gpr, tmp); 1605 1654 */ … … 1732 1781 A_OP(icode, &ptr, 0x0f, 0xc0, 0xc0, 0xcf, 0xc0); 1733 1782 1734 seg = snd_enter_user();1735 1783 icode->gpr_add_control_count = nctl; 1736 icode->gpr_add_controls = (struct snd_emu10k1_fx8010_control_gpr __user *)controls;1784 icode->gpr_add_controls = controls; 1737 1785 emu->support_tlv = 1; /* support TLV */ 1738 err = snd_emu10k1_icode_poke(emu, icode );1786 err = snd_emu10k1_icode_poke(emu, icode, true); 1739 1787 emu->support_tlv = 0; /* clear again */ 1740 snd_leave_user(seg); 1741 1742 __err: 1788 1789 __err: 1743 1790 kfree(controls); 1744 if (icode != NULL) { 1745 kfree((void __force *)icode->gpr_map);1746 kfree(icode); 1747 }1791 __err_ctrls: 1792 kfree(icode->gpr_map); 1793 __err_gpr: 1794 kfree(icode); 1748 1795 return err; 1749 1796 } … … 1756 1803 /* when volume = max, then copy only to avoid volume modification */ 1757 1804 /* with iMAC0 (negative values) */ 1758 static void _ _devinit _volume(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol)1805 static void _volume(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol) 1759 1806 { 1760 1807 OP(icode, ptr, iMAC0, dst, C_00000000, src, vol); … … 1763 1810 OP(icode, ptr, iACC3, dst, src, C_00000000, C_00000000); 1764 1811 } 1765 static void _ _devinit _volume_add(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol)1812 static void _volume_add(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol) 1766 1813 { 1767 1814 OP(icode, ptr, iANDXOR, C_00000000, vol, C_ffffffff, C_7fffffff); … … 1771 1818 OP(icode, ptr, iMAC0, dst, dst, src, vol); 1772 1819 } 1773 static void _ _devinit _volume_out(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol)1820 static void _volume_out(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol) 1774 1821 { 1775 1822 OP(icode, ptr, iANDXOR, C_00000000, vol, C_ffffffff, C_7fffffff); … … 1802 1849 1803 1850 1804 static int _ _devinit _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)1851 static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu) 1805 1852 { 1806 1853 int err, i, z, gpr, tmp, playback, capture; … … 1810 1857 struct snd_emu10k1_fx8010_control_gpr *controls = NULL, *ctl; 1811 1858 u32 *gpr_map; 1812 mm_segment_t seg; 1813 1814 if ((icode = kzalloc(sizeof(*icode), GFP_KERNEL)) == NULL) 1815 return -ENOMEM; 1816 if ((icode->gpr_map = (u_int32_t __user *) 1817 kcalloc(256 + 160 + 160 + 2 * 512, sizeof(u_int32_t), 1818 GFP_KERNEL)) == NULL || 1819 (controls = kcalloc(SND_EMU10K1_GPR_CONTROLS, 1820 sizeof(struct snd_emu10k1_fx8010_control_gpr), 1821 GFP_KERNEL)) == NULL || 1822 (ipcm = kzalloc(sizeof(*ipcm), GFP_KERNEL)) == NULL) { 1823 err = -ENOMEM; 1824 goto __err; 1825 } 1826 gpr_map = (u32 __force *)icode->gpr_map; 1859 1860 err = -ENOMEM; 1861 icode = kzalloc(sizeof(*icode), GFP_KERNEL); 1862 if (!icode) 1863 return err; 1864 1865 icode->gpr_map = kcalloc(256 + 160 + 160 + 2 * 512, 1866 sizeof(u_int32_t), GFP_KERNEL); 1867 if (!icode->gpr_map) 1868 goto __err_gpr; 1869 1870 controls = kcalloc(SND_EMU10K1_GPR_CONTROLS, 1871 sizeof(struct snd_emu10k1_fx8010_control_gpr), 1872 GFP_KERNEL); 1873 if (!controls) 1874 goto __err_ctrls; 1875 1876 ipcm = kzalloc(sizeof(*ipcm), GFP_KERNEL); 1877 if (!ipcm) 1878 goto __err_ipcm; 1879 1880 gpr_map = icode->gpr_map; 1827 1881 1828 1882 icode->tram_data_map = icode->gpr_map + 256; … … 2158 2212 2159 2213 ctl = &controls[i + 0]; 2160 ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;2214 ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER; 2161 2215 strcpy(ctl->id.name, "Tone Control - Bass"); 2162 2216 ctl->vcount = 2; … … 2165 2219 ctl->max = 40; 2166 2220 ctl->value[0] = ctl->value[1] = 20; 2221 ctl->tlv = snd_emu10k1_bass_treble_db_scale; 2167 2222 ctl->translation = EMU10K1_GPR_TRANSLATION_BASS; 2168 2223 ctl = &controls[i + 1]; 2169 ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;2224 ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER; 2170 2225 strcpy(ctl->id.name, "Tone Control - Treble"); 2171 2226 ctl->vcount = 2; … … 2174 2229 ctl->max = 40; 2175 2230 ctl->value[0] = ctl->value[1] = 20; 2231 ctl->tlv = snd_emu10k1_bass_treble_db_scale; 2176 2232 ctl->translation = EMU10K1_GPR_TRANSLATION_TREBLE; 2177 2233 … … 2316 2372 * and EXTOUT_ALFE, so we can't connect inputs to them for multitrack recording. 2317 2373 * 2318 * Since only 14 of the 16 EXTINs are used, this is not a big problem. 2319 * We route AC97L and R to FX capture 14 and 15, SPDIF CD in to FX capture 2320 * 0 and 3, then the rest of the EXTINs to the corresponding FX capture 2321 * channel. Multitrack recorders will still see the center/lfe output signal 2374 * Since only 14 of the 16 EXTINs are used, this is not a big problem. 2375 * We route AC97L and R to FX capture 14 and 15, SPDIF CD in to FX capture 2376 * 0 and 3, then the rest of the EXTINs to the corresponding FX capture 2377 * channel. Multitrack recorders will still see the center/lfe output signal 2322 2378 * on the second and third channels. 2323 2379 */ … … 2332 2388 OP(icode, &ptr, iACC3, FXBUS2(z), C_00000000, C_00000000, EXTIN(z)); 2333 2389 } 2334 2390 2335 2391 2336 2392 if (gpr > tmp) { … … 2351 2407 if ((err = snd_emu10k1_fx8010_tram_setup(emu, ipcm->buffer_size)) < 0) 2352 2408 goto __err; 2353 seg = snd_enter_user();2354 2409 icode->gpr_add_control_count = i; 2355 icode->gpr_add_controls = (struct snd_emu10k1_fx8010_control_gpr __user *)controls;2410 icode->gpr_add_controls = controls; 2356 2411 emu->support_tlv = 1; /* support TLV */ 2357 err = snd_emu10k1_icode_poke(emu, icode );2412 err = snd_emu10k1_icode_poke(emu, icode, true); 2358 2413 emu->support_tlv = 0; /* clear again */ 2359 snd_leave_user(seg);2360 2414 if (err >= 0) 2361 2415 err = snd_emu10k1_ipcm_poke(emu, ipcm); 2362 2416 __err: 2363 2417 kfree(ipcm); 2418 __err_ipcm: 2364 2419 kfree(controls); 2365 if (icode != NULL) { 2366 kfree((void __force *)icode->gpr_map);2367 kfree(icode); 2368 }2420 __err_ctrls: 2421 kfree(icode->gpr_map); 2422 __err_gpr: 2423 kfree(icode); 2369 2424 return err; 2370 2425 } 2371 2426 2372 int __devinitsnd_emu10k1_init_efx(struct snd_emu10k1 *emu)2427 int snd_emu10k1_init_efx(struct snd_emu10k1 *emu) 2373 2428 { 2374 2429 spin_lock_init(&emu->fx8010.irq_lock); … … 2435 2490 2436 2491 if (size > 0) { 2437 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci),2492 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &emu->pci->dev, 2438 2493 size * 2, &emu->fx8010.etram_pages) < 0) 2439 2494 return -ENOMEM; … … 2454 2509 } 2455 2510 2456 static void copy_string(char *dst, c har *src,char *null, int idx)2511 static void copy_string(char *dst, const char *src, const char *null, int idx) 2457 2512 { 2458 2513 if (src == NULL) … … 2465 2520 struct snd_emu10k1_fx8010_info *info) 2466 2521 { 2467 c har **fxbus, **extin, **extout;2522 const char * const *fxbus, * const *extin, * const *extout; 2468 2523 unsigned short fxbus_mask, extin_mask, extout_mask; 2469 2524 int res; … … 2502 2557 return put_user(SNDRV_EMU10K1_VERSION, (int __user *)argp); 2503 2558 case SNDRV_EMU10K1_IOCTL_INFO: 2504 info = k malloc(sizeof(*info), GFP_KERNEL);2559 info = kzalloc(sizeof(*info), GFP_KERNEL); 2505 2560 if (!info) 2506 2561 return -ENOMEM; … … 2519 2574 if (IS_ERR(icode)) 2520 2575 return PTR_ERR(icode); 2521 res = snd_emu10k1_icode_poke(emu, icode );2576 res = snd_emu10k1_icode_poke(emu, icode, false); 2522 2577 kfree(icode); 2523 2578 return res; … … 2623 2678 } 2624 2679 2625 int __devinit snd_emu10k1_fx8010_new(struct snd_emu10k1 *emu, int device, struct snd_hwdep ** rhwdep)2680 int snd_emu10k1_fx8010_new(struct snd_emu10k1 *emu, int device) 2626 2681 { 2627 2682 struct snd_hwdep *hw; 2628 2683 int err; 2629 2684 2630 if (rhwdep)2631 *rhwdep = NULL;2632 2685 if ((err = snd_hwdep_new(emu->card, "FX8010", device, &hw)) < 0) 2633 2686 return err; … … 2638 2691 hw->ops.release = snd_emu10k1_fx8010_release; 2639 2692 hw->private_data = emu; 2640 if (rhwdep)2641 *rhwdep = hw;2642 2693 return 0; 2643 2694 } 2644 2695 2645 #ifdef CONFIG_PM 2646 int __devinitsnd_emu10k1_efx_alloc_pm_buffer(struct snd_emu10k1 *emu)2696 #ifdef CONFIG_PM_SLEEP 2697 int snd_emu10k1_efx_alloc_pm_buffer(struct snd_emu10k1 *emu) 2647 2698 { 2648 2699 int len; 2649 2700 2650 2701 len = emu->audigy ? 0x200 : 0x100; 2651 emu->saved_gpr = kmalloc (len *4, GFP_KERNEL);2702 emu->saved_gpr = kmalloc_array(len, 4, GFP_KERNEL); 2652 2703 if (! emu->saved_gpr) 2653 2704 return -ENOMEM; 2654 2705 len = emu->audigy ? 0x100 : 0xa0; 2655 emu->tram_val_saved = kmalloc (len *4, GFP_KERNEL);2656 emu->tram_addr_saved = kmalloc (len *4, GFP_KERNEL);2706 emu->tram_val_saved = kmalloc_array(len, 4, GFP_KERNEL); 2707 emu->tram_addr_saved = kmalloc_array(len, 4, GFP_KERNEL); 2657 2708 if (! emu->tram_val_saved || ! emu->tram_addr_saved) 2658 2709 return -ENOMEM; 2659 2710 len = emu->audigy ? 2 * 1024 : 2 * 512; 2711 #ifdef TARGET_OS2 2712 emu->saved_icode = vmalloc(array_size(len, 4)); 2713 #else 2660 2714 emu->saved_icode = vmalloc(len * 4); 2715 #endif 2661 2716 if (! emu->saved_icode) 2662 2717 return -ENOMEM;
Note:
See TracChangeset
for help on using the changeset viewer.