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

Add XIP cache maintenance API (fixes #2005) #2013

Merged
merged 4 commits into from
Nov 11, 2024
Merged

Conversation

Wren6991
Copy link
Contributor

@Wren6991 Wren6991 commented Nov 4, 2024

Also add a cache clean to all hardware_flash implementations which flush the cache, to avoid losing cached PSRAM writes.

This adds five new functions:

  • xip_cache_invalidate_all()
  • xip_cache_invalidate_range()
  • xip_cache_clean_all() (no-op on RP2040)
  • xip_cache_clean_range() (no-op on RP2040)
  • xip_cache_pin_range() (unavailable on RP2040)

It uses offsets (- XIP_BASE) instead of addresses, to be consistent with the hardware_flash APIs. If anyone strongly disagrees then we should change it now before we're stuck with it.

The library is unfortunately dependent on hardware_sync, just to get the barrier macros.

Also add a cache clean to hardware_flash implementations, to avoid
losing pending writes on the subsequent invalidate.
@Wren6991 Wren6991 added this to the 2.1.0 milestone Nov 4, 2024
@lurch lurch linked an issue Nov 4, 2024 that may be closed by this pull request
@kilograham
Copy link
Contributor

pls add new library to docs/index.h

will-v-pi
will-v-pi previously approved these changes Nov 7, 2024
Copy link
Contributor

@will-v-pi will-v-pi left a comment

Choose a reason for hiding this comment

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

LGTM for RP2350 - I've tested all the functions and they work as expected with PSRAM and Flash

@kilograham kilograham modified the milestones: 2.2.0, 2.1.0 Nov 11, 2024
@kilograham kilograham merged commit f9eb48b into develop Nov 11, 2024
6 checks passed
@kilograham kilograham deleted the add-xip-cache-api branch November 11, 2024 18:09
@lurch
Copy link
Contributor

lurch commented Nov 20, 2024

@kilograham @Wren6991 If I try building the kitchen_sink in the SDK with arm-none-eabi-gcc 6.3.1 (which is admittedly pretty ancient) it complains at me that:

...../pico-sdk/src/rp2_common/hardware_xip_cache/xip_cache.c:27:29: error: always_inline function might not be inlinable [-Werror=attributes]
 __always_inline static void check_xip_offset_range(uintptr_t start_offset, uintptr_t size_bytes) {
                             ^~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

If I replace the __always_inline there with __force_inline then the kitchen_sink builds successfully to completion.

Let me know if this was the right fix, and I'll submit a PR (or of course you can fix it directly yourself if that's easier).

EDIT: Ahh, and according to https://github.com/raspberrypi/pico-sdk/actions/runs/11936570350 this is failing the CI builds for GCC 6.2.1, GCC 6.3.1 and GCC 7.2.1

@kilograham
Copy link
Contributor

correct; we have __force_inline to work around GCC variations/bugs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add XIP cache management routines
4 participants