Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1 | /***********************************************************************/ |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 2 | /** |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 3 | |
| 4 | AudioScience HPI driver |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 5 | Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com> |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of version 2 of the GNU General Public License as |
| 9 | published by the Free Software Foundation; |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | |
| 20 | \file |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 21 | Functions for reading DSP code using |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 22 | hotplug firmware loader from individual dsp code files |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 23 | */ |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 24 | /***********************************************************************/ |
| 25 | #define SOURCEFILE_NAME "hpidspcd.c" |
| 26 | #include "hpidspcd.h" |
| 27 | #include "hpidebug.h" |
Eliot Blennerhassett | f6baaec | 2011-12-22 13:38:31 +1300 | [diff] [blame] | 28 | #include "hpi_version.h" |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 29 | |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 30 | struct dsp_code_private { |
| 31 | /** Firmware descriptor */ |
| 32 | const struct firmware *firmware; |
| 33 | struct pci_dev *dev; |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 34 | }; |
| 35 | |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 36 | /*-------------------------------------------------------------------*/ |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 37 | short hpi_dsp_code_open(u32 adapter, void *os_data, struct dsp_code *dsp_code, |
| 38 | u32 *os_error_code) |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 39 | { |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 40 | const struct firmware *firmware; |
| 41 | struct pci_dev *dev = os_data; |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 42 | struct code_header header; |
| 43 | char fw_name[20]; |
Jesper Juhl | dc889f1 | 2011-07-31 23:16:43 +0200 | [diff] [blame] | 44 | short err_ret = HPI_ERROR_DSP_FILE_NOT_FOUND; |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 45 | int err; |
| 46 | |
| 47 | sprintf(fw_name, "asihpi/dsp%04x.bin", adapter); |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 48 | |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 49 | err = request_firmware(&firmware, fw_name, &dev->dev); |
Eliot Blennerhassett | 5ed15da | 2011-02-10 17:25:54 +1300 | [diff] [blame] | 50 | |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 51 | if (err || !firmware) { |
Joe Perches | 4ee3bff | 2012-10-28 01:05:54 -0700 | [diff] [blame] | 52 | dev_err(&dev->dev, "%d, request_firmware failed for %s\n", |
| 53 | err, fw_name); |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 54 | goto error1; |
| 55 | } |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 56 | if (firmware->size < sizeof(header)) { |
Joe Perches | 4ee3bff | 2012-10-28 01:05:54 -0700 | [diff] [blame] | 57 | dev_err(&dev->dev, "Header size too small %s\n", fw_name); |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 58 | goto error2; |
| 59 | } |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 60 | memcpy(&header, firmware->data, sizeof(header)); |
| 61 | |
| 62 | if ((header.type != 0x45444F43) || /* "CODE" */ |
| 63 | (header.adapter != adapter) |
| 64 | || (header.size != firmware->size)) { |
Joe Perches | 4ee3bff | 2012-10-28 01:05:54 -0700 | [diff] [blame] | 65 | dev_err(&dev->dev, |
Eliot Blennerhassett | f6baaec | 2011-12-22 13:38:31 +1300 | [diff] [blame] | 66 | "Invalid firmware header size %d != file %zd\n", |
| 67 | header.size, firmware->size); |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 68 | goto error2; |
| 69 | } |
| 70 | |
Eliot Blennerhassett | f6baaec | 2011-12-22 13:38:31 +1300 | [diff] [blame] | 71 | if ((header.version >> 9) != (HPI_VER >> 9)) { |
| 72 | /* Consider even and subsequent odd minor versions to be compatible */ |
Joe Perches | 4ee3bff | 2012-10-28 01:05:54 -0700 | [diff] [blame] | 73 | dev_err(&dev->dev, "Incompatible firmware version DSP image %X != Driver %X\n", |
| 74 | header.version, HPI_VER); |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 75 | goto error2; |
| 76 | } |
| 77 | |
Eliot Blennerhassett | f6baaec | 2011-12-22 13:38:31 +1300 | [diff] [blame] | 78 | if (header.version != HPI_VER) { |
Joe Perches | 4ee3bff | 2012-10-28 01:05:54 -0700 | [diff] [blame] | 79 | dev_info(&dev->dev, |
| 80 | "Firmware: release version mismatch DSP image %X != Driver %X\n", |
| 81 | header.version, HPI_VER); |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 82 | } |
| 83 | |
Eliot Blennerhassett | 5ed15da | 2011-02-10 17:25:54 +1300 | [diff] [blame] | 84 | HPI_DEBUG_LOG(DEBUG, "dsp code %s opened\n", fw_name); |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 85 | dsp_code->pvt = kmalloc(sizeof(*dsp_code->pvt), GFP_KERNEL); |
Jesper Juhl | dc889f1 | 2011-07-31 23:16:43 +0200 | [diff] [blame] | 86 | if (!dsp_code->pvt) { |
| 87 | err_ret = HPI_ERROR_MEMORY_ALLOC; |
| 88 | goto error2; |
| 89 | } |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 90 | |
| 91 | dsp_code->pvt->dev = dev; |
| 92 | dsp_code->pvt->firmware = firmware; |
| 93 | dsp_code->header = header; |
| 94 | dsp_code->block_length = header.size / sizeof(u32); |
| 95 | dsp_code->word_count = sizeof(header) / sizeof(u32); |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 96 | return 0; |
| 97 | |
| 98 | error2: |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 99 | release_firmware(firmware); |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 100 | error1: |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 101 | dsp_code->block_length = 0; |
Jesper Juhl | dc889f1 | 2011-07-31 23:16:43 +0200 | [diff] [blame] | 102 | return err_ret; |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /*-------------------------------------------------------------------*/ |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 106 | void hpi_dsp_code_close(struct dsp_code *dsp_code) |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 107 | { |
Eliot Blennerhassett | 50d5f77 | 2011-12-22 13:38:44 +1300 | [diff] [blame] | 108 | HPI_DEBUG_LOG(DEBUG, "dsp code closed\n"); |
| 109 | release_firmware(dsp_code->pvt->firmware); |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 110 | kfree(dsp_code->pvt); |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /*-------------------------------------------------------------------*/ |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 114 | void hpi_dsp_code_rewind(struct dsp_code *dsp_code) |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 115 | { |
| 116 | /* Go back to start of data, after header */ |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 117 | dsp_code->word_count = sizeof(struct code_header) / sizeof(u32); |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /*-------------------------------------------------------------------*/ |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 121 | short hpi_dsp_code_read_word(struct dsp_code *dsp_code, u32 *pword) |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 122 | { |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 123 | if (dsp_code->word_count + 1 > dsp_code->block_length) |
Eliot Blennerhassett | 5ed15da | 2011-02-10 17:25:54 +1300 | [diff] [blame] | 124 | return HPI_ERROR_DSP_FILE_FORMAT; |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 125 | |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 126 | *pword = ((u32 *)(dsp_code->pvt->firmware->data))[dsp_code-> |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 127 | word_count]; |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 128 | dsp_code->word_count++; |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | /*-------------------------------------------------------------------*/ |
| 133 | short hpi_dsp_code_read_block(size_t words_requested, |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 134 | struct dsp_code *dsp_code, u32 **ppblock) |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 135 | { |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 136 | if (dsp_code->word_count + words_requested > dsp_code->block_length) |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 137 | return HPI_ERROR_DSP_FILE_FORMAT; |
| 138 | |
| 139 | *ppblock = |
Eliot Blennerhassett | 95a4c6e | 2011-07-22 15:52:42 +1200 | [diff] [blame] | 140 | ((u32 *)(dsp_code->pvt->firmware->data)) + |
| 141 | dsp_code->word_count; |
| 142 | dsp_code->word_count += words_requested; |
Eliot Blennerhassett | 719f82d3 | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 143 | return 0; |
| 144 | } |