int pci_sh4_write_config_dword(struct pci_controller *hose, pci_dev_t dev, int offset, u32 value) { u32 par_data = 0x80000000 | dev; p4_out(par_data | (offset & 0xfc), SH7751_PCIPAR); p4_out(value, SH7751_PCIPDR); return 0; }
int pci_sh7751_init(struct pci_controller *hose) { /* Double-check that we're a 7751 or 7751R chip */ if (p4_in(SH7751_PCICONF0) != PCI_SH7751_ID && p4_in(SH7751_PCICONF0) != PCI_SH7751R_ID) { printf("PCI: Unknown PCI host bridge.\n"); return 1; } printf("PCI: SH7751 PCI host bridge found.\n"); /* Double-check some BSC config settings */ /* (Area 3 non-MPX 32-bit, PCI bus pins) */ if ((p4_in(SH7751_BCR1) & 0x20008) == 0x20000) { printf("SH7751_BCR1 value is wrong(0x%08X)\n", (unsigned int)p4_in(SH7751_BCR1)); return 2; } if ((p4_in(SH7751_BCR2) & 0xC0) != 0xC0) { printf("SH7751_BCR2 value is wrong(0x%08X)\n", (unsigned int)p4_in(SH7751_BCR2)); return 3; } if (p4_in(SH7751_BCR2) & 0x01) { printf("SH7751_BCR2 value is wrong(0x%08X)\n", (unsigned int)p4_in(SH7751_BCR2)); return 4; } /* Force BREQEN in BCR1 to allow PCIC access */ p4_out((p4_in(SH7751_BCR1) | BCR1_BREQEN), SH7751_BCR1); /* Toggle PCI reset pin */ p4_out((SH7751_PCICR_PREFIX | SH7751_PCICR_PRST), SH7751_PCICR); udelay(32); p4_out(SH7751_PCICR_PREFIX, SH7751_PCICR); /* Set cmd bits: WCC, PER, BUM, MES */ /* (Addr/Data stepping, Parity enabled, Bus Master, Memory enabled) */ p4_out(0xfb900047, SH7751_PCICONF1); /* K.Kino */ /* Define this host as the host bridge */ p4_out((SH7751_PCI_HOST_BRIDGE << 24), SH7751_PCICONF2); /* Force PCI clock(s) on */ p4_out(0, SH7751_PCICLKR); p4_out(0x03, SH7751_PCICLKR); /* Clear powerdown IRQs, also mask them (unused) */ p4_out((SH7751_PCIPINT_D0 | SH7751_PCIPINT_D3), SH7751_PCIPINT); p4_out(0, SH7751_PCIPINTM); p4_out(0xab000001, SH7751_PCICONF4); /* Set up target memory mappings (for external DMA access) */ /* Map both P0 and P2 range to Area 3 RAM for ease of use */ p4_out((64 - 1) << 20, SH7751_PCILSR0); p4_out(SH7751_CS3_BASE_ADDR, SH7751_PCILAR0); p4_out(0, SH7751_PCILSR1); p4_out(0, SH7751_PCILAR1); p4_out(SH7751_CS3_BASE_ADDR, SH7751_PCICONF5); p4_out(0xd0000000, SH7751_PCICONF6); /* Map memory window to same address on PCI bus */ p4_out(SH7751_PCI_MEM_BASE, SH7751_PCIMBR); /* Map IO window to same address on PCI bus */ p4_out(0x2000 & 0xfffc0000, SH7751_PCIIOBR); /* set BREQEN */ p4_out(inl(SH7751_BCR1) | 0x00080000, SH7751_BCR1); /* Copy BSC registers into PCI BSC */ p4_out(inl(SH7751_BCR1), SH7751_PCIBCR1); p4_out(inw(SH7751_BCR2), SH7751_PCIBCR2); p4_out(inw(SH7751_BCR3), SH7751_PCIBCR3); p4_out(inl(SH7751_WCR1), SH7751_PCIWCR1); p4_out(inl(SH7751_WCR2), SH7751_PCIWCR2); p4_out(inl(SH7751_WCR3), SH7751_PCIWCR3); p4_out(inl(SH7751_MCR), SH7751_PCIMCR); /* Finally, set central function init complete */ p4_out((SH7751_PCICR_PREFIX | SH7751_PCICR_CFIN), SH7751_PCICR); pci_sh4_init(hose); return 0; }
bool example04(char* buffer, const unsigned int buffer_size) { { // Write out and then read back in an array of unsigned ints. std::deque<unsigned int> lst; const unsigned int max_count = 2000; { strtk::binary::writer writer(buffer,buffer_size); writer.clear(); for (unsigned int i = 0; i < max_count; lst.push_back(i++)) ; if (!writer(lst)) { std::cout << "example04() - Failed to write list of 'unsigned int'" << std::endl; return false; } lst.clear(); } { strtk::binary::reader reader(buffer,buffer_size); if (!reader(lst)) { std::cout << "example04() - Failed to read list of 'unsigned int'" << std::endl; return false; } for (unsigned int i = 0; i < max_count; ++i) { if (lst[i] != i) { std::cout << "example04() - 'unsigned int' failure at index: " << i << std::endl; return false; } } } } { // Write out and then read back in an array of floats. std::vector<float> lst; const unsigned int max_count = 2000; const float magic[] = { 111.111f, 333.333f, 555.555f, 777.777f, 135.531f, 357.753f }; const std::size_t magic_count = sizeof(magic) / sizeof(float); { strtk::binary::writer writer(buffer,buffer_size); for (std::size_t i = 0; i < max_count; ++i) { lst.push_back(magic[i % magic_count] * i); } if (!writer(lst)) { std::cout << "example04() - Failed to write list of " << strtk::type_name(lst) << std::endl; return false; } lst.clear(); } { strtk::binary::reader reader(buffer,buffer_size); if (!reader(lst)) { std::cout << "example04() - Failed to read list of " << strtk::type_name(lst) << std::endl; return false; } for (std::size_t i = 0; i < max_count; ++i) { const float d = magic[i % magic_count] * i; if (lst[i] != d) { std::cout << "example04() - 'float' failure at index: " << i << " expected value: " << d << std::endl; return false; } } } } { // Write out and then read back in an array of doubles. std::list<double> lst; const unsigned int max_count = 1000; const double magic[] = { 111.111, 333.333, 555.555, 777.777, 135.531, 357.753 }; const std::size_t magic_count = sizeof(magic) / sizeof(double); { strtk::binary::writer writer(buffer,buffer_size); writer.clear(); for (std::size_t i = 0; i < max_count; ++i) { lst.push_back(magic[i % magic_count] * i); } if (!writer(lst)) { std::cout << "example04() - Failed to write list of " << strtk::type_name(lst) << std::endl; return false; } lst.clear(); } { strtk::binary::reader reader(buffer,buffer_size); if (!reader(lst)) { std::cout << "example04() - Failed to read list of " << strtk::type_name(lst) << std::endl; return false; } std::list<double>::iterator itr = lst.begin(); for (std::size_t i = 0; i < max_count; ++i, ++itr) { const double d = magic[i % magic_count] * i; if (*itr != d) { std::cout << "example04() - 'double' failure at index: " << i << " expected value: " << d << std::endl; return false; } } } } { // Write out and then read back in a set of int. std::set<int> lst; const int max_count = 10000; { strtk::binary::writer writer(buffer,buffer_size); writer.clear(); for (int i = -(max_count / 2); i < (max_count / 2); ++i) { lst.insert(i); } if (!writer(lst)) { std::cout << "example04() - Failed to write list of " << strtk::type_name(lst) << std::endl; return false; } lst.clear(); } { strtk::binary::reader reader(buffer,buffer_size); if (!reader(lst)) { std::cout << "example04() - Failed to read list of " << strtk::type_name(lst) << std::endl; return false; } int i = -(max_count / 2); std::set<int>::iterator itr = lst.begin(); while (lst.end() != itr) { if (i != *itr) { std::cout << "example04() - expected value: " << i << " read value: " << *itr << std::endl; return false; } ++i; ++itr; } } } { // Write out and then read back in a series of elaborate std::pair based types. typedef std::pair<std::string,unsigned int> p1_t; typedef std::pair<p1_t,p1_t> p2_t; typedef std::pair<p2_t,p2_t> p3_t; typedef std::pair<p3_t,p3_t> p4_t; p1_t p1_out("abcxyz",123456789); p2_t p2_out(p1_out,p1_out); p3_t p3_out(p2_out,p2_out); p4_t p4_out(p3_out,p3_out); strtk::binary::writer writer(buffer,buffer_size); if (!writer(p1_out)) { std::cout << "example04() - Failed to write type: " << strtk::type_name(p1_out) << std::endl; return false; } if (!writer(p2_out)) { std::cout << "example04() - Failed to write type: " << strtk::type_name(p2_out) << std::endl; return false; } if (!writer(p3_out)) { std::cout << "example04() - Failed to write type: " << strtk::type_name(p3_out) << std::endl; return false; } if (!writer(p4_out)) { std::cout << "example04() - Failed to write type: " << strtk::type_name(p4_out) << std::endl; return false; } strtk::binary::reader reader(buffer,buffer_size); p1_t p1_in; p2_t p2_in; p3_t p3_in; p4_t p4_in; if (!reader(p1_in)) { std::cout << "example04() - Failed to read type: " << strtk::type_name(p1_in) << std::endl; return false; } if (!reader(p2_in)) { std::cout << "example04() - Failed to read type: " << strtk::type_name(p2_in) << std::endl; return false; } if (!reader(p3_in)) { std::cout << "example04() - Failed to read type: " << strtk::type_name(p3_in) << std::endl; return false; } if (!reader(p4_in)) { std::cout << "example04() - Failed to read type: " << strtk::type_name(p4_in) << std::endl; return false; } if (p1_in != p1_out) { std::cout << "example04() - Comparison between p1_in and p1_out failed." << std::endl; return false; } if (p2_in != p2_out) { std::cout << "example04() - Comparison between p2_in and p2_out failed." << std::endl; return false; } if (p3_in != p3_out) { std::cout << "example04() - Comparison between p3_in and p3_out failed." << std::endl; return false; } if (p4_in != p4_out) { std::cout << "example04() - Comparison between p4_in and p4_out failed." << std::endl; return false; } } { static const std::size_t max = 10; std::vector< std::pair<unsigned long long,person> > p_out_list; std::deque< std::pair<unsigned long long,person> > p_in_list; { person p; p.id = 0LL; p.name = "Mr. Rumpelstilzchen"; p.age = 123; p.height = 123.456; p.weight = 333.7777f; p.is_insane = false; for (std::size_t i = 0; i < max; ++i) { p_out_list.push_back(std::make_pair(i,p)); p.id += 1; p.age += 3; p.height += 1.1; p.weight += 2.2f; } strtk::binary::writer writer (buffer,buffer_size); if (!writer(p_out_list)) { std::cout << "example04() - Failed to write type: " << strtk::type_name(p_out_list) << std::endl; return false; } } { strtk::binary::reader reader(buffer,buffer_size); if (!reader(p_in_list)) { std::cout << "example04() - Failed to read type: " << strtk::type_name(p_in_list) << std::endl; return false; } } if (p_out_list.size() != p_in_list.size()) { std::cout << "example04() - Failure between sizes of p_out_list and p_in_list!" << std::endl; return false; } if (!std::equal(p_out_list.begin(),p_out_list.end(),p_in_list.begin())) { std::cout << "example04() - Failure in comparison between p_out_list and p_in_list!" << std::endl; return false; } } return true; }