| 159 | } |
| 160 | |
| 161 | static rt_err_t pci_ofw_parse_ranges(struct rt_ofw_node *dev_np, const char *propname, |
| 162 | int phy_addr_cells, int phy_size_cells, int cpu_addr_cells, |
| 163 | struct rt_pci_bus_region **out_regions, rt_size_t *out_regions_nr) |
| 164 | { |
| 165 | const fdt32_t *cell; |
| 166 | rt_ssize_t total_cells; |
| 167 | int groups, space_code; |
| 168 | rt_uint32_t phy_addr[3]; |
| 169 | rt_uint64_t cpu_addr, phy_addr_size; |
| 170 | |
| 171 | *out_regions = RT_NULL; |
| 172 | *out_regions_nr = 0; |
| 173 | cell = rt_ofw_prop_read_raw(dev_np, propname, &total_cells); |
| 174 | |
| 175 | if (!cell) |
| 176 | { |
| 177 | return -RT_EEMPTY; |
| 178 | } |
| 179 | |
| 180 | groups = total_cells / sizeof(*cell) / (phy_addr_cells + phy_size_cells + cpu_addr_cells); |
| 181 | *out_regions = rt_malloc(groups * sizeof(struct rt_pci_bus_region)); |
| 182 | |
| 183 | if (!*out_regions) |
| 184 | { |
| 185 | return -RT_ENOMEM; |
| 186 | } |
| 187 | |
| 188 | for (int i = 0; i < groups; ++i) |
| 189 | { |
| 190 | /* |
| 191 | * ranges: |
| 192 | * phys.hi cell: npt000ss bbbbbbbb dddddfff rrrrrrrr |
| 193 | * phys.low cell: llllllll llllllll llllllll llllllll |
| 194 | * phys.mid cell: hhhhhhhh hhhhhhhh hhhhhhhh hhhhhhhh |
| 195 | * |
| 196 | * n: relocatable region flag (doesn't play a role here) |
| 197 | * p: prefetchable (cacheable) region flag |
| 198 | * t: aliased address flag (doesn't play a role here) |
| 199 | * ss: space code |
| 200 | * 00: configuration space |
| 201 | * 01: I/O space |
| 202 | * 10: 32 bit memory space |
| 203 | * 11: 64 bit memory space |
| 204 | * bbbbbbbb: The PCI bus number |
| 205 | * ddddd: The device number |
| 206 | * fff: The function number. Used for multifunction PCI devices. |
| 207 | * rrrrrrrr: Register number; used for configuration cycles. |
| 208 | */ |
| 209 | |
| 210 | for (int j = 0; j < phy_addr_cells; ++j) |
| 211 | { |
| 212 | phy_addr[j] = rt_fdt_read_number(cell++, 1); |
| 213 | } |
| 214 | |
| 215 | space_code = (phy_addr[0] >> 24) & 0x3; |
| 216 | |
| 217 | cpu_addr = rt_fdt_read_number(cell, cpu_addr_cells); |
| 218 | cell += cpu_addr_cells; |
no test coverage detected