Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/arch/host/include/arch/spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@
#ifndef __ARCH_SPINLOCK_H__
#define __ARCH_SPINLOCK_H__

typedef struct {
} spinlock_t;

static inline void arch_spinlock_init(spinlock_t *lock) { }
static inline void arch_spin_lock(spinlock_t *lock) {}
static inline int arch_try_lock(spinlock_t *lock)
{
return 1;
}
static inline void arch_spin_unlock(spinlock_t *lock) {}
struct k_spinlock {
};

static inline void arch_spinlock_init(struct k_spinlock *lock) {}
static inline void arch_spin_lock(struct k_spinlock *lock) {}
static inline void arch_spin_unlock(struct k_spinlock *lock) {}

#endif /* __ARCH_SPINLOCK_H__ */

Expand Down
64 changes: 8 additions & 56 deletions src/arch/xtensa/include/arch/spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
#include <stdint.h>
#include <xtensa/config/core-isa.h>

typedef struct {
struct k_spinlock {
volatile uint32_t lock;
#if CONFIG_DEBUG_LOCKS
uint32_t user;
#endif
} spinlock_t;
};

static inline void arch_spinlock_init(spinlock_t *lock)
static inline void arch_spinlock_init(struct k_spinlock *lock)
{
lock->lock = 0;
}

#if XCHAL_HAVE_EXCLUSIVE && CONFIG_XTENSA_EXCLUSIVE && __XCC__

static inline void arch_spin_lock(spinlock_t *lock)
static inline void arch_spin_lock(struct k_spinlock *lock)
{
uint32_t result;

Expand All @@ -43,27 +43,9 @@ static inline void arch_spin_lock(spinlock_t *lock)
: "memory");
}

static inline int arch_try_lock(spinlock_t *lock)
{
uint32_t result;

__asm__ __volatile__(
" movi %0, 0\n"
" l32ex %0, %1\n"
" movi %0, 1\n"
" s32ex %0, %1\n"
" getex %0\n"
: "=&a" (result)
: "a" (&lock->lock)
: "memory");

/* return 0 for failed lock, 1 otherwise */
return result ? 0 : 1;
}

#elif XCHAL_HAVE_S32C1I

static inline void arch_spin_lock(spinlock_t *lock)
static inline void arch_spin_lock(struct k_spinlock *lock)
{
uint32_t result;

Expand All @@ -82,23 +64,6 @@ static inline void arch_spin_lock(spinlock_t *lock)
: "memory");
}

static inline int arch_try_lock(spinlock_t *lock)
{
uint32_t result;

__asm__ __volatile__(
" movi %0, 0\n"
" wsr %0, scompare1\n"
" movi %0, 1\n"
" s32c1i %0, %1, 0\n"
: "=&a" (result)
: "a" (&lock->lock)
: "memory");

/* return 0 for failed lock, 1 otherwise */
return result ? 0 : 1;
}

#else

#if CONFIG_CORE_COUNT > 1
Expand All @@ -111,7 +76,7 @@ static inline int arch_try_lock(spinlock_t *lock)
* The ISA has no atomic operations so use integer arithmetic on uniprocessor systems.
* This helps support GCC and qemu emulation of certain targets.
*/
static inline void arch_spin_lock(spinlock_t *lock)
static inline void arch_spin_lock(struct k_spinlock *lock)
{
uint32_t result;

Expand All @@ -123,24 +88,11 @@ static inline void arch_spin_lock(spinlock_t *lock)
} while (!result);
}

static inline int arch_try_lock(spinlock_t *lock)
{
uint32_t result;

if (lock->lock == 0) {
lock->lock = 1;
result = 1;
}

/* return 0 for failed lock, 1 otherwise */
return result ? 0 : 1;
}

#endif /* XCHAL_HAVE_EXCLUSIVE && CONFIG_XTENSA_EXCLUSIVE && __XCC__ */

#if XCHAL_HAVE_EXCLUSIVE || XCHAL_HAVE_S32C1I

static inline void arch_spin_unlock(spinlock_t *lock)
static inline void arch_spin_unlock(struct k_spinlock *lock)
{
uint32_t result;

Expand All @@ -164,7 +116,7 @@ static inline void arch_spin_unlock(spinlock_t *lock)
* The ISA has no atomic operations so use integer arithmetic on uniprocessor systems.
* This helps support GCC and qemu emulation of certain targets.
*/
static inline void arch_spin_unlock(spinlock_t *lock)
static inline void arch_spin_unlock(struct k_spinlock *lock)
{
uint32_t result;

Expand Down
8 changes: 4 additions & 4 deletions src/audio/asrc/asrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -987,14 +987,14 @@ static int asrc_copy(struct comp_dev *dev)
sink = list_first_item(&dev->bsink_list, struct comp_buffer,
source_list);

source = buffer_acquire_irq(source);
sink = buffer_acquire_irq(sink);
source = buffer_acquire(source);
sink = buffer_acquire(sink);

frames_src = audio_stream_get_avail_frames(&source->stream);
frames_snk = audio_stream_get_free_frames(&sink->stream);

buffer_release_irq(sink);
buffer_release_irq(source);
buffer_release(sink);
buffer_release(source);

if (cd->mode == ASRC_OM_PULL) {
/* Let ASRC access max number of source frames in pull mode.
Expand Down
8 changes: 4 additions & 4 deletions src/audio/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void comp_update_buffer_produce(struct comp_buffer *buffer, uint32_t bytes)
return;
}

buffer = buffer_acquire_irq(buffer);
buffer = buffer_acquire(buffer);

audio_stream_produce(&buffer->stream, bytes);

Expand All @@ -205,7 +205,7 @@ void comp_update_buffer_produce(struct comp_buffer *buffer, uint32_t bytes)
((char *)buffer->stream.r_ptr - (char *)buffer->stream.addr) << 16 |
((char *)buffer->stream.w_ptr - (char *)buffer->stream.addr));

buffer = buffer_release_irq(buffer);
buffer = buffer_release(buffer);
}

void comp_update_buffer_consume(struct comp_buffer *buffer, uint32_t bytes)
Expand All @@ -226,7 +226,7 @@ void comp_update_buffer_consume(struct comp_buffer *buffer, uint32_t bytes)
return;
}

buffer = buffer_acquire_irq(buffer);
buffer = buffer_acquire(buffer);

audio_stream_consume(&buffer->stream, bytes);

Expand All @@ -240,5 +240,5 @@ void comp_update_buffer_consume(struct comp_buffer *buffer, uint32_t bytes)
((char *)buffer->stream.r_ptr - (char *)buffer->stream.addr) << 16 |
((char *)buffer->stream.w_ptr - (char *)buffer->stream.addr));

buffer = buffer_release_irq(buffer);
buffer = buffer_release(buffer);
}
12 changes: 7 additions & 5 deletions src/audio/component.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,23 @@ DECLARE_TR_CTX(comp_tr, SOF_UUID(comp_uuid), LOG_LEVEL_INFO);
int comp_register(struct comp_driver_info *drv)
{
struct comp_driver_list *drivers = comp_drivers_get();
k_spinlock_key_t key;

spin_lock(&drivers->lock);
key = k_spin_lock(&drivers->lock);
list_item_prepend(&drv->list, &drivers->list);
spin_unlock(&drivers->lock);
k_spin_unlock(&drivers->lock, key);

return 0;
}

void comp_unregister(struct comp_driver_info *drv)
{
struct comp_driver_list *drivers = comp_drivers_get();
k_spinlock_key_t key;

spin_lock(&drivers->lock);
key = k_spin_lock(&drivers->lock);
list_item_del(&drv->list);
spin_unlock(&drivers->lock);
k_spin_unlock(&drivers->lock, key);
}

/* NOTE: Keep the component state diagram up to date:
Expand Down Expand Up @@ -141,7 +143,7 @@ void sys_comp_init(struct sof *sof)
sof->comp_drivers = platform_shared_get(&cd, sizeof(cd));

list_init(&sof->comp_drivers->list);
spinlock_init(&sof->comp_drivers->lock);
k_spinlock_init(&sof->comp_drivers->lock);
}

void comp_get_copy_limits(struct comp_buffer *source, struct comp_buffer *sink,
Expand Down
10 changes: 5 additions & 5 deletions src/audio/crossover/crossover.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,26 +671,26 @@ static int crossover_copy(struct comp_dev *dev)
else
num_sinks = num_assigned_sinks;

source = buffer_acquire_irq(source);
source = buffer_acquire(source);

/* Check if source is active */
if (source->source->state != dev->state) {
source = buffer_release_irq(source);
source = buffer_release(source);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removal seems safer as the "_irq" has been done with a specific pattern and we can now review and conclude it is not needed and we can remove the variant.

return -EINVAL;
}

/* Find the number of frames to copy over */
for (i = 0; i < num_sinks; i++) {
if (!sinks[i])
continue;
sinks[i] = buffer_acquire_irq(sinks[i]);
sinks[i] = buffer_acquire(sinks[i]);
avail = audio_stream_avail_frames(&source->stream,
&sinks[i]->stream);
frames = MIN(frames, avail);
buffer_release_irq(sinks[i]);
buffer_release(sinks[i]);
}

source = buffer_release_irq(source);
source = buffer_release(source);

source_bytes = frames * audio_stream_frame_bytes(&source->stream);

Expand Down
4 changes: 2 additions & 2 deletions src/audio/dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ static int dai_copy(struct comp_dev *dev)
return ret;
}

buf = buffer_acquire_irq(buf);
buf = buffer_acquire(buf);

/* calculate minimum size to copy */
if (dev->direction == SOF_IPC_STREAM_PLAYBACK) {
Expand All @@ -930,7 +930,7 @@ static int dai_copy(struct comp_dev *dev)

copy_bytes = samples * sampling;

buffer_release_irq(buf);
buffer_release(buf);

comp_dbg(dev, "dai_copy(), dir: %d copy_bytes= 0x%x, frames= %d",
dev->direction, copy_bytes,
Expand Down
4 changes: 2 additions & 2 deletions src/audio/google_hotword_detect.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ static int ghd_copy(struct comp_dev *dev)
struct comp_buffer, sink_list);
stream = &source->stream;

source = buffer_acquire_irq(source);
source = buffer_acquire(source);
bytes = audio_stream_get_avail_bytes(&source->stream);
source = buffer_release_irq(source);
source = buffer_release(source);

comp_dbg(dev, "ghd_copy() avail_bytes %u", bytes);
comp_dbg(dev, "buffer begin/r_ptr/end [0x%x 0x%x 0x%x]",
Expand Down
8 changes: 4 additions & 4 deletions src/audio/google_rtc_audio_processing.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ static int google_rtc_audio_processing_prepare(struct comp_dev *dev)
list_for_item(source_buffer_list_item, &dev->bsource_list) {
source_buffer = container_of(source_buffer_list_item, struct comp_buffer,
sink_list);
source_buffer = buffer_acquire_irq(source_buffer);
source_buffer = buffer_acquire(source_buffer);
if (source_buffer->source->ipc_config.type == SOF_COMP_DEMUX)
cd->aec_reference = source_buffer;
else if (source_buffer->source->ipc_config.type == SOF_COMP_DAI)
cd->raw_microphone = source_buffer;
source_buffer = buffer_release_irq(source_buffer);
source_buffer = buffer_release(source_buffer);
}

cd->output = list_first_item(&dev->bsink_list, struct comp_buffer, source_list);
Expand Down Expand Up @@ -297,10 +297,10 @@ static int google_rtc_audio_processing_copy(struct comp_dev *dev)
uint32_t num_aec_reference_frames;
uint32_t num_aec_reference_bytes;

cd->aec_reference = buffer_acquire_irq(cd->aec_reference);
cd->aec_reference = buffer_acquire(cd->aec_reference);
num_aec_reference_frames = audio_stream_get_avail_frames(&cd->aec_reference->stream);
num_aec_reference_bytes = audio_stream_get_avail_bytes(&cd->aec_reference->stream);
cd->aec_reference = buffer_release_irq(cd->aec_reference);
cd->aec_reference = buffer_release(cd->aec_reference);

buffer_stream_invalidate(cd->aec_reference, num_aec_reference_bytes);

Expand Down
12 changes: 6 additions & 6 deletions src/audio/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ static uint32_t host_get_copy_bytes_one_shot(struct comp_dev *dev)
struct comp_buffer *buffer = hd->local_buffer;
uint32_t copy_bytes = 0;

buffer = buffer_acquire_irq(buffer);
buffer = buffer_acquire(buffer);

/* calculate minimum size to copy */
if (dev->direction == SOF_IPC_STREAM_PLAYBACK)
copy_bytes = audio_stream_get_free_bytes(&buffer->stream);
else
copy_bytes = audio_stream_get_avail_bytes(&buffer->stream);

buffer_release_irq(buffer);
buffer_release(buffer);

/* copy_bytes should be aligned to minimum possible chunk of
* data to be copied by dma.
Expand Down Expand Up @@ -240,15 +240,15 @@ static uint32_t host_get_copy_bytes_one_shot(struct comp_dev *dev)
uint32_t copy_bytes = 0;
uint32_t split_value;

buffer = buffer_acquire_irq(buffer);
buffer = buffer_acquire(buffer);

/* calculate minimum size to copy */
if (dev->direction == SOF_IPC_STREAM_PLAYBACK)
copy_bytes = audio_stream_get_free_bytes(&buffer->stream);
else
copy_bytes = audio_stream_get_avail_bytes(&buffer->stream);

buffer_release_irq(buffer);
buffer_release(buffer);

/* copy_bytes should be aligned to minimum possible chunk of
* data to be copied by dma.
Expand Down Expand Up @@ -450,7 +450,7 @@ static uint32_t host_get_copy_bytes_normal(struct comp_dev *dev)
return 0;
}

buffer = buffer_acquire_irq(buffer);
buffer = buffer_acquire(buffer);

/* calculate minimum size to copy */
if (dev->direction == SOF_IPC_STREAM_PLAYBACK) {
Expand All @@ -470,7 +470,7 @@ static uint32_t host_get_copy_bytes_normal(struct comp_dev *dev)
avail_bytes, free_bytes);
}

buffer = buffer_release_irq(buffer);
buffer = buffer_release(buffer);

/* copy_bytes should be aligned to minimum possible chunk of
* data to be copied by dma.
Expand Down
Loading