Module Name: src Committed By: isaki Date: Sun Apr 19 04:13:10 UTC 2020
Modified Files: src/sys/dev/hdaudio: hdafg.c Log Message: Make round_blocksize satisfy all of - restrictions that existed before merging isaki-audio2 branch. - better support for 6 channels hardware. - audio layer's requirement. This may help PR kern/54474. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/sys/dev/hdaudio/hdafg.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/hdaudio/hdafg.c diff -u src/sys/dev/hdaudio/hdafg.c:1.21 src/sys/dev/hdaudio/hdafg.c:1.22 --- src/sys/dev/hdaudio/hdafg.c:1.21 Sat Feb 15 03:04:45 2020 +++ src/sys/dev/hdaudio/hdafg.c Sun Apr 19 04:13:09 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: hdafg.c,v 1.21 2020/02/15 03:04:45 isaki Exp $ */ +/* $NetBSD: hdafg.c,v 1.22 2020/04/19 04:13:09 isaki Exp $ */ /* * Copyright (c) 2009 Precedence Technologies Ltd <supp...@precedence.co.uk> @@ -60,7 +60,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: hdafg.c,v 1.21 2020/02/15 03:04:45 isaki Exp $"); +__KERNEL_RCSID(0, "$NetBSD: hdafg.c,v 1.22 2020/04/19 04:13:09 isaki Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -3942,12 +3942,28 @@ hdafg_set_format(void *opaque, int setmo return 0; } +/* LCM for round_blocksize */ +static u_int gcd(u_int, u_int); +static u_int lcm(u_int, u_int); + +static u_int gcd(u_int a, u_int b) +{ + + return (b == 0) ? a : gcd(b, a % b); +} +static u_int lcm(u_int a, u_int b) +{ + + return a * b / gcd(a, b); +} + static int hdafg_round_blocksize(void *opaque, int blksize, int mode, const audio_params_t *param) { struct hdaudio_audiodev *ad = opaque; struct hdaudio_stream *st; + u_int minblksize; int bufsize; st = (mode == AUMODE_PLAY) ? ad->ad_playback : ad->ad_capture; @@ -3957,6 +3973,15 @@ hdafg_round_blocksize(void *opaque, int return 128; } + if (blksize > 8192) + blksize = 8192; + + /* Make sure there are enough BDL descriptors */ + bufsize = st->st_data.dma_size; + if (bufsize > HDAUDIO_BDL_MAX * blksize) { + blksize = bufsize / HDAUDIO_BDL_MAX; + } + /* * HD audio's buffer constraint looks like following: * - The buffer MUST start on a 128bytes boundary. @@ -3964,13 +3989,15 @@ hdafg_round_blocksize(void *opaque, int * - The buffer size is preferred multiple of 128bytes for efficiency. * * https://www.intel.co.jp/content/www/jp/ja/standards/high-definition-audio-specification.html , p70. + * + * Also, the audio layer requires that the blocksize must be a + * multiple of the number of channels. */ + minblksize = lcm(128, param->channels); + blksize = rounddown(blksize, minblksize); + if (blksize < minblksize) + blksize = minblksize; - /* Make sure there are enough BDL descriptors */ - bufsize = st->st_data.dma_size; - if (bufsize > HDAUDIO_BDL_MAX * blksize) { - blksize = bufsize / HDAUDIO_BDL_MAX; - } return blksize; }