Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pci ep framework #13553

Merged
merged 5 commits into from
Sep 23, 2024
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
20 changes: 2 additions & 18 deletions drivers/clk/clk.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#include <stdint.h>
#include <strings.h>
#include <sys/param.h>

#include <nuttx/bits.h>
#include <nuttx/lib/math32.h>

#ifdef CONFIG_CLK

Expand All @@ -40,9 +42,6 @@

#define MASK(width) (BIT(width) - 1)
#define MULT_ROUND_UP(r, m) ((r) * (m) + (m) - 1)
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
#define DIV_ROUND_CLOSEST(n, d) ((((n) < 0) ^ ((d) < 0)) ? \
(((n) - (d)/2)/(d)) : (((n) + (d)/2)/(d)))

/****************************************************************************
* Inline Functions
Expand Down Expand Up @@ -84,21 +83,6 @@ static inline uint32_t gcd(uint32_t a, uint32_t b)
return b;
}

static inline int is_power_of_2(uint32_t n)
{
return (n != 0 && ((n & (n - 1)) == 0));
}

static inline uint32_t roundup_pow_of_two(uint32_t n)
{
return 1 << fls(n - 1);
}

static inline uint32_t rounddown_pow_of_two(uint32_t n)
{
return 1 << (fls(n) - 1);
}

static inline uint32_t roundup_double(double n)
{
uint32_t intn = (uint32_t)n;
Expand Down
16 changes: 8 additions & 8 deletions drivers/clk/clk_divider.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static uint32_t divider_recalc_rate(uint32_t parent_rate,
return parent_rate;
}

return DIV_ROUND_UP(parent_rate, div);
return div_round_up(parent_rate, div);
}

static uint32_t clk_divider_recalc_rate(FAR struct clk_s *clk,
Expand All @@ -125,7 +125,7 @@ static uint32_t clk_divider_recalc_rate(FAR struct clk_s *clk,
static uint32_t _div_round_up(uint32_t parent_rate, uint32_t rate,
uint16_t flags)
{
uint32_t div = DIV_ROUND_UP(parent_rate, rate);
uint32_t div = div_round_up(parent_rate, rate);

if (flags & CLK_DIVIDER_POWER_OF_TWO)
{
Expand All @@ -143,7 +143,7 @@ static uint32_t _div_round_closest(uint32_t parent_rate,
uint32_t up_rate;
uint32_t down_rate;

up = DIV_ROUND_UP(parent_rate, rate);
up = div_round_up(parent_rate, rate);
down = parent_rate / rate;

if (flags & CLK_DIVIDER_POWER_OF_TWO)
Expand All @@ -152,8 +152,8 @@ static uint32_t _div_round_closest(uint32_t parent_rate,
down = rounddown_pow_of_two(down);
}

up_rate = DIV_ROUND_UP(parent_rate, up);
down_rate = DIV_ROUND_UP(parent_rate, down);
up_rate = div_round_up(parent_rate, up);
down_rate = div_round_up(parent_rate, down);

return (rate - up_rate) <= (down_rate - rate) ? up : down;
}
Expand Down Expand Up @@ -255,7 +255,7 @@ static uint32_t clk_divider_bestdiv(FAR struct clk_s *clk, uint32_t rate,
{
parent_rate = clk_round_rate(clk_get_parent(clk),
rate * i);
now = DIV_ROUND_UP(parent_rate, i);
now = div_round_up(parent_rate, i);
if (_is_best_div(rate, now, best, divider->flags))
{
bestdiv = i;
Expand All @@ -280,7 +280,7 @@ static uint32_t divider_round_rate(FAR struct clk_s *clk, uint32_t rate,

div = clk_divider_bestdiv(clk, rate, prate, width);

return DIV_ROUND_UP(*prate, div);
return div_round_up(*prate, div);
}

static uint32_t clk_divider_round_rate(FAR struct clk_s *clk, uint32_t rate,
Expand All @@ -302,7 +302,7 @@ static int32_t divider_get_val(uint32_t rate, uint32_t parent_rate,
return -EINVAL;
}

div = DIV_ROUND_UP(parent_rate, rate);
div = div_round_up(parent_rate, rate);

if ((flags & CLK_DIVIDER_POWER_OF_TWO) && !is_power_of_2(div))
{
Expand Down
4 changes: 2 additions & 2 deletions drivers/clk/clk_phase.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static int clk_phase_get_phase(FAR struct clk_s *clk)
uint32_t val;

val = (clk_read(phase->reg) >> phase->shift) & MASK(phase->width);
return DIV_ROUND_CLOSEST(360 * val, MASK(phase->width) + 1);
return div_round_closest(360 * val, MASK(phase->width) + 1);
}

static int clk_phase_set_phase(FAR struct clk_s *clk, int degrees)
Expand All @@ -51,7 +51,7 @@ static int clk_phase_set_phase(FAR struct clk_s *clk, int degrees)
uint32_t pha;
uint32_t val;

pha = DIV_ROUND_CLOSEST((MASK(phase->width) + 1) * degrees, 360);
pha = div_round_closest((MASK(phase->width) + 1) * degrees, 360);

if (pha > MASK(phase->width))
{
Expand Down
4 changes: 2 additions & 2 deletions drivers/coresight/coresight_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ int coresight_get_system_trace_id(void)
return -EINVAL;
}

__set_bit(traceid, g_coresight_trace_id_bitmap);
set_bit(traceid, g_coresight_trace_id_bitmap);
spin_unlock_irqrestore(&g_coresight_trace_id_lock, flags);

return traceid;
Expand All @@ -251,7 +251,7 @@ void coresight_put_system_trace_id(int traceid)
irqstate_t flags;

flags = spin_lock_irqsave(&g_coresight_trace_id_lock);
__clear_bit(traceid, g_coresight_trace_id_bitmap);
clear_bit(traceid, g_coresight_trace_id_bitmap);
spin_unlock_irqrestore(&g_coresight_trace_id_lock, flags);
}

Expand Down
9 changes: 3 additions & 6 deletions drivers/coresight/coresight_stm.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <debug.h>
#include <nuttx/kmalloc.h>
#include <nuttx/list.h>
#include <nuttx/lib/math32.h>
#include <nuttx/bits.h>

#include <nuttx/coresight/coresight_stm.h>
Expand Down Expand Up @@ -92,10 +93,6 @@
#define STM_NO_MARKED BIT(4)
#define STM_NO_GUARANTEED BIT(7)

/* Bit operation */

#define rounddown_pow_of_two(n) (1 << (fls(n) - 1))

/****************************************************************************
* Private Types
****************************************************************************/
Expand Down Expand Up @@ -355,11 +352,11 @@ int stm_set_channel_options(FAR struct coresight_stm_dev_s *stmdev,
switch (options)
{
case STM_OPTION_GUARANTEED:
__set_bit(channel, stmdev->guaranteed);
set_bit(channel, stmdev->guaranteed);
break;

case STM_OPTION_INVARIANT:
__clear_bit(channel, stmdev->guaranteed);
clear_bit(channel, stmdev->guaranteed);
break;

default:
Expand Down
8 changes: 4 additions & 4 deletions drivers/input/aw86225.c
Original file line number Diff line number Diff line change
Expand Up @@ -2397,10 +2397,10 @@ int aw86225_initialize(FAR struct i2c_master_s *master,
aw86225_haptic_init(aw86225);
aw86225_ram_work_init(aw86225);

__set_bit(FF_CUSTOM, lower->ffbit);
__set_bit(FF_GAIN, lower->ffbit);
__set_bit(FF_CONSTANT, lower->ffbit);
__set_bit(FF_PERIODIC, lower->ffbit);
set_bit(FF_CUSTOM, lower->ffbit);
set_bit(FF_GAIN, lower->ffbit);
set_bit(FF_CONSTANT, lower->ffbit);
set_bit(FF_PERIODIC, lower->ffbit);

if (aw86225->effects_count + 1 > FF_EFFECT_COUNT_MAX)
{
Expand Down
8 changes: 4 additions & 4 deletions drivers/input/ff_dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ int ff_dummy_initialize(int devno)

/* set dummy device capabilities */

__set_bit(FF_CUSTOM, lower->ffbit);
__set_bit(FF_GAIN, lower->ffbit);
__set_bit(FF_CONSTANT, lower->ffbit);
__set_bit(FF_PERIODIC, lower->ffbit);
set_bit(FF_CUSTOM, lower->ffbit);
set_bit(FF_GAIN, lower->ffbit);
set_bit(FF_CONSTANT, lower->ffbit);
set_bit(FF_PERIODIC, lower->ffbit);

snprintf(path, FF_DEVNAME_MAX, FF_DEVNAME_FMT, devno);
ret = ff_register(lower, path, FF_EFFECT_COUNT_MAX);
Expand Down
4 changes: 2 additions & 2 deletions drivers/lcd/max7219.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,11 @@ static int max7219_putrun(FAR struct lcd_dev_s *dev, fb_coord_t row,
{
if ((*buffer & usrmask) != 0)
{
__set_bit(col % 8 + i, ptr);
set_bit(col % 8 + i, ptr);
}
else
{
__clear_bit(col % 8 + i, ptr);
clear_bit(col % 8 + i, ptr);
}

#ifdef CONFIG_LCD_PACKEDMSFIRST
Expand Down
4 changes: 2 additions & 2 deletions drivers/lcd/memlcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,11 @@ static int memlcd_putrun(FAR struct lcd_dev_s *dev,
{
if ((*buffer & usrmask) != 0)
{
__set_bit(col % 8 + i, p);
set_bit(col % 8 + i, p);
}
else
{
__clear_bit(col % 8 + i, p);
clear_bit(col % 8 + i, p);
}

#ifdef CONFIG_MEMLCD_BYTE_PER_PIXEL
Expand Down
8 changes: 8 additions & 0 deletions drivers/pci/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ if(CONFIG_PCI)
target_sources(drivers PRIVATE ${SRCS})

endif() # CONFIG_PCI

if(CONFIG_PCI_ENDPOINT)

set(SRCS pci_epc.c pci_epc_mem.c pci_epf.c)

target_sources(drivers PRIVATE ${SRCS})

endif() # CONFIG_PCI_ENDPOINT
9 changes: 9 additions & 0 deletions drivers/pci/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,12 @@ config PCI_UIO_IVSHMEM_NPOLLWAITERS
depends on PCI_UIO_IVSHMEM

endif # PCI

menuconfig PCI_ENDPOINT
bool "PCI Endpoint Support"
default n
---help---
Enable this configuration option to support configurable PCI
endpoint. This should be enabled if the platform has a PCI
controller that can operate in endpoint mode.

4 changes: 4 additions & 0 deletions drivers/pci/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ ifeq ($(CONFIG_PCI_UIO_IVSHMEM),y)
CSRCS += pci_uio_ivshmem.c
endif

ifeq ($(CONFIG_PCI_ENDPOINT),y)
CSRCS += pci_epc.c pci_epc_mem.c pci_epf.c
endif

# Include PCI device driver build support

DEPPATH += --dep-path pci
Expand Down
6 changes: 3 additions & 3 deletions drivers/pci/pci_ecam.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <errno.h>

#include <nuttx/kmalloc.h>
#include <nuttx/lib/math32.h>
#include <nuttx/pci/pci.h>
#include <nuttx/pci/pci_ecam.h>
#include <nuttx/nuttx.h>
Expand All @@ -40,8 +41,7 @@
#define readl(a) (*(FAR volatile uint32_t *)(a))
#define writel(v,a) (*(FAR volatile uint32_t *)(a) = (v))

#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
#define IS_ALIGNED(x, a) (((x) & ((a) - 1)) == 0)
#define IS_ALIGNED(x, a) (((x) & ((a) - 1)) == 0)

/****************************************************************************
* Private Function Prototypes
Expand Down Expand Up @@ -145,7 +145,7 @@ static bool pci_ecam_addr_valid(FAR const struct pci_bus_s *bus,
uint32_t devfn)
{
FAR struct pci_ecam_s *ecam = pci_ecam_from_controller(bus->ctrl);
int num_buses = DIV_ROUND_UP(pci_resource_size(&ecam->cfg), 1 << 20);
int num_buses = div_round_up(pci_resource_size(&ecam->cfg), 1 << 20);

return bus->number < num_buses;
}
Expand Down
Loading
Loading