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

Changes from upstream #199

Merged
merged 4 commits into from
Dec 20, 2023
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
27 changes: 1 addition & 26 deletions arch/risc-v/src/common/riscv_pmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <nuttx/compiler.h>
#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/lib/math32.h>

#include "riscv_internal.h"

Expand Down Expand Up @@ -88,32 +89,6 @@ typedef struct pmp_entry_s pmp_entry_t;
* Private Functions
****************************************************************************/

/****************************************************************************
* Name: log2ceil
*
* Description:
* Calculate the up-rounded power-of-two for input.
*
* Input Parameters:
* x - Argument to calculate the power-of-two from.
*
* Returned Value:
* Power-of-two for argument, rounded up.
*
****************************************************************************/

static uintptr_t log2ceil(uintptr_t x)
{
uintptr_t pot = 0;

for (x = x - 1; x; x >>= 1)
{
pot++;
}

return pot;
}

/****************************************************************************
* Name: pmp_check_region_attrs
*
Expand Down
7 changes: 0 additions & 7 deletions arch/risc-v/src/mpfs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -904,13 +904,6 @@ config MPFS_ETHMAC_REGDEBUG
Enable very low-level register access debug. Depends on
CONFIG_DEBUG_FEATURES.

config MPFS_MPU_DMA_ENABLE
bool "Enable ALL memory access for eth DMA"
default n
---help---
Set ALL memory accessible for Ethernet DMA.
This should be done on bootloader. This is mostly for testing only.

endmenu

config MPFS_HAVE_CORERMII
Expand Down
98 changes: 98 additions & 0 deletions arch/risc-v/src/mpfs/hardware/mpfs_mpucfg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/****************************************************************************
* arch/risc-v/src/mpfs/hardware/mpfs_mpucfg.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/

#ifndef __ARCH_RISC_V_SRC_MPFS_HARDWARE_MPFS_MPUCFG_H
#define __ARCH_RISC_V_SRC_MPFS_HARDWARE_MPFS_MPUCFG_H

/* FIC1 (FPGA) PMP configurations - for fabric memory transfers */

#define MPFS_PMPCFG_FIC1_0 (MPFS_MPUCFG_BASE + 0x100)
#define MPFS_PMPCFG_FIC1_1 (MPFS_MPUCFG_BASE + 0x108)
#define MPFS_PMPCFG_FIC1_2 (MPFS_MPUCFG_BASE + 0x110)
#define MPFS_PMPCFG_FIC1_3 (MPFS_MPUCFG_BASE + 0x118)
#define MPFS_PMPCFG_FIC1_4 (MPFS_MPUCFG_BASE + 0x120)
#define MPFS_PMPCFG_FIC1_5 (MPFS_MPUCFG_BASE + 0x128)
#define MPFS_PMPCFG_FIC1_6 (MPFS_MPUCFG_BASE + 0x130)
#define MPFS_PMPCFG_FIC1_7 (MPFS_MPUCFG_BASE + 0x138)
#define MPFS_PMPCFG_FIC1_8 (MPFS_MPUCFG_BASE + 0x140)
#define MPFS_PMPCFG_FIC1_9 (MPFS_MPUCFG_BASE + 0x148)
#define MPFS_PMPCFG_FIC1_10 (MPFS_MPUCFG_BASE + 0x150)
#define MPFS_PMPCFG_FIC1_11 (MPFS_MPUCFG_BASE + 0x158)
#define MPFS_PMPCFG_FIC1_12 (MPFS_MPUCFG_BASE + 0x160)
#define MPFS_PMPCFG_FIC1_13 (MPFS_MPUCFG_BASE + 0x168)
#define MPFS_PMPCFG_FIC1_14 (MPFS_MPUCFG_BASE + 0x170)
#define MPFS_PMPCFG_FIC1_15 (MPFS_MPUCFG_BASE + 0x178)

/* Crpyto PMP configurations - for DMA transfers */

#define MPFS_PMPCFG_CRYPTO_0 (MPFS_MPUCFG_BASE + 0x300)
#define MPFS_PMPCFG_CRYPTO_1 (MPFS_MPUCFG_BASE + 0x308)
#define MPFS_PMPCFG_CRYPTO_2 (MPFS_MPUCFG_BASE + 0x310)
#define MPFS_PMPCFG_CRYPTO_3 (MPFS_MPUCFG_BASE + 0x318)

/* Ethernet PMP configurations - for DMA transfers */

#define MPFS_PMPCFG_ETH0_0 (MPFS_MPUCFG_BASE + 0x400)
#define MPFS_PMPCFG_ETH0_1 (MPFS_MPUCFG_BASE + 0x408)
#define MPFS_PMPCFG_ETH0_2 (MPFS_MPUCFG_BASE + 0x410)
#define MPFS_PMPCFG_ETH0_3 (MPFS_MPUCFG_BASE + 0x418)
#define MPFS_PMPCFG_ETH1_0 (MPFS_MPUCFG_BASE + 0x500)
#define MPFS_PMPCFG_ETH1_1 (MPFS_MPUCFG_BASE + 0x508)
#define MPFS_PMPCFG_ETH1_2 (MPFS_MPUCFG_BASE + 0x510)
#define MPFS_PMPCFG_ETH1_3 (MPFS_MPUCFG_BASE + 0x518)

/* USB PMP configurations - for DMA transfers */

#define MPFS_PMPCFG_USB_0 (MPFS_MPUCFG_BASE + 0x600)
#define MPFS_PMPCFG_USB_1 (MPFS_MPUCFG_BASE + 0x608)
#define MPFS_PMPCFG_USB_2 (MPFS_MPUCFG_BASE + 0x610)
#define MPFS_PMPCFG_USB_3 (MPFS_MPUCFG_BASE + 0x618)

/* MMC PMP configurations - for DMA transfers */

#define MPFS_PMPCFG_MMC_0 (MPFS_MPUCFG_BASE + 0x700)
#define MPFS_PMPCFG_MMC_1 (MPFS_MPUCFG_BASE + 0x708)
#define MPFS_PMPCFG_MMC_2 (MPFS_MPUCFG_BASE + 0x710)
#define MPFS_PMPCFG_MMC_3 (MPFS_MPUCFG_BASE + 0x718)

/* DDR segments - set up by mpfs_ddr.c */

#define MPFS_MPUCFG_SEG0_REG0 (MPFS_MPUCFG_BASE + 0xd00)
#define MPFS_MPUCFG_SEG0_REG1 (MPFS_MPUCFG_BASE + 0xd08)
#define MPFS_MPUCFG_SEG0_REG2 (MPFS_MPUCFG_BASE + 0xd10)
#define MPFS_MPUCFG_SEG0_REG3 (MPFS_MPUCFG_BASE + 0xd18)
#define MPFS_MPUCFG_SEG0_REG4 (MPFS_MPUCFG_BASE + 0xd20)
#define MPFS_MPUCFG_SEG0_REG5 (MPFS_MPUCFG_BASE + 0xd28)
#define MPFS_MPUCFG_SEG0_REG6 (MPFS_MPUCFG_BASE + 0xd30)

#define MPFS_MPUCFG_SEG1_REG0 (MPFS_MPUCFG_BASE + 0xe00)
#define MPFS_MPUCFG_SEG1_REG1 (MPFS_MPUCFG_BASE + 0xe08)
#define MPFS_MPUCFG_SEG1_REG2 (MPFS_MPUCFG_BASE + 0xe10)
#define MPFS_MPUCFG_SEG1_REG3 (MPFS_MPUCFG_BASE + 0xe18)
#define MPFS_MPUCFG_SEG1_REG4 (MPFS_MPUCFG_BASE + 0xe20)
#define MPFS_MPUCFG_SEG1_REG5 (MPFS_MPUCFG_BASE + 0xe28)
#define MPFS_MPUCFG_SEG1_REG6 (MPFS_MPUCFG_BASE + 0xe30)

/* Size of the register area, which is 4K */

#define MPFS_MPUCFG_SIZE (0x1000)
#define MPFS_MPUCFG_END (MPFS_MPUCFG_BASE + MPFS_MPUCFG_SIZE)

#endif /* __NUTTX_ARCH_RISC_V_SRC_MPFS_HARDWARE_MPFS_MPUCFG_H */
32 changes: 0 additions & 32 deletions arch/risc-v/src/mpfs/hardware/mpfs_sgmii.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,6 @@
* Pre-processor Definitions
****************************************************************************/

#define MPFS_MPUCFG_SEG0_REG0_OFFSET 0xd00
#define MPFS_MPUCFG_SEG0_REG1_OFFSET 0xd08
#define MPFS_MPUCFG_SEG0_REG2_OFFSET 0xd10
#define MPFS_MPUCFG_SEG0_REG3_OFFSET 0xd18
#define MPFS_MPUCFG_SEG0_REG4_OFFSET 0xd20
#define MPFS_MPUCFG_SEG0_REG5_OFFSET 0xd28
#define MPFS_MPUCFG_SEG0_REG6_OFFSET 0xd30

#define MPFS_MPUCFG_SEG1_REG0_OFFSET 0xe00
#define MPFS_MPUCFG_SEG1_REG1_OFFSET 0xe08
#define MPFS_MPUCFG_SEG1_REG2_OFFSET 0xe10
#define MPFS_MPUCFG_SEG1_REG3_OFFSET 0xe18
#define MPFS_MPUCFG_SEG1_REG4_OFFSET 0xe20
#define MPFS_MPUCFG_SEG1_REG5_OFFSET 0xe28
#define MPFS_MPUCFG_SEG1_REG6_OFFSET 0xe30

#define MPFS_MPUCFG_SEG0_REG0 (MPFS_MPUCFG_BASE + MPFS_MPUCFG_SEG0_REG0_OFFSET)
#define MPFS_MPUCFG_SEG0_REG1 (MPFS_MPUCFG_BASE + MPFS_MPUCFG_SEG0_REG1_OFFSET)
#define MPFS_MPUCFG_SEG0_REG2 (MPFS_MPUCFG_BASE + MPFS_MPUCFG_SEG0_REG2_OFFSET)
#define MPFS_MPUCFG_SEG0_REG3 (MPFS_MPUCFG_BASE + MPFS_MPUCFG_SEG0_REG3_OFFSET)
#define MPFS_MPUCFG_SEG0_REG4 (MPFS_MPUCFG_BASE + MPFS_MPUCFG_SEG0_REG4_OFFSET)
#define MPFS_MPUCFG_SEG0_REG5 (MPFS_MPUCFG_BASE + MPFS_MPUCFG_SEG0_REG5_OFFSET)
#define MPFS_MPUCFG_SEG0_REG6 (MPFS_MPUCFG_BASE + MPFS_MPUCFG_SEG0_REG6_OFFSET)

#define MPFS_MPUCFG_SEG1_REG0 (MPFS_MPUCFG_BASE + MPFS_MPUCFG_SEG1_REG0_OFFSET)
#define MPFS_MPUCFG_SEG1_REG1 (MPFS_MPUCFG_BASE + MPFS_MPUCFG_SEG1_REG1_OFFSET)
#define MPFS_MPUCFG_SEG1_REG2 (MPFS_MPUCFG_BASE + MPFS_MPUCFG_SEG1_REG2_OFFSET)
#define MPFS_MPUCFG_SEG1_REG3 (MPFS_MPUCFG_BASE + MPFS_MPUCFG_SEG1_REG3_OFFSET)
#define MPFS_MPUCFG_SEG1_REG4 (MPFS_MPUCFG_BASE + MPFS_MPUCFG_SEG1_REG4_OFFSET)
#define MPFS_MPUCFG_SEG1_REG5 (MPFS_MPUCFG_BASE + MPFS_MPUCFG_SEG1_REG5_OFFSET)
#define MPFS_MPUCFG_SEG1_REG6 (MPFS_MPUCFG_BASE + MPFS_MPUCFG_SEG1_REG6_OFFSET)

#define MPFS_IOSCBCFG_TIMER_OFFSET 0x08

#define MPFS_SYSREGSCB_MSS_RESET_CR_OFFSET 0x100
Expand Down
1 change: 1 addition & 0 deletions arch/risc-v/src/mpfs/mpfs_ddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "hardware/mpfs_sysreg.h"
#include "hardware/mpfs_ddr.h"
#include "hardware/mpfs_sgmii.h"
#include "hardware/mpfs_mpucfg.h"

/****************************************************************************
* Pre-processor Definitions
Expand Down
7 changes: 2 additions & 5 deletions arch/risc-v/src/mpfs/mpfs_emmcsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "mpfs_emmcsd.h"
#include "riscv_internal.h"
#include "hardware/mpfs_emmcsd.h"
#include "hardware/mpfs_mpucfg.h"

/****************************************************************************
* Pre-processor Definitions
Expand Down Expand Up @@ -83,11 +84,6 @@
#define MPFS_SYSREG_SUBBLK_CLOCK_CR (MPFS_SYSREG_BASE + \
MPFS_SYSREG_SUBBLK_CLOCK_CR_OFFSET)

#define MPFS_PMPCFG_MMC_0 (MPFS_MPUCFG_BASE + 0x700)
#define MPFS_PMPCFG_MMC_1 (MPFS_MPUCFG_BASE + 0x708)
#define MPFS_PMPCFG_MMC_2 (MPFS_MPUCFG_BASE + 0x710)
#define MPFS_PMPCFG_MMC_3 (MPFS_MPUCFG_BASE + 0x718)

#define MPFS_MMC_CLOCK_400KHZ 400u
#define MPFS_MMC_CLOCK_12_5MHZ 12500u
#define MPFS_MMC_CLOCK_25MHZ 25000u
Expand Down Expand Up @@ -233,6 +229,7 @@
MPFS_EMMCSD_SRS14_TC_IE)

/* SD-Card IOMUX */

#define LIBERO_SETTING_IOMUX1_CR_SD 0x00000000UL
#ifdef CONFIG_MPFS_EMMCSD_MUX_GPIO
#define LIBERO_SETTING_IOMUX2_CR_SD 0X00BB0000UL
Expand Down
23 changes: 3 additions & 20 deletions arch/risc-v/src/mpfs/mpfs_ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
#include "mpfs_dsn.h"
#include "mpfs_i2c.h"

#include "hardware/mpfs_ethernet.h"
#include "hardware/mpfs_mpucfg.h"

#if defined(CONFIG_MPFS_ETH0_PHY_KSZ9477) ||\
defined(CONFIG_MPFS_ETH1_PHY_KSZ9477)
# if !defined(CONFIG_MPFS_MAC_SGMII)
Expand All @@ -78,15 +81,6 @@

#if defined(CONFIG_NET) && defined(CONFIG_MPFS_ETHMAC)

#define MPFS_PMPCFG_ETH0_0 (MPFS_MPUCFG_BASE + 0x400)
#define MPFS_PMPCFG_ETH0_1 (MPFS_MPUCFG_BASE + 0x408)
#define MPFS_PMPCFG_ETH0_2 (MPFS_MPUCFG_BASE + 0x410)
#define MPFS_PMPCFG_ETH0_3 (MPFS_MPUCFG_BASE + 0x418)
#define MPFS_PMPCFG_ETH1_0 (MPFS_MPUCFG_BASE + 0x500)
#define MPFS_PMPCFG_ETH1_1 (MPFS_MPUCFG_BASE + 0x508)
#define MPFS_PMPCFG_ETH1_2 (MPFS_MPUCFG_BASE + 0x510)
#define MPFS_PMPCFG_ETH1_3 (MPFS_MPUCFG_BASE + 0x518)

#if defined(CONFIG_MPFS_ETHMAC_0) && defined(CONFIG_MPFS_ETHMAC_1)
# warning "Using 2 MACs is not yet supported."
# define MPFS_NETHERNET (2)
Expand Down Expand Up @@ -3652,17 +3646,6 @@ int mpfs_ethinitialize(int intf)

mpfs_read_dsn(&priv->dev.d_mac.ether.ether_addr_octet[1], 5);

/* MPU hack for ETH DMA if not enabled by bootloader */

#ifdef CONFIG_MPFS_MPU_DMA_ENABLE
# ifdef CONFIG_MPFS_ETHMAC_0
putreg64(0x1f00000fffffffff, MPFS_PMPCFG_ETH0_0);
# endif
# ifdef CONFIG_MPFS_ETHMAC_1
putreg64(0x1f00000fffffffff, MPFS_PMPCFG_ETH1_0);
# endif
#endif

/* Allocate buffers */

ret = mpfs_buffer_initialize(priv, 0);
Expand Down
2 changes: 0 additions & 2 deletions arch/risc-v/src/mpfs/mpfs_ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

#include <nuttx/config.h>

#include "hardware/mpfs_ethernet.h"

#ifndef __ASSEMBLY__

/****************************************************************************
Expand Down
12 changes: 3 additions & 9 deletions arch/risc-v/src/mpfs/mpfs_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <arch/board/board.h>

#include "hardware/mpfs_usb.h"
#include "hardware/mpfs_mpucfg.h"
#include "riscv_internal.h"
#include "chip.h"

Expand Down Expand Up @@ -107,13 +108,6 @@
#define MPFS_TRACEINTID_EP0_STALLSENT 0x0014
#define MPFS_TRACEINTID_DATA_END 0x0015

/* USB PMP configuration registers */

#define MPFS_PMPCFG_USB_0 (MPFS_MPUCFG_BASE + 0x600)
#define MPFS_PMPCFG_USB_1 (MPFS_MPUCFG_BASE + 0x608)
#define MPFS_PMPCFG_USB_2 (MPFS_MPUCFG_BASE + 0x610)
#define MPFS_PMPCFG_USB_3 (MPFS_MPUCFG_BASE + 0x618)

/* Reset and clock control registers */

#define MPFS_SYSREG_SOFT_RESET_CR (MPFS_SYSREG_BASE + \
Expand Down Expand Up @@ -1754,7 +1748,7 @@ static void *mpfs_ep_allocbuffer(struct usbdev_ep_s *ep, uint16_t nbytes)
{
/* There is not special buffer allocation requirement */

return kumm_malloc(nbytes);
return kmm_malloc(nbytes);
}
#endif

Expand All @@ -1781,7 +1775,7 @@ static void mpfs_ep_freebuffer(struct usbdev_ep_s *ep, void *buf)
{
/* There is not special buffer allocation requirement */

kumm_free(buf);
kmm_free(buf);
}
#endif

Expand Down
32 changes: 32 additions & 0 deletions include/nuttx/lib/math32.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,38 @@ void umul64(FAR const struct uint64_s *factor1,
FAR const struct uint64_s *factor2,
FAR struct uint64_s *product);

/****************************************************************************
* Name: log2ceil
*
* Description:
* Calculate the up-rounded power-of-two for input.
*
* Input Parameters:
* x - Argument to calculate the power-of-two from.
*
* Returned Value:
* Power-of-two for argument, rounded up.
*
****************************************************************************/

uintptr_t log2ceil(uintptr_t x);

/****************************************************************************
* Name: log2floor
*
* Description:
* Calculate the down-rounded (truncated) power-of-two for input.
*
* Input Parameters:
* x - Argument to calculate the power-of-two from.
*
* Returned Value:
* Power-of-two for argument, rounded (truncated) down.
*
****************************************************************************/

uintptr_t log2floor(uintptr_t x);

#undef EXTERN
#ifdef __cplusplus
}
Expand Down
4 changes: 4 additions & 0 deletions libs/libc/misc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ list(
lib_ftok.c
lib_err.c)

# Add generic integer math functions

list(APPEND SRCS lib_log2ceil.c lib_log2floor.c)

# Keyboard driver encoder/decoder

if(CONFIG_LIBC_KBDCODEC)
Expand Down
4 changes: 4 additions & 0 deletions libs/libc/misc/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ CSRCS += lib_crc64.c lib_crc32.c lib_crc16.c lib_crc16ccitt.c lib_crc8.c
CSRCS += lib_crc8ccitt.c lib_crc8table.c lib_glob.c lib_execinfo.c
CSRCS += lib_ftok.c lib_err.c

# Add generic integer math functions

CSRCS += lib_log2ceil.c lib_log2floor.c

# Keyboard driver encoder/decoder

ifeq ($(CONFIG_LIBC_KBDCODEC),y)
Expand Down
Loading
Loading