Skip to content

Commit 1730fd9

Browse files
jrhackertiwai
authored andcommitted
ALSA: fix emu8000 DRAM sizing for AWE64 Value
Applicable to any kernel since 2013: The special case added in commit 1338fc9 did not handle the possibility that the address space on an AWE64 Value would wrap around at 512 KiB. That is what it does, so the memory is still not detected on those cards. Fix that with a logic clean-up that eliminates the need for a special case. Signed-off-by: David Flater <[email protected]> Signed-off-by: Takashi Iwai <[email protected]>
1 parent ace79a3 commit 1730fd9

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

sound/isa/sb/emu8000.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -378,24 +378,32 @@ init_arrays(struct snd_emu8000 *emu)
378378
static void
379379
size_dram(struct snd_emu8000 *emu)
380380
{
381-
int i, size, detected_size;
381+
int i, size;
382382

383383
if (emu->dram_checked)
384384
return;
385385

386386
size = 0;
387-
detected_size = 0;
388387

389388
/* write out a magic number */
390389
snd_emu8000_dma_chan(emu, 0, EMU8000_RAM_WRITE);
391390
snd_emu8000_dma_chan(emu, 1, EMU8000_RAM_READ);
392391
EMU8000_SMALW_WRITE(emu, EMU8000_DRAM_OFFSET);
393392
EMU8000_SMLD_WRITE(emu, UNIQUE_ID1);
394393
snd_emu8000_init_fm(emu); /* This must really be here and not 2 lines back even */
394+
snd_emu8000_write_wait(emu);
395395

396-
while (size < EMU8000_MAX_DRAM) {
396+
/*
397+
* Detect first 512 KiB. If a write succeeds at the beginning of a
398+
* 512 KiB page we assume that the whole page is there.
399+
*/
400+
EMU8000_SMALR_WRITE(emu, EMU8000_DRAM_OFFSET);
401+
EMU8000_SMLD_READ(emu); /* discard stale data */
402+
if (EMU8000_SMLD_READ(emu) != UNIQUE_ID1)
403+
goto skip_detect; /* No RAM */
404+
snd_emu8000_read_wait(emu);
397405

398-
size += 512 * 1024; /* increment 512kbytes */
406+
for (size = 512 * 1024; size < EMU8000_MAX_DRAM; size += 512 * 1024) {
399407

400408
/* Write a unique data on the test address.
401409
* if the address is out of range, the data is written on
@@ -431,18 +439,9 @@ size_dram(struct snd_emu8000 *emu)
431439
snd_emu8000_read_wait(emu);
432440

433441
/* Otherwise, it's valid memory. */
434-
detected_size = size + 512 * 1024;
435-
}
436-
437-
/* Distinguish 512 KiB from 0. */
438-
if (detected_size == 0) {
439-
snd_emu8000_read_wait(emu);
440-
EMU8000_SMALR_WRITE(emu, EMU8000_DRAM_OFFSET);
441-
EMU8000_SMLD_READ(emu); /* discard stale data */
442-
if (EMU8000_SMLD_READ(emu) == UNIQUE_ID1)
443-
detected_size = 512 * 1024;
444442
}
445443

444+
skip_detect:
446445
/* wait until FULL bit in SMAxW register is false */
447446
for (i = 0; i < 10000; i++) {
448447
if ((EMU8000_SMALW_READ(emu) & 0x80000000) == 0)
@@ -455,9 +454,9 @@ size_dram(struct snd_emu8000 *emu)
455454
snd_emu8000_dma_chan(emu, 1, EMU8000_RAM_CLOSE);
456455

457456
snd_printdd("EMU8000 [0x%lx]: %d Kb on-board memory detected\n",
458-
emu->port1, detected_size/1024);
457+
emu->port1, size/1024);
459458

460-
emu->mem_size = detected_size;
459+
emu->mem_size = size;
461460
emu->dram_checked = 1;
462461
}
463462

0 commit comments

Comments
 (0)