auvia: enable -Werror, style fixes

Move util.c from auich (the most up to date version) to the parent
directory of ac97. Use it also for auvia. This means changing several
physical addresses to use phys_addr_t instead of pointers, and declaring
buffers allocated by alloc_mem to be user-accessible or not.

Untested, I don't have the hardware.

Change-Id: I2ababc713384cbf34174fbcecfb3595547a1fd97
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7602
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Alexander von Gluck <alex@terarocket.io>
This commit is contained in:
Muhamed Emad 2024-04-06 14:06:12 +02:00 committed by waddlesplash
parent d6e543c388
commit 464efaf403
8 changed files with 77 additions and 216 deletions

View File

@ -676,7 +676,7 @@ rule ArchitectureSetupWarnings architecture
EnableWerror src add-ons kernel debugger ;
# EnableWerror src add-ons kernel drivers audio ac97 ;
EnableWerror src add-ons kernel drivers audio ac97 auich ;
# EnableWerror src add-ons kernel drivers audio ac97 auvia ;
EnableWerror src add-ons kernel drivers audio ac97 auvia ;
# EnableWerror src add-ons kernel drivers audio ac97 es1370 ;
# EnableWerror src add-ons kernel drivers audio ac97 geode ;
# EnableWerror src add-ons kernel drivers audio ac97 ich ;

View File

@ -73,7 +73,7 @@ auvia_mem_new(auvia_dev *card, size_t size)
if ((mem = malloc(sizeof(*mem))) == NULL)
return (NULL);
mem->area = alloc_mem(&mem->phy_base, &mem->log_base, size, "auvia buffer");
mem->area = alloc_mem(&mem->phy_base, &mem->log_base, size, "auvia buffer", false);
mem->size = size;
if (mem->area < B_OK) {
free(mem);
@ -145,14 +145,14 @@ auvia_stream_set_audioparms(auvia_stream *stream, uint8 channels,
sample_size = stream->b16 + 1;
frame_size = sample_size * stream->channels;
stream->buffer = auvia_mem_alloc(stream->card, stream->bufframes
* frame_size * stream->bufcount);
stream->trigblk = 0; /* This shouldn't be needed */
stream->blkmod = stream->bufcount;
stream->blksize = stream->bufframes * frame_size;
return B_OK;
}
@ -160,50 +160,49 @@ auvia_stream_set_audioparms(auvia_stream *stream, uint8 channels,
status_t
auvia_stream_commit_parms(auvia_stream *stream)
{
int i;
uint32 *page;
uint32 value;
int i;
uint32* page;
uint32 value;
LOG(("auvia_stream_commit_parms\n"));
page = stream->dmaops_log_base;
for(i = 0; i < stream->bufcount; i++) {
page[2*i] = ((uint32)stream->buffer->phy_base) +
i * stream->blksize;
page[2*i + 1] = AUVIA_DMAOP_FLAG | stream->blksize;
page[2 * i] = stream->buffer->phy_base + i * stream->blksize;
page[2 * i + 1] = AUVIA_DMAOP_FLAG | stream->blksize;
}
page[2*stream->bufcount - 1] &= ~AUVIA_DMAOP_FLAG;
page[2*stream->bufcount - 1] |= AUVIA_DMAOP_EOL;
auvia_reg_write_32(&stream->card->config, stream->base + AUVIA_RP_DMAOPS_BASE,
(uint32)stream->dmaops_phy_base);
page[2 * stream->bufcount - 1] &= ~AUVIA_DMAOP_FLAG;
page[2 * stream->bufcount - 1] |= AUVIA_DMAOP_EOL;
auvia_reg_write_32(&stream->card->config, stream->base + AUVIA_RP_DMAOPS_BASE,
stream->dmaops_phy_base);
if(stream->use & AUVIA_USE_RECORD)
auvia_codec_write(&stream->card->config, AC97_PCM_L_R_ADC_RATE,
auvia_codec_write(&stream->card->config, AC97_PCM_L_R_ADC_RATE,
(uint16)stream->sample_rate);
else
auvia_codec_write(&stream->card->config, AC97_PCM_FRONT_DAC_RATE,
auvia_codec_write(&stream->card->config, AC97_PCM_FRONT_DAC_RATE,
(uint16)stream->sample_rate);
if(IS_8233(&stream->card->config)) {
if(stream->base != AUVIA_8233_MP_BASE) {
value = auvia_reg_read_32(&stream->card->config, stream->base
value = auvia_reg_read_32(&stream->card->config, stream->base
+ AUVIA_8233_RP_RATEFMT);
value &= ~(AUVIA_8233_RATEFMT_48K | AUVIA_8233_RATEFMT_STEREO
value &= ~(AUVIA_8233_RATEFMT_48K | AUVIA_8233_RATEFMT_STEREO
| AUVIA_8233_RATEFMT_16BIT);
if(stream->use & AUVIA_USE_PLAY)
value |= AUVIA_8233_RATEFMT_48K * (stream->sample_rate / 20)
value |= AUVIA_8233_RATEFMT_48K * (stream->sample_rate / 20)
/ (48000 / 20);
value |= (stream->channels == 2 ? AUVIA_8233_RATEFMT_STEREO : 0)
| (stream->b16 ? AUVIA_8233_RATEFMT_16BIT : 0);
auvia_reg_write_32(&stream->card->config, stream->base
auvia_reg_write_32(&stream->card->config, stream->base
+ AUVIA_8233_RP_RATEFMT, value);
} else {
static const uint32 slottab[7] = {0, 0xff000011, 0xff000021,
static const uint32 slottab[7] = {0, 0xff000011, 0xff000021,
0xff000521, 0xff004321, 0xff054321, 0xff654321};
value = (stream->b16 ? AUVIA_8233_MP_FORMAT_16BIT : AUVIA_8233_MP_FORMAT_8BIT)
| ((stream->channels << 4) & AUVIA_8233_MP_FORMAT_CHANNEL_MASK) ;
| ((stream->channels << 4) & AUVIA_8233_MP_FORMAT_CHANNEL_MASK);
auvia_reg_write_8(&stream->card->config, stream->base
+ AUVIA_8233_OFF_MP_FORMAT, value);
auvia_reg_write_32(&stream->card->config, stream->base
@ -211,7 +210,7 @@ auvia_stream_commit_parms(auvia_stream *stream)
}
}
//auvia_codec_write(&stream->card->config, AC97_SPDIF_CONTROL, (uint16)stream->sample_rate);
return B_OK;
}
@ -226,7 +225,7 @@ auvia_stream_get_nth_buffer(auvia_stream *stream, uint8 chan, uint8 buf,
sample_size = stream->b16 + 1;
frame_size = sample_size * stream->channels;
*buffer = stream->buffer->log_base + (buf * stream->bufframes * frame_size)
*buffer =(char *)((addr_t)stream->buffer->log_base + (uintptr_t)(buf * stream->bufframes * frame_size))
+ chan * sample_size;
*stride = frame_size;
@ -240,12 +239,12 @@ auvia_stream_curaddr(auvia_stream *stream)
uint32 addr;
if(IS_8233(&stream->card->config)) {
addr = auvia_reg_read_32(&stream->card->config, stream->base + AUVIA_RP_DMAOPS_BASE);
TRACE(("stream_curaddr %p, phy_base %p\n", addr, (uint32)stream->dmaops_phy_base));
return (addr - (uint32)stream->dmaops_phy_base - 4) / 8;
TRACE(("stream_curaddr %p, phy_base %p\n", addr, stream->dmaops_phy_base));
return (addr - stream->dmaops_phy_base - 4) / 8;
} else {
addr = auvia_reg_read_32(&stream->card->config, stream->base + AUVIA_RP_DMAOPS_BASE);
TRACE(("stream_curaddr %p, phy_base %p\n", addr, (uint32)stream->dmaops_phy_base));
return (addr - (uint32)stream->dmaops_phy_base - 8) / 8;
TRACE(("stream_curaddr %p, phy_base %p\n", addr, stream->dmaops_phy_base));
return (addr - stream->dmaops_phy_base - 8) / 8;
}
}
@ -336,7 +335,7 @@ auvia_stream_new(auvia_dev *card, uint8 use, uint32 bufframes, uint8 bufcount)
/* allocate memory for our dma ops */
stream->dmaops_area = alloc_mem(&stream->dmaops_phy_base, &stream->dmaops_log_base,
VIA_TABLE_SIZE, "auvia dmaops");
VIA_TABLE_SIZE, "auvia dmaops", false);
if (stream->dmaops_area < B_OK) {
PRINT(("couldn't allocate memory\n"));

View File

@ -82,10 +82,10 @@
typedef struct _auvia_mem {
LIST_ENTRY(_auvia_mem) next;
void *log_base;
void *phy_base;
area_id area;
size_t size;
void* log_base;
phys_addr_t phy_base;
area_id area;
size_t size;
} auvia_mem;
/*
@ -93,37 +93,37 @@ typedef struct _auvia_mem {
*/
typedef struct _auvia_stream {
struct _auvia_dev *card;
uint8 use;
uint8 state;
uint8 b16;
uint32 sample_rate;
struct _auvia_dev *card;
uint8 use;
uint8 state;
uint8 b16;
uint32 sample_rate;
uint8 channels;
uint32 bufframes;
uint8 bufcount;
uint32 bufframes;
uint8 bufcount;
uint32 base;
LIST_ENTRY(_auvia_stream) next;
void (*inth) (void *);
void *inthparam;
void (*inth) (void *);
void *inthparam;
void *dmaops_log_base;
void *dmaops_phy_base;
area_id dmaops_area;
void* dmaops_log_base;
phys_addr_t dmaops_phy_base;
area_id dmaops_area;
auvia_mem *buffer;
uint16 blksize; /* in samples */
uint16 trigblk; /* blk on which to trigger inth */
uint16 blkmod; /* Modulo value to wrap trigblk */
auvia_mem* buffer;
uint16 blksize; /* in samples */
uint16 trigblk; /* blk on which to trigger inth */
uint16 blkmod; /* Modulo value to wrap trigblk */
/* multi_audio */
volatile int64 frames_count; // for play or record
volatile bigtime_t real_time; // for play or record
volatile int32 buffer_cycle; // for play or record
int32 first_channel;
bool update_needed;
volatile int64 frames_count; // for play or record
volatile bigtime_t real_time; // for play or record
volatile int32 buffer_cycle; // for play or record
int32 first_channel;
bool update_needed;
} auvia_stream;
/*

View File

@ -176,8 +176,8 @@ auvia_ac97_set_mix(void *card, const void *cookie, int32 type, float *values) {
static int32
auvia_create_group_control(multi_dev *multi, int32 *index, int32 parent,
int32 string, const char* name)
auvia_create_group_control(multi_dev* multi, uint32* index, int32 parent, int32 string,
const char* name)
{
int32 i = *index;
(*index)++;
@ -186,9 +186,10 @@ auvia_create_group_control(multi_dev *multi, int32 *index, int32 parent,
multi->controls[i].mix_control.flags = B_MULTI_MIX_GROUP;
multi->controls[i].mix_control.master = EMU_MULTI_CONTROL_MASTERID;
multi->controls[i].mix_control.string = string;
if (name)
if (name) {
strlcpy(multi->controls[i].mix_control.name, name,
sizeof(multi->controls[i].mix_control.name));
}
return multi->controls[i].mix_control.id;
}
@ -198,7 +199,6 @@ static status_t
auvia_create_controls_list(multi_dev *multi)
{
uint32 i = 0, index = 0, count, id, parent, parent2, parent3;
auvia_dev *card = (auvia_dev*)multi->card;
const ac97_source_info *info;
parent = auvia_create_group_control(multi, &index, 0, 0, "Record");
@ -402,7 +402,7 @@ auvia_get_mix(auvia_dev *card, multi_mix_value_info * mmvi)
multi_mixer_control *control = NULL;
for (i = 0; i < mmvi->item_count; i++) {
id = mmvi->values[i].id - EMU_MULTI_CONTROL_FIRSTID;
if (id < 0 || id >= card->multi.control_count) {
if (id < 0 || (uint32)id >= card->multi.control_count) {
PRINT(("auvia_get_mix : "
"invalid control id requested : %" B_PRIi32 "\n", id));
continue;
@ -443,7 +443,7 @@ auvia_set_mix(auvia_dev *card, multi_mix_value_info * mmvi)
multi_mixer_control *control = NULL;
for (i = 0; i < mmvi->item_count; i++) {
id = mmvi->values[i].id - EMU_MULTI_CONTROL_FIRSTID;
if (id < 0 || id >= card->multi.control_count) {
if (id < 0 || (uint32)id >= card->multi.control_count) {
PRINT(("auvia_set_mix : "
"invalid control id requested : %" B_PRIi32 "\n", id));
continue;
@ -454,7 +454,7 @@ auvia_set_mix(auvia_dev *card, multi_mix_value_info * mmvi)
multi_mixer_control *control2 = NULL;
if (i + 1 < mmvi->item_count) {
id = mmvi->values[i + 1].id - EMU_MULTI_CONTROL_FIRSTID;
if (id < 0 || id >= card->multi.control_count) {
if (id < 0 || (uint32)id >= card->multi.control_count) {
PRINT(("auvia_set_mix : "
"invalid control id requested : %" B_PRIi32 "\n", id));
} else {
@ -506,7 +506,7 @@ static status_t
auvia_list_mix_controls(auvia_dev *card, multi_mix_control_info * mmci)
{
multi_mix_control *mmc;
int32 i;
uint32 i;
mmc = mmci->controls;
if (mmci->control_count < 24)
@ -573,7 +573,8 @@ static void
auvia_create_channels_list(multi_dev *multi)
{
auvia_stream *stream;
uint32 index, i, mode, designations;
uint32 index, i, designations;
int32 mode;
multi_channel_info *chans;
uint32 chan_designations[] = {
B_CHANNEL_LEFT,
@ -600,7 +601,8 @@ auvia_create_channels_list(multi_dev *multi)
for (i = 0; i < stream->channels; i++) {
chans[index].channel_id = index;
chans[index].kind = (mode == AUVIA_USE_PLAY) ? B_MULTI_OUTPUT_CHANNEL : B_MULTI_INPUT_CHANNEL;
chans[index].kind =
(mode == AUVIA_USE_PLAY) ? B_MULTI_OUTPUT_CHANNEL : B_MULTI_INPUT_CHANNEL;
chans[index].designations = designations | chan_designations[i];
chans[index].connectors = 0;
index++;
@ -706,7 +708,7 @@ auvia_get_description(auvia_dev *card, multi_description *data)
// channels and input bus channels and finally auxillary channels,
LOG(("request_channel_count = %d\n",data->request_channel_count));
if (data->request_channel_count >= size) {
if (data->request_channel_count >= (int32)size) {
LOG(("copying data\n"));
memcpy(data->channels, card->multi.chans, size * sizeof(card->multi.chans[0]));
}
@ -799,10 +801,10 @@ auvia_get_buffers(auvia_dev *card, multi_buffer_list *data)
pchannels = card->pstream->channels;
rchannels = card->rstream->channels;
if (data->request_playback_buffers < BUFFER_COUNT ||
data->request_playback_channels < (pchannels) ||
data->request_record_buffers < BUFFER_COUNT ||
data->request_record_channels < (rchannels)) {
if (data->request_playback_buffers < BUFFER_COUNT
|| data->request_playback_channels < (int32)(pchannels)
|| data->request_record_buffers < BUFFER_COUNT
|| data->request_record_channels < (int32)(rchannels)) {
LOG(("not enough channels/buffers\n"));
}

View File

@ -1,100 +0,0 @@
/*
* BeOS Driver for Intel ICH AC'97 Link interface
*
* Copyright (c) 2002, Marcus Overhagen <marcus@overhagen.de>
*
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <Errors.h>
#include <OS.h>
#include <string.h>
//#define DEBUG 2
#include "debug.h"
#include "util.h"
spinlock slock = B_SPINLOCK_INITIALIZER;
uint32 round_to_pagesize(uint32 size);
cpu_status
lock(void)
{
cpu_status status = disable_interrupts();
acquire_spinlock(&slock);
return status;
}
void
unlock(cpu_status status)
{
release_spinlock(&slock);
restore_interrupts(status);
}
uint32
round_to_pagesize(uint32 size)
{
return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
}
area_id
alloc_mem(void **phy, void **log, size_t size, const char *name)
{
// TODO: phy should be phys_addr_t*!
physical_entry pe;
void * logadr;
area_id areaid;
status_t rv;
LOG(("allocating %d bytes for %s\n",size,name));
size = round_to_pagesize(size);
areaid = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS, size,
B_32_BIT_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA);
// TODO: The rest of the code doesn't deal correctly with physical
// addresses > 4 GB, so we have to force 32 bit addresses here.
if (areaid < B_OK) {
PRINT(("couldn't allocate area %s\n",name));
return B_ERROR;
}
rv = get_memory_map(logadr,size,&pe,1);
if (rv < B_OK) {
delete_area(areaid);
PRINT(("couldn't map %s\n",name));
return B_ERROR;
}
memset(logadr,0,size);
if (log)
*log = logadr;
if (phy)
*phy = (void*)(addr_t)pe.address;
LOG(("area = %d, size = %d, log = %#08X, phy = %#08X\n",areaid,size,logadr,pe.address));
return areaid;
}

View File

@ -1,40 +0,0 @@
/*
* BeOS Driver for Intel ICH AC'97 Link interface
*
* Copyright (c) 2002, Marcus Overhagen <marcus@overhagen.de>
*
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _UTIL_H_
#define _UTIL_H_
#include <KernelExport.h>
area_id alloc_mem(void **phy, void **log, size_t size, const char *name);
cpu_status lock(void);
void unlock(cpu_status status);
extern spinlock slock;
#endif