Jose Marinho | fc0b2b6 | 2019-06-06 11:18:45 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Hafnium Authors. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 19 | #include "hf/addr.h" |
| 20 | #include "hf/vm.h" |
| 21 | |
| 22 | #include "vmapi/hf/spci.h" |
| 23 | |
Jose Marinho | fc0b2b6 | 2019-06-06 11:18:45 +0100 | [diff] [blame] | 24 | #define SPCI_VERSION_MAJOR 0x0 |
| 25 | #define SPCI_VERSION_MINOR 0x9 |
| 26 | |
| 27 | #define SPCI_VERSION_MAJOR_OFFSET 16 |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 28 | |
| 29 | struct spci_mem_transitions { |
| 30 | int orig_from_mode; |
| 31 | int orig_to_mode; |
| 32 | int from_mode; |
| 33 | int to_mode; |
| 34 | }; |
| 35 | |
Jose Marinho | 713f13a | 2019-05-21 11:54:16 +0100 | [diff] [blame] | 36 | /* TODO: Add device attributes: GRE, cacheability, shareability. */ |
| 37 | static inline uint32_t spci_memory_attrs_to_mode(uint32_t memory_attributes) |
| 38 | { |
| 39 | uint32_t mode = 0; |
| 40 | uint32_t attr_value; |
| 41 | |
| 42 | attr_value = spci_get_lend_access_attr(memory_attributes); |
| 43 | switch (attr_value) { |
| 44 | case SPCI_LEND_RO_NX: |
| 45 | mode |= MM_MODE_R; |
| 46 | break; |
| 47 | |
| 48 | case SPCI_LEND_RO_X: |
| 49 | mode |= MM_MODE_R | MM_MODE_X; |
| 50 | break; |
| 51 | |
| 52 | case SPCI_LEND_RW_NX: |
| 53 | mode |= MM_MODE_R | MM_MODE_W; |
| 54 | break; |
| 55 | |
| 56 | case SPCI_LEND_RW_X: |
| 57 | mode |= MM_MODE_R | MM_MODE_W | MM_MODE_X; |
| 58 | break; |
| 59 | |
| 60 | default: |
| 61 | break; |
| 62 | } |
| 63 | return mode; |
| 64 | } |
| 65 | |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 66 | spci_return_t spci_msg_handle_architected_message( |
| 67 | struct vm_locked to_locked, struct vm_locked from_locked, |
| 68 | const struct spci_architected_message_header |
| 69 | *architected_message_replica, |
| 70 | struct spci_message *from_msg_replica, struct spci_message *to_msg); |
| 71 | |
| 72 | bool spci_msg_check_transition(struct vm *to, struct vm *from, |
| 73 | enum spci_memory_share share, |
| 74 | int *orig_from_mode, ipaddr_t begin, |
| 75 | ipaddr_t end, uint32_t memory_to_attributes, |
| 76 | int *from_mode, int *to_mode); |