mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-18 22:46:44 +07:00
b24413180f
Many source files in the tree are missing licensing information, which makes it harder for compliance tools to determine the correct license. By default all files without license information are under the default license of the kernel, which is GPL version 2. Update the files which contain no license information with the 'GPL-2.0' SPDX license identifier. The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. This patch is based on work done by Thomas Gleixner and Kate Stewart and Philippe Ombredanne. How this work was done: Patches were generated and checked against linux-4.14-rc6 for a subset of the use cases: - file had no licensing information it it. - file was a */uapi/* one with no licensing information in it, - file was a */uapi/* one with existing licensing information, Further patches will be generated in subsequent months to fix up cases where non-standard license headers were used, and references to license had to be inferred by heuristics based on keywords. The analysis to determine which SPDX License Identifier to be applied to a file was done in a spreadsheet of side by side results from of the output of two independent scanners (ScanCode & Windriver) producing SPDX tag:value files created by Philippe Ombredanne. Philippe prepared the base worksheet, and did an initial spot review of a few 1000 files. The 4.13 kernel was the starting point of the analysis with 60,537 files assessed. Kate Stewart did a file by file comparison of the scanner results in the spreadsheet to determine which SPDX license identifier(s) to be applied to the file. She confirmed any determination that was not immediately clear with lawyers working with the Linux Foundation. Criteria used to select files for SPDX license identifier tagging was: - Files considered eligible had to be source code files. - Make and config files were included as candidates if they contained >5 lines of source - File already had some variant of a license header in it (even if <5 lines). All documentation files were explicitly excluded. The following heuristics were used to determine which SPDX license identifiers to apply. - when both scanners couldn't find any license traces, file was considered to have no license information in it, and the top level COPYING file license applied. For non */uapi/* files that summary was: SPDX license identifier # files ---------------------------------------------------|------- GPL-2.0 11139 and resulted in the first patch in this series. If that file was a */uapi/* path one, it was "GPL-2.0 WITH Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was: SPDX license identifier # files ---------------------------------------------------|------- GPL-2.0 WITH Linux-syscall-note 930 and resulted in the second patch in this series. - if a file had some form of licensing information in it, and was one of the */uapi/* ones, it was denoted with the Linux-syscall-note if any GPL family license was found in the file or had no licensing in it (per prior point). Results summary: SPDX license identifier # files ---------------------------------------------------|------ GPL-2.0 WITH Linux-syscall-note 270 GPL-2.0+ WITH Linux-syscall-note 169 ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21 ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17 LGPL-2.1+ WITH Linux-syscall-note 15 GPL-1.0+ WITH Linux-syscall-note 14 ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5 LGPL-2.0+ WITH Linux-syscall-note 4 LGPL-2.1 WITH Linux-syscall-note 3 ((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3 ((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1 and that resulted in the third patch in this series. - when the two scanners agreed on the detected license(s), that became the concluded license(s). - when there was disagreement between the two scanners (one detected a license but the other didn't, or they both detected different licenses) a manual inspection of the file occurred. - In most cases a manual inspection of the information in the file resulted in a clear resolution of the license that should apply (and which scanner probably needed to revisit its heuristics). - When it was not immediately clear, the license identifier was confirmed with lawyers working with the Linux Foundation. - If there was any question as to the appropriate license identifier, the file was flagged for further research and to be revisited later in time. In total, over 70 hours of logged manual review was done on the spreadsheet to determine the SPDX license identifiers to apply to the source files by Kate, Philippe, Thomas and, in some cases, confirmation by lawyers working with the Linux Foundation. Kate also obtained a third independent scan of the 4.13 code base from FOSSology, and compared selected files where the other two scanners disagreed against that SPDX file, to see if there was new insights. The Windriver scanner is based on an older version of FOSSology in part, so they are related. Thomas did random spot checks in about 500 files from the spreadsheets for the uapi headers and agreed with SPDX license identifier in the files he inspected. For the non-uapi files Thomas did random spot checks in about 15000 files. In initial set of patches against 4.14-rc6, 3 files were found to have copy/paste license identifier errors, and have been fixed to reflect the correct identifier. Additionally Philippe spent 10 hours this week doing a detailed manual inspection and review of the 12,461 patched files from the initial patch version early this week with: - a full scancode scan run, collecting the matched texts, detected license ids and scores - reviewing anything where there was a license detected (about 500+ files) to ensure that the applied SPDX license was correct - reviewing anything where there was no detection but the patch license was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied SPDX license was correct This produced a worksheet with 20 files needing minor correction. This worksheet was then exported into 3 different .csv files for the different types of files to be modified. These .csv files were then reviewed by Greg. Thomas wrote a script to parse the csv files and add the proper SPDX tag to the file, in the format that the file expected. This script was further refined by Greg based on the output to detect more types of files automatically and to distinguish between header and source .c files (which need different comment types.) Finally Greg ran the script using the .csv files to generate the patches. Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
361 lines
9.1 KiB
C
361 lines
9.1 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* PC-Speaker driver for Linux
|
|
*
|
|
* Copyright (C) 1993-1997 Michael Beck
|
|
* Copyright (C) 1997-2001 David Woodhouse
|
|
* Copyright (C) 2001-2008 Stas Sergeev
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/gfp.h>
|
|
#include <linux/moduleparam.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/io.h>
|
|
#include <sound/pcm.h>
|
|
#include "pcsp.h"
|
|
|
|
static bool nforce_wa;
|
|
module_param(nforce_wa, bool, 0444);
|
|
MODULE_PARM_DESC(nforce_wa, "Apply NForce chipset workaround "
|
|
"(expect bad sound)");
|
|
|
|
#define DMIX_WANTS_S16 1
|
|
|
|
/*
|
|
* Call snd_pcm_period_elapsed in a tasklet
|
|
* This avoids spinlock messes and long-running irq contexts
|
|
*/
|
|
static void pcsp_call_pcm_elapsed(unsigned long priv)
|
|
{
|
|
if (atomic_read(&pcsp_chip.timer_active)) {
|
|
struct snd_pcm_substream *substream;
|
|
substream = pcsp_chip.playback_substream;
|
|
if (substream)
|
|
snd_pcm_period_elapsed(substream);
|
|
}
|
|
}
|
|
|
|
static DECLARE_TASKLET(pcsp_pcm_tasklet, pcsp_call_pcm_elapsed, 0);
|
|
|
|
/* write the port and returns the next expire time in ns;
|
|
* called at the trigger-start and in hrtimer callback
|
|
*/
|
|
static u64 pcsp_timer_update(struct snd_pcsp *chip)
|
|
{
|
|
unsigned char timer_cnt, val;
|
|
u64 ns;
|
|
struct snd_pcm_substream *substream;
|
|
struct snd_pcm_runtime *runtime;
|
|
unsigned long flags;
|
|
|
|
if (chip->thalf) {
|
|
outb(chip->val61, 0x61);
|
|
chip->thalf = 0;
|
|
return chip->ns_rem;
|
|
}
|
|
|
|
substream = chip->playback_substream;
|
|
if (!substream)
|
|
return 0;
|
|
|
|
runtime = substream->runtime;
|
|
/* assume it is mono! */
|
|
val = runtime->dma_area[chip->playback_ptr + chip->fmt_size - 1];
|
|
if (chip->is_signed)
|
|
val ^= 0x80;
|
|
timer_cnt = val * CUR_DIV() / 256;
|
|
|
|
if (timer_cnt && chip->enable) {
|
|
raw_spin_lock_irqsave(&i8253_lock, flags);
|
|
if (!nforce_wa) {
|
|
outb_p(chip->val61, 0x61);
|
|
outb_p(timer_cnt, 0x42);
|
|
outb(chip->val61 ^ 1, 0x61);
|
|
} else {
|
|
outb(chip->val61 ^ 2, 0x61);
|
|
chip->thalf = 1;
|
|
}
|
|
raw_spin_unlock_irqrestore(&i8253_lock, flags);
|
|
}
|
|
|
|
chip->ns_rem = PCSP_PERIOD_NS();
|
|
ns = (chip->thalf ? PCSP_CALC_NS(timer_cnt) : chip->ns_rem);
|
|
chip->ns_rem -= ns;
|
|
return ns;
|
|
}
|
|
|
|
static void pcsp_pointer_update(struct snd_pcsp *chip)
|
|
{
|
|
struct snd_pcm_substream *substream;
|
|
size_t period_bytes, buffer_bytes;
|
|
int periods_elapsed;
|
|
unsigned long flags;
|
|
|
|
/* update the playback position */
|
|
substream = chip->playback_substream;
|
|
if (!substream)
|
|
return;
|
|
|
|
period_bytes = snd_pcm_lib_period_bytes(substream);
|
|
buffer_bytes = snd_pcm_lib_buffer_bytes(substream);
|
|
|
|
spin_lock_irqsave(&chip->substream_lock, flags);
|
|
chip->playback_ptr += PCSP_INDEX_INC() * chip->fmt_size;
|
|
periods_elapsed = chip->playback_ptr - chip->period_ptr;
|
|
if (periods_elapsed < 0) {
|
|
#if PCSP_DEBUG
|
|
printk(KERN_INFO "PCSP: buffer_bytes mod period_bytes != 0 ? "
|
|
"(%zi %zi %zi)\n",
|
|
chip->playback_ptr, period_bytes, buffer_bytes);
|
|
#endif
|
|
periods_elapsed += buffer_bytes;
|
|
}
|
|
periods_elapsed /= period_bytes;
|
|
/* wrap the pointer _before_ calling snd_pcm_period_elapsed(),
|
|
* or ALSA will BUG on us. */
|
|
chip->playback_ptr %= buffer_bytes;
|
|
|
|
if (periods_elapsed) {
|
|
chip->period_ptr += periods_elapsed * period_bytes;
|
|
chip->period_ptr %= buffer_bytes;
|
|
}
|
|
spin_unlock_irqrestore(&chip->substream_lock, flags);
|
|
|
|
if (periods_elapsed)
|
|
tasklet_schedule(&pcsp_pcm_tasklet);
|
|
}
|
|
|
|
enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle)
|
|
{
|
|
struct snd_pcsp *chip = container_of(handle, struct snd_pcsp, timer);
|
|
int pointer_update;
|
|
u64 ns;
|
|
|
|
if (!atomic_read(&chip->timer_active) || !chip->playback_substream)
|
|
return HRTIMER_NORESTART;
|
|
|
|
pointer_update = !chip->thalf;
|
|
ns = pcsp_timer_update(chip);
|
|
if (!ns) {
|
|
printk(KERN_WARNING "PCSP: unexpected stop\n");
|
|
return HRTIMER_NORESTART;
|
|
}
|
|
|
|
if (pointer_update)
|
|
pcsp_pointer_update(chip);
|
|
|
|
hrtimer_forward(handle, hrtimer_get_expires(handle), ns_to_ktime(ns));
|
|
|
|
return HRTIMER_RESTART;
|
|
}
|
|
|
|
static int pcsp_start_playing(struct snd_pcsp *chip)
|
|
{
|
|
#if PCSP_DEBUG
|
|
printk(KERN_INFO "PCSP: start_playing called\n");
|
|
#endif
|
|
if (atomic_read(&chip->timer_active)) {
|
|
printk(KERN_ERR "PCSP: Timer already active\n");
|
|
return -EIO;
|
|
}
|
|
|
|
raw_spin_lock(&i8253_lock);
|
|
chip->val61 = inb(0x61) | 0x03;
|
|
outb_p(0x92, 0x43); /* binary, mode 1, LSB only, ch 2 */
|
|
raw_spin_unlock(&i8253_lock);
|
|
atomic_set(&chip->timer_active, 1);
|
|
chip->thalf = 0;
|
|
|
|
hrtimer_start(&pcsp_chip.timer, 0, HRTIMER_MODE_REL);
|
|
return 0;
|
|
}
|
|
|
|
static void pcsp_stop_playing(struct snd_pcsp *chip)
|
|
{
|
|
#if PCSP_DEBUG
|
|
printk(KERN_INFO "PCSP: stop_playing called\n");
|
|
#endif
|
|
if (!atomic_read(&chip->timer_active))
|
|
return;
|
|
|
|
atomic_set(&chip->timer_active, 0);
|
|
raw_spin_lock(&i8253_lock);
|
|
/* restore the timer */
|
|
outb_p(0xb6, 0x43); /* binary, mode 3, LSB/MSB, ch 2 */
|
|
outb(chip->val61 & 0xFC, 0x61);
|
|
raw_spin_unlock(&i8253_lock);
|
|
}
|
|
|
|
/*
|
|
* Force to stop and sync the stream
|
|
*/
|
|
void pcsp_sync_stop(struct snd_pcsp *chip)
|
|
{
|
|
local_irq_disable();
|
|
pcsp_stop_playing(chip);
|
|
local_irq_enable();
|
|
hrtimer_cancel(&chip->timer);
|
|
tasklet_kill(&pcsp_pcm_tasklet);
|
|
}
|
|
|
|
static int snd_pcsp_playback_close(struct snd_pcm_substream *substream)
|
|
{
|
|
struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
|
|
#if PCSP_DEBUG
|
|
printk(KERN_INFO "PCSP: close called\n");
|
|
#endif
|
|
pcsp_sync_stop(chip);
|
|
chip->playback_substream = NULL;
|
|
return 0;
|
|
}
|
|
|
|
static int snd_pcsp_playback_hw_params(struct snd_pcm_substream *substream,
|
|
struct snd_pcm_hw_params *hw_params)
|
|
{
|
|
struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
|
|
int err;
|
|
pcsp_sync_stop(chip);
|
|
err = snd_pcm_lib_malloc_pages(substream,
|
|
params_buffer_bytes(hw_params));
|
|
if (err < 0)
|
|
return err;
|
|
return 0;
|
|
}
|
|
|
|
static int snd_pcsp_playback_hw_free(struct snd_pcm_substream *substream)
|
|
{
|
|
struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
|
|
#if PCSP_DEBUG
|
|
printk(KERN_INFO "PCSP: hw_free called\n");
|
|
#endif
|
|
pcsp_sync_stop(chip);
|
|
return snd_pcm_lib_free_pages(substream);
|
|
}
|
|
|
|
static int snd_pcsp_playback_prepare(struct snd_pcm_substream *substream)
|
|
{
|
|
struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
|
|
pcsp_sync_stop(chip);
|
|
chip->playback_ptr = 0;
|
|
chip->period_ptr = 0;
|
|
chip->fmt_size =
|
|
snd_pcm_format_physical_width(substream->runtime->format) >> 3;
|
|
chip->is_signed = snd_pcm_format_signed(substream->runtime->format);
|
|
#if PCSP_DEBUG
|
|
printk(KERN_INFO "PCSP: prepare called, "
|
|
"size=%zi psize=%zi f=%zi f1=%i fsize=%i\n",
|
|
snd_pcm_lib_buffer_bytes(substream),
|
|
snd_pcm_lib_period_bytes(substream),
|
|
snd_pcm_lib_buffer_bytes(substream) /
|
|
snd_pcm_lib_period_bytes(substream),
|
|
substream->runtime->periods,
|
|
chip->fmt_size);
|
|
#endif
|
|
return 0;
|
|
}
|
|
|
|
static int snd_pcsp_trigger(struct snd_pcm_substream *substream, int cmd)
|
|
{
|
|
struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
|
|
#if PCSP_DEBUG
|
|
printk(KERN_INFO "PCSP: trigger called\n");
|
|
#endif
|
|
switch (cmd) {
|
|
case SNDRV_PCM_TRIGGER_START:
|
|
case SNDRV_PCM_TRIGGER_RESUME:
|
|
return pcsp_start_playing(chip);
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
|
pcsp_stop_playing(chip);
|
|
break;
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static snd_pcm_uframes_t snd_pcsp_playback_pointer(struct snd_pcm_substream
|
|
*substream)
|
|
{
|
|
struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
|
|
unsigned int pos;
|
|
spin_lock(&chip->substream_lock);
|
|
pos = chip->playback_ptr;
|
|
spin_unlock(&chip->substream_lock);
|
|
return bytes_to_frames(substream->runtime, pos);
|
|
}
|
|
|
|
static const struct snd_pcm_hardware snd_pcsp_playback = {
|
|
.info = (SNDRV_PCM_INFO_INTERLEAVED |
|
|
SNDRV_PCM_INFO_HALF_DUPLEX |
|
|
SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
|
|
.formats = (SNDRV_PCM_FMTBIT_U8
|
|
#if DMIX_WANTS_S16
|
|
| SNDRV_PCM_FMTBIT_S16_LE
|
|
#endif
|
|
),
|
|
.rates = SNDRV_PCM_RATE_KNOT,
|
|
.rate_min = PCSP_DEFAULT_SRATE,
|
|
.rate_max = PCSP_DEFAULT_SRATE,
|
|
.channels_min = 1,
|
|
.channels_max = 1,
|
|
.buffer_bytes_max = PCSP_BUFFER_SIZE,
|
|
.period_bytes_min = 64,
|
|
.period_bytes_max = PCSP_MAX_PERIOD_SIZE,
|
|
.periods_min = 2,
|
|
.periods_max = PCSP_MAX_PERIODS,
|
|
.fifo_size = 0,
|
|
};
|
|
|
|
static int snd_pcsp_playback_open(struct snd_pcm_substream *substream)
|
|
{
|
|
struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
#if PCSP_DEBUG
|
|
printk(KERN_INFO "PCSP: open called\n");
|
|
#endif
|
|
if (atomic_read(&chip->timer_active)) {
|
|
printk(KERN_ERR "PCSP: still active!!\n");
|
|
return -EBUSY;
|
|
}
|
|
runtime->hw = snd_pcsp_playback;
|
|
chip->playback_substream = substream;
|
|
return 0;
|
|
}
|
|
|
|
static const struct snd_pcm_ops snd_pcsp_playback_ops = {
|
|
.open = snd_pcsp_playback_open,
|
|
.close = snd_pcsp_playback_close,
|
|
.ioctl = snd_pcm_lib_ioctl,
|
|
.hw_params = snd_pcsp_playback_hw_params,
|
|
.hw_free = snd_pcsp_playback_hw_free,
|
|
.prepare = snd_pcsp_playback_prepare,
|
|
.trigger = snd_pcsp_trigger,
|
|
.pointer = snd_pcsp_playback_pointer,
|
|
};
|
|
|
|
int snd_pcsp_new_pcm(struct snd_pcsp *chip)
|
|
{
|
|
int err;
|
|
|
|
err = snd_pcm_new(chip->card, "pcspeaker", 0, 1, 0, &chip->pcm);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
snd_pcm_set_ops(chip->pcm, SNDRV_PCM_STREAM_PLAYBACK,
|
|
&snd_pcsp_playback_ops);
|
|
|
|
chip->pcm->private_data = chip;
|
|
chip->pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX;
|
|
strcpy(chip->pcm->name, "pcsp");
|
|
|
|
snd_pcm_lib_preallocate_pages_for_all(chip->pcm,
|
|
SNDRV_DMA_TYPE_CONTINUOUS,
|
|
snd_dma_continuous_data
|
|
(GFP_KERNEL), PCSP_BUFFER_SIZE,
|
|
PCSP_BUFFER_SIZE);
|
|
|
|
return 0;
|
|
}
|