From laplace at mail.berlios.de Tue May 1 09:54:40 2007 From: laplace at mail.berlios.de (laplace at BerliOS) Date: Tue, 1 May 2007 09:54:40 +0200 Subject: [Haiku-commits] r20942 - in haiku/trunk/src: add-ons/print/drivers/shared/libprint add-ons/print/shared servers/print/shared Message-ID: <200705010754.l417sesC010338@sheep.berlios.de> Author: laplace Date: 2007-05-01 09:54:40 +0200 (Tue, 01 May 2007) New Revision: 20942 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20942&view=rev Modified: haiku/trunk/src/add-ons/print/drivers/shared/libprint/GraphicsDriver.cpp haiku/trunk/src/add-ons/print/shared/PrintJobReader.cpp haiku/trunk/src/servers/print/shared/BeUtils.cpp Log: Support building on Zeta with BeIDE or make. Modified: haiku/trunk/src/add-ons/print/drivers/shared/libprint/GraphicsDriver.cpp =================================================================== --- haiku/trunk/src/add-ons/print/drivers/shared/libprint/GraphicsDriver.cpp 2007-04-30 21:22:26 UTC (rev 20941) +++ haiku/trunk/src/add-ons/print/drivers/shared/libprint/GraphicsDriver.cpp 2007-05-01 07:54:40 UTC (rev 20942) @@ -73,9 +73,12 @@ // already initialized return true; } - + +#ifndef __ZETA__ print_file_header pfh; - +#else + BPrintJob::print_file_header pfh; +#endif spool_file->Seek(0, SEEK_SET); spool_file->Read(&pfh, sizeof(pfh)); Modified: haiku/trunk/src/add-ons/print/shared/PrintJobReader.cpp =================================================================== --- haiku/trunk/src/add-ons/print/shared/PrintJobReader.cpp 2007-04-30 21:22:26 UTC (rev 20941) +++ haiku/trunk/src/add-ons/print/shared/PrintJobReader.cpp 2007-05-01 07:54:40 UTC (rev 20942) @@ -28,6 +28,7 @@ */ #include +#include #include #include "PrintJobReader.h" @@ -103,7 +104,11 @@ , fNumberOfPages(-1) , fPageIndex(NULL) { +#ifndef __ZETA__ print_file_header header; +#else + BPrintJob::print_file_header header; +#endif fJobFile.Seek(0, SEEK_SET); if (fJobFile.Read(&header, sizeof(header)) == sizeof(header) && fJobSettings.Unflatten(&fJobFile) == B_OK) { Modified: haiku/trunk/src/servers/print/shared/BeUtils.cpp =================================================================== --- haiku/trunk/src/servers/print/shared/BeUtils.cpp 2007-04-30 21:22:26 UTC (rev 20941) +++ haiku/trunk/src/servers/print/shared/BeUtils.cpp 2007-05-01 07:54:40 UTC (rev 20942) @@ -103,7 +103,11 @@ void AddFields(BMessage* to, const BMessage* from, const char* excludeList[], const char* includeList[], bool overwrite) { if (to == from) return; +#ifndef __ZETA__ char* name; +#else + const char* name; +#endif type_code type; int32 count; for (int32 i = 0; from->GetInfo(B_ANY_TYPE, i, &name, &type, &count) == B_OK; i ++) { From laplace at mail.berlios.de Tue May 1 09:58:55 2007 From: laplace at mail.berlios.de (laplace at BerliOS) Date: Tue, 1 May 2007 09:58:55 +0200 Subject: [Haiku-commits] r20943 - haiku/trunk/src/add-ons/print/drivers/shared/libprint Message-ID: <200705010758.l417wt12010769@sheep.berlios.de> Author: laplace Date: 2007-05-01 09:58:54 +0200 (Tue, 01 May 2007) New Revision: 20943 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20943&view=rev Modified: haiku/trunk/src/add-ons/print/drivers/shared/libprint/JobSetupDlg.cpp Log: Replace ostringstream with BString. Modified: haiku/trunk/src/add-ons/print/drivers/shared/libprint/JobSetupDlg.cpp =================================================================== --- haiku/trunk/src/add-ons/print/drivers/shared/libprint/JobSetupDlg.cpp 2007-05-01 07:54:40 UTC (rev 20942) +++ haiku/trunk/src/add-ons/print/drivers/shared/libprint/JobSetupDlg.cpp 2007-05-01 07:58:54 UTC (rev 20943) @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -29,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -597,13 +597,13 @@ if (first_page > last_page) last_page = -1; - ostringstream oss1; + BString oss1; oss1 << first_page; - fFromPage->SetText(oss1.str().c_str()); + fFromPage->SetText(oss1.String()); - ostringstream oss2; + BString oss2; oss2 << last_page; - fToPage->SetText(oss2.str().c_str()); + fToPage->SetText(oss2.String()); } fAll->SetTarget(this); @@ -674,9 +674,9 @@ fCopies->SetDivider(width); AllowOnlyDigits(fCopies->TextView(), 3); - ostringstream oss4; + BString oss4; oss4 << fJobData->getCopies(); - fCopies->SetText(oss4.str().c_str()); + fCopies->SetText(oss4.String()); /* collate */ From koki at digintrans.com Tue May 1 10:26:19 2007 From: koki at digintrans.com (Jorge G. Mare (a.k.a. Koki)) Date: Tue, 01 May 2007 01:26:19 -0700 Subject: [Haiku-commits] r19701 - haiku/trunk/src/apps/bemail In-Reply-To: <200701042216.l04MGApm003949@sheep.berlios.de> References: <200701042216.l04MGApm003949@sheep.berlios.de> Message-ID: <4636F9AB.7080902@digintrans.com> Hi, This seems to be the last in a series of commits related to MDR and BeMail for Haiku between mid-December and early January. I am not sure if MDR ever worked in Haiku before this, but at least now (and for probably the last 3-4 months), MDR has been broken. Specifically, it is not possible to add accounts (the UI of the incoming and outgoing screens are incomplete), and the Settings screen is broken too. Screenshots are available on the following bug report: http://dev.haiku-os.org/ticket/1198 Now that the network stack is getting better by the day, and that apps like Vision, BeShare and BeGet work reasonably well in Haiku, it would be nice if MDR/BeMail would be fixed so that it can be used at least for demo purposes. Cheers, Koki darkwyrm at BerliOS wrote: > Author: darkwyrm > Date: 2007-01-04 23:16:09 +0100 (Thu, 04 Jan 2007) > New Revision: 19701 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=19701&view=rev > > Modified: > haiku/trunk/src/apps/bemail/AutoTextControl.cpp > haiku/trunk/src/apps/bemail/AutoTextControl.h > Log: > Style fix, courtesy of Ingo (man, yesterday was bad!) > GCC4 compilation fix, thanks to Frederik Ekdahl > > > Modified: haiku/trunk/src/apps/bemail/AutoTextControl.cpp > =================================================================== > --- haiku/trunk/src/apps/bemail/AutoTextControl.cpp 2007-01-04 15:36:22 UTC (rev 19700) > +++ haiku/trunk/src/apps/bemail/AutoTextControl.cpp 2007-01-04 22:16:09 UTC (rev 19701) > @@ -24,8 +24,8 @@ > } > > filter_result > -AutoTextControlFilter::Filter(BMessage *msg, BHandler **target) { > - > +AutoTextControlFilter::Filter(BMessage *msg, BHandler **target) > +{ > // This is really slick -- all that is needed to allow Escape key cancelling is > // just calling SetEscapeCancel(true) for just *one* AutoTextControl in a window. *heh* > int32 rawchar,mod; > > Modified: haiku/trunk/src/apps/bemail/AutoTextControl.h > =================================================================== > --- haiku/trunk/src/apps/bemail/AutoTextControl.h 2007-01-04 15:36:22 UTC (rev 19700) > +++ haiku/trunk/src/apps/bemail/AutoTextControl.h 2007-01-04 22:16:09 UTC (rev 19701) > @@ -40,7 +40,7 @@ > void SetEscapeCancel(const bool &value) { fEscapeCancel = value; } > bool IsEscapeCancel(void) const { return fEscapeCancel; } > private: > - friend AutoTextControlFilter; > + friend class AutoTextControlFilter; > > AutoTextControlFilter *fFilter; > bool fEscapeCancel; > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From darkwyrm at earthlink.net Tue May 1 12:32:33 2007 From: darkwyrm at earthlink.net (DarkWyrm) Date: Tue, 01 May 2007 06:32:33 -0400 EDT Subject: [Haiku-commits] r19701 - haiku/trunk/src/apps/bemail In-Reply-To: <4636F9AB.7080902@digintrans.com> Message-ID: <1154089777-BeMail@sapphire> > Hi, > > This seems to be the last in a series of commits related to MDR and > BeMail for Haiku between mid-December and early January. I am not > sure > if MDR ever worked in Haiku before this, but at least now (and for > probably the last 3-4 months), MDR has been broken. > > Specifically, it is not possible to add accounts (the UI of the > incoming > and outgoing screens are incomplete), and the Settings screen is > broken too. > > Screenshots are available on the following bug report: > > http://dev.haiku-os.org/ticket/1198 > > Now that the network stack is getting better by the day, and that > apps > like Vision, BeShare and BeGet work reasonably well in Haiku, it > would > be nice if MDR/BeMail would be fixed so that it can be used at least > for > demo purposes. Thanks for the bug report. The fault is mine on this one although I can't see how I would've left something like this. I will work on this when I get home after work and see what happened. --DW From axeld at pinc-software.de Tue May 1 12:44:45 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Tue, 01 May 2007 12:44:45 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r20942_-_in_haiku/trunk/src=3A_ad?= =?iso-8859-15?q?d-ons/print/drivers/shared/libprint_add-ons/print/shared_?= =?iso-8859-15?q?servers/print/shared?= In-Reply-To: <200705010754.l417sesC010338@sheep.berlios.de> Message-ID: <962569411-BeMail@zon> laplace at BerliOS wrote: > +#ifndef __ZETA__ > char* name; > +#else > + const char* name; > +#endif The correct test would be #ifndef B_BEOS_VERSION_DANO as that one introduced the "const" here. BTW I think we should just do the same in Haiku; it's only a minor inconvenience, anyway :-) Bye, Axel. From axeld at pinc-software.de Tue May 1 12:47:17 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Tue, 01 May 2007 12:47:17 +0200 CEST Subject: [Haiku-commits] r19701 - haiku/trunk/src/apps/bemail In-Reply-To: <4636F9AB.7080902@digintrans.com> Message-ID: <1114097581-BeMail@zon> "Jorge G. Mare (a.k.a. Koki)" wrote: > Specifically, it is not possible to add accounts (the UI of the > incoming > and outgoing screens are incomplete), and the Settings screen is > broken too. > > Screenshots are available on the following bug report: > > http://dev.haiku-os.org/ticket/1198 > > Now that the network stack is getting better by the day, and that > apps > like Vision, BeShare and BeGet work reasonably well in Haiku, it > would > be nice if MDR/BeMail would be fixed so that it can be used at least > for > demo purposes. Thanks, I'll look into it by the end of the week. I would guess that only the mail add-ons are missing, anyway - but we'll see. Bye, Axel. From hugosantos at mail.berlios.de Tue May 1 13:38:59 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Tue, 1 May 2007 13:38:59 +0200 Subject: [Haiku-commits] r20944 - in haiku/trunk: headers/private/net src/add-ons/kernel/network/datalink_protocols/arp src/add-ons/kernel/network/datalink_protocols/ethernet_frame src/add-ons/kernel/network/datalink_protocols/loopback_frame src/add-ons/kernel/network/stack Message-ID: <200705011138.l41BcxiB004351@sheep.berlios.de> Author: hugosantos Date: 2007-05-01 13:38:39 +0200 (Tue, 01 May 2007) New Revision: 20944 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20944&view=rev Modified: haiku/trunk/headers/private/net/net_datalink_protocol.h haiku/trunk/src/add-ons/kernel/network/datalink_protocols/arp/arp.cpp haiku/trunk/src/add-ons/kernel/network/datalink_protocols/ethernet_frame/ethernet_frame.cpp haiku/trunk/src/add-ons/kernel/network/datalink_protocols/loopback_frame/loopback_frame.cpp haiku/trunk/src/add-ons/kernel/network/stack/datalink.cpp Log: added join_multicast/leave_multicast to datalink protocols, preparing for full multicast support. Modified: haiku/trunk/headers/private/net/net_datalink_protocol.h =================================================================== --- haiku/trunk/headers/private/net/net_datalink_protocol.h 2007-05-01 07:58:54 UTC (rev 20943) +++ haiku/trunk/headers/private/net/net_datalink_protocol.h 2007-05-01 11:38:39 UTC (rev 20944) @@ -30,6 +30,11 @@ status_t (*control)(net_datalink_protocol *self, int32 op, void *argument, size_t length); + + status_t (*join_multicast)(net_datalink_protocol *self, + const sockaddr *address); + status_t (*leave_multicast)(net_datalink_protocol *self, + const sockaddr *address); }; #endif // NET_DATALINK_PROTOCOL_H Modified: haiku/trunk/src/add-ons/kernel/network/datalink_protocols/arp/arp.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/datalink_protocols/arp/arp.cpp 2007-05-01 07:58:54 UTC (rev 20943) +++ haiku/trunk/src/add-ons/kernel/network/datalink_protocols/arp/arp.cpp 2007-05-01 11:38:39 UTC (rev 20944) @@ -248,6 +248,32 @@ } +static void +ipv4_to_ether_multicast(sockaddr_dl *destination, const sockaddr_in *source) +{ + // RFC 1112 - Host extensions for IP multicasting + // + // ``An IP host group address is mapped to an Ethernet multicast + // address by placing the low-order 23-bits of the IP address into + // the low-order 23 bits of the Ethernet multicast address + // 01-00-5E-00-00-00 (hex).'' + + memcpy(((uint8 *)destination->sdl_data) + 2, &source->sin_addr, + sizeof(in_addr)); + + destination->sdl_len = sizeof(sockaddr_dl); + destination->sdl_family = AF_DLI; + destination->sdl_index = 0; + destination->sdl_type = IFT_ETHER; + destination->sdl_e_type = ETHER_TYPE_IP; + destination->sdl_nlen = destination->sdl_slen = 0; + destination->sdl_alen = ETHER_ADDRESS_LENGTH; + + uint32 *data = (uint32 *)destination->sdl_data; + data[0] = (data[0] & htonl(0x7f)) | htonl(0x01005e00); +} + + // #pragma mark - @@ -791,28 +817,11 @@ entry->hardware_address.sdl_len); if (buffer->flags & MSG_MCAST) { - // RFC 1112 - Host extensions for IP multicasting - // - // ``An IP host group address is mapped to an Ethernet multicast - // address by placing the low-order 23-bits of the IP address into - // the low-order 23 bits of the Ethernet multicast address - // 01-00-5E-00-00-00 (hex).'' - - sockaddr_dl *destination = (sockaddr_dl *)&buffer->destination; - - memmove(((uint8 *)destination->sdl_data) + 2, - &((sockaddr_in *)&buffer->destination)->sin_addr, sizeof(in_addr)); - - destination->sdl_len = sizeof(sockaddr_dl); - destination->sdl_family = AF_DLI; - destination->sdl_index = 0; - destination->sdl_type = IFT_ETHER; - destination->sdl_e_type = ETHER_TYPE_IP; - destination->sdl_nlen = destination->sdl_slen = 0; - destination->sdl_alen = ETHER_ADDRESS_LENGTH; - - uint32 *data = (uint32 *)destination->sdl_data; - data[0] = (data[0] & htonl(0x7f)) | htonl(0x01005e00); + sockaddr_dl multicastDestination; + ipv4_to_ether_multicast(&multicastDestination, + (sockaddr_in *)&buffer->destination); + memcpy(&buffer->destination, &multicastDestination, + sizeof(multicastDestination)); } else if ((buffer->flags & MSG_BCAST) == 0) { // Lookup destination (we may need to wait for this) entry = arp_entry::Lookup( @@ -928,6 +937,34 @@ static status_t +arp_join_multicast(net_datalink_protocol *protocol, const sockaddr *address) +{ + if (address->sa_family != AF_INET) + return EINVAL; + + sockaddr_dl multicastAddress; + ipv4_to_ether_multicast(&multicastAddress, (const sockaddr_in *)address); + + return protocol->next->module->join_multicast(protocol->next, + (sockaddr *)&multicastAddress); +} + + +static status_t +arp_leave_multicast(net_datalink_protocol *protocol, const sockaddr *address) +{ + if (address->sa_family != AF_INET) + return EINVAL; + + sockaddr_dl multicastAddress; + ipv4_to_ether_multicast(&multicastAddress, (const sockaddr_in *)address); + + return protocol->next->module->leave_multicast(protocol->next, + (sockaddr *)&multicastAddress); +} + + +static status_t arp_std_ops(int32 op, ...) { switch (op) { @@ -954,6 +991,8 @@ arp_up, arp_down, arp_control, + arp_join_multicast, + arp_leave_multicast, }; Modified: haiku/trunk/src/add-ons/kernel/network/datalink_protocols/ethernet_frame/ethernet_frame.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/datalink_protocols/ethernet_frame/ethernet_frame.cpp 2007-05-01 07:58:54 UTC (rev 20943) +++ haiku/trunk/src/add-ons/kernel/network/datalink_protocols/ethernet_frame/ethernet_frame.cpp 2007-05-01 11:38:39 UTC (rev 20944) @@ -170,6 +170,22 @@ static status_t +ethernet_frame_join_multicast(net_datalink_protocol *protocol, + const sockaddr *address) +{ + return protocol->next->module->join_multicast(protocol, address); +} + + +static status_t +ethernet_frame_leave_multicast(net_datalink_protocol *protocol, + const sockaddr *address) +{ + return protocol->next->module->leave_multicast(protocol, address); +} + + +static status_t ethernet_frame_std_ops(int32 op, ...) { switch (op) { @@ -197,6 +213,8 @@ ethernet_frame_up, ethernet_frame_down, ethernet_frame_control, + ethernet_frame_join_multicast, + ethernet_frame_leave_multicast, }; module_info *modules[] = { Modified: haiku/trunk/src/add-ons/kernel/network/datalink_protocols/loopback_frame/loopback_frame.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/datalink_protocols/loopback_frame/loopback_frame.cpp 2007-05-01 07:58:54 UTC (rev 20943) +++ haiku/trunk/src/add-ons/kernel/network/datalink_protocols/loopback_frame/loopback_frame.cpp 2007-05-01 11:38:39 UTC (rev 20944) @@ -131,6 +131,22 @@ static status_t +loopback_frame_join_multicast(net_datalink_protocol *protocol, + const sockaddr *address) +{ + return protocol->next->module->join_multicast(protocol, address); +} + + +static status_t +loopback_frame_leave_multicast(net_datalink_protocol *protocol, + const sockaddr *address) +{ + return protocol->next->module->leave_multicast(protocol, address); +} + + +static status_t loopback_frame_std_ops(int32 op, ...) { switch (op) { @@ -158,6 +174,8 @@ loopback_frame_up, loopback_frame_down, loopback_frame_control, + loopback_frame_join_multicast, + loopback_frame_leave_multicast, }; module_info *modules[] = { Modified: haiku/trunk/src/add-ons/kernel/network/stack/datalink.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/stack/datalink.cpp 2007-05-01 07:58:54 UTC (rev 20943) +++ haiku/trunk/src/add-ons/kernel/network/stack/datalink.cpp 2007-05-01 11:38:39 UTC (rev 20944) @@ -799,6 +799,24 @@ } +static status_t +interface_protocol_join_multicast(net_datalink_protocol *_protocol, + const sockaddr *address) +{ + // TODO + return EINVAL; +} + + +static status_t +interface_protocol_leave_multicast(net_datalink_protocol *_protocol, + const sockaddr *address) +{ + // TODO + return EINVAL; +} + + net_datalink_module_info gNetDatalinkModule = { { NET_DATALINK_MODULE_NAME, @@ -835,4 +853,6 @@ interface_protocol_up, interface_protocol_down, interface_protocol_control, + interface_protocol_join_multicast, + interface_protocol_leave_multicast, }; From hugosantos at mail.berlios.de Tue May 1 13:39:21 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Tue, 1 May 2007 13:39:21 +0200 Subject: [Haiku-commits] r20945 - in haiku/trunk: headers/private/kernel/util src/add-ons/kernel/network/protocols/ipv4 src/add-ons/kernel/network/stack Message-ID: <200705011139.l41BdLVh004382@sheep.berlios.de> Author: hugosantos Date: 2007-05-01 13:38:59 +0200 (Tue, 01 May 2007) New Revision: 20945 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20945&view=rev Modified: haiku/trunk/headers/private/kernel/util/MultiHashTable.h haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/multicast.cpp haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/multicast.h haiku/trunk/src/add-ons/kernel/network/stack/datalink.cpp Log: prepared the ipv4 multicast code for full multicast support. Modified: haiku/trunk/headers/private/kernel/util/MultiHashTable.h =================================================================== --- haiku/trunk/headers/private/kernel/util/MultiHashTable.h 2007-05-01 11:38:39 UTC (rev 20944) +++ haiku/trunk/headers/private/kernel/util/MultiHashTable.h 2007-05-01 11:38:59 UTC (rev 20945) @@ -85,6 +85,8 @@ return true; } + Iterator GetIterator() const { return HashTable::GetIterator(); } + private: void _Insert(ValueType **table, size_t tableSize, ValueType *value) { Modified: haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp 2007-05-01 11:38:39 UTC (rev 20944) +++ haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp 2007-05-01 11:38:59 UTC (rev 20945) @@ -11,6 +11,7 @@ #include "multicast.h" #include +#include #include #include #include @@ -22,7 +23,7 @@ #include #include #include -#include +#include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include //#define TRACE_IPV4 @@ -118,48 +120,6 @@ }; -class MulticastGroup { -public: - MulticastGroup(const in_addr &address); - - status_t Deliver(net_protocol_module_info *module, net_buffer *buffer, - bool raw); - - void Add(IPv4Multicast::GroupState *groupState); - void Remove(IPv4Multicast::GroupState *groupState); - bool IsEmpty() const { return fLinks.IsEmpty(); } - - struct HashDefinition { - typedef void ParentType; - typedef const in_addr KeyType; - typedef MulticastGroup ValueType; - - size_t HashKey(const in_addr &address) const - { return address.s_addr; } - size_t Hash(MulticastGroup *group) const - { return HashKey(group->fMulticastAddress); } - bool Compare(const in_addr &address, MulticastGroup *group) const - { return group->fMulticastAddress.s_addr == address.s_addr; } - HashTableLink *GetLink(MulticastGroup *group) const - { return &group->fLink; } - }; - - void DumpInternalState() const; - -private: - // for g++ 2.95 - friend class HashDefinition; - - typedef DoublyLinkedList Links; - - in_addr fMulticastAddress; - Links fLinks; - - HashTableLink fLink; -}; - - - class RawSocket : public DoublyLinkedListLinkImpl, public DatagramSocket<> { public: RawSocket(net_socket *socket); @@ -167,8 +127,29 @@ typedef DoublyLinkedList RawSocketList; +typedef MulticastGroupInterface IPv4GroupInterface; typedef MulticastFilter IPv4MulticastFilter; +struct MulticastStateHash { + typedef void ParentType; + typedef std::pair KeyType; + typedef IPv4GroupInterface ValueType; + + size_t HashKey(const KeyType &key) const + { return key.first->s_addr ^ key.second; } + size_t Hash(ValueType *value) const + { return HashKey(std::make_pair(&value->Address(), + value->Interface()->index)); } + bool Compare(const KeyType &key, ValueType *value) const + { return value->Interface()->index == key.second + && value->Address().s_addr == key.first->s_addr; } + bool CompareValues(ValueType *value1, ValueType *value2) const + { return value1->Interface()->index == value2->Interface()->index + && value1->Address().s_addr == value2->Address().s_addr; } + HashTableLink *GetLink(ValueType *value) const { return value; } +}; + + struct ipv4_protocol : net_protocol { ipv4_protocol() : multicast_filter(this) {} @@ -205,8 +186,10 @@ static benaphore sFragmentLock; static hash_table *sFragmentHash; static benaphore sMulticastGroupsLock; -typedef OpenHashTable MulticastGroups; -static MulticastGroups *sMulticastGroups; + +typedef MultiHashTable MulticastState; +static MulticastState *sMulticastState; + static net_protocol_module_info *sReceivingProtocol[256]; static benaphore sReceivingProtocolLock; @@ -461,73 +444,6 @@ } -MulticastGroup::MulticastGroup(const in_addr &address) - : fMulticastAddress(address) -{ -} - - -status_t -MulticastGroup::Deliver(net_protocol_module_info *module, net_buffer *buffer, - bool deliverToRaw) -{ - Links::Iterator iterator = fLinks.GetIterator(); - - while (iterator.HasNext()) { - IPv4Multicast::GroupState *groupState = iterator.Next(); - - if (deliverToRaw && groupState->Socket()->raw == NULL) - continue; - - if (groupState->FilterAccepts(buffer)) { - // as Multicast filters are installed with an IPv4 protocol - // reference, we need to go and find the appropriate instance - // related to the 'receiving protocol' with module 'module'. - net_protocol *proto = groupState->Socket()->socket->first_protocol; - - while (proto && proto->module != module) - proto = proto->next; - - if (proto) - module->deliver_data(proto, buffer); - } - } - - return B_OK; -} - - -void -MulticastGroup::Add(IPv4Multicast::GroupState *groupState) -{ - fLinks.Add(groupState); -} - - -void -MulticastGroup::Remove(IPv4Multicast::GroupState *groupState) -{ - fLinks.Remove(groupState); -} - - -void -MulticastGroup::DumpInternalState() const -{ - char addrBuf[64]; - - kprintf("group %s (%p)\n", print_address(&fMulticastAddress, addrBuf, - sizeof(addrBuf)), this); - - Links::ConstIterator it = fLinks.GetIterator(); - while (it.HasNext()) { - IPv4Multicast::GroupState *group = it.Next(); - - kprintf(" socket %p\n", group->Socket()); - } -} - - // #pragma mark - @@ -730,12 +646,37 @@ BenaphoreLocker _(sMulticastGroupsLock); - MulticastGroup *group = sMulticastGroups->Lookup( - ((sockaddr_in *)&buffer->destination)->sin_addr); - if (group == NULL) - return B_OK; + sockaddr_in *multicastAddr = (sockaddr_in *)&buffer->destination; - return group->Deliver(module, buffer, deliverToRaw); + MulticastState::Iterator it = sMulticastState->Lookup(std::make_pair( + &multicastAddr->sin_addr, buffer->interface->index)); + + while (it.HasNext()) { + IPv4GroupInterface *state = it.Next(); + + if (state->Interface()->index != buffer->interface->index + || state->Address().s_addr != multicastAddr->sin_addr.s_addr) + break; + + if (deliverToRaw && state->Parent()->Socket()->raw == NULL) + continue; + + if (state->FilterAccepts(buffer)) { + // as Multicast filters are installed with an IPv4 protocol + // reference, we need to go and find the appropriate instance + // related to the 'receiving protocol' with module 'module'. + net_protocol *proto = + state->Parent()->Socket()->socket->first_protocol; + + while (proto && proto->module != module) + proto = proto->next; + + if (proto) + module->deliver_data(proto, buffer); + } + } + + return B_OK; } @@ -770,40 +711,42 @@ status_t -IPv4Multicast::JoinGroup(GroupState *groupState) +IPv4Multicast::JoinGroup(IPv4GroupInterface *state) { BenaphoreLocker _(sMulticastGroupsLock); - MulticastGroup *group = sMulticastGroups->Lookup(groupState->Address()); - if (group == NULL) { - group = new (std::nothrow) MulticastGroup(groupState->Address()); - if (group == NULL) - return B_NO_MEMORY; + sockaddr_in groupAddr; + memset(&groupAddr, 0, sizeof(groupAddr)); + groupAddr.sin_addr = state->Address(); - sMulticastGroups->Insert(group); - } + net_interface *intf = state->Interface(); - group->Add(groupState); + status_t status = + intf->first_protocol->module->join_multicast(intf->first_protocol, + (sockaddr *)&groupAddr); + if (status < B_OK) + return status; + + sMulticastState->Insert(state); return B_OK; } status_t -IPv4Multicast::LeaveGroup(GroupState *groupState) +IPv4Multicast::LeaveGroup(IPv4GroupInterface *state) { BenaphoreLocker _(sMulticastGroupsLock); - MulticastGroup *group = sMulticastGroups->Lookup(groupState->Address()); - if (group == NULL) - return ENOENT; + sMulticastState->Remove(state); - group->Remove(groupState); - if (group->IsEmpty()) { - sMulticastGroups->Remove(group); - delete group; - } + sockaddr_in groupAddr; + memset(&groupAddr, 0, sizeof(groupAddr)); + groupAddr.sin_addr = state->Address(); - return B_OK; + net_interface *intf = state->Interface(); + + return intf->first_protocol->module->join_multicast(intf->first_protocol, + (sockaddr *)&groupAddr); } @@ -838,22 +781,22 @@ static status_t -ipv4_delta_group(IPv4MulticastFilter::GroupState *group, int option, +ipv4_delta_group(IPv4GroupInterface *group, int option, net_interface *interface, const in_addr *sourceAddr) { switch (option) { case IP_ADD_MEMBERSHIP: - return group->Add(interface); + return group->Add(); case IP_DROP_MEMBERSHIP: - return group->Drop(interface); + return group->Drop(); case IP_BLOCK_SOURCE: - return group->BlockSource(interface, *sourceAddr); + return group->BlockSource(*sourceAddr); case IP_UNBLOCK_SOURCE: - return group->UnblockSource(interface, *sourceAddr); + return group->UnblockSource(*sourceAddr); case IP_ADD_SOURCE_MEMBERSHIP: - return group->AddSSM(interface, *sourceAddr); + return group->AddSSM(*sourceAddr); case IP_DROP_SOURCE_MEMBERSHIP: - return group->DropSSM(interface, *sourceAddr); + return group->DropSSM(*sourceAddr); } return B_ERROR; @@ -866,22 +809,21 @@ const in_addr *sourceAddr) { IPv4MulticastFilter &filter = protocol->multicast_filter; - IPv4MulticastFilter::GroupState *group = NULL; + IPv4GroupInterface *state = NULL; + status_t status = B_OK; switch (option) { case IP_ADD_MEMBERSHIP: case IP_ADD_SOURCE_MEMBERSHIP: - group = filter.GetGroup(*groupAddr, true); - if (group == NULL) - return ENOBUFS; + status = filter.GetState(*groupAddr, interface, state, true); break; case IP_DROP_MEMBERSHIP: case IP_BLOCK_SOURCE: case IP_UNBLOCK_SOURCE: case IP_DROP_SOURCE_MEMBERSHIP: - group = filter.GetGroup(*groupAddr, false); - if (group == NULL) { + filter.GetState(*groupAddr, interface, state, false); + if (state == NULL) { if (option == IP_DROP_MEMBERSHIP || option == IP_DROP_SOURCE_MEMBERSHIP) return EADDRNOTAVAIL; @@ -891,10 +833,11 @@ break; } - status_t status = ipv4_delta_group(group, option, interface, sourceAddr); + if (status < B_OK) + return status; - filter.ReturnGroup(group); - + status = ipv4_delta_group(state, option, interface, sourceAddr); + filter.ReturnState(state); return status; } @@ -1590,11 +1533,18 @@ static int dump_ipv4_multicast(int argc, char *argv[]) { - MulticastGroups::Iterator it = sMulticastGroups->GetIterator(); + MulticastState::Iterator it = sMulticastState->GetIterator(); - while (it.HasNext()) - it.Next()->DumpInternalState(); + while (it.HasNext()) { + IPv4GroupInterface *state = it.Next(); + char addrBuf[64]; + + kprintf("%p: group <%s, %s> sock %p\n", state, + state->Interface()->name, print_address(&state->Address(), + addrBuf, sizeof(addrBuf)), state->Parent()->Socket()); + } + return 0; } @@ -1623,11 +1573,11 @@ if (status < B_OK) goto err3; - sMulticastGroups = new MulticastGroups(); - if (sMulticastGroups == NULL) + sMulticastState = new MulticastState(); + if (sMulticastState == NULL) goto err4; - status = sMulticastGroups->InitCheck(); + status = sMulticastState->InitCheck(); if (status < B_OK) goto err5; @@ -1659,7 +1609,7 @@ err6: hash_uninit(sFragmentHash); err5: - delete sMulticastGroups; + delete sMulticastState; err4: benaphore_destroy(&sReceivingProtocolLock); err3: @@ -1688,7 +1638,7 @@ gStackModule->unregister_domain(sDomain); benaphore_unlock(&sReceivingProtocolLock); - delete sMulticastGroups; + delete sMulticastState; hash_uninit(sFragmentHash); benaphore_destroy(&sMulticastGroupsLock); Modified: haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/multicast.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/multicast.cpp 2007-05-01 11:38:39 UTC (rev 20944) +++ haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/multicast.cpp 2007-05-01 11:38:59 UTC (rev 20945) @@ -23,230 +23,123 @@ using std::nothrow; -template -MulticastGroupInterfaceState::MulticastGroupInterfaceState( - net_interface *interface) - : fInterface(interface) -{ -} - - -template -MulticastGroupInterfaceState::~MulticastGroupInterfaceState() -{ - typename SourceList::Iterator iterator = fSources.GetIterator(); - while (iterator.HasNext()) { - _Remove(iterator.Next()); - } -} - - -template status_t -MulticastGroupInterfaceState::Add(const AddressType &address) -{ - return _Get(address, true) ? B_OK : ENOBUFS; -} - - -template status_t -MulticastGroupInterfaceState::Remove(const AddressType &address) -{ - Source *state = _Get(address, false); - if (state == NULL) - return EADDRNOTAVAIL; - - _Remove(state); - return B_OK; -} - - -template typename MulticastGroupInterfaceState::Source * -MulticastGroupInterfaceState::_Get(const AddressType &address, - bool create) -{ - typename SourceList::Iterator iterator = fSources.GetIterator(); - while (iterator.HasNext()) { - Source *state = iterator.Next(); - if (state->address == address) - return state; - } - - if (!create) - return false; - - Source *state = new (nothrow) Source; - if (state) { - state->address = address; - fSources.Add(state); - } - - return state; -} - - -template void -MulticastGroupInterfaceState::_Remove(Source *state) -{ - fSources.Remove(state); - delete state; -} - - template -MulticastGroupState::MulticastGroupState(ProtocolType *socket, - const AddressType &address) - : fSocket(socket), fMulticastAddress(address), fFilterMode(kInclude) +MulticastGroupInterface::MulticastGroupInterface(Filter *parent, + const AddressType &address, net_interface *interface) + : fParent(parent), fMulticastAddress(address), fInterface(interface) { } template -MulticastGroupState::~MulticastGroupState() +MulticastGroupInterface::~MulticastGroupInterface() { Clear(); } template status_t -MulticastGroupState::Add(net_interface *interface) +MulticastGroupInterface::Add() { - if (fFilterMode == kInclude && !fInterfaces.IsEmpty()) + if (fFilterMode == kInclude && !fAddresses.IsEmpty()) return EINVAL; fFilterMode = kExclude; - - return _GetInterface(interface, true) != NULL ? B_OK : ENOBUFS; + return B_OK; } template status_t -MulticastGroupState::Drop(net_interface *interface) +MulticastGroupInterface::Drop() { - InterfaceState *state = _GetInterface(interface, false); - if (state == NULL) - return EADDRNOTAVAIL; - - _RemoveInterface(state); - - if (fInterfaces.IsEmpty()) - fFilterMode = kInclude; - + fAddresses.Clear(); + fFilterMode = kInclude; return B_OK; } template status_t -MulticastGroupState::BlockSource(net_interface *interface, +MulticastGroupInterface::BlockSource( const AddressType &sourceAddress) { if (fFilterMode != kExclude) return EINVAL; - InterfaceState *state = _GetInterface(interface, false); - if (state == NULL) - return EINVAL; - - return state->Add(sourceAddress); + fAddresses.Add(sourceAddress); + return B_OK; } template status_t -MulticastGroupState::UnblockSource(net_interface *interface, +MulticastGroupInterface::UnblockSource( const AddressType &sourceAddress) { if (fFilterMode != kExclude) return EINVAL; - InterfaceState *state = _GetInterface(interface, false); - if (state == NULL) - return EINVAL; + if (!fAddresses.Has(sourceAddress)) + return EADDRNOTAVAIL; - return state->Remove(sourceAddress); + fAddresses.Add(sourceAddress); + return B_OK; } + template status_t -MulticastGroupState::AddSSM(net_interface *interface, - const AddressType &sourceAddress) +MulticastGroupInterface::AddSSM(const AddressType &sourceAddress) { if (fFilterMode == kExclude) return EINVAL; - InterfaceState *state = _GetInterface(interface, true); - if (state == NULL) - return ENOBUFS; - - return state->Add(sourceAddress); + fAddresses.Add(sourceAddress); + return B_OK; } template status_t -MulticastGroupState::DropSSM(net_interface *interface, - const AddressType &sourceAddress) +MulticastGroupInterface::DropSSM(const AddressType &sourceAddress) { if (fFilterMode == kExclude) return EINVAL; - InterfaceState *state = _GetInterface(interface, false); - if (state == NULL) + if (!fAddresses.Has(sourceAddress)) return EADDRNOTAVAIL; - return state->Remove(sourceAddress); + fAddresses.Add(sourceAddress); + return B_OK; } -template void -MulticastGroupState::Clear() +template bool +MulticastGroupInterface::IsEmpty() const { - typename InterfaceList::Iterator iterator = fInterfaces.GetIterator(); - while (iterator.HasNext()) - _RemoveInterface(iterator.Next()); + return fFilterMode == kInclude && fAddresses.IsEmpty(); } -template bool -MulticastGroupState::FilterAccepts(net_buffer *buffer) +template void +MulticastGroupInterface::Clear() { - InterfaceState *state = _GetInterface(buffer->interface, false); - if (state == NULL) - return false; + if (IsEmpty()) + return; - bool has = state->Contains(Addressing::AddressFromSockAddr( - (sockaddr *)&buffer->source)); - - return (has && fFilterMode == kInclude) || (!has && fFilterMode == kExclude); + fFilterMode = kInclude; + fAddresses.Clear(); + Addressing::LeaveGroup(this); } -template typename MulticastGroupState::InterfaceState * -MulticastGroupState::_GetInterface(net_interface *interface, - bool create) +template bool +MulticastGroupInterface::FilterAccepts(net_buffer *buffer) const { - typename InterfaceList::Iterator iterator = fInterfaces.GetIterator(); - while (iterator.HasNext()) { - InterfaceState *state = iterator.Next(); - if (state->Interface() == interface) - return state; - } + bool has = fAddresses.Has(Addressing::AddressFromSockAddr( + (sockaddr *)&buffer->source)); - if (!create) - return false; - - InterfaceState *state = new (nothrow) InterfaceState(interface); - if (state) - fInterfaces.Add(state); - - return state; + return (has && fFilterMode == kInclude) + || (!has && fFilterMode == kExclude); } -template void -MulticastGroupState::_RemoveInterface(InterfaceState *state) -{ - fInterfaces.Remove(state); - delete state; -} - - template MulticastFilter::MulticastFilter(ProtocolType *socket) : fParent(socket), fStates((size_t)0) @@ -262,56 +155,58 @@ if (!iterator.HasNext()) return; - GroupState *state = iterator.Next(); + GroupInterface *state = iterator.Next(); state->Clear(); - _ReturnGroup(state); + _ReturnState(state); } } -template typename MulticastFilter::GroupState * -MulticastFilter::GetGroup(const AddressType &groupAddress, - bool create) +template status_t +MulticastFilter::GetState(const AddressType &groupAddress, + net_interface *interface, GroupInterface* &state, bool create) { - GroupState *state = fStates.Lookup(groupAddress); - if (state) - return state; + state = fStates.Lookup(std::make_pair(&groupAddress, interface->index)); - if (create) { - state = new (nothrow) GroupState(fParent, groupAddress); - if (state) { - if (fStates.Insert(state) >= B_OK) { - if (Addressing::JoinGroup(state) >= B_OK) - return state; + if (state == NULL && create) { + state = new (nothrow) GroupInterface(this, groupAddress, interface); + if (state == NULL) + return B_NO_MEMORY; - fStates.Remove(state); - } + status_t status = fStates.Insert(state); + if (status < B_OK) { + delete state; + return status; + } + status = Addressing::JoinGroup(state); + if (status < B_OK) { + fStates.Remove(state); delete state; + return status; } + } - return NULL; + return B_OK; } template void -MulticastFilter::ReturnGroup(GroupState *group) +MulticastFilter::ReturnState(GroupInterface *state) { - if (group->IsEmpty()) - _ReturnGroup(group); + if (state->IsEmpty()) + _ReturnState(state); } template void -MulticastFilter::_ReturnGroup(GroupState *group) +MulticastFilter::_ReturnState(GroupInterface *state) { - Addressing::LeaveGroup(group); - fStates.Remove(group); - delete group; + fStates.Remove(state); + delete state; } // IPv4 explicit template instantiation template class MulticastFilter; -template class MulticastGroupState; -template class MulticastGroupInterfaceState; +template class MulticastGroupInterface; Modified: haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/multicast.h =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/multicast.h 2007-05-01 11:38:39 UTC (rev 20944) +++ haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/multicast.h 2007-05-01 11:38:59 UTC (rev 20945) @@ -12,25 +12,28 @@ #include #include +#include + #include +#include + struct net_buffer; -struct net_interface; struct net_protocol; // This code is template'ized as it is reusable for IPv6 template class MulticastFilter; -template class MulticastGroupState; +template class MulticastGroupInterface; // TODO move this elsewhere... struct IPv4Multicast { typedef struct in_addr AddressType; typedef struct ipv4_protocol ProtocolType; - typedef MulticastGroupState GroupState; + typedef MulticastGroupInterface GroupInterface; - static status_t JoinGroup(GroupState *); - static status_t LeaveGroup(GroupState *); + static status_t JoinGroup(GroupInterface *); + static status_t LeaveGroup(GroupInterface *); static const in_addr &AddressFromSockAddr(const sockaddr *sockaddr) { return ((const sockaddr_in *)sockaddr)->sin_addr; } @@ -39,106 +42,131 @@ }; template -struct MulticastSource - : DoublyLinkedListLinkImpl< MulticastSource > { - AddressType address; -}; - -template -class MulticastGroupInterfaceState - : public DoublyLinkedListLinkImpl< MulticastGroupInterfaceState > { +class AddressSet { public: - MulticastGroupInterfaceState(net_interface *interface); - ~MulticastGroupInterfaceState(); + struct ContainedAddress : DoublyLinkedListLinkImpl { + AddressType address; + }; - net_interface *Interface() const { return fInterface; } + ~AddressSet() { Clear(); } - status_t Add(const AddressType &address); - status_t Remove(const AddressType &address); + status_t Add(const AddressType &address) + { + if (Has(address)) + return B_OK; - bool Contains(const AddressType &address) - { return _Get(address, false) != NULL; } + ContainedAddress *container = new ContainedAddress(); + if (container == NULL) + return B_NO_MEMORY; + container->address = address; + fAddresses.Add(container); + + return B_OK; + } + + void Remove(const AddressType &address) + { + ContainedAddress *container = _Get(address); + if (container == NULL) + return; + + fAddresses.Remove(container); + delete container; + } + + bool Has(const AddressType &address) const + { + return _Get(address) != NULL; + } + + bool IsEmpty() const { return fAddresses.IsEmpty(); } + + void Clear() + { + while (!fAddresses.IsEmpty()) + Remove(fAddresses.Head()->address); + } + private: - typedef MulticastSource Source; - typedef DoublyLinkedList SourceList; + typedef DoublyLinkedList AddressList; - Source *_Get(const AddressType &address, bool create); - void _Remove(Source *state); + ContainedAddress *_Get(const AddressType &address) const + { + AddressList::ConstIterator it = fAddresses.GetIterator(); + while (it.HasNext()) { + ContainedAddress *container = it.Next(); + if (container->address == address) + return container; + } + return NULL; + } - net_interface *fInterface; - // TODO make this an hash table as well - SourceList fSources; + AddressList fAddresses; }; + template -class MulticastGroupState - : public DoublyLinkedListLinkImpl< MulticastGroupState > { +class MulticastGroupInterface + : public HashTableLink< MulticastGroupInterface > { public: - typedef MulticastGroupState ThisType; + typedef MulticastGroupInterface ThisType; typedef HashTableLink HashLink; typedef typename Addressing::AddressType AddressType; - typedef typename Addressing::ProtocolType ProtocolType; + typedef MulticastFilter Filter; - MulticastGroupState(ProtocolType *parent, const AddressType &address); - ~MulticastGroupState(); + enum FilterMode { + kInclude, + kExclude + }; - ProtocolType *Socket() const { return fSocket; } + MulticastGroupInterface(Filter *parent, const AddressType &address, + net_interface *interface); + ~MulticastGroupInterface(); + Filter *Parent() const { return fParent; } + const AddressType &Address() const { return fMulticastAddress; } - bool IsEmpty() const - { return fFilterMode == kInclude && fInterfaces.IsEmpty(); } + net_interface *Interface() const { return fInterface; } - status_t Add(net_interface *interface); - status_t Drop(net_interface *interface); - status_t BlockSource(net_interface *interface, - const AddressType &sourceAddress); - status_t UnblockSource(net_interface *interface, - const AddressType &sourceAddress); - status_t AddSSM(net_interface *interface, - const AddressType &sourceAddress); - status_t DropSSM(net_interface *interface, - const AddressType &sourceAddress); + status_t Add(); + status_t Drop(); + status_t BlockSource(const AddressType &sourceAddress); + status_t UnblockSource(const AddressType &sourceAddress); + status_t AddSSM(const AddressType &sourceAddress); + status_t DropSSM(const AddressType &sourceAddress); + bool IsEmpty() const; void Clear(); - bool FilterAccepts(net_buffer *buffer); + bool FilterAccepts(net_buffer *buffer) const; struct HashDefinition { typedef void ParentType; - typedef typename MulticastGroupState::AddressType KeyType; - typedef typename MulticastGroupState::ThisType ValueType; - typedef typename MulticastGroupState::HashLink HashLink; + typedef std::pair KeyType; + typedef ThisType ValueType; size_t HashKey(const KeyType &key) const - { return Addressing::HashAddress(key); } + { return Addressing::HashAddress(*key.first) ^ key.second; } [... truncated: 93 lines follow ...] From michael.pfeiffer at utanet.at Tue May 1 13:40:28 2007 From: michael.pfeiffer at utanet.at (Michael Pfeiffer) Date: Tue, 1 May 2007 13:40:28 +0200 Subject: [Haiku-commits] r20942 - in haiku/trunk/src: add-ons/print/drivers/shared/libprint add-ons/print/shared servers/print/shared In-Reply-To: <962569411-BeMail@zon> References: <962569411-BeMail@zon> Message-ID: <9B2CB1F6-E1E3-4FBD-B7DF-ED616C00D858@utanet.at> Am 01.05.2007 um 12:44 schrieb Axel D?rfler: > laplace at BerliOS wrote: >> +#ifndef __ZETA__ >> char* name; >> +#else >> + const char* name; >> +#endif > > The correct test would be #ifndef B_BEOS_VERSION_DANO as that one > introduced the "const" here. Thanks for the info. Will change it soon. Cheers, Michael From stefano.ceccherini at gmail.com Tue May 1 14:12:49 2007 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Tue, 1 May 2007 14:12:49 +0200 Subject: [Haiku-commits] r19701 - haiku/trunk/src/apps/bemail In-Reply-To: <1114097581-BeMail@zon> References: <4636F9AB.7080902@digintrans.com> <1114097581-BeMail@zon> Message-ID: <894b9700705010512h406f0a36if75bbdb69168e30c@mail.gmail.com> 2007/5/1, Axel D?rfler : > > Thanks, I'll look into it by the end of the week. I would guess that > only the mail add-ons are missing, anyway - but we'll see. The mail add-ons are indeed missing from the image. From hugosantos at mail.berlios.de Tue May 1 14:16:57 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Tue, 1 May 2007 14:16:57 +0200 Subject: [Haiku-commits] r20946 - in haiku/trunk: headers/private/kernel/util src/add-ons/kernel/network/protocols/ipv4 src/add-ons/kernel/network/protocols/tcp Message-ID: <200705011216.l41CGvl0006740@sheep.berlios.de> Author: hugosantos Date: 2007-05-01 14:16:36 +0200 (Tue, 01 May 2007) New Revision: 20946 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20946&view=rev Modified: haiku/trunk/headers/private/kernel/util/MultiHashTable.h haiku/trunk/headers/private/kernel/util/OpenHashTable.h haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/multicast.h haiku/trunk/src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp Log: added a ValueIterator to MultiHashTable to present a limited view in result of Lookup()s. Modified: haiku/trunk/headers/private/kernel/util/MultiHashTable.h =================================================================== --- haiku/trunk/headers/private/kernel/util/MultiHashTable.h 2007-05-01 11:38:59 UTC (rev 20945) +++ haiku/trunk/headers/private/kernel/util/MultiHashTable.h 2007-05-01 12:16:36 UTC (rev 20946) @@ -40,24 +40,6 @@ status_t InitCheck() const { return HashTable::InitCheck(); } - Iterator Lookup(const KeyType &key) const - { - size_t index = HashTable::fDefinition.HashKey(key) - & (HashTable::fTableSize - 1); - ValueType *slot = HashTable::fTable[index]; - - while (slot) { - if (HashTable::fDefinition.Compare(key, slot)) - break; - slot = HashTable::_Link(slot)->fNext; - } - - if (slot == NULL) - return Iterator(this, HashTable::fTableSize, NULL); - - return Iterator(this, index, slot); - } - void Insert(ValueType *value) { if (AutoExpand @@ -87,7 +69,63 @@ Iterator GetIterator() const { return HashTable::GetIterator(); } + class ValueIterator : protected Iterator { + public: + ValueIterator(const HashTable *table, size_t index, ValueType *value) + : fOriginalIndex(index), fOriginalValue(value) + { + Iterator::fTable = table; + Iterator::fIndex = index; + Iterator::fNext = value; + } + + bool HasNext() const + { + if (Iterator::fNext == NULL) + return false; + if (Iterator::fNext == fOriginalValue) + return true; + return ((const MultiTable *)Iterator::fTable)->_Definition().CompareValues( + fOriginalValue, Iterator::fNext); + } + + void Rewind() + { + Iterator::fIndex = fOriginalIndex; + Iterator::fNext = fOriginalValue; + } + + ValueType *Next() { return Iterator::Next(); } + + private: + size_t fOriginalIndex; + ValueType *fOriginalValue; + }; + + ValueIterator Lookup(const KeyType &key) const + { + size_t index = HashTable::fDefinition.HashKey(key) + & (HashTable::fTableSize - 1); + ValueType *slot = HashTable::fTable[index]; + + while (slot) { + if (HashTable::fDefinition.Compare(key, slot)) + break; + slot = HashTable::_Link(slot)->fNext; + } + + if (slot == NULL) + return ValueIterator(this, HashTable::fTableSize, NULL); + + return ValueIterator(this, index, slot); + } + private: + // for g++ 2.95 + friend class ValueIterator; + + const Definition &_Definition() const { return HashTable::fDefinition; } + void _Insert(ValueType **table, size_t tableSize, ValueType *value) { size_t index = HashTable::fDefinition.Hash(value) & (tableSize - 1); Modified: haiku/trunk/headers/private/kernel/util/OpenHashTable.h =================================================================== --- haiku/trunk/headers/private/kernel/util/OpenHashTable.h 2007-05-01 11:38:59 UTC (rev 20945) +++ haiku/trunk/headers/private/kernel/util/OpenHashTable.h 2007-05-01 12:16:36 UTC (rev 20946) @@ -207,7 +207,9 @@ _GetNext(); } - private: + protected: + Iterator() {} + void _GetNext() { if (fNext) Modified: haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp 2007-05-01 11:38:59 UTC (rev 20945) +++ haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp 2007-05-01 12:16:36 UTC (rev 20946) @@ -648,16 +648,12 @@ sockaddr_in *multicastAddr = (sockaddr_in *)&buffer->destination; - MulticastState::Iterator it = sMulticastState->Lookup(std::make_pair( + MulticastState::ValueIterator it = sMulticastState->Lookup(std::make_pair( &multicastAddr->sin_addr, buffer->interface->index)); while (it.HasNext()) { IPv4GroupInterface *state = it.Next(); - if (state->Interface()->index != buffer->interface->index - || state->Address().s_addr != multicastAddr->sin_addr.s_addr) - break; - if (deliverToRaw && state->Parent()->Socket()->raw == NULL) continue; Modified: haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/multicast.h =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/multicast.h 2007-05-01 11:38:59 UTC (rev 20945) +++ haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/multicast.h 2007-05-01 12:16:36 UTC (rev 20946) @@ -93,7 +93,7 @@ ContainedAddress *_Get(const AddressType &address) const { - AddressList::ConstIterator it = fAddresses.GetIterator(); + typename AddressList::ConstIterator it = fAddresses.GetIterator(); while (it.HasNext()) { ContainedAddress *container = it.Next(); if (container->address == address) Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp 2007-05-01 11:38:59 UTC (rev 20945) +++ haiku/trunk/src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp 2007-05-01 12:16:36 UTC (rev 20946) @@ -278,12 +278,10 @@ if (ntohs(port) <= kLastReservedPort && geteuid() != 0) return B_PERMISSION_DENIED; - EndpointTable::Iterator portUsers = fEndpointHash.Lookup(port); + EndpointTable::ValueIterator portUsers = fEndpointHash.Lookup(port); while (portUsers.HasNext()) { TCPEndpoint *user = portUsers.Next(); - if (user->LocalAddress().Port() != port) - break; if (user->LocalAddress().IsEmpty(false) || address.EqualTo(*user->LocalAddress(), false)) { From hugosantos at mail.berlios.de Tue May 1 14:26:23 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Tue, 1 May 2007 14:26:23 +0200 Subject: [Haiku-commits] r20947 - in haiku/trunk: headers/private/net src/add-ons/kernel/network/devices/ethernet src/add-ons/kernel/network/devices/loopback src/add-ons/kernel/network/stack Message-ID: <200705011226.l41CQNx9007361@sheep.berlios.de> Author: hugosantos Date: 2007-05-01 14:26:03 +0200 (Tue, 01 May 2007) New Revision: 20947 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20947&view=rev Modified: haiku/trunk/headers/private/net/net_device.h haiku/trunk/src/add-ons/kernel/network/devices/ethernet/ethernet.cpp haiku/trunk/src/add-ons/kernel/network/devices/loopback/loopback.cpp haiku/trunk/src/add-ons/kernel/network/stack/datalink.cpp Log: added add_multi/rem_multi to net_devices. Glued the interface protocol multicast handling with net_device via add_multi/rem_multi. Modified: haiku/trunk/headers/private/net/net_device.h =================================================================== --- haiku/trunk/headers/private/net/net_device.h 2007-05-01 12:16:36 UTC (rev 20946) +++ haiku/trunk/headers/private/net/net_device.h 2007-05-01 12:26:03 UTC (rev 20947) @@ -55,10 +55,8 @@ status_t (*set_promiscuous)(struct net_device *device, bool promiscuous); status_t (*set_media)(struct net_device *device, uint32 media); - status_t (*get_multicast_addrs)(struct net_device *device, - net_hardware_address **addressArray, uint32 count); - status_t (*set_multicast_addrs)(struct net_device *device, - const net_hardware_address **addressArray, uint32 count); + status_t (*add_multi)(struct net_device *device, const sockaddr *); + status_t (*rem_multi)(struct net_device *device, const sockaddr *); }; #endif // NET_DEVICE_H Modified: haiku/trunk/src/add-ons/kernel/network/devices/ethernet/ethernet.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/devices/ethernet/ethernet.cpp 2007-05-01 12:16:36 UTC (rev 20946) +++ haiku/trunk/src/add-ons/kernel/network/devices/ethernet/ethernet.cpp 2007-05-01 12:26:03 UTC (rev 20947) @@ -380,8 +380,7 @@ status_t -ethernet_get_multicast_addrs(struct net_device *device, - net_hardware_address **addressArray, uint32 count) +ethernet_add_multi(struct net_device *device, const sockaddr *address) { // TODO: see etherpci driver for details return EOPNOTSUPP; @@ -389,8 +388,7 @@ status_t -ethernet_set_multicast_addrs(struct net_device *device, - const net_hardware_address **addressArray, uint32 count) +ethernet_rem_multi(struct net_device *device, const sockaddr *address) { // TODO: see etherpci driver for details return EOPNOTSUPP; @@ -463,8 +461,8 @@ ethernet_set_mtu, ethernet_set_promiscuous, ethernet_set_media, - ethernet_get_multicast_addrs, - ethernet_set_multicast_addrs + ethernet_add_multi, + ethernet_rem_multi, }; module_info *modules[] = { Modified: haiku/trunk/src/add-ons/kernel/network/devices/loopback/loopback.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/devices/loopback/loopback.cpp 2007-05-01 12:16:36 UTC (rev 20946) +++ haiku/trunk/src/add-ons/kernel/network/devices/loopback/loopback.cpp 2007-05-01 12:26:03 UTC (rev 20947) @@ -192,6 +192,20 @@ } +status_t +loopback_add_multi(net_device *device, const sockaddr *address) +{ + return B_OK; +} + + +status_t +loopback_rem_multi(net_device *device, const sockaddr *address) +{ + return B_OK; +} + + static status_t loopback_std_ops(int32 op, ...) { @@ -222,6 +236,8 @@ loopback_set_mtu, loopback_set_promiscuous, loopback_set_media, + loopback_add_multi, + loopback_rem_multi, }; module_info *modules[] = { Modified: haiku/trunk/src/add-ons/kernel/network/stack/datalink.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/stack/datalink.cpp 2007-05-01 12:16:36 UTC (rev 20946) +++ haiku/trunk/src/add-ons/kernel/network/stack/datalink.cpp 2007-05-01 12:26:03 UTC (rev 20947) @@ -803,8 +803,8 @@ interface_protocol_join_multicast(net_datalink_protocol *_protocol, const sockaddr *address) { - // TODO - return ENOTSUP; + interface_protocol *protocol = (interface_protocol *)_protocol; + return protocol->device_module->add_multi(protocol->device, address); } @@ -812,8 +812,8 @@ interface_protocol_leave_multicast(net_datalink_protocol *_protocol, const sockaddr *address) { - // TODO - return ENOTSUP; + interface_protocol *protocol = (interface_protocol *)_protocol; + return protocol->device_module->rem_multi(protocol->device, address); } From hugosantos at mail.berlios.de Tue May 1 14:41:56 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Tue, 1 May 2007 14:41:56 +0200 Subject: [Haiku-commits] r20948 - haiku/trunk/src/add-ons/kernel/network/devices/ethernet Message-ID: <200705011241.l41Cfu9c008475@sheep.berlios.de> Author: hugosantos Date: 2007-05-01 14:41:44 +0200 (Tue, 01 May 2007) New Revision: 20948 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20948&view=rev Modified: haiku/trunk/src/add-ons/kernel/network/devices/ethernet/ethernet.cpp Log: ethernet_device's add_multi/rem_multi now call into the driver using the ETHER_ADDMULTI/ETHER_REMMULTI ioctls. Modified: haiku/trunk/src/add-ons/kernel/network/devices/ethernet/ethernet.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/devices/ethernet/ethernet.cpp 2007-05-01 12:26:03 UTC (rev 20947) +++ haiku/trunk/src/add-ons/kernel/network/devices/ethernet/ethernet.cpp 2007-05-01 12:41:44 UTC (rev 20948) @@ -380,18 +380,36 @@ status_t -ethernet_add_multi(struct net_device *device, const sockaddr *address) +ethernet_add_multi(struct net_device *_device, const sockaddr *_address) { - // TODO: see etherpci driver for details - return EOPNOTSUPP; + ethernet_device *device = (ethernet_device *)_device; + + if (_address->sa_family != AF_DLI) + return EINVAL; + + const sockaddr_dl *address = (const sockaddr_dl *)_address; + if (address->sdl_type != IFT_ETHER) + return EINVAL; + + return ioctl(device->fd, ETHER_ADDMULTI, address->sdl_data, + address->sdl_alen); } status_t -ethernet_rem_multi(struct net_device *device, const sockaddr *address) +ethernet_rem_multi(struct net_device *_device, const sockaddr *_address) { - // TODO: see etherpci driver for details - return EOPNOTSUPP; + ethernet_device *device = (ethernet_device *)_device; + + if (_address->sa_family != AF_DLI) + return EINVAL; + + const sockaddr_dl *address = (const sockaddr_dl *)_address; + if (address->sdl_type != IFT_ETHER) + return EINVAL; + + return ioctl(device->fd, ETHER_REMMULTI, address->sdl_data, + address->sdl_alen); } From hugosantos at mail.berlios.de Tue May 1 14:57:38 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Tue, 1 May 2007 14:57:38 +0200 Subject: [Haiku-commits] r20949 - in haiku/trunk/src/add-ons/kernel/network/datalink_protocols: ethernet_frame loopback_frame Message-ID: <200705011257.l41Cvc71009214@sheep.berlios.de> Author: hugosantos Date: 2007-05-01 14:57:26 +0200 (Tue, 01 May 2007) New Revision: 20949 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20949&view=rev Modified: haiku/trunk/src/add-ons/kernel/network/datalink_protocols/ethernet_frame/ethernet_frame.cpp haiku/trunk/src/add-ons/kernel/network/datalink_protocols/loopback_frame/loopback_frame.cpp Log: call the callbacks with ->next (...) Modified: haiku/trunk/src/add-ons/kernel/network/datalink_protocols/ethernet_frame/ethernet_frame.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/datalink_protocols/ethernet_frame/ethernet_frame.cpp 2007-05-01 12:41:44 UTC (rev 20948) +++ haiku/trunk/src/add-ons/kernel/network/datalink_protocols/ethernet_frame/ethernet_frame.cpp 2007-05-01 12:57:26 UTC (rev 20949) @@ -173,7 +173,7 @@ ethernet_frame_join_multicast(net_datalink_protocol *protocol, const sockaddr *address) { - return protocol->next->module->join_multicast(protocol, address); + return protocol->next->module->join_multicast(protocol->next, address); } @@ -181,7 +181,7 @@ ethernet_frame_leave_multicast(net_datalink_protocol *protocol, const sockaddr *address) { - return protocol->next->module->leave_multicast(protocol, address); + return protocol->next->module->leave_multicast(protocol->next, address); } Modified: haiku/trunk/src/add-ons/kernel/network/datalink_protocols/loopback_frame/loopback_frame.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/datalink_protocols/loopback_frame/loopback_frame.cpp 2007-05-01 12:41:44 UTC (rev 20948) +++ haiku/trunk/src/add-ons/kernel/network/datalink_protocols/loopback_frame/loopback_frame.cpp 2007-05-01 12:57:26 UTC (rev 20949) @@ -134,7 +134,7 @@ loopback_frame_join_multicast(net_datalink_protocol *protocol, const sockaddr *address) { - return protocol->next->module->join_multicast(protocol, address); + return protocol->next->module->join_multicast(protocol->next, address); } @@ -142,7 +142,7 @@ loopback_frame_leave_multicast(net_datalink_protocol *protocol, const sockaddr *address) { - return protocol->next->module->leave_multicast(protocol, address); + return protocol->next->module->leave_multicast(protocol->next, address); } From marcusoverhagen at mail.berlios.de Tue May 1 15:00:40 2007 From: marcusoverhagen at mail.berlios.de (marcusoverhagen at BerliOS) Date: Tue, 1 May 2007 15:00:40 +0200 Subject: [Haiku-commits] r20950 - haiku/trunk/src/system/kernel/debug Message-ID: <200705011300.l41D0eKo009710@sheep.berlios.de> Author: marcusoverhagen Date: 2007-05-01 15:00:33 +0200 (Tue, 01 May 2007) New Revision: 20950 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20950&view=rev Modified: haiku/trunk/src/system/kernel/debug/debug.c Log: Make no-settings-file defaults match the empty-settings-file defaults. Modified: haiku/trunk/src/system/kernel/debug/debug.c =================================================================== --- haiku/trunk/src/system/kernel/debug/debug.c 2007-05-01 12:57:26 UTC (rev 20949) +++ haiku/trunk/src/system/kernel/debug/debug.c 2007-05-01 13:00:33 UTC (rev 20950) @@ -46,8 +46,8 @@ int dbg_register_file[B_MAX_CPU_COUNT][14]; /* XXXmpetit -- must be made generic */ -static bool sSerialDebugEnabled = false; -static bool sSyslogOutputEnabled = false; +static bool sSerialDebugEnabled = true; +static bool sSyslogOutputEnabled = true; static bool sBlueScreenEnabled = false; static bool sDebugScreenEnabled = false; static bool sBlueScreenOutput = true; From mmlr at mail.berlios.de Tue May 1 15:06:58 2007 From: mmlr at mail.berlios.de (mmlr at BerliOS) Date: Tue, 1 May 2007 15:06:58 +0200 Subject: [Haiku-commits] r20951 - in haiku/trunk/src/tests/add-ons/kernel: . busses busses/scsi busses/scsi/example Message-ID: <200705011306.l41D6wnO010229@sheep.berlios.de> Author: mmlr Date: 2007-05-01 15:06:57 +0200 (Tue, 01 May 2007) New Revision: 20951 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20951&view=rev Added: haiku/trunk/src/tests/add-ons/kernel/busses/ haiku/trunk/src/tests/add-ons/kernel/busses/Jamfile haiku/trunk/src/tests/add-ons/kernel/busses/scsi/ haiku/trunk/src/tests/add-ons/kernel/busses/scsi/Jamfile haiku/trunk/src/tests/add-ons/kernel/busses/scsi/example/ haiku/trunk/src/tests/add-ons/kernel/busses/scsi/example/Jamfile haiku/trunk/src/tests/add-ons/kernel/busses/scsi/example/example_scsi.c Modified: haiku/trunk/src/tests/add-ons/kernel/Jamfile Log: Commiting an example SCSI driver written to understand the new SCSI API. But the module isn't used even when installed and linked as a boot driver. Modified: haiku/trunk/src/tests/add-ons/kernel/Jamfile =================================================================== --- haiku/trunk/src/tests/add-ons/kernel/Jamfile 2007-05-01 13:00:33 UTC (rev 20950) +++ haiku/trunk/src/tests/add-ons/kernel/Jamfile 2007-05-01 13:06:57 UTC (rev 20951) @@ -23,6 +23,7 @@ list.c khash.c ] = [ FDirName $(HAIKU_TOP) src system kernel util ] ; +SubInclude HAIKU_TOP src tests add-ons kernel busses ; # SubInclude HAIKU_TOP src tests add-ons kernel disk_scanner ; SubInclude HAIKU_TOP src tests add-ons kernel drivers ; SubInclude HAIKU_TOP src tests add-ons kernel file_systems ; Added: haiku/trunk/src/tests/add-ons/kernel/busses/Jamfile =================================================================== --- haiku/trunk/src/tests/add-ons/kernel/busses/Jamfile 2007-05-01 13:00:33 UTC (rev 20950) +++ haiku/trunk/src/tests/add-ons/kernel/busses/Jamfile 2007-05-01 13:06:57 UTC (rev 20951) @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src tests add-ons kernel busses ; + +SubInclude HAIKU_TOP src tests add-ons kernel busses scsi ; Added: haiku/trunk/src/tests/add-ons/kernel/busses/scsi/Jamfile =================================================================== --- haiku/trunk/src/tests/add-ons/kernel/busses/scsi/Jamfile 2007-05-01 13:00:33 UTC (rev 20950) +++ haiku/trunk/src/tests/add-ons/kernel/busses/scsi/Jamfile 2007-05-01 13:06:57 UTC (rev 20951) @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src tests add-ons kernel busses scsi ; + +SubInclude HAIKU_TOP src tests add-ons kernel busses scsi example ; Added: haiku/trunk/src/tests/add-ons/kernel/busses/scsi/example/Jamfile =================================================================== --- haiku/trunk/src/tests/add-ons/kernel/busses/scsi/example/Jamfile 2007-05-01 13:00:33 UTC (rev 20950) +++ haiku/trunk/src/tests/add-ons/kernel/busses/scsi/example/Jamfile 2007-05-01 13:06:57 UTC (rev 20951) @@ -0,0 +1,5 @@ +SubDir HAIKU_TOP src tests add-ons kernel busses scsi example ; + +KernelAddon example_scsi : + example_scsi.c +; Added: haiku/trunk/src/tests/add-ons/kernel/busses/scsi/example/example_scsi.c =================================================================== --- haiku/trunk/src/tests/add-ons/kernel/busses/scsi/example/example_scsi.c 2007-05-01 13:00:33 UTC (rev 20950) +++ haiku/trunk/src/tests/add-ons/kernel/busses/scsi/example/example_scsi.c 2007-05-01 13:06:57 UTC (rev 20951) @@ -0,0 +1,220 @@ +/* + * Copyright 2007, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Michael Lotz + */ +#include +#include +#include + + +#define MODULE_NAME "example_scsi" + + +static scsi_for_sim_interface *sSimInterface; +static device_manager_info *sDeviceManager; + + +// module functions +static status_t +example_std_ops(int32 op, ...) +{ + dprintf(MODULE_NAME": std ops\n"); + + switch (op) { + case B_MODULE_INIT: { + dprintf(MODULE_NAME": B_MODULE_INIT\n"); + return B_OK; + } + + case B_MODULE_UNINIT: { + dprintf(MODULE_NAME": B_MODULE_UNINIT\n"); + return B_OK; + } + } + + return B_ERROR; +} + + +// driver functions +static float +example_supports_device(device_node_handle parent, bool *noConnection) +{ + dprintf(MODULE_NAME": supports device\n"); + return 0.0f; +} + + +static status_t +example_register_device(device_node_handle parent) +{ + dprintf(MODULE_NAME": register device\n"); + return B_OK; +} + + +static status_t +example_init_driver(device_node_handle node, void *userCookie, void **cookie) +{ + dprintf(MODULE_NAME": init driver\n"); + return B_OK; +} + + +static status_t +example_uninit_driver(void *cookie) +{ + dprintf(MODULE_NAME": uninit driver\n"); + return B_OK; +} + + +static void +example_device_removed(device_node_handle node, void *cookie) +{ + dprintf(MODULE_NAME": device removed\n"); +} + + +static void +example_device_cleanup(device_node_handle node) +{ + dprintf(MODULE_NAME": device cleanup\n"); +} + + +static void +example_get_supported_paths(const char ***busses, const char ***devices) +{ + static const char *sBusses[] = { "pci", NULL }; + static const char *sDevices[] = { "drivers/dev/example", NULL }; + + dprintf(MODULE_NAME": get supported paths\n"); + *busses = sBusses; + *devices = sDevices; +} + + +// sim functions +static void +example_scsi_io(scsi_sim_cookie cookie, scsi_ccb *ccb) +{ + dprintf(MODULE_NAME": scsi io\n"); +} + + +static uchar +example_abort(scsi_sim_cookie cookie, scsi_ccb *ccbToAbort) +{ + dprintf(MODULE_NAME": abort\n"); + return 0; +} + + +static uchar +example_reset_device(scsi_sim_cookie cookie, uchar targetID, uchar targetLUN) +{ + dprintf(MODULE_NAME": reset device\n"); + return 0; +} + + +static uchar +example_term_io(scsi_sim_cookie cookie, scsi_ccb *ccbToTerminate) +{ + dprintf(MODULE_NAME": terminate io\n"); + return 0; +} + + +static uchar +example_path_inquiry(scsi_sim_cookie cookie, scsi_path_inquiry *inquiryData) +{ + dprintf(MODULE_NAME": path inquiry\n"); + return 0; +} + + +static uchar +example_scan_bus(scsi_sim_cookie cookie) +{ + dprintf(MODULE_NAME": scan bus\n"); + return 0; +} + + +static uchar +example_reset_bus(scsi_sim_cookie cookie) +{ + dprintf(MODULE_NAME": reset bus\n"); + return 0; +} + + +static void +example_get_restrictions(scsi_sim_cookie cookie, uchar targetID, bool *isATAPI, + bool *noAutosense, uint32 *maxBlocks) +{ + dprintf(MODULE_NAME": get restrictions\n"); +} + + +static status_t +example_ioctl(scsi_sim_cookie cookie, uint8 targetID, uint32 op, void *buffer, + size_t bufferLength) +{ + dprintf(MODULE_NAME": io control\n"); + return B_ERROR; +} + + +// module management +module_dependency module_dependencies[] = { + { SCSI_FOR_SIM_MODULE_NAME, (module_info **)&sSimInterface }, + { B_DEVICE_MANAGER_MODULE_NAME, (module_info **)&sDeviceManager }, + {} +}; + + +scsi_sim_interface example_sim = { + { // driver_module_info + { // module_info + "busses/scsi/example/v1", // module name + 0, // module flags + example_std_ops // module standard ops + }, + + example_supports_device, // supports device + example_register_device, // register device + + example_init_driver, // init driver + example_uninit_driver, // uninit driver + + example_device_removed, // device removed + example_device_cleanup, // device cleanup + + example_get_supported_paths // get supported paths + }, + + example_scsi_io, // scsi io + example_abort, // abort + example_reset_device, // reset device + example_term_io, // terminate io + + example_path_inquiry, // path inquiry + example_scan_bus, // scan bus + example_reset_bus, // reset bus + + example_get_restrictions, // get restrictions + + example_ioctl // io control +}; + + +module_info *modules[] = { + (module_info *)&example_sim, + NULL +}; From mmlr at mlotz.ch Tue May 1 15:10:06 2007 From: mmlr at mlotz.ch (Michael Lotz) Date: Tue, 01 May 2007 15:10:06 +0200 CEST Subject: [Haiku-commits] =?windows-1252?q?r20951_-_in_haiku/trunk/src/test?= =?windows-1252?q?s/add-ons/kernel=3A_=2E_busses__busses/scsi_busses/scsi/?= =?windows-1252?q?example?= In-Reply-To: <200705011306.l41D6wnO010229@sheep.berlios.de> Message-ID: <13309368483-BeMail@primary> Hi > Commiting an example SCSI driver written to understand the new SCSI > API. But the module isn't used even when installed and linked as a boot driver. As stated in the commit log, the module isn't picked up at boot. Does anyone have an insight on how to get a SCSI SIM module used by the SCSI subsystem? I'd like to port over the usb_scsi module to the new SCSI module API to get USB boot working, but the driver simply isn't used by the bus manager. Any comments welcome. Regards Michael From zharik at gmx.li Tue May 1 16:42:13 2007 From: zharik at gmx.li (Siarzhuk Zharski) Date: Tue, 01 May 2007 16:42:13 +0200 Subject: [Haiku-commits] r20951 - in haiku/trunk/src/tests/add-ons/kernel: . busses busses/scsi busses/scsi/example In-Reply-To: <13309368483-BeMail@primary> References: <13309368483-BeMail@primary> Message-ID: <463751C5.20104@gmx.li> Hi! Michael Lotz wrote: > I'd like to port over the usb_scsi module to the new SCSI module API to > get USB boot working, but the driver simply isn't used by the bus > manager. Any comments welcome. > Ups... Some days ago I began to look into those usb_scsi module sources. ;-D Just wanted to adapt it for Haiku too. If you don't mind and not spent already lot of effort on it - I'll do this work for you. ;-) PS: If you agree to left this task for me - please reassign ticket #1106 to me (siarzhuk). Thank you. Kind Regards, S.Zharski. From axeld at pinc-software.de Tue May 1 17:07:16 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Tue, 01 May 2007 17:07:16 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r20947_-_in_haiku/trunk=3A_header?= =?iso-8859-15?q?s/private/net_src/add-ons/kernel/network/devices/ethernet?= =?iso-8859-15?q?_src/add-ons/kernel/network/devices/loopback_src/add-ons/?= =?iso-8859-15?q?kernel/network/stack?= In-Reply-To: <200705011226.l41CQNx9007361@sheep.berlios.de> Message-ID: <16714011049-BeMail@zon> hugosantos at mail.berlios.de wrote: > + status_t (*add_multi)(struct net_device *device, const sockaddr > *); > + status_t (*rem_multi)(struct net_device *device, const sockaddr > *); What about a bit more meaningful names like add_multicast_address()? Bye, Axel. From hugosantos at gmail.com Tue May 1 17:12:05 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Tue, 1 May 2007 16:12:05 +0100 Subject: [Haiku-commits] r20947 - in haiku/trunk: headers/private/net src/add-ons/kernel/network/devices/ethernet src/add-ons/kernel/network/devices/loopback src/add-ons/kernel/network/stack In-Reply-To: <16714011049-BeMail@zon> References: <200705011226.l41CQNx9007361@sheep.berlios.de> <16714011049-BeMail@zon> Message-ID: <9c46321e0705010812x2735b847y671621753fdaecb8@mail.gmail.com> I called them add_multi/rem_multi to follow the ioctl names, ADDMULTI and REMMULTI. I also find add_multicast_address to be too long: return protocol->device_module->add_multicast_address(protocol->device, address); Hugo On 5/1/07, Axel D?rfler wrote: > hugosantos at mail.berlios.de wrote: > > + status_t (*add_multi)(struct net_device *device, const sockaddr > > *); > > + status_t (*rem_multi)(struct net_device *device, const sockaddr > > *); > > What about a bit more meaningful names like add_multicast_address()? > > Bye, > Axel. > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From hugosantos at mail.berlios.de Tue May 1 17:16:04 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Tue, 1 May 2007 17:16:04 +0200 Subject: [Haiku-commits] r20952 - haiku/trunk/src/add-ons/kernel/network/protocols/ipv4 Message-ID: <200705011516.l41FG456003421@sheep.berlios.de> Author: hugosantos Date: 2007-05-01 17:15:47 +0200 (Tue, 01 May 2007) New Revision: 20952 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20952&view=rev Modified: haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp Log: select the default interface to be used for multicast through a routing table query. Modified: haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp 2007-05-01 13:06:57 UTC (rev 20951) +++ haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp 2007-05-01 15:15:47 UTC (rev 20952) @@ -860,6 +860,24 @@ } +static net_interface * +get_multicast_interface(ipv4_protocol *protocol, const in_addr *address) +{ + sockaddr_in groupAddr; + memset(&groupAddr, 0, sizeof(groupAddr)); + groupAddr.sin_family = AF_INET; + if (address) + groupAddr.sin_addr = *address; + + net_route *route = sDatalinkModule->get_route(sDomain, + (sockaddr *)&groupAddr); + if (route == NULL) + return NULL; + + return route->interface; +} + + static status_t ipv4_delta_membership(ipv4_protocol *protocol, int option, in_addr *interfaceAddr, in_addr *groupAddr, in_addr *sourceAddr) @@ -867,7 +885,7 @@ net_interface *interface = NULL; if (interfaceAddr->s_addr == INADDR_ANY) { - interface = sDatalinkModule->get_interface_with_address(sDomain, NULL); + interface = get_multicast_interface(protocol, groupAddr); } else { sockaddr_in address; fill_sockaddr_in(&address, interfaceAddr->s_addr); From korli at mail.berlios.de Tue May 1 19:30:29 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Tue, 1 May 2007 19:30:29 +0200 Subject: [Haiku-commits] r20953 - haiku/trunk/build/jam Message-ID: <200705011730.l41HUT6P030379@sheep.berlios.de> Author: korli Date: 2007-05-01 19:30:29 +0200 (Tue, 01 May 2007) New Revision: 20953 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20953&view=rev Modified: haiku/trunk/build/jam/HaikuImage Log: added mail_daemon addons Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2007-05-01 15:15:47 UTC (rev 20952) +++ haiku/trunk/build/jam/HaikuImage 2007-05-01 17:30:29 UTC (rev 20953) @@ -288,6 +288,11 @@ : $(X86_ONLY)Mesa\ Software\ Renderer ; AddFilesToHaikuImage beos system add-ons Translators : $(BEOS_ADD_ONS_TRANSLATORS) ; +AddFilesToHaikuImage beos system add-ons mail_daemon inbound_protocols : POP3 IMAP ; +AddFilesToHaikuImage beos system add-ons mail_daemon outbound_protocols : SMTP ; +AddFilesToHaikuImage beos system add-ons mail_daemon inbound_filters : Match\ Header Spam\ Filter R5\ Daemon\ Filter ; +AddFilesToHaikuImage beos system add-ons mail_daemon outbound_filters : Fortune ; +AddFilesToHaikuImage beos system add-ons mail_daemon system_filters : Inbox New\ Mail\ Notification Outbox Message\ Parser ; AddFilesToHaikuImage beos system add-ons media : $(BEOS_ADD_ONS_MEDIA) ; AddFilesToHaikuImage beos system add-ons media plugins : $(BEOS_ADD_ONS_MEDIA_PLUGINS) ; From marcusoverhagen at arcor.de Tue May 1 19:51:08 2007 From: marcusoverhagen at arcor.de (Marcus Overhagen) Date: Tue, 1 May 2007 19:51:08 +0200 (CEST) Subject: [Haiku-commits] (no subject) In-Reply-To: <13309368483-BeMail@primary> References: <13309368483-BeMail@primary> Message-ID: <12488931.1178041868080.JavaMail.ngmail@webmail13> try to list it in build/jam/HaikuImage section AddBootModuleSymlinks ----- Original Nachricht ---- Von: Michael Lotz An: SVN commits to the Haiku source repository Datum: 01.05.2007 15:10 Betreff: Re: [Haiku-commits] r20951 - in haiku/trunk/src/tests/add-ons/kernel: . busses busses/scsi busses/scsi/example > Hi > > > Commiting an example SCSI driver written to understand the new SCSI > > API. But the module isn't used even when installed and linked as a boot > driver. > > As stated in the commit log, the module isn't picked up at boot. Does > anyone have an insight on how to get a SCSI SIM module used by the SCSI > subsystem? > I'd like to port over the usb_scsi module to the new SCSI module API to > get USB boot working, but the driver simply isn't used by the bus > manager. Any comments welcome. > > Regards > Michael > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > 50? AMAZON-Einkaufsgutschein bei Bestellung von Arcor-DSL: Viel oder wenig? Schnell oder langsam? Unbegrenzt surfen + telefonieren ohne Zeit- und Volumenbegrenzung? DAS TOP ANGEBOT JETZT bei Arcor: g?nstig und schnell mit DSL - das All-Inclusive-Paket f?r clevere Doppel-Sparer, nur 39,85 ? inkl. DSL- und ISDN-Grundgeb?hr! http://www.arcor.de/rd/emf-dsl-2 From marcusoverhagen at mail.berlios.de Tue May 1 20:10:12 2007 From: marcusoverhagen at mail.berlios.de (marcusoverhagen at BerliOS) Date: Tue, 1 May 2007 20:10:12 +0200 Subject: [Haiku-commits] r20954 - haiku/trunk/src/servers/syslog_daemon Message-ID: <200705011810.l41IACah000212@sheep.berlios.de> Author: marcusoverhagen Date: 2007-05-01 20:10:12 +0200 (Tue, 01 May 2007) New Revision: 20954 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20954&view=rev Modified: haiku/trunk/src/servers/syslog_daemon/syslog_output.cpp Log: insert the missing space Modified: haiku/trunk/src/servers/syslog_daemon/syslog_output.cpp =================================================================== --- haiku/trunk/src/servers/syslog_daemon/syslog_output.cpp 2007-05-01 17:30:29 UTC (rev 20953) +++ haiku/trunk/src/servers/syslog_daemon/syslog_output.cpp 2007-05-01 18:10:12 UTC (rev 20954) @@ -126,7 +126,7 @@ // parse & nicely print the time stamp from the message struct tm when; localtime_r(&message.when, &when); - pos = strftime(header, sizeof(header), "%Y-%m-%d %H:%M:%S", &when); + pos = strftime(header, sizeof(header), "%Y-%m-%d %H:%M:%S ", &when); } // add facility From marcusoverhagen at mail.berlios.de Tue May 1 20:13:02 2007 From: marcusoverhagen at mail.berlios.de (marcusoverhagen at BerliOS) Date: Tue, 1 May 2007 20:13:02 +0200 Subject: [Haiku-commits] r20955 - haiku/trunk/src/system/kernel/debug Message-ID: <200705011813.l41ID2e3000511@sheep.berlios.de> Author: marcusoverhagen Date: 2007-05-01 20:13:01 +0200 (Tue, 01 May 2007) New Revision: 20955 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20955&view=rev Modified: haiku/trunk/src/system/kernel/debug/debug.c Log: restore previous serial debug output setting when leaving kernel debugger Modified: haiku/trunk/src/system/kernel/debug/debug.c =================================================================== --- haiku/trunk/src/system/kernel/debug/debug.c 2007-05-01 18:10:12 UTC (rev 20954) +++ haiku/trunk/src/system/kernel/debug/debug.c 2007-05-01 18:13:01 UTC (rev 20955) @@ -855,8 +855,6 @@ { va_list args; char temp[128]; - - set_dprintf_enabled(true); va_start(args, format); vsnprintf(temp, sizeof(temp), format, args); @@ -870,9 +868,10 @@ kernel_debugger(const char *message) { cpu_status state; + bool dprintfState; arch_debug_save_registers(&dbg_register_file[smp_get_current_cpu()][0]); - set_dprintf_enabled(true); + dprintfState = set_dprintf_enabled(true); state = disable_interrupts(); @@ -894,6 +893,8 @@ kernel_debugger_loop(); + set_dprintf_enabled(dprintfState); + sBlueScreenEnabled = false; restore_interrupts(state); From mmlr at mlotz.ch Tue May 1 20:17:50 2007 From: mmlr at mlotz.ch (Michael Lotz) Date: Tue, 01 May 2007 20:17:50 +0200 CEST Subject: [Haiku-commits] (no subject) In-Reply-To: <12488931.1178041868080.JavaMail.ngmail@webmail13> Message-ID: <1998602103-BeMail@primary> Hi Marcus Yes, I tried that, but it didn't seem to be loaded. No output was generated. I have looked at the SCSI bus_manager, but as far as I can tell, it doesn't explicitly look for modules. In the USB bus manager bus modules are looked up with open_module_list(), but I couldn't find anything like this in the SCSI bus manager. I guess the SIM module needs to register itself in the SCSI bus manager, but how to do that if the module never get's loaded in the first place. Regards Michael > > try to list it in build/jam/HaikuImage section AddBootModuleSymlinks > > ----- Original Nachricht ---- > Von: Michael Lotz > An: SVN commits to the Haiku source repository > > Datum: 01.05.2007 15:10 > Betreff: Re: [Haiku-commits] > r20951 - in haiku/trunk/src/tests/add-ons/kernel: . busses busses/ > scsi busses/scsi/example > > > Hi > > > > > Commiting an example SCSI driver written to understand the new > > > SCSI > > > API. But the module isn't used even when installed and linked as > > > a boot > > driver. > > > > As stated in the commit log, the module isn't picked up at boot. > > Does > > anyone have an insight on how to get a SCSI SIM module used by the > > SCSI > > subsystem? > > I'd like to port over the usb_scsi module to the new SCSI module > > API to > > get USB boot working, but the driver simply isn't used by the bus > > manager. Any comments welcome. > > > > Regards > > Michael > > _______________________________________________ > > Haiku-commits mailing list > > Haiku-commits at lists.berlios.de > > https://lists.berlios.de/mailman/listinfo/haiku-commits > > > > 50? AMAZON-Einkaufsgutschein bei Bestellung von Arcor-DSL: > Viel oder wenig? Schnell oder langsam? Unbegrenzt surfen + > telefonieren > ohne Zeit- und Volumenbegrenzung? DAS TOP ANGEBOT JETZT bei Arcor: > g?nstig > und schnell mit DSL - das All-Inclusive-Paket f?r clevere Doppel- > Sparer, > nur 39,85 ? inkl. DSL- und ISDN-Grundgeb?hr! > http://www.arcor.de/rd/emf-dsl-2 > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits From korli at mail.berlios.de Tue May 1 20:34:45 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Tue, 1 May 2007 20:34:45 +0200 Subject: [Haiku-commits] r20956 - haiku/trunk/src/servers/input Message-ID: <200705011834.l41IYjn1002439@sheep.berlios.de> Author: korli Date: 2007-05-01 20:34:45 +0200 (Tue, 01 May 2007) New Revision: 20956 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20956&view=rev Modified: haiku/trunk/src/servers/input/InputServer.h Log: added a commented option to activate input_server serial log Modified: haiku/trunk/src/servers/input/InputServer.h =================================================================== --- haiku/trunk/src/servers/input/InputServer.h 2007-05-01 18:13:01 UTC (rev 20955) +++ haiku/trunk/src/servers/input/InputServer.h 2007-05-01 18:34:45 UTC (rev 20956) @@ -5,6 +5,7 @@ #ifndef INPUT_SERVER_APP_H #define INPUT_SERVER_APP_H +// #define DEBUG 1 #include "AddOnManager.h" #include "DeviceManager.h" From korli at mail.berlios.de Tue May 1 20:58:22 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Tue, 1 May 2007 20:58:22 +0200 Subject: [Haiku-commits] r20957 - haiku/trunk/build/jam Message-ID: <200705011858.l41IwMet004217@sheep.berlios.de> Author: korli Date: 2007-05-01 20:58:22 +0200 (Tue, 01 May 2007) New Revision: 20957 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20957&view=rev Modified: haiku/trunk/build/jam/HaikuImage Log: added an empty input methods system directory, to be able to add the canna IM in fact, the directory is only monitored when existing Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2007-05-01 18:34:45 UTC (rev 20956) +++ haiku/trunk/build/jam/HaikuImage 2007-05-01 18:58:22 UTC (rev 20957) @@ -322,6 +322,7 @@ AddDirectoryToHaikuImage home config add-ons Screen\ Savers ; AddDirectoryToHaikuImage home config add-ons Translators ; AddDirectoryToHaikuImage beos etc synth ; +AddDirectoryToHaikuImage beos system add-ons input_server methods ; #optional AddFilesToHaikuImage optional beos system add-ons input_server methods : canna ; From koki at digintrans.com Tue May 1 21:27:53 2007 From: koki at digintrans.com (Jorge G. Mare (a.k.a. Koki)) Date: Tue, 01 May 2007 12:27:53 -0700 Subject: [Haiku-commits] r20957 - haiku/trunk/build/jam In-Reply-To: <200705011858.l41IwMet004217@sheep.berlios.de> References: <200705011858.l41IwMet004217@sheep.berlios.de> Message-ID: <463794B9.6070208@digintrans.com> korli at BerliOS wrote: > Author: korli > Date: 2007-05-01 20:58:22 +0200 (Tue, 01 May 2007) > New Revision: 20957 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20957&view=rev > > Modified: > haiku/trunk/build/jam/HaikuImage > Log: > added an empty input methods system directory, to be able to add the canna IM > in fact, the directory is only monitored when existing > Korli, thanks a lot! I just tried it and "It Just Works" including the loading of the Deskbar replicant! :) Cheers, Koki From marcusoverhagen at mail.berlios.de Tue May 1 21:57:18 2007 From: marcusoverhagen at mail.berlios.de (marcusoverhagen at BerliOS) Date: Tue, 1 May 2007 21:57:18 +0200 Subject: [Haiku-commits] r20958 - haiku/trunk/src/add-ons/kernel/bus_managers/ps2 Message-ID: <200705011957.l41JvIcR009907@sheep.berlios.de> Author: marcusoverhagen Date: 2007-05-01 21:57:18 +0200 (Tue, 01 May 2007) New Revision: 20958 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20958&view=rev Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_mouse.c Log: reduce timeout to 150ms inside close hook, the mouse might already be gone Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_mouse.c =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_mouse.c 2007-05-01 18:58:22 UTC (rev 20957) +++ haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_mouse.c 2007-05-01 19:57:18 UTC (rev 20958) @@ -415,7 +415,7 @@ TRACE("ps2: mouse_close %s enter\n", cookie->dev->name); - ps2_dev_command(cookie->dev, PS2_CMD_DISABLE, NULL, 0, NULL, 0); + ps2_dev_command_timeout(cookie->dev, PS2_CMD_DISABLE, NULL, 0, NULL, 0, 150000); delete_packet_buffer(cookie->mouse_buffer); delete_sem(cookie->mouse_sem); From marcusoverhagen at mail.berlios.de Wed May 2 01:03:41 2007 From: marcusoverhagen at mail.berlios.de (marcusoverhagen at BerliOS) Date: Wed, 2 May 2007 01:03:41 +0200 Subject: [Haiku-commits] r20959 - haiku/trunk/src/add-ons/kernel/bus_managers/ps2 Message-ID: <200705012303.l41N3fZj013266@sheep.berlios.de> Author: marcusoverhagen Date: 2007-05-02 01:03:40 +0200 (Wed, 02 May 2007) New Revision: 20959 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20959&view=rev Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_service.c Log: delay device publishing by 1 second, for better testing of possible input server race condition Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_service.c =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_service.c 2007-05-01 19:57:18 UTC (rev 20958) +++ haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_service.c 2007-05-01 23:03:40 UTC (rev 20959) @@ -104,6 +104,7 @@ packet_buffer_read(sServiceCmdBuffer, (uint8 *)&cmd, sizeof(cmd)); switch (cmd.id) { case PS2_SERVICE_NOTIFY_DEVICE_ADDED: + snooze(1000000); // for better testing of possible input server race condition TRACE("ps2: PS2_SERVICE_NOTIFY_DEVICE_ADDED %s\n", cmd.dev->name); ps2_dev_publish(cmd.dev); break; From agmsmith at rogers.com Wed May 2 01:48:28 2007 From: agmsmith at rogers.com (Alexander G. M. Smith) Date: Tue, 01 May 2007 19:48:28 -0400 EDT Subject: [Haiku-commits] =?iso-8859-1?q?r20947_-_in_haiku/trunk=3A_headers?= =?iso-8859-1?q?/private/net_src/add-ons/kernel/network/devices/ethernet_s?= =?iso-8859-1?q?rc/add-ons/kernel/network/devices/loopback_src/add-ons/ker?= =?iso-8859-1?q?nel/network/stack?= In-Reply-To: <9c46321e0705010812x2735b847y671621753fdaecb8@mail.gmail.com> Message-ID: <163426214138-BeMail@cr593174-a> > On 5/1/07, Axel D?rfler wrote: > > What about a bit more meaningful names like add_multicast_address()? Hugo Santos wrote on Tue, 1 May 2007 16:12:05 +0100: > I called them add_multi/rem_multi to follow the ioctl names, ADDMULTI > and REMMULTI. I also find add_multicast_address to be too long: > > return protocol->device_module->add_multicast_address(protocol->device, > address); I agree with Axel about using more readable meaningful names when possible. But then I'm perhaps a bit over the top with my ultra mega verbose coding style, at least compared to most programmers. My thesis advisor did get me to avoid using abbreviations as names, so maybe that's where UMV coding comes from. :-) - Alex From hugosantos at gmail.com Wed May 2 02:05:45 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Wed, 2 May 2007 01:05:45 +0100 Subject: [Haiku-commits] r20947 - in haiku/trunk: headers/private/net src/add-ons/kernel/network/devices/ethernet src/add-ons/kernel/network/devices/loopback src/add-ons/kernel/network/stack In-Reply-To: <163426214138-BeMail@cr593174-a> References: <9c46321e0705010812x2735b847y671621753fdaecb8@mail.gmail.com> <163426214138-BeMail@cr593174-a> Message-ID: <9c46321e0705011705u7b23f1d9g91c31426ac0acaa@mail.gmail.com> I tend to agree with Rob Pike on this: ``Length is not a virtue in a name; clarity of expression is.'' [1] There is a single caller to both add_multi and rem_multi, and they are called join_multicast and leave_multicast. Whoever is reading the code can understand those fine -- including people who might develop new device modules. Driver developer's will have to use ETHER_ADDMULTI/ETHER_REMMULTI anyway. From previous discussions it seems the core developers prefer a more Java-ish approach to programming, if i may say so. And by that i mean longer names and more objects. I prefer a more traditional C++ approach i guess, with a bit of Rob Pike in the mix (oh the irony), with clarity over verbosity (less letters to read, more efficiency -- i.e. "ctx" vs. "context") and concepts vs. objects (more templates -- a la STL, less Java). Hugo [1] http://www.lysator.liu.se/c/pikestyle.html On 5/2/07, Alexander G. M. Smith wrote: > > On 5/1/07, Axel D?rfler wrote: > > > What about a bit more meaningful names like add_multicast_address()? > > Hugo Santos wrote on Tue, 1 May 2007 16:12:05 +0100: > > I called them add_multi/rem_multi to follow the ioctl names, ADDMULTI > > and REMMULTI. I also find add_multicast_address to be too long: > > > > return protocol->device_module->add_multicast_address(protocol->device, > > address); > > I agree with Axel about using more readable meaningful names when possible. > But then I'm perhaps a bit over the top with my ultra mega verbose coding > style, at least compared to most programmers. My thesis advisor did get me > to avoid using abbreviations as names, so maybe that's where UMV coding > comes from. :-) > > - Alex > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From hugosantos at mail.berlios.de Wed May 2 02:10:19 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 2 May 2007 02:10:19 +0200 Subject: [Haiku-commits] r20960 - in haiku/trunk: headers/posix/net src/add-ons/kernel/drivers/network/ipro1000 Message-ID: <200705020010.l420AJWE013019@sheep.berlios.de> Author: hugosantos Date: 2007-05-02 02:10:00 +0200 (Wed, 02 May 2007) New Revision: 20960 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20960&view=rev Modified: haiku/trunk/headers/posix/net/if.h haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/device.c haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/if_compat.c haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/if_compat.h haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/if_em.c haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/if_em_osdep.h Log: added ADDMULTI/REMMULTI support to ipro1000. Also cleaned up the compat. layer a bit to reuse some of the system's definitions. Modified: haiku/trunk/headers/posix/net/if.h =================================================================== --- haiku/trunk/headers/posix/net/if.h 2007-05-01 23:03:40 UTC (rev 20959) +++ haiku/trunk/headers/posix/net/if.h 2007-05-02 00:10:00 UTC (rev 20960) @@ -52,6 +52,7 @@ int ifr_mtu; int ifr_media; int ifr_type; + int ifr_reqcap; }; }; Modified: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/device.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/device.c 2007-05-01 23:03:40 UTC (rev 20959) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/device.c 2007-05-02 00:10:00 UTC (rev 20960) @@ -296,6 +296,13 @@ } +static struct ifnet * +device_ifp(ipro1000_device *device) +{ + return &device->adapter->interface_data.ac_if; +} + + status_t ipro1000_control(void *cookie, uint32 op, void *arg, size_t len) { @@ -322,13 +329,24 @@ return B_OK; case ETHER_ADDMULTI: - DEVICE_DEBUGOUT("ipro1000_control() ETHER_ADDMULTI not supported"); - break; - case ETHER_REMMULTI: - DEVICE_DEBUGOUT("ipro1000_control() ETHER_REMMULTI not supported"); - return B_OK; - + { + struct ifnet *ifp = device_ifp(device); + struct sockaddr_dl address; + + if (len != ETHER_ADDR_LEN) + return EINVAL; + + memset(&address, 0, sizeof(address)); + address.sdl_family = AF_LINK; + memcpy(LLADDR(&address), arg, ETHER_ADDR_LEN); + + if (op == ETHER_ADDMULTI) + return ether_add_multi(ifp, (struct sockaddr *)&address); + else + return ether_rem_multi(ifp, (struct sockaddr *)&address); + } + case ETHER_SETPROMISC: if (*(int32 *)arg) { DEVICE_DEBUGOUT("promiscuous mode on not supported"); @@ -345,14 +363,13 @@ #ifdef HAIKU_TARGET_PLATFORM_HAIKU case ETHER_GET_LINK_STATE: { - struct ifnet ifp = { .if_softc = device->adapter }; struct ifmediareq mediareq; ether_link_state_t state; if (len < sizeof(ether_link_state_t)) return ENOBUFS; - em_media_status(&ifp, &mediareq); + em_media_status(device_ifp(device), &mediareq); state.media = mediareq.ifm_active; if (mediareq.ifm_status & IFM_ACTIVE) Modified: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/if_compat.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/if_compat.c 2007-05-01 23:03:40 UTC (rev 20959) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/if_compat.c 2007-05-02 00:10:00 UTC (rev 20960) @@ -22,6 +22,9 @@ #include "debug.h" #include "mempool.h" +#undef malloc +#undef free + spinlock mbuf_lock = 0; struct mbuf * @@ -96,6 +99,8 @@ INIT_DEBUGOUT("ether_ifattach"); + TAILQ_INIT(&ifp->if_multiaddrs); + memcpy(dev->macaddr, etheraddr, 6); ifp->if_input = ether_input; @@ -108,12 +113,85 @@ INIT_DEBUGOUT("done calling if_init!"); } + +static struct ifmultiaddr * +ether_find_multi(struct ifnet *ifp, const struct sockaddr *_address) +{ + const struct sockaddr_dl *address = (const struct sockaddr_dl *)_address; + struct ifmultiaddr *ifma; + + TAILQ_FOREACH (ifma, &ifp->if_multiaddrs, ifma_link) { + if (memcmp(LLADDR(address), + LLADDR((struct sockaddr_dl *)ifma->ifma_addr), + ETHER_ADDR_LEN) == 0) + return ifma; + } + + return NULL; +} + + +int +ether_add_multi(struct ifnet *ifp, const struct sockaddr *address) +{ + struct ifmultiaddr *addr = ether_find_multi(ifp, address); + + if (addr != NULL) { + addr->ifma_refcount++; + return 0; + } + + addr = (struct ifmultiaddr *)malloc(sizeof(struct ifmultiaddr)); + if (addr == NULL) + return ENOBUFS; + + memcpy(&addr->ifma_addr_storage, address, sizeof(struct sockaddr_dl)); + addr->ifma_addr = (struct sockaddr *)&addr->ifma_addr_storage; + + addr->ifma_refcount = 1; + + TAILQ_INSERT_HEAD(&ifp->if_multiaddrs, addr, ifma_link); + + return ifp->if_ioctl(ifp, SIOCADDMULTI, NULL); +} + + +static void +ether_delete_multi(struct ifnet *ifp, struct ifmultiaddr *ifma) +{ + TAILQ_REMOVE(&ifp->if_multiaddrs, ifma, ifma_link); + free(ifma); +} + + +int +ether_rem_multi(struct ifnet *ifp, const struct sockaddr *address) +{ + struct ifmultiaddr *addr = ether_find_multi(ifp, address); + if (addr == NULL) + return EADDRNOTAVAIL; + + addr->ifma_refcount--; + if (addr->ifma_refcount == 0) { + ether_delete_multi(ifp, addr); + return ifp->if_ioctl(ifp, SIOCDELMULTI, NULL); + } + + return 0; +} + + void ether_ifdetach(struct ifnet *ifp) { + struct ifmultiaddr *ifma, *next; + INIT_DEBUGOUT("ether_ifdetach"); delete_sem(ifp->if_rcv_sem); + + TAILQ_FOREACH_SAFE(ifma, &ifp->if_multiaddrs, ifma_link, next) + ether_delete_multi(ifp, ifma); } struct mbuf * Modified: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/if_compat.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/if_compat.h 2007-05-01 23:03:40 UTC (rev 20959) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/if_compat.h 2007-05-02 00:10:00 UTC (rev 20960) @@ -20,18 +20,16 @@ #define __IF_COMPAT_H #include +#include +#include #include +#include "if_em_osdep.h" // for TAILQ_... + #define __FreeBSD_version 500001 -#define IFF_BROADCAST 0x0001 -#define IFF_SIMPLEX 0x0002 -#define IFF_MULTICAST 0x0004 -#define IFF_RUNNING 0x0008 -#define IFF_OACTIVE 0x0010 -#define IFF_UP 0x0020 -#define IFF_PROMISC 0x0040 -#define IFF_ALLMULTI 0x0080 +#define IFF_RUNNING 0x10000 +#define IFF_OACTIVE 0x20000 #define IFCAP_HWCSUM 0x0001 #define IFCAP_VLAN_HWTAGGING 0x0002 @@ -203,15 +201,19 @@ void ether_ifattach(struct ifnet *ifp, const uint8 *etheraddr); void ether_ifdetach(struct ifnet *ifp); -#define AF_LINK 0 -struct ifma_addr -{ - int sa_family; // must be AF_LINK -}; +int ether_add_multi(struct ifnet *ifp, const struct sockaddr *address); +int ether_rem_multi(struct ifnet *ifp, const struct sockaddr *address); +TAILQ_HEAD(ifmultihead, ifmultiaddr); + struct ifmultiaddr { - struct ifma_addr *ifma_addr; + TAILQ_ENTRY(ifmultiaddr) ifma_link; + struct sockaddr *ifma_addr; + int ifma_refcount; + + /* private */ + struct sockaddr_dl ifma_addr_storage; }; struct if_data @@ -257,8 +259,8 @@ sem_id if_rcv_sem; -// struct if_multiaddrs if_multiaddrs; // multicast addr list struct if_data if_data; + struct ifmultihead if_multiaddrs; if_start if_start; if_ioctl if_ioctl; @@ -295,34 +297,12 @@ SIOCSIFCAP, }; -struct ifreq // ioctl command data -{ - uint32 ifr_reqcap; - int ifr_mtu; -}; - // used for media properties #define ifmedia_init(a, b, c, d) #define ifmedia_add(a, b, c, d) #define ifmedia_set(a, b) #define ifmedia_ioctl(ifp, ifr, media, command) 0 -// used inside multicast stuff -struct sockaddr_dl -{ - u_char sdl_len; - u_char sdl_family; - u_short sdl_index; - u_char sdl_type; - u_char sdl_nlen; - u_char sdl_alen; - u_char sdl_slen; - char sdl_data[46]; -}; - -// used inside multicast stuff -#define LLADDR(s) ((caddr_t)((s)->sdl_data + (s)->sdl_nlen)) - // called for SIOCxIFADDR (Get/Set Interface Addr) #define ether_ioctl(ifp, command, data) Modified: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/if_em.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/if_em.c 2007-05-01 23:03:40 UTC (rev 20959) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/if_em.c 2007-05-02 00:10:00 UTC (rev 20960) @@ -1293,7 +1293,7 @@ u_int8_t mta[MAX_NUM_MULTICAST_ADDRESSES * ETH_LENGTH_OF_ADDRESS]; struct ifmultiaddr *ifma; int mcnt = 0; -// struct ifnet *ifp = &adapter->interface_data.ac_if; + struct ifnet *ifp = &adapter->interface_data.ac_if; IOCTL_DEBUGOUT("em_set_multi: begin"); Modified: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/if_em_osdep.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/if_em_osdep.h 2007-05-01 23:03:40 UTC (rev 20959) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/if_em_osdep.h 2007-05-02 00:10:00 UTC (rev 20960) @@ -45,6 +45,7 @@ #include #include +#include #include #define usec_delay(x) snooze(x) @@ -71,18 +72,6 @@ #define hz 1000000LL -typedef uint64 u_int64_t; -typedef uint32 u_int32_t; -typedef uint16 u_int16_t; -typedef uint8 u_int8_t; -typedef uint64 uint64_t; -typedef uint32 uint32_t; -typedef uint16 uint16_t; -typedef uint8 uint8_t; -typedef int64 int64_t; -typedef int32 int32_t; -typedef int16 int16_t; -typedef int8 int8_t; typedef bool boolean_t; typedef unsigned long vm_offset_t; @@ -210,16 +199,45 @@ #define E1000_WRITE_REG_ARRAY(hw, reg, index, value) \ E1000_WRITE_OFFSET(hw, E1000_REG_OFFSET(hw, reg) + ((index) << 2), value) +#define TAILQ_HEAD(name, type) \ + struct name { struct type *tqh_first, **tqh_last; } -/* -#define TAILQ_FIRST(head) ((head)->tqh_first) -#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) -#define TAILQ_FOREACH(var, head, field) \ - for ((var) = TAILQ_FIRST((head)); \ - (var); \ - (var) = TAILQ_NEXT((var), field)) -*/ -// used only for multicast setup, fix later... -#define TAILQ_FOREACH(a, b, c) for (a = 0; a != 0; a = 0) +#define TAILQ_ENTRY(type) \ + struct { struct type *tqe_next, **tqe_prev; } +#define TAILQ_FIRST(head) \ + ((head)->tqh_first) + +#define TAILQ_NEXT(elm, field) \ + ((elm)->field.tqe_next) + +#define TAILQ_FOREACH(var, head, field) \ + for ((var) = TAILQ_FIRST((head)); (var); (var) = TAILQ_NEXT((var), field)) + +#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = TAILQ_FIRST((head)); \ + (var) && ((tvar) = TAILQ_NEXT((var), field), 1); (var) = (tvar)) + +#define TAILQ_INIT(head) do { \ + TAILQ_FIRST((head)) = NULL; \ + (head)->tqh_last = &TAILQ_FIRST((head)); \ +} while (0) + +#define TAILQ_INSERT_HEAD(head, elm, field) do { \ + if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \ + TAILQ_FIRST((head))->field.tqe_prev = &TAILQ_NEXT((elm), field); \ + else \ + (head)->tqh_last = &TAILQ_NEXT((elm), field); \ + TAILQ_FIRST((head)) = (elm); \ + (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \ +} while (0) + +#define TAILQ_REMOVE(head, elm, field) do { \ + if ((TAILQ_NEXT((elm), field)) != NULL) \ + TAILQ_NEXT((elm), field)->field.tqe_prev = (elm)->field.tqe_prev; \ + else \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \ +} while (0) + #endif From mmu_man at mail.berlios.de Wed May 2 02:22:40 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Wed, 2 May 2007 02:22:40 +0200 Subject: [Haiku-commits] r20961 - haiku/trunk/src/add-ons/kernel/file_systems/nfs Message-ID: <200705020022.l420MeoD015613@sheep.berlios.de> Author: mmu_man Date: 2007-05-02 02:22:39 +0200 (Wed, 02 May 2007) New Revision: 20961 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20961&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/nfs/nfs_add_on.c Log: don't provide get_vnode_name as we don't know how to do it. just set it to NULL and let the VFS handle it. This should fix oddities in Tracker. Modified: haiku/trunk/src/add-ons/kernel/file_systems/nfs/nfs_add_on.c =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/nfs/nfs_add_on.c 2007-05-02 00:10:00 UTC (rev 20960) +++ haiku/trunk/src/add-ons/kernel/file_systems/nfs/nfs_add_on.c 2007-05-02 00:22:39 UTC (rev 20961) @@ -862,6 +862,10 @@ } #ifdef __HAIKU__ +/* no reason to do it, + * the VFS does it the best possible way for an unix fs anyway. + * so we use NULL for this call. + */ extern int fs_get_vnode_name(fs_nspace *ns, fs_node *node, char *buffer, size_t len) { @@ -2441,7 +2445,7 @@ /* vnode operations */ &fs_walk, - &fs_get_vnode_name, + NULL, // &fs_get_vnode_name, &fs_read_vnode, &fs_release_vnode, &fs_remove_vnode, From mmu_man at mail.berlios.de Wed May 2 02:31:45 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Wed, 2 May 2007 02:31:45 +0200 Subject: [Haiku-commits] r20962 - haiku/trunk/headers/private/drivers Message-ID: <200705020031.l420VjkE016326@sheep.berlios.de> Author: mmu_man Date: 2007-05-02 02:31:45 +0200 (Wed, 02 May 2007) New Revision: 20962 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20962&view=rev Added: haiku/trunk/headers/private/drivers/ksocket.h Log: Kernel socket helper funcs, with BONE compatibility. Shared by at laest 2 fs addons, and soon other drivers, so move it in here. Added: haiku/trunk/headers/private/drivers/ksocket.h =================================================================== --- haiku/trunk/headers/private/drivers/ksocket.h 2007-05-02 00:22:39 UTC (rev 20961) +++ haiku/trunk/headers/private/drivers/ksocket.h 2007-05-02 00:31:45 UTC (rev 20962) @@ -0,0 +1,114 @@ +/* + * kernel-level support for sockets, includes userland support as well for testing. + * Fran?ois Revol. + */ + +#ifndef _KSOCKET_H +#define _KSOCKET_H + +#include + +#ifndef _KERNEL_MODE /* userland wrapper */ + +#define ksocket socket +#define kbind bind +#define kconnect connect +#define kgetsockname getsockname +#define kgetpeername getpeername +#define kaccept accept +#define ksendmsg sendmsg +#define krecvmsg recvmsg +#define krecvfrom recvfrom +#define ksendto sendto +#define krecv recv +#define ksend send +#define klisten listen +#define kshutdown shutdown +#define kclosesocket close +#define ksocket_init() ({B_OK;}) +#define ksocket_cleanup() ({B_OK;}) +#define kmessage(fmt, ...) printf(fmt "\n", ##__VA_ARGS__) +#define KSOCKET_MODULE_DECL /* nothing */ + +#elif defined(__HAIKU__) + +/* Haiku socket module */ +#include + +extern struct socket_module_info *gSocket; +#define ksocket (gSocket->socket) +#define kbind (gSocket->bind) +#define kconnect (gSocket->connect) +#define kgetsockname (gSocket->getsockname) +#define kgetpeername (gSocket->getpeername) +#define kaccept (gSocket->accept) +//#define kaccept(_fd, _addr, _sz) ({int thesock; thesock = (gSocket->accept)(_fd, _addr, _sz); dprintf("kaccept(%d, , ) = %d\n", _fd, thesock); thesock; }) +#define ksendmsg (gSocket->sendmsg) +#define krecvmsg (gSocket->recvmsg) +#define krecvfrom (gSocket->recvfrom) +#define ksendto (gSocket->sendto) +#define krecv (gSocket->recv) +#define ksend (gSocket->send) +#define klisten (gSocket->listen) +#define kshutdown (gSocket->shutdown) +#define kclosesocket close +#define kmessage(fmt, ...) dprintf("ksocket: " fmt "\n", ##__VA_ARGS__) + +extern status_t ksocket_init (void); +extern status_t ksocket_cleanup (void); + +#define KSOCKET_MODULE_DECL \ +struct socket_module_info *gSocket; \ +status_t ksocket_init (void) { \ + return get_module(B_SOCKET_MODULE_NAME, (module_info **)&gSocket); \ +} \ + \ +status_t ksocket_cleanup (void) { \ + return put_module(B_SOCKET_MODULE_NAME); \ +} + +#elif defined(BONE_VERSION) + +/* BONE socket module */ +#include + +extern bone_socket_info_t *gSocket; +#define ksocket (gSocket->socket) +//#define ksocket(_fam, _typ, _pro) ({int thesock; thesock = (gSocket->socket)(_fam, _typ, _pro); dprintf("ksocket(%d, %d, %d) = %d\n", _fam, _typ, _pro, thesock); thesock;}) +#define kbind (gSocket->bind) +#define kconnect (gSocket->connect) +#define kgetsockname (gSocket->getsockname) +#define kgetpeername (gSocket->getpeername) +#define kaccept (gSocket->accept) +//#define kaccept(_fd, _addr, _sz) ({int thesock; thesock = (gSocket->accept)(_fd, _addr, _sz); dprintf("kaccept(%d, , ) = %d\n", _fd, thesock); thesock; }) +#define ksendmsg _ERROR_no_sendmsg_in_BONE +#define krecvmsg _ERROR_no_recvmsg_in_BONE +#define krecvfrom (gSocket->recvfrom) +#define ksendto (gSocket->sendto) +#define krecv (gSocket->recv) +#define ksend (gSocket->send) +#define klisten (gSocket->listen) +#define kshutdown (gSocket->shutdown) +#define kclosesocket close +#define kmessage(fmt, ...) dprintf("ksocket: " fmt "\n", ##__VA_ARGS__) + +extern status_t ksocket_init (void); +extern status_t ksocket_cleanup (void); + +#define KSOCKET_MODULE_DECL \ +bone_socket_info_t *gSocket; \ +status_t ksocket_init (void) { \ + return get_module(BONE_SOCKET_MODULE, (module_info **)&gSocket); \ +} \ + \ +status_t ksocket_cleanup (void) { \ + return put_module(BONE_SOCKET_MODULE); \ +} + +#else /* _KERNEL_MODE, !BONE_VERSION */ + +#error feel free to put back ksocketd support if you dare + +#endif /* _KERNEL_MODE, BONE_VERSION */ + +#endif /* _KSOCKET_H */ From mmu_man at mail.berlios.de Wed May 2 02:38:46 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Wed, 2 May 2007 02:38:46 +0200 Subject: [Haiku-commits] r20963 - in haiku/trunk/src/add-ons/kernel/drivers/disk: . virtual virtual/fmap virtual/nbd Message-ID: <200705020038.l420ck6h016870@sheep.berlios.de> Author: mmu_man Date: 2007-05-02 02:38:45 +0200 (Wed, 02 May 2007) New Revision: 20963 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20963&view=rev Added: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/Jamfile haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/fmap/ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/fmap/Jamfile haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/fmap/fmap.c haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/Jamfile haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd-server.py haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.h Log: skeleton for an fmap driver (IMAGE.BE). Start of an Network Block Device driver. NBD server python script I foundon the net for testing. Added: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/Jamfile 2007-05-02 00:31:45 UTC (rev 20962) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/Jamfile 2007-05-02 00:38:45 UTC (rev 20963) @@ -0,0 +1,4 @@ +SubDir HAIKU_TOP src add-ons kernel drivers disk virtual ; + +#SubInclude HAIKU_TOP src add-ons kernel drivers disk virtual fmap ; +SubInclude HAIKU_TOP src add-ons kernel drivers disk virtual nbd ; Added: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/fmap/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/fmap/Jamfile 2007-05-02 00:31:45 UTC (rev 20962) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/fmap/Jamfile 2007-05-02 00:38:45 UTC (rev 20963) @@ -0,0 +1,13 @@ +SubDir HAIKU_TOP src add-ons kernel drivers disk virtual fmap ; + +SetSubDirSupportedPlatformsBeOSCompatible ; + +if $(TARGET_PLATFORM) != haiku { + # Needed for . Unfortunately we also get the other headers there, + # that we don't really want. + UsePublicHeaders drivers ; +} + +KernelAddon fmap : kernel drivers bin : + fmap.c + ; Added: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/fmap/fmap.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/fmap/fmap.c 2007-05-02 00:31:45 UTC (rev 20962) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/fmap/fmap.c 2007-05-02 00:38:45 UTC (rev 20963) @@ -0,0 +1,60 @@ +/* + * Copyright 2006, Fran?ois Revol. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +/* + fmap driver for Haiku + + Maps BEOS/IMAGE.BE files as virtual partitions. +*/ + +#include +#include +#include + +#define MAX_FMAPS 4 +#define DEVNAME_FMT "disk/virtual/fmap/%2d" + +status_t +init_hardware (void) +{ + return B_OK; +} + +status_t +init_driver (void) +{ + return B_OK; +} + +void +uninit_driver (void) +{ +} + +static const char *fmap_name[MAX_FMAPS+1] = { + NULL +}; + +device_hooks fmap_hooks = { + NULL, /* open */ + NULL, /* close */ + NULL, /* free */ + NULL, /* control */ + NULL, /* read */ + NULL, /* write */ + NULL, NULL, NULL, NULL +}; + +const char** +publish_devices() +{ + return fmap_name; +} + +device_hooks* +find_device(const char* name) +{ + return &fmap_hooks; +} Added: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/Jamfile 2007-05-02 00:31:45 UTC (rev 20962) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/Jamfile 2007-05-02 00:38:45 UTC (rev 20963) @@ -0,0 +1,15 @@ +SubDir HAIKU_TOP src add-ons kernel drivers disk virtual nbd ; + +SetSubDirSupportedPlatformsBeOSCompatible ; + +#if $(TARGET_PLATFORM) != haiku { +# # Needed for . Unfortunately we also get the other headers there, +# # that we don't really want. +# UsePublicHeaders drivers ; +#} + +UsePrivateHeaders drivers ; + +KernelAddon nbd : + nbd.c + ; Added: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd-server.py =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd-server.py 2007-05-02 00:31:45 UTC (rev 20962) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd-server.py 2007-05-02 00:38:45 UTC (rev 20963) @@ -0,0 +1,136 @@ +#!/usr/bin/python +# from http://lists.canonical.org/pipermail/kragen-hacks/2004-May/000397.html +import struct, socket, sys +# network block device server, substitute for nbd-server. Probably slower. +# But it works! And it's probably a lot easier to improve the +# performance of this Python version than of the C version. This +# Python version is 14% of the size and perhaps 20% of the features of +# the C version. Hmm, that's not so great after all... +# Working: +# - nbd protocol +# - read/write serving up files +# - error handling +# - file size detection +# - in theory, large file support... not really +# - so_reuseaddr +# - nonforking +# Missing: +# - reporting errors to client (in particular writing and reading past end) +# - multiple clients (this probably requires copy-on-write or read-only) +# - copy on write +# - read-only +# - permission tracking +# - idle timeouts +# - running from inetd +# - filename substitution +# - partial file exports +# - exports of large files (bigger than 1/4 of RAM) +# - manual exportsize specification +# - so_keepalive +# - that "split an export file into multiple files" thing that sticks the .0 +# on the end of your filename +# - backgrounding +# - daemonizing + +class Error(Exception): pass + +class buffsock: + "Buffered socket wrapper; always returns the amount of data you want." + def __init__(self, sock): self.sock = sock + def recv(self, nbytes): + rv = '' + while len(rv) < nbytes: + more = self.sock.recv(nbytes - len(rv)) + if more == '': raise Error(nbytes) + rv += more + return rv + def send(self, astring): self.sock.send(astring) + def close(self): self.sock.close() + + +class debugsock: + "Debugging socket wrapper." + def __init__(self, sock): self.sock = sock + def recv(self, nbytes): + print "recv(%d) =" % nbytes, + rv = self.sock.recv(nbytes) + print `rv` + return rv + def send(self, astring): + print "send(%r) =" % astring, + rv = self.sock.send(astring) + print `rv` + return rv + def close(self): + print "close()" + self.sock.close() + +def negotiation(exportsize): + "Returns initial NBD negotiation sequence for exportsize in bytes." + return ('NBDMAGIC' + '\x00\x00\x42\x02\x81\x86\x12\x53' + + struct.pack('>Q', exportsize) + '\0' * 128); + +def nbd_reply(error=0, handle=1, data=''): + "Construct an NBD reply." + assert type(handle) is type('') and len(handle) == 8 + return ('\x67\x44\x66\x98' + struct.pack('>L', error) + handle + data) + +# possible request types +read_request = 0 +write_request = 1 +disconnect_request = 2 + +class nbd_request: + "Decodes an NBD request off the TCP socket." + def __init__(self, conn): + conn = buffsock(conn) + template = '>LL8sQL' + header = conn.recv(struct.calcsize(template)) + (self.magic, self.type, self.handle, self.offset, + self.len) = struct.unpack(template, header) + if self.magic != 0x25609513: raise Error(self.magic) + if self.type == write_request: + self.data = conn.recv(self.len) + assert len(self.data) == self.len + def reply(self, error, data=''): + return nbd_reply(error=error, handle=self.handle, data=data) + def range(self): + return slice(self.offset, self.offset + self.len) + +def serveclient(asock, afile): + "Serves a single client until it exits." + afile.seek(0) + abuf = list(afile.read()) + asock.send(negotiation(len(abuf))) + while 1: + req = nbd_request(asock) + if req.type == read_request: + asock.send(req.reply(error=0, + data=''.join(abuf[req.range()]))) + elif req.type == write_request: + abuf[req.range()] = req.data + afile.seek(req.offset) + afile.write(req.data) + afile.flush() + asock.send(req.reply(error=0)) + elif req.type == disconnect_request: + asock.close() + return + +def mainloop(listensock, afile): + "Serves clients forever." + while 1: + (sock, addr) = listensock.accept() + print "got conn on", addr + serveclient(sock, afile) + +def main(argv): + "Given a port and a filename, serves up the file." + afile = file(argv[2], 'rb+') + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + sock.bind(('', int(argv[1]))) + sock.listen(5) + mainloop(sock, afile) + +if __name__ == '__main__': main(sys.argv) \ No newline at end of file Added: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-02 00:31:45 UTC (rev 20962) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-02 00:38:45 UTC (rev 20963) @@ -0,0 +1,218 @@ +/* + * Copyright 2006-2007, Fran?ois Revol. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +/* + nbd driver for Haiku + + Maps BEOS/IMAGE.BE files as virtual partitions. +*/ + +#include +#include +#include +#include + +#include "nbd.h" + +#define MAX_NBDS 4 +#define DEVICE_PREFIX "disk/virtual/nbd/" +#define DEVICE_FMT DEVICE_PREFIX "%2d/raw" +#define DEVICE_NAME_MAX 32 +#define MAX_REQ_SIZE (32*1024*1024) + +struct nbd_request_entry { + struct nbd_request_entry *next; + struct nbd_request req; + bool r; /* is read */ + size_t len; + void *buffer; /* write: ptr to passed buffer; read: ptr to malloc()ed extra */ +}; + +struct nbd_device { + //lock + vint32 refcnt; + uint64 req; /* next ID for requests */ + int sock; + thread_id postoffice; + uint64 size; + struct nbd_request_entry *reqs; +}; + +typedef struct cookie { + struct nbd_device *dev; + +} cookie_t; + +/* data=NULL on read */ +status_t nbd_alloc_request(struct nbd_device, struct nbd_request_entry **req, size_t len, const char *data); +status_t nbd_post_request(struct nbd_device, uint64 handle, struct nbd_request_entry **req); +status_t nbd_dequeue_request(struct nbd_device, uint64 handle, struct nbd_request_entry **req); +status_t nbd_free_request(struct nbd_device, struct nbd_request_entry *req); + +#pragma mark ==== request manager ==== + + +#pragma mark ==== nbd handler ==== + +int32 postoffice(void *arg) +{ + struct nbd_device *dev = (struct nbd_device *)arg; + int sock = dev->sock; + + + + return 0; +} + +#pragma mark ==== device hooks ==== + +status_t nbd_open(const char *name, uint32 flags, cookie_t **cookie) { + (void)name; (void)flags; + *cookie = (void*)malloc(sizeof(cookie_t)); + if (*cookie == NULL) { + dprintf("nbd_open : error allocating cookie\n"); + goto err0; + } + memset(*cookie, 0, sizeof(cookie_t)); + return B_OK; +err0: + return B_ERROR; +} + +status_t nbd_close(void *cookie) { + (void)cookie; + return B_OK; +} + +status_t nbd_free(cookie_t *cookie) { + free(cookie); + return B_OK; +} + +status_t nbd_control(cookie_t *cookie, uint32 op, void *data, size_t len) { + switch (op) { + case B_GET_DEVICE_SIZE: /* this one is broken anyway... */ + if (data) { + *(size_t *)data = (size_t)cookie->dev->size; + return B_OK; + } + return EINVAL; + case B_SET_DEVICE_SIZE: /* broken */ + return EINVAL; + case B_SET_NONBLOCKING_IO: + return EINVAL; + case B_SET_BLOCKING_IO: + return B_OK; + case B_GET_READ_STATUS: + case B_GET_WRITE_STATUS: + if (data) { + *(bool *)data = false; + return B_OK; + } + return EINVAL; + case B_GET_GEOMETRY: + case B_GET_BIOS_GEOMETRY: + if (data) { + device_geometry *geom = (device_geometry *)data; + geom->bytes_per_sector = 256; + geom->sectors_per_track = 1; + geom->cylinder_count = cookie->dev->size / 256; + geom->head_count = 1; + geom->device_type = B_DISK; + geom->removable = false; + geom->read_only = false; // XXX + geom->write_once = false; + return B_OK; + } + return EINVAL; + case B_GET_MEDIA_STATUS: + if (data) { + *(status_t *)data = B_OK; + return B_OK; + } + return EINVAL; + + case B_EJECT_DEVICE: + case B_LOAD_MEDIA: + return ENOSYS; + case B_FLUSH_DRIVE_CACHE: /* wait for request list to be empty ? */ + default: + return ENOSYS; + } + return B_NOT_ALLOWED; +} + +status_t nbd_read(cookie_t *cookie, off_t position, void *data, size_t *numbytes) { + *numbytes = 0; + return B_NOT_ALLOWED; +} + +status_t nbd_write(cookie_t *cookie, off_t position, const void *data, size_t *numbytes) { + (void)cookie; (void)position; (void)data; (void)numbytes; + *numbytes = 0; + return EIO; +} + +device_hooks nbd_hooks={ + (device_open_hook)nbd_open, + nbd_close, + (device_free_hook)nbd_free, + (device_control_hook)nbd_control, + (device_read_hook)nbd_read, + (device_write_hook)nbd_write, + NULL, + NULL, + NULL, + NULL +}; + + +#pragma mark ==== driver hooks ==== + +static const char *nbd_name[MAX_NBDS+1] = { + NULL +}; + +status_t +init_hardware (void) +{ + return B_OK; +} + +status_t +init_driver (void) +{ + int i; + // load settings + for (i = 0; i < MAX_NBDS; i++) { + nbd_name[i] = malloc(DEVICE_NAME_MAX); + if (nbd_name[i] == NULL) + break; + sprintf(nbd_name[i], DEVICE_FMT, i); + } + nbd_name[i] = NULL; + return B_OK; +} + +void +uninit_driver (void) +{ + int i; + for (i = 0; i < MAX_NBDS; i++) { + free(nbd_name[i]); + } +} + +const char** +publish_devices() +{ + return nbd_name; +} + +device_hooks* +find_device(const char* name) +{ + return &nbd_hooks; +} Added: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.h 2007-05-02 00:31:45 UTC (rev 20962) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.h 2007-05-02 00:38:45 UTC (rev 20963) @@ -0,0 +1,46 @@ +/* + * Network Block Device protocol + * Copyright 2006-2007, Fran?ois Revol. All rights reserved. + * Distributed under the terms of the MIT License. + * + * references: + * include/linux/nbd.h + */ + +enum { + NBD_CMD_READ = 0, + NBD_CMD_WRITE, + NBD_CMD_DISC +}; + +#define NBD_REQUEST_MAGIC 0x25609513 +#define NBD_REPLY_MAGIC 0x67446698 + +/* in network byte order */ +struct nbd_request { + uint32 magic; /* REQUEST_MAGIC */ + uint32 type; + uint64 handle; //char handle[8]; + uint64 from; + uint32 len; +} _PACKED; + +/* in network byte order */ +struct nbd_reply { + uint32 magic; /* REPLY_MAGIC */ + uint32 error; + uint64 handle; //char handle[8]; +} _PACKED; + +/* initialization protocol (ENBD ? or at least Linux specific ?) */ + +#define NBD_INIT_PASSWD "NBDMAGIC" +#define NBD_INIT_MAGIC 0x0000420281861253LL + +/* in network byte order */ +struct nbd_init_packet { + uint8 passwd[8]; /* "NBDMAGIC" */ + uint64 magic; /* INIT_MAGIC */ + uint64 device_size; /* size in bytes */ + uint8 dummy[128]; /* reserved for future use */ +} _PACKED; \ No newline at end of file From hugosantos at gmail.com Wed May 2 02:44:17 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Wed, 2 May 2007 01:44:17 +0100 Subject: [Haiku-commits] r20959 - haiku/trunk/src/add-ons/kernel/bus_managers/ps2 In-Reply-To: <200705012303.l41N3fZj013266@sheep.berlios.de> References: <200705012303.l41N3fZj013266@sheep.berlios.de> Message-ID: <9c46321e0705011744o75fc21bfm23721b6e4158f3c8@mail.gmail.com> After this change i can no longer use the mouse or keyboard in VMWare. Also, adding this kind of debug stuff without a #ifdef DEBUG or something of the sorts around it seems a bit drastic. Hugo On 5/2/07, marcusoverhagen at BerliOS wrote: > Author: marcusoverhagen > Date: 2007-05-02 01:03:40 +0200 (Wed, 02 May 2007) > New Revision: 20959 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20959&view=rev > > Modified: > haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_service.c > Log: > delay device publishing by 1 second, for better testing of possible input server race condition > > > Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_service.c > =================================================================== > --- haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_service.c 2007-05-01 19:57:18 UTC (rev 20958) > +++ haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_service.c 2007-05-01 23:03:40 UTC (rev 20959) > @@ -104,6 +104,7 @@ > packet_buffer_read(sServiceCmdBuffer, (uint8 *)&cmd, sizeof(cmd)); > switch (cmd.id) { > case PS2_SERVICE_NOTIFY_DEVICE_ADDED: > + snooze(1000000); // for better testing of possible input server race condition > TRACE("ps2: PS2_SERVICE_NOTIFY_DEVICE_ADDED %s\n", cmd.dev->name); > ps2_dev_publish(cmd.dev); > break; > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From mmu_man at mail.berlios.de Wed May 2 03:04:36 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Wed, 2 May 2007 03:04:36 +0200 Subject: [Haiku-commits] r20964 - haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd Message-ID: <200705020104.l4214aVm020668@sheep.berlios.de> Author: mmu_man Date: 2007-05-02 03:04:36 +0200 (Wed, 02 May 2007) New Revision: 20964 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20964&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/Jamfile haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c Log: Find the device and point the cookie to it on open(). Comment. Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/Jamfile 2007-05-02 00:38:45 UTC (rev 20963) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/Jamfile 2007-05-02 01:04:36 UTC (rev 20964) @@ -8,6 +8,7 @@ # UsePublicHeaders drivers ; #} +# not Haiku-specific, ksocket.h also works in BONE. UsePrivateHeaders drivers ; KernelAddon nbd : Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-02 00:38:45 UTC (rev 20963) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-02 01:04:36 UTC (rev 20964) @@ -6,7 +6,7 @@ /* nbd driver for Haiku - Maps BEOS/IMAGE.BE files as virtual partitions. + Maps a Network Block Device as virtual partitions. */ #include @@ -51,6 +51,8 @@ status_t nbd_dequeue_request(struct nbd_device, uint64 handle, struct nbd_request_entry **req); status_t nbd_free_request(struct nbd_device, struct nbd_request_entry *req); +struct nbd_device *nbd_find_device(const char* name); + #pragma mark ==== request manager ==== @@ -68,14 +70,21 @@ #pragma mark ==== device hooks ==== +static struct nbd_device nbd_devices[MAX_NBDS]; + status_t nbd_open(const char *name, uint32 flags, cookie_t **cookie) { + struct nbd_device *dev = NULL; (void)name; (void)flags; + dev = nbd_find_device(name); + if (!dev) + return ENOENT; *cookie = (void*)malloc(sizeof(cookie_t)); if (*cookie == NULL) { dprintf("nbd_open : error allocating cookie\n"); goto err0; } memset(*cookie, 0, sizeof(cookie_t)); + (*cookie)->dev = dev; return B_OK; err0: return B_ERROR; @@ -191,6 +200,7 @@ if (nbd_name[i] == NULL) break; sprintf(nbd_name[i], DEVICE_FMT, i); + // XXX: init nbd_devices[i] } nbd_name[i] = NULL; return B_OK; @@ -216,3 +226,14 @@ { return &nbd_hooks; } + +struct nbd_device* +nbd_find_device(const char* name) +{ + int i; + for (i = 0; i < MAX_NBDS; i++) { + if (!strcmp(nbd_name[i], name)) + return &nbd_devices[i]; + } + return NULL; +} From bonefish at cs.tu-berlin.de Wed May 2 05:02:54 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Wed, 02 May 2007 05:02:54 +0200 Subject: [Haiku-commits] r20947 - in haiku/trunk: headers/private/net src/add-ons/kernel/network/devices/ethernet src/add-ons/kernel/network/devices/loopback src/add-ons/kernel/network/stack In-Reply-To: <9c46321e0705011705u7b23f1d9g91c31426ac0acaa@mail.gmail.com> References: <9c46321e0705010812x2735b847y671621753fdaecb8@mail.gmail.com> <163426214138-BeMail@cr593174-a> <9c46321e0705011705u7b23f1d9g91c31426ac0acaa@mail.gmail.com> Message-ID: <20070502050254.594.1@cs.tu-berlin.de> On 2007-05-02 at 02:05:45 [+0200], Hugo Santos wrote: > I tend to agree with Rob Pike on this: > > ``Length is not a virtue in a name; clarity of expression is.'' [1] > > There is a single caller to both add_multi and rem_multi, and they > are called join_multicast and leave_multicast. Whoever is reading the > code can understand those fine -- including people who might develop > new device modules. Driver developer's will have to use > ETHER_ADDMULTI/ETHER_REMMULTI anyway. Easy solution: Rename those, too. :-) CU, Ingo From hugosantos at mail.berlios.de Wed May 2 12:57:40 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 2 May 2007 12:57:40 +0200 Subject: [Haiku-commits] r20965 - in haiku/trunk/src/add-ons/mail_daemon: inbound_protocols/imap outbound_protocols/smtp Message-ID: <200705021057.l42AvePN027366@sheep.berlios.de> Author: hugosantos Date: 2007-05-02 12:57:27 +0200 (Wed, 02 May 2007) New Revision: 20965 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20965&view=rev Modified: haiku/trunk/src/add-ons/mail_daemon/inbound_protocols/imap/imap_client.cpp haiku/trunk/src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.cpp Log: couple fixes to make MDR addons build with gcc 4. Modified: haiku/trunk/src/add-ons/mail_daemon/inbound_protocols/imap/imap_client.cpp =================================================================== --- haiku/trunk/src/add-ons/mail_daemon/inbound_protocols/imap/imap_client.cpp 2007-05-02 01:04:36 UTC (rev 20964) +++ haiku/trunk/src/add-ons/mail_daemon/inbound_protocols/imap/imap_client.cpp 2007-05-02 10:57:27 UTC (rev 20965) @@ -45,6 +45,8 @@ BString server_mb_name; }; +class NoopWorker; + class IMAP4Client : public BRemoteMailStorageProtocol { public: IMAP4Client(BMessage *settings, BMailChainRunner *run); Modified: haiku/trunk/src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.cpp =================================================================== --- haiku/trunk/src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.cpp 2007-05-02 01:04:36 UTC (rev 20964) +++ haiku/trunk/src/add-ons/mail_daemon/outbound_protocols/smtp/smtp.cpp 2007-05-02 10:57:27 UTC (rev 20965) @@ -51,6 +51,8 @@ # define D(x) ; #endif +using namespace std; + /* ** Function: md5_hmac ** taken from the file rfc2104.txt From hugosantos at mail.berlios.de Wed May 2 14:41:00 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 2 May 2007 14:41:00 +0200 Subject: [Haiku-commits] r20966 - haiku/trunk/src/add-ons/kernel/network/protocols/ipv4 Message-ID: <200705021241.l42Cf0Jm009714@sheep.berlios.de> Author: hugosantos Date: 2007-05-02 14:40:50 +0200 (Wed, 02 May 2007) New Revision: 20966 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20966&view=rev Modified: haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/multicast.h Log: also dump filter mode and sources in 'ipv4_multicast'. Modified: haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp 2007-05-02 10:57:27 UTC (rev 20965) +++ haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp 2007-05-02 12:40:50 UTC (rev 20966) @@ -1554,9 +1554,21 @@ char addrBuf[64]; - kprintf("%p: group <%s, %s> sock %p\n", state, - state->Interface()->name, print_address(&state->Address(), - addrBuf, sizeof(addrBuf)), state->Parent()->Socket()); + kprintf("%p: group <%s, %s, %s {", state, state->Interface()->name, + print_address(&state->Address(), addrBuf, sizeof(addrBuf)), + state->Mode() == IPv4GroupInterface::kExclude ? "Exclude" : + "Include"); + + int count = 0; + IPv4GroupInterface::AddressSet::Iterator it = + state->Sources().GetIterator(); + while (it.HasNext()) { + kprintf("%s%s", count > 0 ? ", " : "", print_address(&it.Next(), + addrBuf, sizeof(addrBuf))); + count++; + } + + kprintf("}> sock %p\n", state->Parent()->Socket()); } return 0; Modified: haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/multicast.h =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/multicast.h 2007-05-02 10:57:27 UTC (rev 20965) +++ haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/multicast.h 2007-05-02 12:40:50 UTC (rev 20966) @@ -43,11 +43,16 @@ template class AddressSet { -public: struct ContainedAddress : DoublyLinkedListLinkImpl { AddressType address; }; + typedef DoublyLinkedList AddressList; + +public: + AddressSet() + : fCount(0) {} + ~AddressSet() { Clear(); } status_t Add(const AddressType &address) @@ -88,9 +93,21 @@ Remove(fAddresses.Head()->address); } + class Iterator { + public: + Iterator(const AddressList &addresses) + : fBaseIterator(addresses.GetIterator()) {} + + bool HasNext() const { return fBaseIterator.HasNext(); } + AddressType &Next() { return fBaseIterator.Next()->address; } + + private: + typename AddressList::ConstIterator fBaseIterator; + }; + + Iterator GetIterator() const { return Iterator(fAddresses); } + private: - typedef DoublyLinkedList AddressList; - ContainedAddress *_Get(const AddressType &address) const { typename AddressList::ConstIterator it = fAddresses.GetIterator(); @@ -103,6 +120,7 @@ } AddressList fAddresses; + int fCount; }; @@ -114,6 +132,7 @@ typedef HashTableLink HashLink; typedef typename Addressing::AddressType AddressType; typedef MulticastFilter Filter; + typedef AddressSet AddressSet; enum FilterMode { kInclude, @@ -139,6 +158,9 @@ bool IsEmpty() const; void Clear(); + FilterMode Mode() const { return fFilterMode; } + const AddressSet &Sources() const { return fAddresses; } + bool FilterAccepts(net_buffer *buffer) const; struct HashDefinition { @@ -165,7 +187,7 @@ AddressType fMulticastAddress; net_interface *fInterface; FilterMode fFilterMode; - AddressSet fAddresses; + AddressSet fAddresses; HashLink fLink; }; From hugosantos at mail.berlios.de Wed May 2 14:41:25 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 2 May 2007 14:41:25 +0200 Subject: [Haiku-commits] r20967 - in haiku/trunk/src/add-ons/kernel/network: datalink_protocols/arp datalink_protocols/ipv4_datagram devices/ethernet protocols/ipv4 Message-ID: <200705021241.l42CfPL9009762@sheep.berlios.de> Author: hugosantos Date: 2007-05-02 14:41:00 +0200 (Wed, 02 May 2007) New Revision: 20967 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20967&view=rev Modified: haiku/trunk/src/add-ons/kernel/network/datalink_protocols/arp/arp.cpp haiku/trunk/src/add-ons/kernel/network/datalink_protocols/ipv4_datagram/ipv4_datagram.cpp haiku/trunk/src/add-ons/kernel/network/devices/ethernet/ethernet.cpp haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp Log: when 0 is specified as the interface index with the generic multicast delta API, the stack should select an interface for the application. Modified: haiku/trunk/src/add-ons/kernel/network/datalink_protocols/arp/arp.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/datalink_protocols/arp/arp.cpp 2007-05-02 12:40:50 UTC (rev 20966) +++ haiku/trunk/src/add-ons/kernel/network/datalink_protocols/arp/arp.cpp 2007-05-02 12:41:00 UTC (rev 20967) @@ -258,9 +258,6 @@ // the low-order 23 bits of the Ethernet multicast address // 01-00-5E-00-00-00 (hex).'' - memcpy(((uint8 *)destination->sdl_data) + 2, &source->sin_addr, - sizeof(in_addr)); - destination->sdl_len = sizeof(sockaddr_dl); destination->sdl_family = AF_DLI; destination->sdl_index = 0; @@ -269,7 +266,8 @@ destination->sdl_nlen = destination->sdl_slen = 0; destination->sdl_alen = ETHER_ADDRESS_LENGTH; - uint32 *data = (uint32 *)destination->sdl_data; + memcpy(LLADDR(destination) + 2, &source->sin_addr, sizeof(in_addr)); + uint32 *data = (uint32 *)LLADDR(destination); data[0] = (data[0] & htonl(0x7f)) | htonl(0x01005e00); } Modified: haiku/trunk/src/add-ons/kernel/network/datalink_protocols/ipv4_datagram/ipv4_datagram.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/datalink_protocols/ipv4_datagram/ipv4_datagram.cpp 2007-05-02 12:40:50 UTC (rev 20966) +++ haiku/trunk/src/add-ons/kernel/network/datalink_protocols/ipv4_datagram/ipv4_datagram.cpp 2007-05-02 12:41:00 UTC (rev 20967) @@ -98,6 +98,22 @@ static status_t +ipv4_datalink_join_multicast(net_datalink_protocol *protocol, + const sockaddr *address) +{ + return protocol->next->module->join_multicast(protocol->next, address); +} + + +static status_t +ipv4_datalink_leave_multicast(net_datalink_protocol *protocol, + const sockaddr *address) +{ + return protocol->next->module->leave_multicast(protocol->next, address); +} + + +static status_t ipv4_datalink_std_ops(int32 op, ...) { switch (op) { @@ -123,6 +139,8 @@ ipv4_datalink_up, ipv4_datalink_down, ipv4_datalink_control, + ipv4_datalink_join_multicast, + ipv4_datalink_leave_multicast, }; module_info *modules[] = { Modified: haiku/trunk/src/add-ons/kernel/network/devices/ethernet/ethernet.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/devices/ethernet/ethernet.cpp 2007-05-02 12:40:50 UTC (rev 20966) +++ haiku/trunk/src/add-ons/kernel/network/devices/ethernet/ethernet.cpp 2007-05-02 12:41:00 UTC (rev 20967) @@ -391,8 +391,7 @@ if (address->sdl_type != IFT_ETHER) return EINVAL; - return ioctl(device->fd, ETHER_ADDMULTI, address->sdl_data, - address->sdl_alen); + return ioctl(device->fd, ETHER_ADDMULTI, LLADDR(address), 6); } @@ -408,8 +407,7 @@ if (address->sdl_type != IFT_ETHER) return EINVAL; - return ioctl(device->fd, ETHER_REMMULTI, address->sdl_data, - address->sdl_alen); + return ioctl(device->fd, ETHER_REMMULTI, LLADDR(address), 6); } Modified: haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp 2007-05-02 12:40:50 UTC (rev 20966) +++ haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp 2007-05-02 12:41:00 UTC (rev 20967) @@ -706,20 +706,26 @@ } +static sockaddr * +fill_sockaddr_in(sockaddr_in *destination, const in_addr &source) +{ + memset(destination, 0, sizeof(sockaddr_in)); + destination->sin_family = AF_INET; + destination->sin_addr = source; + return (sockaddr *)destination; +} + + status_t IPv4Multicast::JoinGroup(IPv4GroupInterface *state) { BenaphoreLocker _(sMulticastGroupsLock); sockaddr_in groupAddr; - memset(&groupAddr, 0, sizeof(groupAddr)); - groupAddr.sin_addr = state->Address(); - net_interface *intf = state->Interface(); - status_t status = - intf->first_protocol->module->join_multicast(intf->first_protocol, - (sockaddr *)&groupAddr); + status_t status = intf->first_info->join_multicast(intf->first_protocol, + fill_sockaddr_in(&groupAddr, state->Address())); if (status < B_OK) return status; @@ -736,13 +742,10 @@ sMulticastState->Remove(state); sockaddr_in groupAddr; - memset(&groupAddr, 0, sizeof(groupAddr)); - groupAddr.sin_addr = state->Address(); - net_interface *intf = state->Interface(); return intf->first_protocol->module->join_multicast(intf->first_protocol, - (sockaddr *)&groupAddr); + fill_sockaddr_in(&groupAddr, state->Address())); } @@ -913,14 +916,19 @@ if (_sourceAddr && _sourceAddr->ss_family != AF_INET) return EINVAL; - net_interface *interface = sDatalinkModule->get_interface(sDomain, index); - if (interface == NULL) - return ENODEV; - + net_interface *interface; const in_addr *groupAddr, *sourceAddr = NULL; groupAddr = &((const sockaddr_in *)_groupAddr)->sin_addr; + if (index == 0) + interface = get_multicast_interface(protocol, groupAddr); + else + interface = sDatalinkModule->get_interface(sDomain, index); + + if (interface == NULL) + return ENODEV; + if (_sourceAddr) sourceAddr = &((const sockaddr_in *)_sourceAddr)->sin_addr; From bonefish at mail.berlios.de Wed May 2 15:07:55 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 2 May 2007 15:07:55 +0200 Subject: [Haiku-commits] r20968 - haiku/trunk/src/tools/fs_shell Message-ID: <200705021307.l42D7ssW011338@sheep.berlios.de> Author: bonefish Date: 2007-05-02 15:07:54 +0200 (Wed, 02 May 2007) New Revision: 20968 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20968&view=rev Removed: haiku/trunk/src/tools/fs_shell/sem_unix.cpp Log: Obsolete file. Deleted: haiku/trunk/src/tools/fs_shell/sem_unix.cpp From bonefish at mail.berlios.de Wed May 2 15:10:53 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 2 May 2007 15:10:53 +0200 Subject: [Haiku-commits] r20969 - in haiku/trunk/src/tools: bfs_shell fs_shell Message-ID: <200705021310.l42DArTD011664@sheep.berlios.de> Author: bonefish Date: 2007-05-02 15:10:52 +0200 (Wed, 02 May 2007) New Revision: 20969 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20969&view=rev Modified: haiku/trunk/src/tools/bfs_shell/Jamfile haiku/trunk/src/tools/fs_shell/Jamfile Log: Changed grist. Modified: haiku/trunk/src/tools/bfs_shell/Jamfile =================================================================== --- haiku/trunk/src/tools/bfs_shell/Jamfile 2007-05-02 13:07:54 UTC (rev 20968) +++ haiku/trunk/src/tools/bfs_shell/Jamfile 2007-05-02 13:10:52 UTC (rev 20969) @@ -26,7 +26,7 @@ UsePrivateHeaders fs_shell ; -BuildPlatformMain bfs_shell +BuildPlatformMain bfs_shell : BlockAllocator.cpp BPlusTree.cpp Modified: haiku/trunk/src/tools/fs_shell/Jamfile =================================================================== --- haiku/trunk/src/tools/fs_shell/Jamfile 2007-05-02 13:07:54 UTC (rev 20968) +++ haiku/trunk/src/tools/fs_shell/Jamfile 2007-05-02 13:10:52 UTC (rev 20969) @@ -25,8 +25,7 @@ externalCommandsSources = external_commands_unix.cpp ; } - -BuildPlatformStaticLibrary fs_shell.a : +BuildPlatformStaticLibrary fs_shell.a : atomic.cpp block_cache.cpp command_cp.cpp @@ -59,6 +58,6 @@ fssh.cpp ; -BuildPlatformMain fs_shell_command +BuildPlatformMain fs_shell_command : fs_shell_command.cpp $(fsShellCommandSources) : $(HOST_LIBSUPC++) ; From bonefish at mail.berlios.de Wed May 2 15:13:36 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 2 May 2007 15:13:36 +0200 Subject: [Haiku-commits] r20970 - haiku/trunk/src/tools/bfs_shell Message-ID: <200705021313.l42DDacx011827@sheep.berlios.de> Author: bonefish Date: 2007-05-02 15:13:36 +0200 (Wed, 02 May 2007) New Revision: 20970 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20970&view=rev Modified: haiku/trunk/src/tools/bfs_shell/Jamfile Log: Missed this one. Modified: haiku/trunk/src/tools/bfs_shell/Jamfile =================================================================== --- haiku/trunk/src/tools/bfs_shell/Jamfile 2007-05-02 13:10:52 UTC (rev 20969) +++ haiku/trunk/src/tools/bfs_shell/Jamfile 2007-05-02 13:13:36 UTC (rev 20970) @@ -41,6 +41,6 @@ kernel_interface.cpp - : fs_shell.a $(libHaikuCompat) $(HOST_LIBSUPC++) $(HOST_LIBSTDC++) + : fs_shell.a $(libHaikuCompat) $(HOST_LIBSUPC++) $(HOST_LIBSTDC++) $(HOST_LIBROOT) ; From bonefish at mail.berlios.de Wed May 2 15:45:17 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 2 May 2007 15:45:17 +0200 Subject: [Haiku-commits] r20971 - haiku/trunk/src/tools/fs_shell Message-ID: <200705021345.l42DjH1H016241@sheep.berlios.de> Author: bonefish Date: 2007-05-02 15:45:17 +0200 (Wed, 02 May 2007) New Revision: 20971 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20971&view=rev Modified: haiku/trunk/src/tools/fs_shell/file_cache.cpp Log: Incorrect vfs_put_vnode(). Missed that one when changing from vfs_get_vnode() to vfs_lookup_vnode(). Modified: haiku/trunk/src/tools/fs_shell/file_cache.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/file_cache.cpp 2007-05-02 13:13:36 UTC (rev 20970) +++ haiku/trunk/src/tools/fs_shell/file_cache.cpp 2007-05-02 13:45:17 UTC (rev 20971) @@ -1744,7 +1744,6 @@ if (error != FSSH_B_OK) { fssh_dprintf("file_cache_create(): Failed to init mutex: %s\n", fssh_strerror(error)); - vfs_put_vnode(ref->node); delete ref; return NULL; } From axeld at pinc-software.de Wed May 2 16:03:04 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Wed, 02 May 2007 16:03:04 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r20963_-_in_haiku/trunk/src/add-o?= =?iso-8859-15?q?ns/kernel/drivers/disk=3A_=2E_virtual_virtual/fmap_virtua?= =?iso-8859-15?q?l/nbd?= In-Reply-To: <200705020038.l420ck6h016870@sheep.berlios.de> Message-ID: <2385736623-BeMail@zon> mmu_man at BerliOS wrote: > haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.h > Log: > skeleton for an fmap driver (IMAGE.BE). Start of an Network Block > Device driver. > NBD server python script I foundon the net for testing. I'm not sure what you're doing so I probably don't appreciate it enough, but can we please get rid of names like "nbd"? Bye, Axel. From bonefish at mail.berlios.de Wed May 2 16:07:10 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 2 May 2007 16:07:10 +0200 Subject: [Haiku-commits] r20972 - haiku/trunk/src/build/libroot Message-ID: <200705021407.l42E7AWA021462@sheep.berlios.de> Author: bonefish Date: 2007-05-02 16:07:09 +0200 (Wed, 02 May 2007) New Revision: 20972 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20972&view=rev Modified: haiku/trunk/src/build/libroot/sem.cpp Log: Buffed maximal semaphore count. Modified: haiku/trunk/src/build/libroot/sem.cpp =================================================================== --- haiku/trunk/src/build/libroot/sem.cpp 2007-05-02 13:45:17 UTC (rev 20971) +++ haiku/trunk/src/build/libroot/sem.cpp 2007-05-02 14:07:09 UTC (rev 20972) @@ -10,12 +10,12 @@ // semaphores. Simple fakes are sufficient. struct semaphore { - char name[B_OS_NAME_LENGTH]; + char* name; int32 count; bool inUse; }; -static const int kSemaphoreCount = 1024; +static const int kSemaphoreCount = 10240; static semaphore sSemaphores[kSemaphoreCount]; @@ -34,9 +34,13 @@ for (int i = 0; i < kSemaphoreCount; i++) { semaphore &sem = sSemaphores[i]; if (!sem.inUse) { + sem.name = strdup(name ? name : "unnamed sem"); + if (!sem.name) + return B_NO_MEMORY; + sem.inUse = true; sem.count = count; - strlcpy(sem.name, name, sizeof(sem.name)); + return i; } } @@ -178,7 +182,7 @@ info->sem = id; info->team = 1; - info->name[0] = '\0'; + strlcpy(info->name, sSemaphores[id].name, sizeof(info->name)); info->count = sSemaphores[id].count; info->latest_holder = -1; From axeld at pinc-software.de Wed May 2 16:08:03 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Wed, 02 May 2007 16:08:03 +0200 CEST Subject: [Haiku-commits] r20957 - haiku/trunk/build/jam In-Reply-To: <200705011858.l41IwMet004217@sheep.berlios.de> Message-ID: <2684127359-BeMail@zon> korli at BerliOS wrote: > Log: > added an empty input methods system directory, to be able to add the > canna IM > in fact, the directory is only monitored when existing That should actually be fixed in the input_server, I think. Would you mind if I work on this (also for keyboard and mouse input) as part of #1192? Bye, Axel. From bonefish at mail.berlios.de Wed May 2 16:09:04 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 2 May 2007 16:09:04 +0200 Subject: [Haiku-commits] r20973 - haiku/trunk/src/tools/fs_shell Message-ID: <200705021409.l42E94mO021660@sheep.berlios.de> Author: bonefish Date: 2007-05-02 16:09:03 +0200 (Wed, 02 May 2007) New Revision: 20973 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20973&view=rev Modified: haiku/trunk/src/tools/fs_shell/vfs.cpp Log: Reduced number of unused vnodes the VFS keeps around. We were hitting the maximal number of (emulated) semphores on Linux before. Modified: haiku/trunk/src/tools/fs_shell/vfs.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/vfs.cpp 2007-05-02 14:07:09 UTC (rev 20972) +++ haiku/trunk/src/tools/fs_shell/vfs.cpp 2007-05-02 14:09:03 UTC (rev 20973) @@ -48,7 +48,7 @@ namespace FSShell { -const static uint32_t kMaxUnusedVnodes = 8192; +const static uint32_t kMaxUnusedVnodes = 1024; // This is the maximum number of unused vnodes that the system // will keep around (weak limit, if there is enough memory left, // they won't get flushed even when hitting that limit). From hugosantos at mail.berlios.de Wed May 2 16:09:12 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 2 May 2007 16:09:12 +0200 Subject: [Haiku-commits] r20974 - in haiku/trunk: headers/private/kernel/util src/add-ons/kernel/network/protocols/udp Message-ID: <200705021409.l42E9Cpi021676@sheep.berlios.de> Author: hugosantos Date: 2007-05-02 16:08:55 +0200 (Wed, 02 May 2007) New Revision: 20974 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20974&view=rev Modified: haiku/trunk/headers/private/kernel/util/MultiHashTable.h haiku/trunk/headers/private/kernel/util/OpenHashTable.h haiku/trunk/src/add-ons/kernel/network/protocols/udp/udp.cpp Log: set ValueIterator's fIndex to the next slot so OpenHashTable's Iterator properly gets it. Modified: haiku/trunk/headers/private/kernel/util/MultiHashTable.h =================================================================== --- haiku/trunk/headers/private/kernel/util/MultiHashTable.h 2007-05-02 14:09:03 UTC (rev 20973) +++ haiku/trunk/headers/private/kernel/util/MultiHashTable.h 2007-05-02 14:08:55 UTC (rev 20974) @@ -75,8 +75,7 @@ : fOriginalIndex(index), fOriginalValue(value) { Iterator::fTable = table; - Iterator::fIndex = index; - Iterator::fNext = value; + Rewind(); } bool HasNext() const @@ -91,7 +90,7 @@ void Rewind() { - Iterator::fIndex = fOriginalIndex; + Iterator::fIndex = fOriginalIndex + 1; Iterator::fNext = fOriginalValue; } Modified: haiku/trunk/headers/private/kernel/util/OpenHashTable.h =================================================================== --- haiku/trunk/headers/private/kernel/util/OpenHashTable.h 2007-05-02 14:09:03 UTC (rev 20973) +++ haiku/trunk/headers/private/kernel/util/OpenHashTable.h 2007-05-02 14:08:55 UTC (rev 20974) @@ -114,16 +114,8 @@ void InsertUnchecked(ValueType *value) { - if (CheckDuplicates) { - for (size_t i = 0; i < fTableSize; i++) { - ValueType *bucket = fTable[i]; - while (bucket) { - if (bucket == value) - panic("Hash Table: value already in table."); - bucket = _Link(bucket)->fNext; - } - } - } + if (CheckDuplicates && _ExaustiveSearch(value)) + panic("Hash Table: value already in table."); _Insert(fTable, fTableSize, value); fItemCount++; @@ -164,16 +156,8 @@ if (slot == NULL) return false; - if (CheckDuplicates) { - for (size_t i = 0; i < fTableSize; i++) { - ValueType *bucket = fTable[i]; - while (bucket) { - if (bucket == value) - panic("Hash Table: duplicate detected."); - bucket = _Link(bucket)->fNext; - } - } - } + if (CheckDuplicates && _ExaustiveSearch(value)) + panic("Hash Table: duplicate detected."); fItemCount--; return true; @@ -270,6 +254,20 @@ return fDefinition.GetLink(bucket); } + bool _ExaustiveSearch(ValueType *value) const + { + for (size_t i = 0; i < fTableSize; i++) { + ValueType *bucket = fTable[i]; + while (bucket) { + if (bucket == value) + return true; + bucket = _Link(bucket)->fNext; + } + } + + return false; + } + Definition fDefinition; size_t fTableSize, fItemCount; ValueType **fTable; Modified: haiku/trunk/src/add-ons/kernel/network/protocols/udp/udp.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/udp/udp.cpp 2007-05-02 14:09:03 UTC (rev 20973) +++ haiku/trunk/src/add-ons/kernel/network/protocols/udp/udp.cpp 2007-05-02 14:08:55 UTC (rev 20974) @@ -933,6 +933,8 @@ status_t UdpEndpoint::DeliverData(net_buffer *_buffer) { + TRACE_EP("DeliverData(%p [%ld bytes])", _buffer, _buffer->size); + net_buffer *buffer = gBufferModule->clone(_buffer, false); if (buffer == NULL) return B_NO_MEMORY; From bonefish at mail.berlios.de Wed May 2 16:12:04 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 2 May 2007 16:12:04 +0200 Subject: [Haiku-commits] r20975 - haiku/trunk/build/jam Message-ID: <200705021412.l42EC4FX021840@sheep.berlios.de> Author: bonefish Date: 2007-05-02 16:12:04 +0200 (Wed, 02 May 2007) New Revision: 20975 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20975&view=rev Modified: haiku/trunk/build/jam/HaikuImage Log: Create the Haiku image using the new FS shell. Successfully tested on BeOS R5 and x86 Linux so far. Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2007-05-02 14:08:55 UTC (rev 20974) +++ haiku/trunk/build/jam/HaikuImage 2007-05-02 14:12:04 UTC (rev 20975) @@ -358,8 +358,8 @@ AddVariableToScript $(script) : addBuildCompatibilityLibDir : $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) ; AddVariableToScript $(script) : updateOnly : $(HAIKU_IMAGE_UPDATE_ONLY) ; -AddTargetVariableToScript $(script) : bfs_shell : bfsShell ; -AddTargetVariableToScript $(script) : fs_shell_command : fsShellCommand ; +AddTargetVariableToScript $(script) : bfs_shell : bfsShell ; +AddTargetVariableToScript $(script) : fs_shell_command : fsShellCommand ; AddTargetVariableToScript $(script) : copyattr ; AddTargetVariableToScript $(script) : makebootable ; AddTargetVariableToScript $(script) : rc ; From hugosantos at gmail.com Wed May 2 16:17:36 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Wed, 2 May 2007 15:17:36 +0100 Subject: [Haiku-commits] r20975 - haiku/trunk/build/jam In-Reply-To: <200705021412.l42EC4FX021840@sheep.berlios.de> References: <200705021412.l42EC4FX021840@sheep.berlios.de> Message-ID: <9c46321e0705020717r738ed2eap8f52ba48d5675741@mail.gmail.com> I was hoping to give you good news but unfortunately that's not the case :-( Doing a full build here in Ubuntu Linux (native gcc 4.1.2, cross compiler gcc 2.95) it fails copying the files to the image, generally with 'Command failed: Bad file descriptor', for instance: Error: Failed to open source path `/home/hugo/build/haiku-gcc2.95/objects/haiku/x86/release/add-ons/kernel/bus_managers /pci/pci': Bad file descriptor Error: Command failed: Bad file descriptor Error: Command was: cp :/home/hugo/build/haiku-gcc2.95/objects/haiku/x86/release/add-ons/kernel/bus_managers/pci/pci :/home/hugo/build/ha iku-gcc2.95/objects/haiku/x86/release/add-ons/kernel/bus_managers/ps2/ps2 :/home/hugo/build/haiku-gcc2.95/objects/haiku /x86/release/add-ons/kernel/bus_managers/isa/isa :/home/hugo/build/haiku-gcc2.95/objects/haiku/x86/release/add-ons/kern el/bus_managers/ide/ide :/home/hugo/build/haiku-gcc2.95/objects/haiku/x86/release/add-ons/kernel/bus_managers/scsi/scsi :/home/hugo/build/haiku-gcc2.95/objects/haiku/x86/release/add-ons/kernel/bus_managers/config_manager/config_manager :/ home/hugo/build/haiku-gcc2.95/objects/haiku/x86/release/add-ons/kernel/bus_managers/agp/agp :/home/hugo/build/haiku-gcc 2.95/objects/haiku/x86/release/add-ons/kernel/bus_managers/usb/usb /myfs/beos/system/add-ons/kernel/bus_managers Any instructions on what i can test to help? Hugo On 5/2/07, bonefish at BerliOS wrote: > Author: bonefish > Date: 2007-05-02 16:12:04 +0200 (Wed, 02 May 2007) > New Revision: 20975 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20975&view=rev > > Modified: > haiku/trunk/build/jam/HaikuImage > Log: > Create the Haiku image using the new FS shell. Successfully tested on > BeOS R5 and x86 Linux so far. > > > Modified: haiku/trunk/build/jam/HaikuImage > =================================================================== > --- haiku/trunk/build/jam/HaikuImage 2007-05-02 14:08:55 UTC (rev 20974) > +++ haiku/trunk/build/jam/HaikuImage 2007-05-02 14:12:04 UTC (rev 20975) > @@ -358,8 +358,8 @@ > AddVariableToScript $(script) : addBuildCompatibilityLibDir > : $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) ; > AddVariableToScript $(script) : updateOnly : $(HAIKU_IMAGE_UPDATE_ONLY) ; > -AddTargetVariableToScript $(script) : bfs_shell : bfsShell ; > -AddTargetVariableToScript $(script) : fs_shell_command : fsShellCommand ; > +AddTargetVariableToScript $(script) : bfs_shell : bfsShell ; > +AddTargetVariableToScript $(script) : fs_shell_command : fsShellCommand ; > AddTargetVariableToScript $(script) : copyattr ; > AddTargetVariableToScript $(script) : makebootable ; > AddTargetVariableToScript $(script) : rc ; > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From bonefish at mail.berlios.de Wed May 2 16:26:34 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 2 May 2007 16:26:34 +0200 Subject: [Haiku-commits] r20976 - in haiku/trunk: headers/private/fs_shell src/tools/fs_shell Message-ID: <200705021426.l42EQYox023119@sheep.berlios.de> Author: bonefish Date: 2007-05-02 16:26:29 +0200 (Wed, 02 May 2007) New Revision: 20976 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20976&view=rev Modified: haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h haiku/trunk/headers/private/fs_shell/fssh_defs.h haiku/trunk/headers/private/fs_shell/fssh_os.h haiku/trunk/src/tools/fs_shell/command_cp.h haiku/trunk/src/tools/fs_shell/external_commands.h haiku/trunk/src/tools/fs_shell/fs_shell_command.h haiku/trunk/src/tools/fs_shell/fs_shell_command_unix.h haiku/trunk/src/tools/fs_shell/fssh.h haiku/trunk/src/tools/fs_shell/module.h haiku/trunk/src/tools/fs_shell/path_util.h haiku/trunk/src/tools/fs_shell/syscalls.h Log: Thou shall not leave a blank line between copyright header and header guard. Modified: haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h 2007-05-02 14:12:04 UTC (rev 20975) +++ haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h 2007-05-02 14:26:29 UTC (rev 20976) @@ -2,7 +2,6 @@ * Copyright 2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. * Distributed under the terms of the MIT License. */ - #ifndef _FSSH_API_WRAPPER_H #define _FSSH_API_WRAPPER_H Modified: haiku/trunk/headers/private/fs_shell/fssh_defs.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_defs.h 2007-05-02 14:12:04 UTC (rev 20975) +++ haiku/trunk/headers/private/fs_shell/fssh_defs.h 2007-05-02 14:26:29 UTC (rev 20976) @@ -2,7 +2,6 @@ * Copyright 2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. * Distributed under the terms of the MIT License. */ - #ifndef _FSSH_DEFS_H #define _FSSH_DEFS_H Modified: haiku/trunk/headers/private/fs_shell/fssh_os.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_os.h 2007-05-02 14:12:04 UTC (rev 20975) +++ haiku/trunk/headers/private/fs_shell/fssh_os.h 2007-05-02 14:26:29 UTC (rev 20976) @@ -3,7 +3,6 @@ * Copyright 2004-2006, Haiku Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ - #ifndef _FSSH_SEM_H #define _FSSH_SEM_H Modified: haiku/trunk/src/tools/fs_shell/command_cp.h =================================================================== --- haiku/trunk/src/tools/fs_shell/command_cp.h 2007-05-02 14:12:04 UTC (rev 20975) +++ haiku/trunk/src/tools/fs_shell/command_cp.h 2007-05-02 14:26:29 UTC (rev 20976) @@ -2,7 +2,6 @@ * Copyright 2005-2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. * Distributed under the terms of the MIT License. */ - #ifndef _FSSH_COMMAND_CP_H #define _FSSH_COMMAND_CP_H Modified: haiku/trunk/src/tools/fs_shell/external_commands.h =================================================================== --- haiku/trunk/src/tools/fs_shell/external_commands.h 2007-05-02 14:12:04 UTC (rev 20975) +++ haiku/trunk/src/tools/fs_shell/external_commands.h 2007-05-02 14:26:29 UTC (rev 20976) @@ -2,7 +2,6 @@ * Copyright 2005-2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. * Distributed under the terms of the MIT License. */ - #ifndef _FSSH_EXTERNAL_COMMANDS_H #define _FSSH_EXTERNAL_COMMANDS_H Modified: haiku/trunk/src/tools/fs_shell/fs_shell_command.h =================================================================== --- haiku/trunk/src/tools/fs_shell/fs_shell_command.h 2007-05-02 14:12:04 UTC (rev 20975) +++ haiku/trunk/src/tools/fs_shell/fs_shell_command.h 2007-05-02 14:26:29 UTC (rev 20976) @@ -2,7 +2,6 @@ * Copyright 2005-2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. * Distributed under the terms of the MIT License. */ - #ifndef _FSSH_FS_SHELL_COMMAND_H #define _FSSH_FS_SHELL_COMMAND_H Modified: haiku/trunk/src/tools/fs_shell/fs_shell_command_unix.h =================================================================== --- haiku/trunk/src/tools/fs_shell/fs_shell_command_unix.h 2007-05-02 14:12:04 UTC (rev 20975) +++ haiku/trunk/src/tools/fs_shell/fs_shell_command_unix.h 2007-05-02 14:26:29 UTC (rev 20976) @@ -2,7 +2,6 @@ * Copyright 2005-2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. * Distributed under the terms of the MIT License. */ - #ifndef _FSSH_FS_SHELL_COMMAND_UNIX_H #define _FSSH_FS_SHELL_COMMAND_UNIX_H Modified: haiku/trunk/src/tools/fs_shell/fssh.h =================================================================== --- haiku/trunk/src/tools/fs_shell/fssh.h 2007-05-02 14:12:04 UTC (rev 20975) +++ haiku/trunk/src/tools/fs_shell/fssh.h 2007-05-02 14:26:29 UTC (rev 20976) @@ -2,7 +2,6 @@ * Copyright 2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. * Distributed under the terms of the MIT License. */ - #ifndef _FSSH_FSSH_H #define _FSSH_FSSH_H Modified: haiku/trunk/src/tools/fs_shell/module.h =================================================================== --- haiku/trunk/src/tools/fs_shell/module.h 2007-05-02 14:12:04 UTC (rev 20975) +++ haiku/trunk/src/tools/fs_shell/module.h 2007-05-02 14:26:29 UTC (rev 20976) @@ -2,7 +2,6 @@ * Copyright 2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. * Distributed under the terms of the MIT License. */ - #ifndef _FSSH_MODULE_PRIVATE_H #define _FSSH_MODULE_PRIVATE_H Modified: haiku/trunk/src/tools/fs_shell/path_util.h =================================================================== --- haiku/trunk/src/tools/fs_shell/path_util.h 2007-05-02 14:12:04 UTC (rev 20975) +++ haiku/trunk/src/tools/fs_shell/path_util.h 2007-05-02 14:26:29 UTC (rev 20976) @@ -2,7 +2,6 @@ * Copyright 2005-2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. * Distributed under the terms of the MIT License. */ - #ifndef _FSSH_PATH_UTIL_H #define _FSSH_PATH_UTIL_H Modified: haiku/trunk/src/tools/fs_shell/syscalls.h =================================================================== --- haiku/trunk/src/tools/fs_shell/syscalls.h 2007-05-02 14:12:04 UTC (rev 20975) +++ haiku/trunk/src/tools/fs_shell/syscalls.h 2007-05-02 14:26:29 UTC (rev 20976) @@ -2,7 +2,6 @@ * Copyright 2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. * Distributed under the terms of the MIT License. */ - #ifndef _FSSH_SYSCALLS_H #define _FSSH_SYSCALLS_H From korli at users.berlios.de Wed May 2 16:30:54 2007 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Wed, 2 May 2007 16:30:54 +0200 Subject: [Haiku-commits] r20957 - haiku/trunk/build/jam In-Reply-To: <2684127359-BeMail@zon> References: <200705011858.l41IwMet004217@sheep.berlios.de> <2684127359-BeMail@zon> Message-ID: Hi Axel, 2007/5/2, Axel D?rfler : > korli at BerliOS wrote: > > Log: > > added an empty input methods system directory, to be able to add the > > canna IM > > in fact, the directory is only monitored when existing > > That should actually be fixed in the input_server, I think. > Would you mind if I work on this (also for keyboard and mouse input) as > part of #1192? > I should be able to handle this, except if you have an excess of free time :) BTW, about addons, I think it could be cool to have the creation of monitored directories done optionally in src/kits/storage/AddOnMonitorHandler.cpp. This one is also used by the media_server and it could benefit from this too. Bye, J?r?me From hugosantos at gmail.com Wed May 2 16:39:08 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Wed, 2 May 2007 15:39:08 +0100 Subject: [Haiku-commits] r20975 - haiku/trunk/build/jam In-Reply-To: <9c46321e0705020717r738ed2eap8f52ba48d5675741@mail.gmail.com> References: <200705021412.l42EC4FX021840@sheep.berlios.de> <9c46321e0705020717r738ed2eap8f52ba48d5675741@mail.gmail.com> Message-ID: <9c46321e0705020739r4c3bc095tab5ef1c204834dd8@mail.gmail.com> From bonefish at cs.tu-berlin.de Wed May 2 17:07:03 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Wed, 02 May 2007 17:07:03 +0200 Subject: [Haiku-commits] r20975 - haiku/trunk/build/jam In-Reply-To: <9c46321e0705020739r4c3bc095tab5ef1c204834dd8@mail.gmail.com> References: <200705021412.l42EC4FX021840@sheep.berlios.de> <9c46321e0705020717r738ed2eap8f52ba48d5675741@mail.gmail.com> <9c46321e0705020739r4c3bc095tab5ef1c204834dd8@mail.gmail.com> Message-ID: <20070502170703.796.1@cs.tu-berlin.de> On 2007-05-02 at 16:39:08 [+0200], Hugo Santos wrote: > >From a strace to the build: > > 11442 > open("/home/hugo/build/haiku-gcc2.95/objects/haiku/x86/release/tests/kits/ne > t/tcptester/tcptester", > O_RDONLY|O_LARGEFILE) = 6 > 11442 fstat64(6, {st_mode=S_IFREG|0711, st_size=14979, ...}) = 0 > 11442 close(6) = 0 > 11442 write(2, "Error: Failed to open source pat"..., 149) = 149 > > That would be 'failed to open source path ...tcptester'. Which doesn't > sound very good considering the open() and stat() didn't fail. :-) Thanks. Have you enabled xattr support for the build? CU, Ingo From hugosantos at gmail.com Wed May 2 17:16:07 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Wed, 2 May 2007 16:16:07 +0100 Subject: [Haiku-commits] r20975 - haiku/trunk/build/jam In-Reply-To: <20070502170703.796.1@cs.tu-berlin.de> References: <200705021412.l42EC4FX021840@sheep.berlios.de> <9c46321e0705020717r738ed2eap8f52ba48d5675741@mail.gmail.com> <9c46321e0705020739r4c3bc095tab5ef1c204834dd8@mail.gmail.com> <20070502170703.796.1@cs.tu-berlin.de> Message-ID: <9c46321e0705020816k7bdc7fc5t748ac80e98d20af8@mail.gmail.com> Nope, i haven't. I can give it a go with xattr if you think it could help. Hugo On 5/2/07, Ingo Weinhold wrote: > > On 2007-05-02 at 16:39:08 [+0200], Hugo Santos wrote: > > >From a strace to the build: > > > > 11442 > > open("/home/hugo/build/haiku-gcc2.95/objects/haiku/x86/release/tests/kits/ne > > t/tcptester/tcptester", > > O_RDONLY|O_LARGEFILE) = 6 > > 11442 fstat64(6, {st_mode=S_IFREG|0711, st_size=14979, ...}) = 0 > > 11442 close(6) = 0 > > 11442 write(2, "Error: Failed to open source pat"..., 149) = 149 > > > > That would be 'failed to open source path ...tcptester'. Which doesn't > > sound very good considering the open() and stat() didn't fail. :-) > > Thanks. Have you enabled xattr support for the build? > > CU, Ingo > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From bonefish at cs.tu-berlin.de Wed May 2 17:23:55 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Wed, 02 May 2007 17:23:55 +0200 Subject: [Haiku-commits] r20975 - haiku/trunk/build/jam In-Reply-To: <9c46321e0705020816k7bdc7fc5t748ac80e98d20af8@mail.gmail.com> References: <200705021412.l42EC4FX021840@sheep.berlios.de> <9c46321e0705020717r738ed2eap8f52ba48d5675741@mail.gmail.com> <9c46321e0705020739r4c3bc095tab5ef1c204834dd8@mail.gmail.com> <20070502170703.796.1@cs.tu-berlin.de> <9c46321e0705020816k7bdc7fc5t748ac80e98d20af8@mail.gmail.com> Message-ID: <20070502172355.842.2@cs.tu-berlin.de> On 2007-05-02 at 17:16:07 [+0200], Hugo Santos wrote: > Nope, i haven't. I can give it a go with xattr if you think it could help. No, thanks. I can reproduce the problem without xattr support. Working on it. CU, Ingo From axeld at pinc-software.de Wed May 2 17:22:51 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Wed, 02 May 2007 17:22:51 +0200 CEST Subject: [Haiku-commits] r20972 - haiku/trunk/src/build/libroot In-Reply-To: <200705021407.l42E7AWA021462@sheep.berlios.de> Message-ID: <7172037088-BeMail@zon> bonefish at BerliOS wrote: > Log: > Buffed maximal semaphore count. [...] > struct semaphore { > - char name[B_OS_NAME_LENGTH]; > + char* name; Is it a good idea to never free "name"? :-) Bye, Axel. From axeld at pinc-software.de Wed May 2 17:28:33 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Wed, 02 May 2007 17:28:33 +0200 CEST Subject: [Haiku-commits] r20957 - haiku/trunk/build/jam In-Reply-To: Message-ID: <7514591310-BeMail@zon> Hi J?r?me, "J?r?me Duval" wrote: > > That should actually be fixed in the input_server, I think. > > Would you mind if I work on this (also for keyboard and mouse > > input) as > > part of #1192? > I should be able to handle this, except if you have an excess of free > time :) Fine with me, too :-) > BTW, about addons, I think it could be cool to have the creation of > monitored directories done optionally in > src/kits/storage/AddOnMonitorHandler.cpp. This one is also used by > the > media_server and it could benefit from this too. That's where I would have started, too, including supporting parent directories. I see you've taken over #1192, too? Thanks! :-) Bye, Axel. From bonefish at cs.tu-berlin.de Wed May 2 17:47:13 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Wed, 02 May 2007 17:47:13 +0200 Subject: [Haiku-commits] r20972 - haiku/trunk/src/build/libroot In-Reply-To: <7172037088-BeMail@zon> References: <7172037088-BeMail@zon> Message-ID: <20070502174713.908.3@cs.tu-berlin.de> On 2007-05-02 at 17:22:51 [+0200], Axel D?rfler wrote: > bonefish at BerliOS wrote: > > Log: > > Buffed maximal semaphore count. > [...] > > struct semaphore { > > - char name[B_OS_NAME_LENGTH]; > > + char* name; > > Is it a good idea to never free "name"? :-) Yeah, freeing memory is totally overrated. ;-) CU, Ingo From laplace at mail.berlios.de Wed May 2 17:46:25 2007 From: laplace at mail.berlios.de (laplace at BerliOS) Date: Wed, 2 May 2007 17:46:25 +0200 Subject: [Haiku-commits] r20977 - in haiku/trunk/src: add-ons/print/drivers/shared/libprint add-ons/print/shared servers/print/shared Message-ID: <200705021546.l42FkPov000722@sheep.berlios.de> Author: laplace Date: 2007-05-02 17:46:25 +0200 (Wed, 02 May 2007) New Revision: 20977 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20977&view=rev Modified: haiku/trunk/src/add-ons/print/drivers/shared/libprint/GraphicsDriver.cpp haiku/trunk/src/add-ons/print/shared/PrintJobReader.cpp haiku/trunk/src/servers/print/shared/BeUtils.cpp Log: Changed __ZETA__ to B_BEOS_VERSION_DANO as suggested by Axel. Modified: haiku/trunk/src/add-ons/print/drivers/shared/libprint/GraphicsDriver.cpp =================================================================== --- haiku/trunk/src/add-ons/print/drivers/shared/libprint/GraphicsDriver.cpp 2007-05-02 14:26:29 UTC (rev 20976) +++ haiku/trunk/src/add-ons/print/drivers/shared/libprint/GraphicsDriver.cpp 2007-05-02 15:46:25 UTC (rev 20977) @@ -74,7 +74,7 @@ return true; } -#ifndef __ZETA__ +#ifndef B_BEOS_VERSION_DANO print_file_header pfh; #else BPrintJob::print_file_header pfh; Modified: haiku/trunk/src/add-ons/print/shared/PrintJobReader.cpp =================================================================== --- haiku/trunk/src/add-ons/print/shared/PrintJobReader.cpp 2007-05-02 14:26:29 UTC (rev 20976) +++ haiku/trunk/src/add-ons/print/shared/PrintJobReader.cpp 2007-05-02 15:46:25 UTC (rev 20977) @@ -104,7 +104,7 @@ , fNumberOfPages(-1) , fPageIndex(NULL) { -#ifndef __ZETA__ +#ifndef B_BEOS_VERSION_DANO print_file_header header; #else BPrintJob::print_file_header header; Modified: haiku/trunk/src/servers/print/shared/BeUtils.cpp =================================================================== --- haiku/trunk/src/servers/print/shared/BeUtils.cpp 2007-05-02 14:26:29 UTC (rev 20976) +++ haiku/trunk/src/servers/print/shared/BeUtils.cpp 2007-05-02 15:46:25 UTC (rev 20977) @@ -103,7 +103,7 @@ void AddFields(BMessage* to, const BMessage* from, const char* excludeList[], const char* includeList[], bool overwrite) { if (to == from) return; -#ifndef __ZETA__ +#ifndef B_BEOS_VERSION_DANO char* name; #else const char* name; From bga at bug-br.org.br Wed May 2 17:43:06 2007 From: bga at bug-br.org.br (Bruno Albuquerque) Date: Wed, 02 May 2007 12:43:06 -0300 Subject: [Haiku-commits] r20975 - haiku/trunk/build/jam In-Reply-To: <20070502172355.842.2@cs.tu-berlin.de> References: <200705021412.l42EC4FX021840@sheep.berlios.de> <9c46321e0705020717r738ed2eap8f52ba48d5675741@mail.gmail.com> <9c46321e0705020739r4c3bc095tab5ef1c204834dd8@mail.gmail.com> <20070502170703.796.1@cs.tu-berlin.de> <9c46321e0705020816k7bdc7fc5t748ac80e98d20af8@mail.gmail.com> <20070502172355.842.2@cs.tu-berlin.de> Message-ID: <4638B18A.70009@bug-br.org.br> Ingo Weinhold wrote: >> Nope, i haven't. I can give it a go with xattr if you think it could help. > > No, thanks. I can reproduce the problem without xattr support. Working on it. For what is worth, I am also having problems under Linux + GCC4: C++ generated/objects/linux/x86/release/tools/fs_shell/vfs.o src/tools/fs_shell/vfs.cpp: In function 'fssh_off_t FSShell::file_seek(FSShell::file_descriptor*, fssh_off_t, int)': src/tools/fs_shell/vfs.cpp:2792: error: 'LONGLONG_MAX' was not declared in this scope src/tools/fs_shell/vfs.cpp: In function 'fssh_off_t FSShell::attr_seek(FSShell::file_descriptor*, fssh_off_t, int)': src/tools/fs_shell/vfs.cpp:3720: error: 'LONGLONG_MAX' was not declared in this scope cc -c "src/tools/fs_shell/vfs.cpp" -O -Wall -Wno-ctor-dtor-privacy -Woverloaded-virtual -Wpointer-arith -Wcast-align -Wsign-compare -Wno-multichar -D_ZETA_USING_DEPRECATED_API_=1 -D_ZETA_TS_FIND_DIR_=1 -DARCH_x86 -D_NO_INLINE_ASM -D__INTEL__ -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DHAIKU_HOST_PLATFORM_LINUX -iquote src/tools/fs_shell -iquote generated/objects/common/tools/fs_shell -iquote generated/objects/linux/x86/common/tools/fs_shell -iquote generated/objects/haiku/x86/common/tools/fs_shell -I headers/build -I headers/build/os -I headers/build/os/kernel -I headers/build/os/storage -I headers/build/os/support -I headers/private/fs_shell -I headers/private/shared -I headers/build/host/linux -o "generated/objects/linux/x86/release/tools/fs_shell/vfs.o" ; ...failed C++ generated/objects/linux/x86/release/tools/fs_shell/vfs.o ... ...skipped fs_shell.a for lack of fs_shell.a(vfs.o)... ...skipped bfs_shell for lack of fs_shell.a... ...skipped haiku.image-init-vars for lack of bfs_shell... ...skipped haiku.image for lack of haiku.image-init-vars... ...skipped haiku.vmdk for lack of haiku.image... ...failed updating 1 target(s)... ...skipped 5 target(s)... ...updated 47 target(s)... From axeld at mail.berlios.de Wed May 2 18:48:22 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 2 May 2007 18:48:22 +0200 Subject: [Haiku-commits] r20978 - haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid Message-ID: <200705021648.l42GmM68003580@sheep.berlios.de> Author: axeld Date: 2007-05-02 18:48:21 +0200 (Wed, 02 May 2007) New Revision: 20978 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20978&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/hid.c Log: Fixed a bug reported by Stippi: when a report from the USB device contained a key up and a key down event at the same time, the key repeat timer didn't work. Modified: haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/hid.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/hid.c 2007-05-02 15:46:25 UTC (rev 20977) +++ haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/hid.c 2007-05-02 16:48:21 UTC (rev 20978) @@ -414,6 +414,7 @@ { uint8 modifiers = ((uint8*)device->buffer)[0]; uint8 bits = device->last_buffer[0] ^ modifiers; + bool timerSet = false; uint32 i, j; if (bits) { @@ -446,6 +447,7 @@ // unmapped key key = 0x200000 + ((uint8*)device->buffer)[i]; } + //dprintf("key down: %x, mapping: %lx\n", ((uint8*)device->buffer)[i], key); write_key(device, key, true); @@ -454,6 +456,7 @@ device->repeat_timer.key = key; add_timer(&device->repeat_timer.timer, timer_delay_hook, device->repeat_delay, B_ONE_SHOT_RELATIVE_TIMER); + timerSet = true; } } else break; @@ -485,7 +488,8 @@ } write_key(device, key, false); - cancel_timer(&device->repeat_timer.timer); + if (!timerSet) + cancel_timer(&device->repeat_timer.timer); } } else break; From bonefish at mail.berlios.de Wed May 2 18:50:25 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 2 May 2007 18:50:25 +0200 Subject: [Haiku-commits] r20979 - haiku/trunk/src/build/libroot Message-ID: <200705021650.l42GoPVf004736@sheep.berlios.de> Author: bonefish Date: 2007-05-02 18:50:25 +0200 (Wed, 02 May 2007) New Revision: 20979 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20979&view=rev Modified: haiku/trunk/src/build/libroot/sem.cpp Log: Memory leak spotted by Axel. Modified: haiku/trunk/src/build/libroot/sem.cpp =================================================================== --- haiku/trunk/src/build/libroot/sem.cpp 2007-05-02 16:48:21 UTC (rev 20978) +++ haiku/trunk/src/build/libroot/sem.cpp 2007-05-02 16:50:25 UTC (rev 20979) @@ -1,6 +1,7 @@ #include +#include #include #include @@ -56,6 +57,8 @@ return B_BAD_SEM_ID; sSemaphores[id].inUse = false; + free(sSemaphores[id].name); + sSemaphores[id].name = NULL; return B_OK; } From bonefish at mail.berlios.de Wed May 2 18:59:11 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 2 May 2007 18:59:11 +0200 Subject: [Haiku-commits] r20980 - haiku/trunk/src/tools/fs_shell Message-ID: <200705021659.l42GxBOn019288@sheep.berlios.de> Author: bonefish Date: 2007-05-02 18:59:10 +0200 (Wed, 02 May 2007) New Revision: 20980 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20980&view=rev Modified: haiku/trunk/src/tools/fs_shell/command_cp.cpp haiku/trunk/src/tools/fs_shell/fcntl.cpp haiku/trunk/src/tools/fs_shell/fd.cpp haiku/trunk/src/tools/fs_shell/stat.cpp haiku/trunk/src/tools/fs_shell/syscalls.h haiku/trunk/src/tools/fs_shell/unistd.cpp haiku/trunk/src/tools/fs_shell/vfs.cpp Log: * Moved the syscalls into the FSShell namespace, so that they don't collide with the functions defined in libroot_build.so. * On BeOS incompatible platforms fssh_open() and fssh_close() use the libroot_build.so _kern_open() and _kern_close() respectively, so that the attribute support works also when using the generic attribute emulation. * Use fssh_open()/fssh_close() instead of open()/close() for the cp command, so that we get attribute support on BeOS incompatible platforms when the generic attribute emulation is used. Modified: haiku/trunk/src/tools/fs_shell/command_cp.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/command_cp.cpp 2007-05-02 16:50:25 UTC (rev 20979) +++ haiku/trunk/src/tools/fs_shell/command_cp.cpp 2007-05-02 16:59:10 UTC (rev 20980) @@ -22,6 +22,7 @@ #include "fssh_fs_attr.h" #include "fssh_stat.h" #include "fssh_string.h" +#include "fssh_unistd.h" #include "path_util.h" #include "stat_util.h" #include "syscalls.h" @@ -136,7 +137,7 @@ virtual ~HostNode() { if (fFD >= 0) - close(fFD); + fssh_close(fFD); if (fAttrDir) fs_close_attr_dir(fAttrDir); } @@ -340,40 +341,36 @@ virtual fssh_status_t Open(const char *path, int openMode, Node *&_node) { // open the node - int fd = open(path, to_platform_open_mode(openMode)); + int fd = fssh_open(path, openMode); if (fd < 0) return fssh_get_errno(); // stat the node - struct stat st; - if (fstat(fd, &st) < 0) { - close(fd); + struct fssh_stat st; + if (fssh_fstat(fd, &st) < 0) { + fssh_close(fd); return fssh_get_errno(); } // check the node type and create the node HostNode *node = NULL; - switch (st.st_mode & S_IFMT) { - case S_IFLNK: + switch (st.fssh_st_mode & FSSH_S_IFMT) { + case FSSH_S_IFLNK: node = new HostSymLink; break; - case S_IFREG: + case FSSH_S_IFREG: node = new HostFile; break; - case S_IFDIR: + case FSSH_S_IFDIR: node = new HostDirectory; break; default: - close(fd); + fssh_close(fd); return FSSH_EINVAL; } - // convert the stat - struct fssh_stat myst; - from_platform_stat(&st, &myst); - // init the node - fssh_status_t error = node->Init(path, fd, myst); + fssh_status_t error = node->Init(path, fd, st); // the node receives ownership of the FD if (error != FSSH_B_OK) { delete node; @@ -385,26 +382,23 @@ } virtual fssh_status_t CreateFile(const char *path, - const struct fssh_stat &myst, File *&_file) + const struct fssh_stat &st, File *&_file) { - struct stat st; - to_platform_stat(&myst, &st); - // create the file - int fd = creat(path, st.st_mode & S_IUMSK); + int fd = fssh_creat(path, st.fssh_st_mode & FSSH_S_IUMSK); if (fd < 0) return fssh_get_errno(); // apply the other stat fields fssh_status_t error = _ApplyStat(fd, st); if (error != FSSH_B_OK) { - close(fd); + fssh_close(fd); return error; } // create the object HostFile *file = new HostFile; - error = file->Init(path, fd, myst); + error = file->Init(path, fd, st); if (error != FSSH_B_OK) { delete file; return error; @@ -415,30 +409,27 @@ } virtual fssh_status_t CreateDirectory(const char *path, - const struct fssh_stat &myst, Directory *&_dir) + const struct fssh_stat &st, Directory *&_dir) { - struct stat st; - to_platform_stat(&myst, &st); - // create the dir - if (mkdir(path, st.st_mode & S_IUMSK) < 0) + if (fssh_mkdir(path, st.fssh_st_mode & FSSH_S_IUMSK) < 0) return fssh_get_errno(); // open the dir node - int fd = open(path, O_RDONLY | O_NOTRAVERSE); + int fd = fssh_open(path, FSSH_O_RDONLY | FSSH_O_NOTRAVERSE); if (fd < 0) return fssh_get_errno(); // apply the other stat fields fssh_status_t error = _ApplyStat(fd, st); if (error != FSSH_B_OK) { - close(fd); + fssh_close(fd); return error; } // create the object HostDirectory *dir = new HostDirectory; - error = dir->Init(path, fd, myst); + error = dir->Init(path, fd, st); if (error != FSSH_B_OK) { delete dir; return error; @@ -449,30 +440,27 @@ } virtual fssh_status_t CreateSymLink(const char *path, const char *linkTo, - const struct fssh_stat &myst, SymLink *&_link) + const struct fssh_stat &st, SymLink *&_link) { - struct stat st; - to_platform_stat(&myst, &st); - // create the link if (symlink(linkTo, path) < 0) return fssh_get_errno(); // open the symlink node - int fd = open(path, O_RDONLY | O_NOTRAVERSE); + int fd = fssh_open(path, FSSH_O_RDONLY | FSSH_O_NOTRAVERSE); if (fd < 0) return fssh_get_errno(); // apply the other stat fields fssh_status_t error = _ApplyStat(fd, st); if (error != FSSH_B_OK) { - close(fd); + fssh_close(fd); return error; } // create the object HostSymLink *link = new HostSymLink; - error = link->Init(path, fd, myst); + error = link->Init(path, fd, st); if (error != FSSH_B_OK) { delete link; return error; @@ -485,13 +473,13 @@ virtual fssh_status_t Unlink(const char *path) { - if (unlink(path) < 0) + if (fssh_unlink(path) < 0) return fssh_get_errno(); return FSSH_B_OK; } private: - fssh_status_t _ApplyStat(int fd, const struct stat &st) + fssh_status_t _ApplyStat(int fd, const struct fssh_stat &st) { // TODO: Set times... return FSSH_B_OK; Modified: haiku/trunk/src/tools/fs_shell/fcntl.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/fcntl.cpp 2007-05-02 16:50:25 UTC (rev 20979) +++ haiku/trunk/src/tools/fs_shell/fcntl.cpp 2007-05-02 16:59:10 UTC (rev 20980) @@ -8,12 +8,20 @@ #include #include +#include "fssh_errno.h" #include "stat_util.h" using namespace FSShell; +#ifndef __BEOS__ + // The _kern_open() defined in libroot_build.so. + extern "C" int _kern_open(int fd, const char *path, int openMode, + int perms); +#endif + + int fssh_open(const char *pathname, int oflags, ...) { @@ -27,8 +35,26 @@ va_end(args); -// TODO: That's not perfect yet: We should use open() on BeOS compatible -// platforms and _kern_open() otherwise. - return open(pathname, to_platform_open_mode(oflags), - to_platform_mode(mode)); + // Use the _kern_open() defined in libroot on BeOS incompatible systems. + // Required for proper attribute emulation support. + #if __BEOS__ + return open(pathname, to_platform_open_mode(oflags), + to_platform_mode(mode)); + #else + int fd = _kern_open(-1, pathname, to_platform_open_mode(oflags), + to_platform_mode(mode)); + if (fd < 0) { + fssh_set_errno(fd); + return -1; + } + + return fd; + #endif } + + +int +fssh_creat(const char *path, fssh_mode_t mode) +{ + return fssh_open(path, FSSH_O_WRONLY | FSSH_O_CREAT | FSSH_O_TRUNC, mode); +} Modified: haiku/trunk/src/tools/fs_shell/fd.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/fd.cpp 2007-05-02 16:50:25 UTC (rev 20979) +++ haiku/trunk/src/tools/fs_shell/fd.cpp 2007-05-02 16:59:10 UTC (rev 20980) @@ -458,17 +458,11 @@ return FSSH_B_OK; } -} // namespace FSShell - - // #pragma mark - // Kernel calls -using namespace FSShell; - - fssh_ssize_t _kern_read(int fd, fssh_off_t pos, void *buffer, fssh_size_t length) { @@ -735,3 +729,4 @@ return dup2_fd(ofd, nfd, true); } +} // namespace FSShell Modified: haiku/trunk/src/tools/fs_shell/stat.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/stat.cpp 2007-05-02 16:50:25 UTC (rev 20979) +++ haiku/trunk/src/tools/fs_shell/stat.cpp 2007-05-02 16:59:10 UTC (rev 20980) @@ -13,9 +13,17 @@ using FSShell::from_platform_stat; +using FSShell::to_platform_mode; int +fssh_mkdir(const char *path, fssh_mode_t mode) +{ + return mkdir(path, to_platform_mode(mode)); +} + + +int fssh_stat(const char *path, struct fssh_stat *fsshStat) { struct stat st; Modified: haiku/trunk/src/tools/fs_shell/syscalls.h =================================================================== --- haiku/trunk/src/tools/fs_shell/syscalls.h 2007-05-02 16:50:25 UTC (rev 20979) +++ haiku/trunk/src/tools/fs_shell/syscalls.h 2007-05-02 16:59:10 UTC (rev 20980) @@ -11,6 +11,9 @@ struct fssh_iovec; +namespace FSShell { + + // defined in vfs.cpp fssh_dev_t _kern_mount(const char *path, const char *device, const char *fsName, uint32_t flags, const char *args, @@ -89,4 +92,8 @@ int _kern_dup(int fd); int _kern_dup2(int ofd, int nfd); + +} // namespace FSShell + + #endif // _FSSH_SYSCALLS_H Modified: haiku/trunk/src/tools/fs_shell/unistd.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/unistd.cpp 2007-05-02 16:50:25 UTC (rev 20979) +++ haiku/trunk/src/tools/fs_shell/unistd.cpp 2007-05-02 16:59:10 UTC (rev 20980) @@ -27,6 +27,12 @@ #endif +#ifndef __BEOS__ + // The _kern_close() defined in libroot_build.so. + extern "C" status_t _kern_close(int fd); +#endif + + #ifdef HAIKU_HOST_PLATFORM_LINUX static bool @@ -67,11 +73,24 @@ int fssh_close(int fd) { - return close(fd); + // Use the _kern_close() defined in libroot on BeOS incompatible systems. + // Required for proper attribute emulation support. + #if __BEOS__ + return close(fd); + #else + return _kern_close(fd); + #endif } int +fssh_unlink(const char *name) +{ + return unlink(name); +} + + +int fssh_ioctl(int fd, unsigned long op, ...) { status_t error = B_BAD_VALUE; Modified: haiku/trunk/src/tools/fs_shell/vfs.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/vfs.cpp 2007-05-02 16:50:25 UTC (rev 20979) +++ haiku/trunk/src/tools/fs_shell/vfs.cpp 2007-05-02 16:59:10 UTC (rev 20980) @@ -4551,16 +4551,10 @@ } -} // namespace FSShell - - // #pragma mark - // Calls from within the kernel -using namespace FSShell; - - fssh_dev_t _kern_mount(const char *path, const char *device, const char *fsName, uint32_t flags, const char *args, fssh_size_t argsLength) @@ -5208,3 +5202,4 @@ return status; } +} // namespace FSShell From bonefish at cs.tu-berlin.de Wed May 2 19:03:24 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Wed, 02 May 2007 19:03:24 +0200 Subject: [Haiku-commits] r20975 - haiku/trunk/build/jam In-Reply-To: <20070502172355.842.2@cs.tu-berlin.de> References: <200705021412.l42EC4FX021840@sheep.berlios.de> <9c46321e0705020717r738ed2eap8f52ba48d5675741@mail.gmail.com> <9c46321e0705020739r4c3bc095tab5ef1c204834dd8@mail.gmail.com> <20070502170703.796.1@cs.tu-berlin.de> <9c46321e0705020816k7bdc7fc5t748ac80e98d20af8@mail.gmail.com> <20070502172355.842.2@cs.tu-berlin.de> Message-ID: <20070502190324.1067.4@cs.tu-berlin.de> On 2007-05-02 at 17:23:55 [+0200], Ingo Weinhold wrote: > > On 2007-05-02 at 17:16:07 [+0200], Hugo Santos wrote: > > Nope, i haven't. I can give it a go with xattr if you think it could help. > > No, thanks. I can reproduce the problem without xattr support. Working on > it. Should be fixed in r20980. Can you please retry. CU, Ingo From bonefish at cs.tu-berlin.de Wed May 2 19:11:12 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Wed, 02 May 2007 19:11:12 +0200 Subject: [Haiku-commits] r20975 - haiku/trunk/build/jam In-Reply-To: <4638B18A.70009@bug-br.org.br> References: <200705021412.l42EC4FX021840@sheep.berlios.de> <9c46321e0705020717r738ed2eap8f52ba48d5675741@mail.gmail.com> <9c46321e0705020739r4c3bc095tab5ef1c204834dd8@mail.gmail.com> <20070502170703.796.1@cs.tu-berlin.de> <9c46321e0705020816k7bdc7fc5t748ac80e98d20af8@mail.gmail.com> <20070502172355.842.2@cs.tu-berlin.de> <4638B18A.70009@bug-br.org.br> Message-ID: <20070502191112.1036.5@cs.tu-berlin.de> On 2007-05-02 at 17:43:06 [+0200], Bruno Albuquerque wrote: > Ingo Weinhold wrote: > > >> Nope, i haven't. I can give it a go with xattr if you think it could > >> help. > > > > No, thanks. I can reproduce the problem without xattr support. Working on > > it. > > For what is worth, I am also having problems under Linux + GCC4: > > C++ generated/objects/linux/x86/release/tools/fs_shell/vfs.o > src/tools/fs_shell/vfs.cpp: In function 'fssh_off_t > FSShell::file_seek(FSShell::file_descriptor*, fssh_off_t, int)': > src/tools/fs_shell/vfs.cpp:2792: error: 'LONGLONG_MAX' was not declared > in this scope Apparently your platform doesn't define LLONG_* in (which it should for POSIX compliance). BeOS doesn't either, but defines LONGLONG_* to which I simply mapped the former, if they aren't defined. Does your platform define anything similar, or are LLONG_* defined as enum values and not as macros (they should be macros according to the standard)? CU, Ingo From hugosantos at gmail.com Wed May 2 19:17:35 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Wed, 2 May 2007 18:17:35 +0100 Subject: [Haiku-commits] r20975 - haiku/trunk/build/jam In-Reply-To: <20070502190324.1067.4@cs.tu-berlin.de> References: <200705021412.l42EC4FX021840@sheep.berlios.de> <9c46321e0705020717r738ed2eap8f52ba48d5675741@mail.gmail.com> <9c46321e0705020739r4c3bc095tab5ef1c204834dd8@mail.gmail.com> <20070502170703.796.1@cs.tu-berlin.de> <9c46321e0705020816k7bdc7fc5t748ac80e98d20af8@mail.gmail.com> <20070502172355.842.2@cs.tu-berlin.de> <20070502190324.1067.4@cs.tu-berlin.de> Message-ID: <9c46321e0705021017y7c5b6190q81d11b371381dc76@mail.gmail.com> Working now, thanks Ingo. Hugo On 5/2/07, Ingo Weinhold wrote: > > On 2007-05-02 at 17:23:55 [+0200], Ingo Weinhold > wrote: > > > > On 2007-05-02 at 17:16:07 [+0200], Hugo Santos wrote: > > > Nope, i haven't. I can give it a go with xattr if you think it could help. > > > > No, thanks. I can reproduce the problem without xattr support. Working on > > it. > > Should be fixed in r20980. Can you please retry. > > CU, Ingo > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From bga at bug-br.org.br Wed May 2 20:55:59 2007 From: bga at bug-br.org.br (Bruno Albuquerque) Date: Wed, 02 May 2007 15:55:59 -0300 Subject: [Haiku-commits] r20975 - haiku/trunk/build/jam In-Reply-To: <20070502191112.1036.5@cs.tu-berlin.de> References: <200705021412.l42EC4FX021840@sheep.berlios.de> <9c46321e0705020717r738ed2eap8f52ba48d5675741@mail.gmail.com> <9c46321e0705020739r4c3bc095tab5ef1c204834dd8@mail.gmail.com> <20070502170703.796.1@cs.tu-berlin.de> <9c46321e0705020816k7bdc7fc5t748ac80e98d20af8@mail.gmail.com> <20070502172355.842.2@cs.tu-berlin.de> <4638B18A.70009@bug-br.org.br> <20070502191112.1036.5@cs.tu-berlin.de> Message-ID: <4638DEBF.9080102@bug-br.org.br> Ingo Weinhold wrote: >> C++ generated/objects/linux/x86/release/tools/fs_shell/vfs.o >> src/tools/fs_shell/vfs.cpp: In function 'fssh_off_t >> FSShell::file_seek(FSShell::file_descriptor*, fssh_off_t, int)': >> src/tools/fs_shell/vfs.cpp:2792: error: 'LONGLONG_MAX' was not declared >> in this scope > > Apparently your platform doesn't define LLONG_* in (which it > should for POSIX compliance). BeOS doesn't either, but defines LONGLONG_* to > which I simply mapped the former, if they aren't defined. Does your platform > define anything similar, or are LLONG_* defined as enum values and not as > macros (they should be macros according to the standard)? Well, the platform is Linux. :P Ubuntu, to be exact. And there are LLONG* defines. LONGLONG_MAX is what is not defined. bga at librarian:/usr/include$ grep _MAX limits.h #define MB_LEN_MAX 16 # define SCHAR_MAX 127 # define UCHAR_MAX 255 # define CHAR_MAX UCHAR_MAX # define CHAR_MAX SCHAR_MAX # define SHRT_MAX 32767 # define USHRT_MAX 65535 # define INT_MIN (-INT_MAX - 1) # define INT_MAX 2147483647 # define UINT_MAX 4294967295U # define LONG_MAX 9223372036854775807L # define LONG_MAX 2147483647L # define LONG_MIN (-LONG_MAX - 1L) # define ULONG_MAX 18446744073709551615UL # define ULONG_MAX 4294967295UL # define LLONG_MAX 9223372036854775807LL # define LLONG_MIN (-LLONG_MAX - 1LL) # define ULLONG_MAX 18446744073709551615ULL LLONG_MAX, and ULLONG_MAX. Instead only the values gcc defined for # ifndef LLONG_MAX # define LLONG_MAX LONG_LONG_MAX # ifndef ULLONG_MAX # define ULLONG_MAX ULONG_LONG_MAX -Bruno From korli at mail.berlios.de Wed May 2 21:02:17 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Wed, 2 May 2007 21:02:17 +0200 Subject: [Haiku-commits] r20981 - haiku/trunk/src/kits/storage Message-ID: <200705021902.l42J2HHH028795@sheep.berlios.de> Author: korli Date: 2007-05-02 21:02:17 +0200 (Wed, 02 May 2007) New Revision: 20981 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20981&view=rev Modified: haiku/trunk/src/kits/storage/Directory.cpp Log: fixed a typo was U instead of O Modified: haiku/trunk/src/kits/storage/Directory.cpp =================================================================== --- haiku/trunk/src/kits/storage/Directory.cpp 2007-05-02 16:59:10 UTC (rev 20980) +++ haiku/trunk/src/kits/storage/Directory.cpp 2007-05-02 19:02:17 UTC (rev 20981) @@ -746,7 +746,7 @@ return B_BAD_VALUE; // create the dir status_t error = _kern_create_dir(fDirFd, path, - S_IRWXU | S_IRWXG | S_IRWXU); + S_IRWXU | S_IRWXG | S_IRWXO); if (error != B_OK) return error; if (!dir) @@ -833,7 +833,7 @@ return B_BAD_VALUE; // create the symlink status_t error = _kern_create_symlink(fDirFd, path, linkToPath, - S_IRWXU | S_IRWXG | S_IRWXU); + S_IRWXU | S_IRWXG | S_IRWXO); if (error != B_OK) return error; if (!link) From korli at mail.berlios.de Wed May 2 21:04:06 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Wed, 2 May 2007 21:04:06 +0200 Subject: [Haiku-commits] r20982 - haiku/trunk/src/system/kernel/fs Message-ID: <200705021904.l42J46p8028897@sheep.berlios.de> Author: korli Date: 2007-05-02 21:04:06 +0200 (Wed, 02 May 2007) New Revision: 20982 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20982&view=rev Modified: haiku/trunk/src/system/kernel/fs/devfs.cpp Log: devfs now accepts to create directories is scanning needed here ? Modified: haiku/trunk/src/system/kernel/fs/devfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/devfs.cpp 2007-05-02 19:02:17 UTC (rev 20981) +++ haiku/trunk/src/system/kernel/fs/devfs.cpp 2007-05-02 19:04:06 UTC (rev 20982) @@ -1422,7 +1422,29 @@ devfs_create_dir(fs_volume _fs, fs_vnode _dir, const char *name, int perms, vnode_id *_newVnodeID) { - return EROFS; + struct devfs *fs = (struct devfs *)_fs; + struct devfs_vnode *dir = (struct devfs_vnode *)_dir; + + struct devfs_vnode *vnode = devfs_find_in_dir(dir, name); + if (vnode != NULL) { + return EEXIST; + } + + vnode = devfs_create_vnode(fs, dir, name); + if (vnode == NULL) { + return B_NO_MEMORY; + } + + // set up the new directory + vnode->stream.type = S_IFDIR | perms; + vnode->stream.u.dir.dir_head = NULL; + list_init(&vnode->stream.u.dir.cookies); + + hash_insert(sDeviceFileSystem->vnode_hash, vnode); + devfs_insert_in_dir(dir, vnode); + + *_newVnodeID = vnode->id; + return B_OK; } From korli at mail.berlios.de Wed May 2 21:04:45 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Wed, 2 May 2007 21:04:45 +0200 Subject: [Haiku-commits] r20983 - haiku/trunk/src/add-ons/input_server/devices/mouse Message-ID: <200705021904.l42J4jSl028981@sheep.berlios.de> Author: korli Date: 2007-05-02 21:04:44 +0200 (Wed, 02 May 2007) New Revision: 20983 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20983&view=rev Modified: haiku/trunk/src/add-ons/input_server/devices/mouse/MouseInputDevice.cpp Log: clean Modified: haiku/trunk/src/add-ons/input_server/devices/mouse/MouseInputDevice.cpp =================================================================== --- haiku/trunk/src/add-ons/input_server/devices/mouse/MouseInputDevice.cpp 2007-05-02 19:04:06 UTC (rev 20982) +++ haiku/trunk/src/add-ons/input_server/devices/mouse/MouseInputDevice.cpp 2007-05-02 19:04:44 UTC (rev 20983) @@ -89,7 +89,7 @@ va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); - fputs(buf, MouseInputDevice::sLogFile); fflush(MouseInputDevice::sLogFile); + fputs(buf, MouseInputDevice::sLogFile); fflush(MouseInputDevice::sLogFile); } #endif From korli at mail.berlios.de Wed May 2 21:05:57 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Wed, 2 May 2007 21:05:57 +0200 Subject: [Haiku-commits] r20984 - haiku/trunk/src/servers/input Message-ID: <200705021905.l42J5v2U029144@sheep.berlios.de> Author: korli Date: 2007-05-02 21:05:57 +0200 (Wed, 02 May 2007) New Revision: 20984 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20984&view=rev Modified: haiku/trunk/src/servers/input/DeviceManager.cpp Log: now creates the monitored directories if they don't exist (0755) Modified: haiku/trunk/src/servers/input/DeviceManager.cpp =================================================================== --- haiku/trunk/src/servers/input/DeviceManager.cpp 2007-05-02 19:04:44 UTC (rev 20983) +++ haiku/trunk/src/servers/input/DeviceManager.cpp 2007-05-02 19:05:57 UTC (rev 20984) @@ -163,12 +163,28 @@ node_ref nref; BDirectory directory; BPath path("/dev"); - if (((err = path.Append(device)) != B_OK) - || ((err = directory.SetTo(path.Path())) != B_OK) - || ((err = directory.GetNodeRef(&nref)) != B_OK)) { - PRINTERR(("DeviceManager::StartMonitoringDevice error %s: %s\n", path.Path(), strerror(err))); + if ((err = path.Append(device)) != B_OK) { + PRINTERR(("DeviceManager::StartMonitoringDevice BPath::Append() error %s: %s\n", path.Path(), strerror(err))); return err; } + + if ((err = directory.SetTo(path.Path())) != B_OK) { + if (err != B_ENTRY_NOT_FOUND) { + PRINTERR(("DeviceManager::StartMonitoringDevice SetTo error %s: %s\n", path.Path(), strerror(err))); + return err; + } + if ((err = create_directory(path.Path(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) != B_OK + || (err = directory.SetTo(path.Path())) != B_OK) { + PRINTERR(("DeviceManager::StartMonitoringDevice CreateDirectory error %s: %s\n", path.Path(), strerror(err))); + return err; + } + } + + if ((err = directory.GetNodeRef(&nref)) != B_OK) { + PRINTERR(("DeviceManager::StartMonitoringDevice GetNodeRef error %s: %s\n", path.Path(), strerror(err))); + return err; + } + // test if already monitored bool alreadyMonitored = false; _BDeviceAddOn_ *tmpaddon = NULL; From revol at free.fr Wed May 2 23:07:05 2007 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Wed, 02 May 2007 23:07:05 +0200 CEST Subject: [Haiku-commits] r20963 - in haiku/trunk/src/add-ons/kernel/drivers/disk: . virtual virtual/fmap virtual/nbd In-Reply-To: <2385736623-BeMail@zon> Message-ID: <2204504448-BeMail@laptop> > mmu_man at BerliOS wrote: > > haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.h > > Log: > > skeleton for an fmap driver (IMAGE.BE). Start of an Network Block > > Device driver. > NBD server python script I foundon the net for > testing. > > I'm not sure what you're doing so I probably don't appreciate it > enough, but can we please get rid of names like "nbd"? > Sorry I have a crush for cryptic names :D fmap was the name R5 used for that \BEOS\IMAGE.BE-as-partition trick (file map). nbd is the usual name for the same driver in linux: Network Block Device. It's a simplistic tcp-based protocol to export block devices, so we could try for ex to remote mount /boot as BFS from a linux server. See http://nbd.sourceforge.net/ for ex. Feel free to suggest better names for those, I just don't have any idea. Fran?ois. From axeld at pinc-software.de Wed May 2 23:12:17 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Wed, 02 May 2007 23:12:17 +0200 CEST Subject: [Haiku-commits] r20982 - haiku/trunk/src/system/kernel/fs In-Reply-To: <200705021904.l42J46p8028897@sheep.berlios.de> Message-ID: <28138776773-BeMail@zon> korli at BerliOS wrote: > Log: > devfs now accepts to create directories > is scanning needed here? No, it's automatically done as soon as you open the directory, anyway. Thanks! Bye, Axel. From bonefish at cs.tu-berlin.de Wed May 2 23:51:16 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Wed, 02 May 2007 23:51:16 +0200 Subject: [Haiku-commits] r20982 - haiku/trunk/src/system/kernel/fs In-Reply-To: <200705021904.l42J46p8028897@sheep.berlios.de> References: <200705021904.l42J46p8028897@sheep.berlios.de> Message-ID: <20070502235116.1662.6@cs.tu-berlin.de> On 2007-05-02 at 21:04:06 [+0200], korli at BerliOS wrote: > Author: korli > Date: 2007-05-02 21:04:06 +0200 (Wed, 02 May 2007) > New Revision: 20982 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20982&view=rev > > Modified: > haiku/trunk/src/system/kernel/fs/devfs.cpp > Log: > devfs now accepts to create directories > is scanning needed here ? Out of curiosity, why would one want to create a directory in the devfs? CU, Ingo From bonefish at cs.tu-berlin.de Thu May 3 00:04:20 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Thu, 03 May 2007 00:04:20 +0200 Subject: [Haiku-commits] r20975 - haiku/trunk/build/jam In-Reply-To: <4638DEBF.9080102@bug-br.org.br> References: <200705021412.l42EC4FX021840@sheep.berlios.de> <9c46321e0705020717r738ed2eap8f52ba48d5675741@mail.gmail.com> <9c46321e0705020739r4c3bc095tab5ef1c204834dd8@mail.gmail.com> <20070502170703.796.1@cs.tu-berlin.de> <9c46321e0705020816k7bdc7fc5t748ac80e98d20af8@mail.gmail.com> <20070502172355.842.2@cs.tu-berlin.de> <4638B18A.70009@bug-br.org.br> <20070502191112.1036.5@cs.tu-berlin.de> <4638DEBF.9080102@bug-br.org.br> Message-ID: <20070503000420.1694.7@cs.tu-berlin.de> On 2007-05-02 at 20:55:59 [+0200], Bruno Albuquerque wrote: > Ingo Weinhold wrote: > > >> C++ generated/objects/linux/x86/release/tools/fs_shell/vfs.o > >> src/tools/fs_shell/vfs.cpp: In function 'fssh_off_t > >> FSShell::file_seek(FSShell::file_descriptor*, fssh_off_t, int)': > >> src/tools/fs_shell/vfs.cpp:2792: error: 'LONGLONG_MAX' was not declared > >> in this scope > > > > Apparently your platform doesn't define LLONG_* in (which it > > should for POSIX compliance). BeOS doesn't either, but defines LONGLONG_* > > to > > which I simply mapped the former, if they aren't defined. Does your > > platform > > define anything similar, or are LLONG_* defined as enum values and not as > > macros (they should be macros according to the standard)? > > Well, the platform is Linux. :P Ubuntu, to be exact. > > And there are LLONG* defines. LONGLONG_MAX is what is not defined. > > bga at librarian:/usr/include$ grep _MAX limits.h > #define MB_LEN_MAX 16 > # define SCHAR_MAX 127 > # define UCHAR_MAX 255 > # define CHAR_MAX UCHAR_MAX > # define CHAR_MAX SCHAR_MAX > # define SHRT_MAX 32767 > # define USHRT_MAX 65535 > # define INT_MIN (-INT_MAX - 1) > # define INT_MAX 2147483647 > # define UINT_MAX 4294967295U > # define LONG_MAX 9223372036854775807L > # define LONG_MAX 2147483647L > # define LONG_MIN (-LONG_MAX - 1L) > # define ULONG_MAX 18446744073709551615UL > # define ULONG_MAX 4294967295UL > # define LLONG_MAX 9223372036854775807LL > # define LLONG_MIN (-LLONG_MAX - 1LL) > # define ULLONG_MAX 18446744073709551615ULL > LLONG_MAX, and ULLONG_MAX. Instead only the values gcc defined for > # ifndef LLONG_MAX > # define LLONG_MAX LONG_LONG_MAX > # ifndef ULLONG_MAX > # define ULLONG_MAX ULONG_LONG_MAX Well, src/tools/fs_shell/vfs.cpp reads: [...] #include "posix_compatibility.h" [...] // assumes fssh_off_t is 64 bits wide if (offset > 0 && LLONG_MAX - offset < pos) return FSSH_EOVERFLOW; [...] And the included src/tools/fs_shell/posix_compatibility.h: [...] // BeOS doesn't define [U]LLONG_{MIN,MAX}, but [U]LONGLONG_{MIN,MAX} #include #ifndef LLONG_MIN # define LLONG_MIN LONGLONG_MIN # define LLONG_MAX LONGLONG_MAX # define ULLONG_MAX ULONGLONG_MAX #endif [...] So at least LLONG_MIN is not defined on your platform when is included. Given that the macro definitions are indented I suspose they are conditional. Please check, what's going on there. CU, Ingo From bga at bug-br.org.br Thu May 3 00:09:55 2007 From: bga at bug-br.org.br (Bruno G. Albuquerque) Date: Wed, 02 May 2007 22:09:55 -0000 Subject: [Haiku-commits] r20975 - haiku/trunk/build/jam In-Reply-To: <20070503000420.1694.7@cs.tu-berlin.de> Message-ID: <993979469-BeMail@guglielmo> On Thu, 03 May 2007 00:04:20 +0200, Ingo Weinhold said: > So at least LLONG_MIN is not defined on your platform when > is > included. Given that the macro definitions are indented I suspose > they are > conditional. Please check, what's going on there. B_WILL_DO when I am back at work tomorrow. -Bruno -- Fortune Cookie Says: Our country has plenty of good five-cent cigars, but the trouble is they charge fifteen cents for them. From hugosantos at mail.berlios.de Thu May 3 01:11:00 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Thu, 3 May 2007 01:11:00 +0200 Subject: [Haiku-commits] r20985 - in haiku/trunk/src/libs: . compat compat/freebsd_network compat/freebsd_network/compat compat/freebsd_network/compat/altq compat/freebsd_network/compat/dev compat/freebsd_network/compat/dev/mii compat/freebsd_network/compat/dev/ofw compat/freebsd_network/compat/dev/pci compat/freebsd_network/compat/machine compat/freebsd_network/compat/net compat/freebsd_network/compat/sys Message-ID: <200705022311.l42NB0Xv003652@sheep.berlios.de> Author: hugosantos Date: 2007-05-03 01:10:18 +0200 (Thu, 03 May 2007) New Revision: 20985 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20985&view=rev Added: haiku/trunk/src/libs/compat/ haiku/trunk/src/libs/compat/Jamfile haiku/trunk/src/libs/compat/freebsd_network/ haiku/trunk/src/libs/compat/freebsd_network/Jamfile haiku/trunk/src/libs/compat/freebsd_network/README haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/compat/ haiku/trunk/src/libs/compat/freebsd_network/compat/altq/ haiku/trunk/src/libs/compat/freebsd_network/compat/altq/if_altq.h haiku/trunk/src/libs/compat/freebsd_network/compat/dev/ haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/ haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/mii.h haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/miivar.h haiku/trunk/src/libs/compat/freebsd_network/compat/dev/ofw/ haiku/trunk/src/libs/compat/freebsd_network/compat/dev/ofw/openfirm.h haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/ haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcireg.h haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcivar.h haiku/trunk/src/libs/compat/freebsd_network/compat/machine/ haiku/trunk/src/libs/compat/freebsd_network/compat/machine/bus.h haiku/trunk/src/libs/compat/freebsd_network/compat/machine/clock.h haiku/trunk/src/libs/compat/freebsd_network/compat/machine/endian.h haiku/trunk/src/libs/compat/freebsd_network/compat/machine/ofw_machdep.h haiku/trunk/src/libs/compat/freebsd_network/compat/machine/resource.h haiku/trunk/src/libs/compat/freebsd_network/compat/miibus_if.h haiku/trunk/src/libs/compat/freebsd_network/compat/net/ haiku/trunk/src/libs/compat/freebsd_network/compat/net/bpf.h haiku/trunk/src/libs/compat/freebsd_network/compat/net/ethernet.h haiku/trunk/src/libs/compat/freebsd_network/compat/net/if.h haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_arp.h haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_media.h haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_var.h haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_vlan_var.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/_task.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus_dma.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/callout.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/cdefs.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/endian.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/event.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/eventhandler.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kernel.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/ktr.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/lock.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/malloc.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/module.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mutex.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/param.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/queue.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/rman.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/sockio.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/sysctl.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/systm.h Modified: haiku/trunk/src/libs/Jamfile Log: initial work towards a FreeBSD network driver source level compatibility layer. Modified: haiku/trunk/src/libs/Jamfile =================================================================== --- haiku/trunk/src/libs/Jamfile 2007-05-02 19:05:57 UTC (rev 20984) +++ haiku/trunk/src/libs/Jamfile 2007-05-02 23:10:18 UTC (rev 20985) @@ -2,6 +2,7 @@ SubInclude HAIKU_TOP src libs agg ; SubInclude HAIKU_TOP src libs bsd ; +SubInclude HAIKU_TOP src libs compat ; SubInclude HAIKU_TOP src libs crypt ; SubInclude HAIKU_TOP src libs edit ; SubInclude HAIKU_TOP src libs expat ; Added: haiku/trunk/src/libs/compat/Jamfile =================================================================== --- haiku/trunk/src/libs/compat/Jamfile 2007-05-02 19:05:57 UTC (rev 20984) +++ haiku/trunk/src/libs/compat/Jamfile 2007-05-02 23:10:18 UTC (rev 20985) @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src libs compat ; + +SubInclude HAIKU_TOP src libs compat freebsd_network ; Added: haiku/trunk/src/libs/compat/freebsd_network/Jamfile =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-02 19:05:57 UTC (rev 20984) +++ haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-02 23:10:18 UTC (rev 20985) @@ -0,0 +1,12 @@ +SubDir HAIKU_TOP src libs compat freebsd_network ; + +UsePrivateHeaders kernel net ; + +UseHeaders [ FDirName $(SUBDIR) ] : true ; +UseHeaders [ FDirName $(SUBDIR) headers ] : true ; + +SubDirCcFlags [ FDefines _KERNEL=1 ] ; + +Library libfreebsd_network.a : + compat.c + ; Added: haiku/trunk/src/libs/compat/freebsd_network/README =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/README 2007-05-02 19:05:57 UTC (rev 20984) +++ haiku/trunk/src/libs/compat/freebsd_network/README 2007-05-02 23:10:18 UTC (rev 20985) @@ -0,0 +1,3 @@ +FreeBSD network driver compatability layer. Based on FreeBSD 6.2. + + - Hugo, 3 May 2007 Added: haiku/trunk/src/libs/compat/freebsd_network/compat/altq/if_altq.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/altq/if_altq.h 2007-05-02 19:05:57 UTC (rev 20984) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/altq/if_altq.h 2007-05-02 23:10:18 UTC (rev 20985) @@ -0,0 +1,33 @@ +#ifndef _FBSD_COMPAT_ALTQ_IF_ALTQ_H_ +#define _FBSD_COMPAT_ALTQ_IF_ALTQ_H_ + +#include +#include + +struct ifaltq { + struct mbuf * ifq_head; + struct mbuf * ifq_tail; + + int ifq_len; + int ifq_maxlen; + struct mtx ifq_mtx; + + struct mbuf * ifq_drv_head; + struct mbuf * ifq_drv_tail; + int ifq_drv_len; + int ifq_drv_maxlen; + + int altq_flags; +}; + +#define ALTQF_READY 0x1 + +#define ALTDQ_REMOVE 1 + +#define ALTQ_IS_ENABLED(ifq) 0 +#define ALTQ_DEQUEUE(ifr, m) (m) = NULL + +#define TBR_IS_ENABLED(ifq) 0 +#define tbr_dequeue_ptr(ifq, v) NULL + +#endif Added: haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/mii.h =================================================================== Added: haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/miivar.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/miivar.h 2007-05-02 19:05:57 UTC (rev 20984) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/miivar.h 2007-05-02 23:10:18 UTC (rev 20985) @@ -0,0 +1,229 @@ +/* $NetBSD: miivar.h,v 1.8 1999/04/23 04:24:32 thorpej Exp $ */ + +/*- + * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/sys/dev/mii/miivar.h,v 1.15.14.1 2006/06/24 06:14:24 oleg Exp $ + */ + +#ifndef _DEV_MII_MIIVAR_H_ +#define _DEV_MII_MIIVAR_H_ + +#include + +/* + * Media Independent Interface configuration defintions. + */ + +struct mii_softc; + +/* + * Callbacks from MII layer into network interface device driver. + */ +typedef int (*mii_readreg_t)(struct device *, int, int); +typedef void (*mii_writereg_t)(struct device *, int, int, int); +typedef void (*mii_statchg_t)(struct device *); + +/* + * A network interface driver has one of these structures in its softc. + * It is the interface from the network interface driver to the MII + * layer. + */ +struct mii_data { + struct ifmedia mii_media; /* media information */ + struct ifnet *mii_ifp; /* pointer back to network interface */ + + /* + * For network interfaces with multiple PHYs, a list of all + * PHYs is required so they can all be notified when a media + * request is made. + */ + LIST_HEAD(mii_listhead, mii_softc) mii_phys; + int mii_instance; + + /* + * PHY driver fills this in with active media status. + */ + int mii_media_status; + int mii_media_active; + + /* + * Calls from MII layer into network interface driver. + */ + mii_readreg_t mii_readreg; + mii_writereg_t mii_writereg; + mii_statchg_t mii_statchg; +}; +typedef struct mii_data mii_data_t; + +/* + * This call is used by the MII layer to call into the PHY driver + * to perform a `service request'. + */ +typedef int (*mii_downcall_t)(struct mii_softc *, struct mii_data *, int); + +/* + * Requests that can be made to the downcall. + */ +#define MII_TICK 1 /* once-per-second tick */ +#define MII_MEDIACHG 2 /* user changed media; perform the switch */ +#define MII_POLLSTAT 3 /* user requested media status; fill it in */ + +/* + * Each PHY driver's softc has one of these as the first member. + * XXX This would be better named "phy_softc", but this is the name + * XXX BSDI used, and we would like to have the same interface. + */ +struct mii_softc { + device_t mii_dev; /* generic device glue */ + + LIST_ENTRY(mii_softc) mii_list; /* entry on parent's PHY list */ + + int mii_phy; /* our MII address */ + int mii_inst; /* instance for ifmedia */ + + mii_downcall_t mii_service; /* our downcall */ + struct mii_data *mii_pdata; /* pointer to parent's mii_data */ + + int mii_flags; /* misc. flags; see below */ + int mii_capabilities; /* capabilities from BMSR */ + int mii_extcapabilities; /* extended capabilities */ + int mii_ticks; /* MII_TICK counter */ + int mii_anegticks; /* ticks before retrying aneg */ + int mii_media_active; /* last active media */ + int mii_media_status; /* last active status */ +}; +typedef struct mii_softc mii_softc_t; + +/* mii_flags */ +#define MIIF_INITDONE 0x0001 /* has been initialized (mii_data) */ +#define MIIF_NOISOLATE 0x0002 /* do not isolate the PHY */ +#define MIIF_NOLOOP 0x0004 /* no loopback capability */ +#define MIIF_AUTOTSLEEP 0x0010 /* use tsleep(), not callout() */ +#define MIIF_HAVEFIBER 0x0020 /* from parent: has fiber interface */ +#define MIIF_HAVE_GTCR 0x0040 /* has 100base-T2/1000base-T CR */ +#define MIIF_IS_1000X 0x0080 /* is a 1000BASE-X device */ +#define MIIF_DOPAUSE 0x0100 /* advertise PAUSE capability */ +#define MIIF_IS_HPNA 0x0200 /* is a HomePNA device */ + +/* Default mii_anegticks values */ +#define MII_ANEGTICKS 5 +#define MII_ANEGTICKS_GIGE 17 + +#define MIIF_INHERIT_MASK (MIIF_NOISOLATE|MIIF_NOLOOP|MIIF_AUTOTSLEEP) + +/* + * Used to attach a PHY to a parent. + */ +struct mii_attach_args { + struct mii_data *mii_data; /* pointer to parent data */ + int mii_phyno; /* MII address */ + int mii_id1; /* PHY ID register 1 */ + int mii_id2; /* PHY ID register 2 */ + int mii_capmask; /* capability mask from BMSR */ +}; +typedef struct mii_attach_args mii_attach_args_t; + +/* + * Used to match a PHY. + */ +struct mii_phydesc { + u_int32_t mpd_oui; /* the PHY's OUI */ + u_int32_t mpd_model; /* the PHY's model */ + const char *mpd_name; /* the PHY's name */ +}; + +/* + * An array of these structures map MII media types to BMCR/ANAR settings. + */ +struct mii_media { + int mm_bmcr; /* BMCR settings for this media */ + int mm_anar; /* ANAR settings for this media */ + int mm_gtcr; /* 100base-T2 or 1000base-T CR */ +}; + +#define MII_MEDIA_NONE 0 +#define MII_MEDIA_10_T 1 +#define MII_MEDIA_10_T_FDX 2 +#define MII_MEDIA_100_T4 3 +#define MII_MEDIA_100_TX 4 +#define MII_MEDIA_100_TX_FDX 5 +#define MII_MEDIA_1000_X 6 +#define MII_MEDIA_1000_X_FDX 7 +#define MII_MEDIA_1000_T 8 +#define MII_MEDIA_1000_T_FDX 9 +#define MII_NMEDIA 10 + +#ifdef _KERNEL + +#define PHY_READ(p, r) \ + MIIBUS_READREG((p)->mii_dev, (p)->mii_phy, (r)) + +#define PHY_WRITE(p, r, v) \ + MIIBUS_WRITEREG((p)->mii_dev, (p)->mii_phy, (r), (v)) + +extern devclass_t miibus_devclass; +extern driver_t miibus_driver; + +int miibus_probe(device_t); +int miibus_attach(device_t); +int miibus_detach(device_t); + +int mii_anar(int); +void mii_down(struct mii_data *); +int mii_mediachg(struct mii_data *); +void mii_tick(struct mii_data *); +void mii_pollstat(struct mii_data *); +int mii_phy_probe(device_t, device_t *, ifm_change_cb_t, ifm_stat_cb_t); +void mii_add_media(struct mii_softc *); +void mii_phy_add_media(struct mii_softc *); + +int mii_media_from_bmcr(int); + +int mii_phy_auto(struct mii_softc *); +int mii_phy_detach(device_t dev); +void mii_phy_down(struct mii_softc *); +void mii_phy_reset(struct mii_softc *); +void mii_phy_setmedia(struct mii_softc *sc); +void mii_phy_update(struct mii_softc *, int); +int mii_phy_tick(struct mii_softc *); + +const struct mii_phydesc * mii_phy_match(const struct mii_attach_args *ma, const struct mii_phydesc *mpd); + +void ukphy_status(struct mii_softc *); +#endif /* _KERNEL */ + +#endif /* _DEV_MII_MIIVAR_H_ */ Added: haiku/trunk/src/libs/compat/freebsd_network/compat/dev/ofw/openfirm.h =================================================================== Added: haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcireg.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcireg.h 2007-05-02 19:05:57 UTC (rev 20984) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcireg.h 2007-05-02 23:10:18 UTC (rev 20985) @@ -0,0 +1,14 @@ +#ifndef _FBSD_COMPAT_DEV_PCI_PCIREG_H_ +#define _FBSD_COMPAT_DEV_PCI_PCIREG_H_ + +#define PCIR_COMMAND 0x04 +#define PCIR_REVID 0x08 +#define PCIR_CACHELNSZ 0x0c +#define PCIR_SUBVEND_0 0x2c +#define PCIR_SUBDEV_0 0x2e + +#define PCIM_CMD_PORTEN 0x0001 +#define PCIM_CMD_MEMEN 0x0002 +#define PCIM_CMD_MWRICEN 0x0010 + +#endif Added: haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcivar.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcivar.h 2007-05-02 19:05:57 UTC (rev 20984) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcivar.h 2007-05-02 23:10:18 UTC (rev 20985) @@ -0,0 +1,21 @@ +#ifndef _FBSD_COMPAT_DEV_PCI_PCIVAR_H_ +#define _FBSD_COMPAT_DEV_PCI_PCIVAR_H_ + +#include + +int pci_enable_busmaster(device_t dev); + +uint32_t pci_get_devid(device_t dev); +void pci_set_intpin(device_t dev, uint8_t pin); +uint8_t pci_get_intpin(device_t dev); + +uint16_t pci_get_vendor(device_t dev); +uint16_t pci_get_device(device_t dev); +uint16_t pci_get_subvendor(device_t dev); +uint16_t pci_get_subdevice(device_t dev); +uint8_t pci_get_revid(device_t dev); + +uint32_t pci_read_config(device_t dev, int reg, int width); +void pci_write_config(device_t dev, int reg, uint32_t val, int width); + +#endif Added: haiku/trunk/src/libs/compat/freebsd_network/compat/machine/bus.h =================================================================== Added: haiku/trunk/src/libs/compat/freebsd_network/compat/machine/clock.h =================================================================== Added: haiku/trunk/src/libs/compat/freebsd_network/compat/machine/endian.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/machine/endian.h 2007-05-02 19:05:57 UTC (rev 20984) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/machine/endian.h 2007-05-02 23:10:18 UTC (rev 20985) @@ -0,0 +1,4 @@ +#ifndef _FBSD_COMPAT_MACHINE_ENDIAN_H_ +#define _FBSD_COMPAT_MACHINE_ENDIAN_H_ + +#endif Added: haiku/trunk/src/libs/compat/freebsd_network/compat/machine/ofw_machdep.h =================================================================== Added: haiku/trunk/src/libs/compat/freebsd_network/compat/machine/resource.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/machine/resource.h 2007-05-02 19:05:57 UTC (rev 20984) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/machine/resource.h 2007-05-02 23:10:18 UTC (rev 20985) @@ -0,0 +1,9 @@ +#ifndef _FBSD_COMPAT_MACHINE_RESOURCE_H_ +#define _FBSD_COMPAT_MACHINE_RESOURCE_H_ + +#define SYS_RES_IRQ 0x1 +#define SYS_RES_DRQ 0x2 +#define SYS_RES_MEMORY 0x3 +#define SYS_RES_IOPORT 0x4 + +#endif Added: haiku/trunk/src/libs/compat/freebsd_network/compat/miibus_if.h =================================================================== Added: haiku/trunk/src/libs/compat/freebsd_network/compat/net/bpf.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/net/bpf.h 2007-05-02 19:05:57 UTC (rev 20984) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/net/bpf.h 2007-05-02 23:10:18 UTC (rev 20985) @@ -0,0 +1,7 @@ +#ifndef _FBSD_COMPAT_NET_BPF_H_ +#define _FBSD_COMPAT_NET_BPF_H_ + +#define bpf_mtap(bpf_if, mbuf) do { } while (0) +#define BPF_MTAP(ifp, m) do { } while (0) + +#endif Added: haiku/trunk/src/libs/compat/freebsd_network/compat/net/ethernet.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/net/ethernet.h 2007-05-02 19:05:57 UTC (rev 20984) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/net/ethernet.h 2007-05-02 23:10:18 UTC (rev 20985) @@ -0,0 +1,382 @@ +/* + * Fundamental constants relating to ethernet. + * + * $FreeBSD: src/sys/net/ethernet.h,v 1.24 2004/10/05 19:28:52 sam Exp $ + * + */ + +#ifndef _NET_ETHERNET_H_ +#define _NET_ETHERNET_H_ + +/* + * Somce basic Ethernet constants. + */ +#define ETHER_ADDR_LEN 6 /* length of an Ethernet address */ +#define ETHER_TYPE_LEN 2 /* length of the Ethernet type field */ +#define ETHER_CRC_LEN 4 /* length of the Ethernet CRC */ +#define ETHER_HDR_LEN (ETHER_ADDR_LEN*2+ETHER_TYPE_LEN) +#define ETHER_MIN_LEN 64 /* minimum frame len, including CRC */ +#define ETHER_MAX_LEN 1518 /* maximum frame len, including CRC */ +#define ETHER_MAX_LEN_JUMBO 9018 /* max jumbo frame len, including CRC */ + +#define ETHER_VLAN_ENCAP_LEN 4 /* len of 802.1Q VLAN encapsulation */ +/* + * Mbuf adjust factor to force 32-bit alignment of IP header. + * Drivers should do m_adj(m, ETHER_ALIGN) when setting up a + * receive so the upper layers get the IP header properly aligned + * past the 14-byte Ethernet header. + */ +#define ETHER_ALIGN 2 /* driver adjust for IP hdr alignment */ + +/* + * Compute the maximum frame size based on ethertype (i.e. possible + * encapsulation) and whether or not an FCS is present. + */ +#define ETHER_MAX_FRAME(ifp, etype, hasfcs) \ + ((ifp)->if_mtu + ETHER_HDR_LEN + \ + ((hasfcs) ? ETHER_CRC_LEN : 0) + \ + (((etype) == ETHERTYPE_VLAN) ? ETHER_VLAN_ENCAP_LEN : 0)) + +/* + * Ethernet-specific mbuf flags. + */ +#define M_HASFCS M_PROTO5 /* FCS included at end of frame */ + +/* + * Ethernet CRC32 polynomials (big- and little-endian verions). + */ +#define ETHER_CRC_POLY_LE 0xedb88320 +#define ETHER_CRC_POLY_BE 0x04c11db6 + +/* + * A macro to validate a length with + */ +#define ETHER_IS_VALID_LEN(foo) \ + ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN) + +/* + * Structure of a 10Mb/s Ethernet header. + */ +struct ether_header { + u_char ether_dhost[ETHER_ADDR_LEN]; + u_char ether_shost[ETHER_ADDR_LEN]; + u_short ether_type; +}; + +/* + * Structure of a 48-bit Ethernet address. + */ +struct ether_addr { + u_char octet[ETHER_ADDR_LEN]; +}; + +#define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */ + +/* + * NOTE: 0x0000-0x05DC (0..1500) are generally IEEE 802.3 length fields. + * However, there are some conflicts. + */ + +#define ETHERTYPE_8023 0x0004 /* IEEE 802.3 packet */ + /* 0x0101 .. 0x1FF Experimental */ +#define ETHERTYPE_PUP 0x0200 /* Xerox PUP protocol - see 0A00 */ +#define ETHERTYPE_PUPAT 0x0200 /* PUP Address Translation - see 0A01 */ +#define ETHERTYPE_SPRITE 0x0500 /* ??? */ + /* 0x0400 Nixdorf */ +#define ETHERTYPE_NS 0x0600 /* XNS */ +#define ETHERTYPE_NSAT 0x0601 /* XNS Address Translation (3Mb only) */ +#define ETHERTYPE_DLOG1 0x0660 /* DLOG (?) */ +#define ETHERTYPE_DLOG2 0x0661 /* DLOG (?) */ +#define ETHERTYPE_IP 0x0800 /* IP protocol */ +#define ETHERTYPE_X75 0x0801 /* X.75 Internet */ +#define ETHERTYPE_NBS 0x0802 /* NBS Internet */ +#define ETHERTYPE_ECMA 0x0803 /* ECMA Internet */ +#define ETHERTYPE_CHAOS 0x0804 /* CHAOSnet */ +#define ETHERTYPE_X25 0x0805 /* X.25 Level 3 */ +#define ETHERTYPE_ARP 0x0806 /* Address resolution protocol */ +#define ETHERTYPE_NSCOMPAT 0x0807 /* XNS Compatibility */ +#define ETHERTYPE_FRARP 0x0808 /* Frame Relay ARP (RFC1701) */ + /* 0x081C Symbolics Private */ + /* 0x0888 - 0x088A Xyplex */ +#define ETHERTYPE_UBDEBUG 0x0900 /* Ungermann-Bass network debugger */ +#define ETHERTYPE_IEEEPUP 0x0A00 /* Xerox IEEE802.3 PUP */ +#define ETHERTYPE_IEEEPUPAT 0x0A01 /* Xerox IEEE802.3 PUP Address Translation */ +#define ETHERTYPE_VINES 0x0BAD /* Banyan VINES */ +#define ETHERTYPE_VINESLOOP 0x0BAE /* Banyan VINES Loopback */ +#define ETHERTYPE_VINESECHO 0x0BAF /* Banyan VINES Echo */ + +/* 0x1000 - 0x100F Berkeley Trailer */ +/* + * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have + * (type-ETHERTYPE_TRAIL)*512 bytes of data followed + * by an ETHER type (as given above) and then the (variable-length) header. + */ +#define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */ +#define ETHERTYPE_NTRAILER 16 + +#define ETHERTYPE_DCA 0x1234 /* DCA - Multicast */ +#define ETHERTYPE_VALID 0x1600 /* VALID system protocol */ +#define ETHERTYPE_DOGFIGHT 0x1989 /* Artificial Horizons ("Aviator" dogfight simulator [on Sun]) */ +#define ETHERTYPE_RCL 0x1995 /* Datapoint Corporation (RCL lan protocol) */ + + /* The following 3C0x types + are unregistered: */ +#define ETHERTYPE_NBPVCD 0x3C00 /* 3Com NBP virtual circuit datagram (like XNS SPP) not registered */ +#define ETHERTYPE_NBPSCD 0x3C01 /* 3Com NBP System control datagram not registered */ +#define ETHERTYPE_NBPCREQ 0x3C02 /* 3Com NBP Connect request (virtual cct) not registered */ +#define ETHERTYPE_NBPCRSP 0x3C03 /* 3Com NBP Connect repsonse not registered */ +#define ETHERTYPE_NBPCC 0x3C04 /* 3Com NBP Connect complete not registered */ +#define ETHERTYPE_NBPCLREQ 0x3C05 /* 3Com NBP Close request (virtual cct) not registered */ +#define ETHERTYPE_NBPCLRSP 0x3C06 /* 3Com NBP Close response not registered */ +#define ETHERTYPE_NBPDG 0x3C07 /* 3Com NBP Datagram (like XNS IDP) not registered */ +#define ETHERTYPE_NBPDGB 0x3C08 /* 3Com NBP Datagram broadcast not registered */ +#define ETHERTYPE_NBPCLAIM 0x3C09 /* 3Com NBP Claim NetBIOS name not registered */ +#define ETHERTYPE_NBPDLTE 0x3C0A /* 3Com NBP Delete Netbios name not registered */ +#define ETHERTYPE_NBPRAS 0x3C0B /* 3Com NBP Remote adaptor status request not registered */ +#define ETHERTYPE_NBPRAR 0x3C0C /* 3Com NBP Remote adaptor response not registered */ +#define ETHERTYPE_NBPRST 0x3C0D /* 3Com NBP Reset not registered */ + +#define ETHERTYPE_PCS 0x4242 /* PCS Basic Block Protocol */ +#define ETHERTYPE_IMLBLDIAG 0x424C /* Information Modes Little Big LAN diagnostic */ +#define ETHERTYPE_DIDDLE 0x4321 /* THD - Diddle */ +#define ETHERTYPE_IMLBL 0x4C42 /* Information Modes Little Big LAN */ +#define ETHERTYPE_SIMNET 0x5208 /* BBN Simnet Private */ +#define ETHERTYPE_DECEXPER 0x6000 /* DEC Unassigned, experimental */ +#define ETHERTYPE_MOPDL 0x6001 /* DEC MOP dump/load */ +#define ETHERTYPE_MOPRC 0x6002 /* DEC MOP remote console */ +#define ETHERTYPE_DECnet 0x6003 /* DEC DECNET Phase IV route */ +#define ETHERTYPE_DN ETHERTYPE_DECnet /* libpcap, tcpdump */ +#define ETHERTYPE_LAT 0x6004 /* DEC LAT */ +#define ETHERTYPE_DECDIAG 0x6005 /* DEC diagnostic protocol (at interface initialization?) */ +#define ETHERTYPE_DECCUST 0x6006 /* DEC customer protocol */ +#define ETHERTYPE_SCA 0x6007 /* DEC LAVC, SCA */ +#define ETHERTYPE_AMBER 0x6008 /* DEC AMBER */ +#define ETHERTYPE_DECMUMPS 0x6009 /* DEC MUMPS */ + /* 0x6010 - 0x6014 3Com Corporation */ +#define ETHERTYPE_TRANSETHER 0x6558 /* Trans Ether Bridging (RFC1701)*/ +#define ETHERTYPE_RAWFR 0x6559 /* Raw Frame Relay (RFC1701) */ +#define ETHERTYPE_UBDL 0x7000 /* Ungermann-Bass download */ +#define ETHERTYPE_UBNIU 0x7001 /* Ungermann-Bass NIUs */ +#define ETHERTYPE_UBDIAGLOOP 0x7002 /* Ungermann-Bass diagnostic/loopback */ +#define ETHERTYPE_UBNMC 0x7003 /* Ungermann-Bass ??? (NMC to/from UB Bridge) */ +#define ETHERTYPE_UBBST 0x7005 /* Ungermann-Bass Bridge Spanning Tree */ +#define ETHERTYPE_OS9 0x7007 /* OS/9 Microware */ +#define ETHERTYPE_OS9NET 0x7009 /* OS/9 Net? */ + /* 0x7020 - 0x7029 LRT (England) (now Sintrom) */ +#define ETHERTYPE_RACAL 0x7030 /* Racal-Interlan */ +#define ETHERTYPE_PRIMENTS 0x7031 /* Prime NTS (Network Terminal Service) */ +#define ETHERTYPE_CABLETRON 0x7034 /* Cabletron */ +#define ETHERTYPE_CRONUSVLN 0x8003 /* Cronus VLN */ +#define ETHERTYPE_CRONUS 0x8004 /* Cronus Direct */ +#define ETHERTYPE_HP 0x8005 /* HP Probe */ +#define ETHERTYPE_NESTAR 0x8006 /* Nestar */ +#define ETHERTYPE_ATTSTANFORD 0x8008 /* AT&T/Stanford (local use) */ +#define ETHERTYPE_EXCELAN 0x8010 /* Excelan */ +#define ETHERTYPE_SG_DIAG 0x8013 /* SGI diagnostic type */ +#define ETHERTYPE_SG_NETGAMES 0x8014 /* SGI network games */ +#define ETHERTYPE_SG_RESV 0x8015 /* SGI reserved type */ +#define ETHERTYPE_SG_BOUNCE 0x8016 /* SGI bounce server */ +#define ETHERTYPE_APOLLODOMAIN 0x8019 /* Apollo DOMAIN */ +#define ETHERTYPE_TYMSHARE 0x802E /* Tymeshare */ +#define ETHERTYPE_TIGAN 0x802F /* Tigan, Inc. */ +#define ETHERTYPE_REVARP 0x8035 /* Reverse addr resolution protocol */ +#define ETHERTYPE_AEONIC 0x8036 /* Aeonic Systems */ +#define ETHERTYPE_IPXNEW 0x8037 /* IPX (Novell Netware?) */ +#define ETHERTYPE_LANBRIDGE 0x8038 /* DEC LANBridge */ +#define ETHERTYPE_DSMD 0x8039 /* DEC DSM/DDP */ +#define ETHERTYPE_ARGONAUT 0x803A /* DEC Argonaut Console */ +#define ETHERTYPE_VAXELN 0x803B /* DEC VAXELN */ +#define ETHERTYPE_DECDNS 0x803C /* DEC DNS Naming Service */ +#define ETHERTYPE_ENCRYPT 0x803D /* DEC Ethernet Encryption */ +#define ETHERTYPE_DECDTS 0x803E /* DEC Distributed Time Service */ +#define ETHERTYPE_DECLTM 0x803F /* DEC LAN Traffic Monitor */ +#define ETHERTYPE_DECNETBIOS 0x8040 /* DEC PATHWORKS DECnet NETBIOS Emulation */ +#define ETHERTYPE_DECLAST 0x8041 /* DEC Local Area System Transport */ + /* 0x8042 DEC Unassigned */ +#define ETHERTYPE_PLANNING 0x8044 /* Planning Research Corp. */ + /* 0x8046 - 0x8047 AT&T */ +#define ETHERTYPE_DECAM 0x8048 /* DEC Availability Manager for Distributed Systems DECamds (but someone at DEC says not) */ +#define ETHERTYPE_EXPERDATA 0x8049 /* ExperData */ +#define ETHERTYPE_VEXP 0x805B /* Stanford V Kernel exp. */ +#define ETHERTYPE_VPROD 0x805C /* Stanford V Kernel prod. */ +#define ETHERTYPE_ES 0x805D /* Evans & Sutherland */ +#define ETHERTYPE_LITTLE 0x8060 /* Little Machines */ +#define ETHERTYPE_COUNTERPOINT 0x8062 /* Counterpoint Computers */ + /* 0x8065 - 0x8066 Univ. of Mass @ Amherst */ +#define ETHERTYPE_VEECO 0x8067 /* Veeco Integrated Auto. */ +#define ETHERTYPE_GENDYN 0x8068 /* General Dynamics */ +#define ETHERTYPE_ATT 0x8069 /* AT&T */ +#define ETHERTYPE_AUTOPHON 0x806A /* Autophon */ +#define ETHERTYPE_COMDESIGN 0x806C /* ComDesign */ +#define ETHERTYPE_COMPUGRAPHIC 0x806D /* Compugraphic Corporation */ + /* 0x806E - 0x8077 Landmark Graphics Corp. */ +#define ETHERTYPE_MATRA 0x807A /* Matra */ +#define ETHERTYPE_DDE 0x807B /* Dansk Data Elektronik */ +#define ETHERTYPE_MERIT 0x807C /* Merit Internodal (or Univ of Michigan?) */ + /* 0x807D - 0x807F Vitalink Communications */ +#define ETHERTYPE_VLTLMAN 0x8080 /* Vitalink TransLAN III Management */ + /* 0x8081 - 0x8083 Counterpoint Computers */ + /* 0x8088 - 0x808A Xyplex */ +#define ETHERTYPE_ATALK 0x809B /* AppleTalk */ +#define ETHERTYPE_AT ETHERTYPE_ATALK /* old NetBSD */ +#define ETHERTYPE_APPLETALK ETHERTYPE_ATALK /* HP-UX */ + /* 0x809C - 0x809E Datability */ +#define ETHERTYPE_SPIDER 0x809F /* Spider Systems Ltd. */ + /* 0x80A3 Nixdorf */ + /* 0x80A4 - 0x80B3 Siemens Gammasonics Inc. */ + /* 0x80C0 - 0x80C3 DCA (Digital Comm. Assoc.) Data Exchange Cluster */ + /* 0x80C4 - 0x80C5 Banyan Systems */ +#define ETHERTYPE_PACER 0x80C6 /* Pacer Software */ +#define ETHERTYPE_APPLITEK 0x80C7 /* Applitek Corporation */ + /* 0x80C8 - 0x80CC Intergraph Corporation */ + /* 0x80CD - 0x80CE Harris Corporation */ + /* 0x80CF - 0x80D2 Taylor Instrument */ + /* 0x80D3 - 0x80D4 Rosemount Corporation */ +#define ETHERTYPE_SNA 0x80D5 /* IBM SNA Services over Ethernet */ +#define ETHERTYPE_VARIAN 0x80DD /* Varian Associates */ + /* 0x80DE - 0x80DF TRFS (Integrated Solutions Transparent Remote File System) */ + /* 0x80E0 - 0x80E3 Allen-Bradley */ + /* 0x80E4 - 0x80F0 Datability */ +#define ETHERTYPE_RETIX 0x80F2 /* Retix */ +#define ETHERTYPE_AARP 0x80F3 /* AppleTalk AARP */ + /* 0x80F4 - 0x80F5 Kinetics */ +#define ETHERTYPE_APOLLO 0x80F7 /* Apollo Computer */ +#define ETHERTYPE_VLAN 0x8100 /* IEEE 802.1Q VLAN tagging (XXX conflicts) */ + /* 0x80FF - 0x8101 Wellfleet Communications (XXX conflicts) */ +#define ETHERTYPE_BOFL 0x8102 /* Wellfleet; BOFL (Breath OF Life) pkts [every 5-10 secs.] */ +#define ETHERTYPE_WELLFLEET 0x8103 /* Wellfleet Communications */ + /* 0x8107 - 0x8109 Symbolics Private */ +#define ETHERTYPE_TALARIS 0x812B /* Talaris */ +#define ETHERTYPE_WATERLOO 0x8130 /* Waterloo Microsystems Inc. (XXX which?) */ +#define ETHERTYPE_HAYES 0x8130 /* Hayes Microcomputers (XXX which?) */ +#define ETHERTYPE_VGLAB 0x8131 /* VG Laboratory Systems */ + /* 0x8132 - 0x8137 Bridge Communications */ +#define ETHERTYPE_IPX 0x8137 /* Novell (old) NetWare IPX (ECONFIG E option) */ +#define ETHERTYPE_NOVELL 0x8138 /* Novell, Inc. */ + /* 0x8139 - 0x813D KTI */ +#define ETHERTYPE_MUMPS 0x813F /* M/MUMPS data sharing */ +#define ETHERTYPE_AMOEBA 0x8145 /* Vrije Universiteit (NL) Amoeba 4 RPC (obsolete) */ +#define ETHERTYPE_FLIP 0x8146 /* Vrije Universiteit (NL) FLIP (Fast Local Internet Protocol) */ +#define ETHERTYPE_VURESERVED 0x8147 /* Vrije Universiteit (NL) [reserved] */ +#define ETHERTYPE_LOGICRAFT 0x8148 /* Logicraft */ +#define ETHERTYPE_NCD 0x8149 /* Network Computing Devices */ +#define ETHERTYPE_ALPHA 0x814A /* Alpha Micro */ +#define ETHERTYPE_SNMP 0x814C /* SNMP over Ethernet (see RFC1089) */ + /* 0x814D - 0x814E BIIN */ +#define ETHERTYPE_TEC 0x814F /* Technically Elite Concepts */ +#define ETHERTYPE_RATIONAL 0x8150 /* Rational Corp */ + /* 0x8151 - 0x8153 Qualcomm */ + /* 0x815C - 0x815E Computer Protocol Pty Ltd */ + /* 0x8164 - 0x8166 Charles River Data Systems */ +#define ETHERTYPE_XTP 0x817D /* Protocol Engines XTP */ +#define ETHERTYPE_SGITW 0x817E /* SGI/Time Warner prop. */ +#define ETHERTYPE_HIPPI_FP 0x8180 /* HIPPI-FP encapsulation */ +#define ETHERTYPE_STP 0x8181 /* Scheduled Transfer STP, HIPPI-ST */ + /* 0x8182 - 0x8183 Reserved for HIPPI-6400 */ + /* 0x8184 - 0x818C SGI prop. */ +#define ETHERTYPE_MOTOROLA 0x818D /* Motorola */ +#define ETHERTYPE_NETBEUI 0x8191 /* PowerLAN NetBIOS/NetBEUI (PC) */ + /* 0x819A - 0x81A3 RAD Network Devices */ + /* 0x81B7 - 0x81B9 Xyplex */ + /* 0x81CC - 0x81D5 Apricot Computers */ + /* 0x81D6 - 0x81DD Artisoft Lantastic */ + /* 0x81E6 - 0x81EF Polygon */ + /* 0x81F0 - 0x81F2 Comsat Labs */ + /* 0x81F3 - 0x81F5 SAIC */ + /* 0x81F6 - 0x81F8 VG Analytical */ + /* 0x8203 - 0x8205 QNX Software Systems Ltd. */ + /* 0x8221 - 0x8222 Ascom Banking Systems */ + /* 0x823E - 0x8240 Advanced Encryption Systems */ + /* 0x8263 - 0x826A Charles River Data Systems */ + /* 0x827F - 0x8282 Athena Programming */ + /* 0x829A - 0x829B Inst Ind Info Tech */ + /* 0x829C - 0x82AB Taurus Controls */ + /* 0x82AC - 0x8693 Walker Richer & Quinn */ +#define ETHERTYPE_ACCTON 0x8390 /* Accton Technologies (unregistered) */ +#define ETHERTYPE_TALARISMC 0x852B /* Talaris multicast */ +#define ETHERTYPE_KALPANA 0x8582 /* Kalpana */ + /* 0x8694 - 0x869D Idea Courier */ + /* 0x869E - 0x86A1 Computer Network Tech */ + /* 0x86A3 - 0x86AC Gateway Communications */ +#define ETHERTYPE_SECTRA 0x86DB /* SECTRA */ +#define ETHERTYPE_IPV6 0x86DD /* IP protocol version 6 */ +#define ETHERTYPE_DELTACON 0x86DE /* Delta Controls */ +#define ETHERTYPE_ATOMIC 0x86DF /* ATOMIC */ + /* 0x86E0 - 0x86EF Landis & Gyr Powers */ + /* 0x8700 - 0x8710 Motorola */ +#define ETHERTYPE_RDP 0x8739 /* Control Technology Inc. RDP Without IP */ +#define ETHERTYPE_MICP 0x873A /* Control Technology Inc. Mcast Industrial Ctrl Proto. */ + /* 0x873B - 0x873C Control Technology Inc. Proprietary */ +#define ETHERTYPE_TCPCOMP 0x876B /* TCP/IP Compression (RFC1701) */ +#define ETHERTYPE_IPAS 0x876C /* IP Autonomous Systems (RFC1701) */ +#define ETHERTYPE_SECUREDATA 0x876D /* Secure Data (RFC1701) */ +#define ETHERTYPE_FLOWCONTROL 0x8808 /* 802.3x flow control packet */ +#define ETHERTYPE_PPP 0x880B /* PPP (obsolete by PPPOE) */ +#define ETHERTYPE_HITACHI 0x8820 /* Hitachi Cable (Optoelectronic Systems Laboratory) */ +#define ETHERTYPE_MPLS 0x8847 /* MPLS Unicast */ +#define ETHERTYPE_MPLS_MCAST 0x8848 /* MPLS Multicast */ +#define ETHERTYPE_AXIS 0x8856 /* Axis Communications AB proprietary bootstrap/config */ +#define ETHERTYPE_PPPOEDISC 0x8863 /* PPP Over Ethernet Discovery Stage */ +#define ETHERTYPE_PPPOE 0x8864 /* PPP Over Ethernet Session Stage */ +#define ETHERTYPE_LANPROBE 0x8888 /* HP LanProbe test? */ +#define ETHERTYPE_PAE 0x888e /* EAPOL PAE/802.1x */ +#define ETHERTYPE_LOOPBACK 0x9000 /* Loopback: used to test interfaces */ +#define ETHERTYPE_LBACK ETHERTYPE_LOOPBACK /* DEC MOP loopback */ +#define ETHERTYPE_XNSSM 0x9001 /* 3Com (Formerly Bridge Communications), XNS Systems Management */ +#define ETHERTYPE_TCPSM 0x9002 /* 3Com (Formerly Bridge Communications), TCP/IP Systems Management */ +#define ETHERTYPE_BCLOOP 0x9003 /* 3Com (Formerly Bridge Communications), loopback detection */ +#define ETHERTYPE_DEBNI 0xAAAA /* DECNET? Used by VAX 6220 DEBNI */ +#define ETHERTYPE_SONIX 0xFAF5 /* Sonix Arpeggio */ +#define ETHERTYPE_VITAL 0xFF00 /* BBN VITAL-LanBridge cache wakeups */ + /* 0xFF00 - 0xFFOF ISC Bunker Ramo */ + +#define ETHERTYPE_MAX 0xFFFF /* Maximum valid ethernet type, reserved */ + +/* + * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have + * (type-ETHERTYPE_TRAIL)*512 bytes of data followed + * by an ETHER type (as given above) and then the (variable-length) header. + */ +#define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */ +#define ETHERTYPE_NTRAILER 16 + +#define ETHERMTU (ETHER_MAX_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN) +#define ETHERMIN (ETHER_MIN_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN) +#define ETHERMTU_JUMBO (ETHER_MAX_LEN_JUMBO - ETHER_HDR_LEN - ETHER_CRC_LEN) + +#ifdef _KERNEL + +struct ifnet; +struct mbuf; +struct rtentry; +struct sockaddr; + +extern uint32_t ether_crc32_le(const uint8_t *, size_t); +extern uint32_t ether_crc32_be(const uint8_t *, size_t); +extern void ether_demux(struct ifnet *, struct mbuf *); +extern void ether_ifattach(struct ifnet *, const u_int8_t *); +extern void ether_ifdetach(struct ifnet *); +extern int ether_ioctl(struct ifnet *, int, caddr_t); +extern int ether_output(struct ifnet *, + struct mbuf *, struct sockaddr *, struct rtentry *); +extern int ether_output_frame(struct ifnet *, struct mbuf *); +extern char *ether_sprintf(const u_int8_t *); + +#else /* _KERNEL */ + +#include + +/* + * Ethernet address conversion/parsing routines. + */ +__BEGIN_DECLS +struct ether_addr *ether_aton(const char *); +int ether_hostton(const char *, struct ether_addr *); +int ether_line(const char *, struct ether_addr *, char *); +char *ether_ntoa(const struct ether_addr *); +int ether_ntohost(char *, const struct ether_addr *); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_NET_ETHERNET_H_ */ Added: haiku/trunk/src/libs/compat/freebsd_network/compat/net/if.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/net/if.h 2007-05-02 19:05:57 UTC (rev 20984) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/net/if.h 2007-05-02 23:10:18 UTC (rev 20985) @@ -0,0 +1,73 @@ +#ifndef _FBSD_COMPAT_NET_IF_H_ +#define _FBSD_COMPAT_NET_IF_H_ + +#include + +#include /* for timeval */ + + +/* Capabilities that interfaces can advertise. */ +#define IFCAP_RXCSUM 0x0001 /* can offload checksum on RX */ +#define IFCAP_TXCSUM 0x0002 /* can offload checksum on TX */ +#define IFCAP_NETCONS 0x0004 /* can be a network console */ +#define IFCAP_VLAN_MTU 0x0008 /* VLAN-compatible MTU */ +#define IFCAP_VLAN_HWTAGGING 0x0010 /* hardware VLAN tag support */ +#define IFCAP_JUMBO_MTU 0x0020 /* 9000 byte MTU supported */ +#define IFCAP_POLLING 0x0040 /* driver supports polling */ + +#define IFCAP_HWCSUM (IFCAP_RXCSUM | IFCAP_TXCSUM) + + +#define IFF_DRV_RUNNING 0x10000 +#define IFF_DRV_OACTIVE 0x20000 +#define IFF_LINK0 0x40000 + + +struct ifmediareq { + char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + int ifm_current; /* current media options */ + int ifm_mask; /* don't care mask */ + int ifm_status; /* media status */ + int ifm_active; /* active options */ + int ifm_count; /* # entries in ifm_ulist array */ + int *ifm_ulist; /* media words */ +}; + +/* + * Structure describing information about an interface + * which may be of interest to management entities. + */ +struct if_data { + /* generic interface information */ + u_char ifi_type; /* ethernet, tokenring, etc */ + u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ + u_char ifi_addrlen; /* media address length */ + u_char ifi_hdrlen; /* media header length */ + u_char ifi_link_state; /* current link state */ + u_char ifi_recvquota; /* polling quota for receive intrs */ + u_char ifi_xmitquota; /* polling quota for xmit intrs */ + u_char ifi_datalen; /* length of this data struct */ + u_long ifi_mtu; /* maximum transmission unit */ + u_long ifi_metric; /* routing metric (external only) */ + u_long ifi_baudrate; /* linespeed */ + /* volatile statistics */ + u_long ifi_ipackets; /* packets received on interface */ + u_long ifi_ierrors; /* input errors on interface */ + u_long ifi_opackets; /* packets sent on interface */ + u_long ifi_oerrors; /* output errors on interface */ + u_long ifi_collisions; /* collisions on csma interfaces */ + u_long ifi_ibytes; /* total number of octets received */ + u_long ifi_obytes; /* total number of octets sent */ + u_long ifi_imcasts; /* packets received via multicast */ + u_long ifi_omcasts; /* packets sent via multicast */ + u_long ifi_iqdrops; /* dropped on input, this interface */ + u_long ifi_noproto; /* destined for unsupported protocol */ + u_long ifi_hwassist; /* HW offload capabilities */ + time_t ifi_epoch; /* uptime at attach or stat reset */ +#ifdef __alpha__ + u_int ifi_timepad; /* time_t is int, not long on alpha */ +#endif + struct timeval ifi_lastchange; /* time of last administrative change */ +}; + +#endif Added: haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_arp.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_arp.h 2007-05-02 19:05:57 UTC (rev 20984) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_arp.h 2007-05-02 23:10:18 UTC (rev 20985) @@ -0,0 +1,115 @@ +/*- + * Copyright (c) 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)if_arp.h 8.1 (Berkeley) 6/10/93 + * $FreeBSD: src/sys/net/if_arp.h,v 1.22 2005/06/10 16:49:18 brooks Exp $ + */ + +#ifndef _NET_IF_ARP_H_ +#define _NET_IF_ARP_H_ + +/* + * Address Resolution Protocol. + * + * See RFC 826 for protocol description. ARP packets are variable + * in size; the arphdr structure defines the fixed-length portion. + * Protocol type values are the same as those for 10 Mb/s Ethernet. + * It is followed by the variable-sized fields ar_sha, arp_spa, + * arp_tha and arp_tpa in that order, according to the lengths + * specified. Field names used correspond to RFC 826. + */ +struct arphdr { + u_short ar_hrd; /* format of hardware address */ +#define ARPHRD_ETHER 1 /* ethernet hardware format */ +#define ARPHRD_IEEE802 6 /* token-ring hardware format */ +#define ARPHRD_ARCNET 7 /* arcnet hardware format */ +#define ARPHRD_FRELAY 15 /* frame relay hardware format */ +#define ARPHRD_IEEE1394 24 /* firewire hardware format */ + u_short ar_pro; /* format of protocol address */ + u_char ar_hln; /* length of hardware address */ + u_char ar_pln; /* length of protocol address */ + u_short ar_op; /* one of: */ +#define ARPOP_REQUEST 1 /* request to resolve address */ +#define ARPOP_REPLY 2 /* response to previous request */ +#define ARPOP_REVREQUEST 3 /* request protocol address given hardware */ +#define ARPOP_REVREPLY 4 /* response giving protocol address */ +#define ARPOP_INVREQUEST 8 /* request to identify peer */ +#define ARPOP_INVREPLY 9 /* response identifying peer */ +/* + * The remaining fields are variable in size, + * according to the sizes above. + */ +#ifdef COMMENT_ONLY + u_char ar_sha[]; /* sender hardware address */ + u_char ar_spa[]; /* sender protocol address */ + u_char ar_tha[]; /* target hardware address */ + u_char ar_tpa[]; /* target protocol address */ +#endif +}; + +#define ar_sha(ap) (((caddr_t)((ap)+1)) + 0) +#define ar_spa(ap) (((caddr_t)((ap)+1)) + (ap)->ar_hln) +#define ar_tha(ap) (((caddr_t)((ap)+1)) + (ap)->ar_hln + (ap)->ar_pln) +#define ar_tpa(ap) (((caddr_t)((ap)+1)) + 2*(ap)->ar_hln + (ap)->ar_pln) + +#define arphdr_len2(ar_hln, ar_pln) \ + (sizeof(struct arphdr) + 2*(ar_hln) + 2*(ar_pln)) +#define arphdr_len(ap) (arphdr_len2((ap)->ar_hln, (ap)->ar_pln)) + +/* + * ARP ioctl request + */ +struct arpreq { + struct sockaddr arp_pa; /* protocol address */ + struct sockaddr arp_ha; /* hardware address */ + int arp_flags; /* flags */ +}; +/* arp_flags and at_flags field values */ +#define ATF_INUSE 0x01 /* entry in use */ +#define ATF_COM 0x02 /* completed entry (enaddr valid) */ +#define ATF_PERM 0x04 /* permanent entry */ +#define ATF_PUBL 0x08 /* publish entry (respond for other host) */ +#define ATF_USETRAILERS 0x10 /* has requested trailers */ + +#ifdef _KERNEL +/* + * Structure shared between the ethernet driver modules and + * the address resolution code. [... truncated: 3603 lines follow ...] From hugosantos at mail.berlios.de Thu May 3 01:11:10 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Thu, 3 May 2007 01:11:10 +0200 Subject: [Haiku-commits] r20986 - haiku/trunk/src/libs/compat/freebsd_network Message-ID: <200705022311.l42NBAll004196@sheep.berlios.de> Author: hugosantos Date: 2007-05-03 01:11:00 +0200 (Thu, 03 May 2007) New Revision: 20986 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20986&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/README Log: typo. Modified: haiku/trunk/src/libs/compat/freebsd_network/README =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/README 2007-05-02 23:10:18 UTC (rev 20985) +++ haiku/trunk/src/libs/compat/freebsd_network/README 2007-05-02 23:11:00 UTC (rev 20986) @@ -1,3 +1,3 @@ -FreeBSD network driver compatability layer. Based on FreeBSD 6.2. +FreeBSD network driver compatibility layer. Based on FreeBSD 6.2. - Hugo, 3 May 2007 From hugosantos at mail.berlios.de Thu May 3 02:46:18 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Thu, 3 May 2007 02:46:18 +0200 Subject: [Haiku-commits] r20987 - haiku/trunk/src/libs/compat/freebsd_network Message-ID: <200705030046.l430kI2e032755@sheep.berlios.de> Author: hugosantos Date: 2007-05-03 02:46:07 +0200 (Thu, 03 May 2007) New Revision: 20987 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20987&view=rev Added: haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/device.h haiku/trunk/src/libs/compat/freebsd_network/mbuf.c haiku/trunk/src/libs/compat/freebsd_network/mutex.c Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile haiku/trunk/src/libs/compat/freebsd_network/compat.c Log: freebsd compat. layer, a few more methods. Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-02 23:11:00 UTC (rev 20986) +++ haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-03 00:46:07 UTC (rev 20987) @@ -3,10 +3,13 @@ UsePrivateHeaders kernel net ; UseHeaders [ FDirName $(SUBDIR) ] : true ; -UseHeaders [ FDirName $(SUBDIR) headers ] : true ; +UseHeaders [ FDirName $(SUBDIR) compat ] : true ; SubDirCcFlags [ FDefines _KERNEL=1 ] ; Library libfreebsd_network.a : compat.c + device.c + mbuf.c + mutex.c ; Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-02 23:11:00 UTC (rev 20986) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-03 00:46:07 UTC (rev 20987) @@ -8,9 +8,11 @@ * Some of this code is based on previous work by Marcus Overhagen. */ +#include "device.h" +#include + #include -#include #include #include @@ -21,31 +23,57 @@ pci_module_info *gPci; -struct device { - int devId; - pci_info * pciInfo; - - uint8 pciBus; - uint8 pciDev; - uint8 pciFunc; -}; - uint32_t pci_read_config(device_t dev, int offset, int size) { - return gPci->read_pci_config(dev->pciBus, dev->pciDev, dev->pciFunc, - offset, size); + return gPci->read_pci_config(dev->pciInfo->bus, dev->pciInfo->device, + dev->pciInfo->function, offset, size); } void pci_write_config(device_t dev, int offset, uint32_t value, int size) { - gPci->write_pci_config(dev->pciBus, dev->pciDev, dev->pciFunc, offset, - size, value); + gPci->write_pci_config(dev->pciInfo->bus, dev->pciInfo->device, + dev->pciInfo->function, offset, size, value); } +uint16_t +pci_get_vendor(device_t dev) +{ + return pci_read_config(dev, PCI_vendor_id, 2); +} + + +uint16_t +pci_get_device(device_t dev) +{ + return pci_read_config(dev, PCI_device_id, 2); +} + + +uint8_t +pci_get_revid(device_t dev) +{ + return pci_read_config(dev, PCI_revision, 1); +} + + +int +device_printf(device_t dev, const char *format, ...) +{ + char buf[256]; + va_list vl; + va_start(vl, format); + vsnprintf(buf, sizeof(buf), format, vl); + va_end(vl); + + dprintf("[...] %s", buf); + return 0; +} + + status_t init_compat_layer() { Added: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-02 23:11:00 UTC (rev 20986) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-03 00:46:07 UTC (rev 20987) @@ -0,0 +1,96 @@ +/* + * Copyright 2007, Hugo Santos. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Hugo Santos, hugosantos at gmail.com + * + * Some of this code is based on previous work by Marcus Overhagen. + */ + +#include "device.h" + +#include + +#include +#include + + +static status_t +compat_open(const char *name, uint32 flags, void **cookie) +{ + return B_ERROR; +} + + +static status_t +compat_close(void *cookie) +{ + device_t dev = cookie; + return B_ERROR; +} + + +static status_t +compat_free(void *cookie) +{ + device_t dev = cookie; + free(dev); + return B_ERROR; +} + + +static status_t +compat_read(void *cookie, off_t position, void *buf, size_t *numBytes) +{ + uint32 semFlags = B_CAN_INTERRUPT; + device_t dev = cookie; + status_t status; + struct mbuf *mb; + size_t len; + + if (atomic_or(&dev->flags, 0) & DEVICE_CLOSED) + return B_INTERRUPTED; + + if (atomic_or(&dev->flags, 0) & DEVICE_NON_BLOCK) + semFlags |= B_RELATIVE_TIMEOUT; + + + do { + status = acquire_sem_etc(dev->receive_sem, 1, semFlags, 0); + if (atomic_or(&dev->flags, 0) & DEVICE_CLOSED) + return B_INTERRUPTED; + + if (status == B_WOULD_BLOCK) { + *numBytes = 0; + return B_OK; + } else if (status < B_OK) + return status; + + IF_DEQUEUE(&dev->receive_queue, mb); + } while (mb == NULL); + + len = min_c(max_c(mb->m_len, 0), *numBytes); + + // TODO we need something that cna join various chunks + memcpy(buf, mtod(mb, const void *), len); + *numBytes = len; + + m_freem(mb); + return B_OK; +} + + +static status_t +compat_write(void *cookie, off_t position, const void *buffer, + size_t *numBytes) +{ + return B_ERROR; +} + + +static status_t +compat_control(void *cookie, uint32 op, void *arg, size_t len) +{ + return B_ERROR; +} Added: haiku/trunk/src/libs/compat/freebsd_network/device.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-02 23:11:00 UTC (rev 20986) +++ haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-03 00:46:07 UTC (rev 20987) @@ -0,0 +1,45 @@ +/* + * Copyright 2007, Hugo Santos. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Hugo Santos, hugosantos at gmail.com + * + * Some of this code is based on previous work by Marcus Overhagen. + */ +#ifndef _DEVICE_H_ +#define _DEVICE_H_ + +#include + +#include +#include + +#include +#include +#include + +struct ifnet; + +struct device { + int devId; + pci_info * pciInfo; + + int32 flags; + + struct ifqueue receive_queue; + sem_id receive_sem; + + struct ifnet * ifp; +}; + + +enum { + DEVICE_CLOSED = 1 << 0, + DEVICE_NON_BLOCK = 1 << 1, +}; + + +extern pci_module_info *gPci; + +#endif Added: haiku/trunk/src/libs/compat/freebsd_network/mbuf.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/mbuf.c 2007-05-02 23:11:00 UTC (rev 20986) +++ haiku/trunk/src/libs/compat/freebsd_network/mbuf.c 2007-05-03 00:46:07 UTC (rev 20987) @@ -0,0 +1,68 @@ +/* + * Copyright 2007, Hugo Santos. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Hugo Santos, hugosantos at gmail.com + * + * Some of this code is based on previous work by Marcus Overhagen. + */ + +#include +#include + +#include + + +status_t init_mbufs(void); +void uninit_mbufs(void); + + +#define CHUNK_SIZE 2048 + +static object_cache *sMBufCache; +static object_cache *sChunkCache; + + +void +m_freem(struct mbuf *mp) +{ + struct mbuf *next = mp; + + do { + mp = next; + next = next->m_next; + + if (mp->m_flags & M_EXT) + object_cache_free(sChunkCache, mp->m_ext.ext_buf); + object_cache_free(sMBufCache, mp); + } while (next); +} + + +status_t +init_mbufs() +{ + sMBufCache = create_object_cache("mbufs", sizeof(struct mbuf), 8, NULL, + NULL, NULL); + if (sMBufCache == NULL) + return B_NO_MEMORY; + + sChunkCache = create_object_cache("mbuf chunks", CHUNK_SIZE, 0, NULL, NULL, + NULL); + if (sChunkCache == NULL) { + delete_object_cache(sMBufCache); + return B_NO_MEMORY; + } + + return B_OK; +} + + +void +uninit_mbufs() +{ + delete_object_cache(sMBufCache); + delete_object_cache(sChunkCache); +} + Added: haiku/trunk/src/libs/compat/freebsd_network/mutex.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/mutex.c 2007-05-02 23:11:00 UTC (rev 20986) +++ haiku/trunk/src/libs/compat/freebsd_network/mutex.c 2007-05-03 00:46:07 UTC (rev 20987) @@ -0,0 +1,62 @@ +/* + * Copyright 2007, Hugo Santos. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Hugo Santos, hugosantos at gmail.com + */ + +#include + +#include + + +status_t init_mutexes(void); +void uninit_mutexes(void); + + +// these methods are bit unfriendly, a bit too much panic() around + +struct mutex Giant; + + +void +mtx_init(struct mtx *m, const char *name, const char *type, int opts) +{ + if (opts == MTX_DEF) { + if (mutex_init(&m->u.mutex, name) < B_OK) + panic("Panic! Dance like it's 1979, we ran out of semaphores"); + } else if (opts == MTX_RECURSE) { + if (recursive_lock_init(&m->u.recursive, name) < B_OK) + panic("Hell just froze as someone was trying to init a recursive mutex."); + } else + panic("Uh-oh, someone is pressing the wrong buttons"); + + m->type = opts; +} + + +void +mtx_destroy(struct mtx *m) +{ + if (m->type == MTX_DEF) { + mutex_destroy(&m->u.mutex); + } else if (m->type == MTX_RECURSE) { + recursive_lock_destroy(&m->u.recursive); + } else + panic("Uh-oh, someone is pressing the wrong buttons"); +} + + +status_t +init_mutexes() +{ + return B_ERROR; +} + + +void +uninit_mutexes() +{ +} + From mmu_man at mail.berlios.de Thu May 3 03:08:37 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Thu, 3 May 2007 03:08:37 +0200 Subject: [Haiku-commits] r20988 - haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd Message-ID: <200705030108.l4318b0Y000883@sheep.berlios.de> Author: mmu_man Date: 2007-05-03 03:08:36 +0200 (Thu, 03 May 2007) New Revision: 20988 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20988&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c Log: Locking for Haiku & R5. Init stuff (driver_settings, not finished). open/free(). Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-03 00:46:07 UTC (rev 20987) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-03 01:08:36 UTC (rev 20988) @@ -4,18 +4,37 @@ */ /* - nbd driver for Haiku + * nbd driver for Haiku + * + * Maps a Network Block Device as virtual partitions. + */ - Maps a Network Block Device as virtual partitions. -*/ - #include #include #include +#include #include +#include +#ifdef __HAIKU__ +#include +#else +/* wrappers */ +#ifndef _IMPEXP_KERNEL +#define _IMPEXP_KERNEL +#endif +#include "lock.h" +#define benaphore lock +#define benaphore_init new_lock +#define benaphore_destroy free_lock +#define benaphore_lock LOCK +#define benaphore_unlock UNLOCK +#endif + #include "nbd.h" +#define DRV "nbd" +#define D "nbd:" #define MAX_NBDS 4 #define DEVICE_PREFIX "disk/virtual/nbd/" #define DEVICE_FMT DEVICE_PREFIX "%2d/raw" @@ -31,7 +50,9 @@ }; struct nbd_device { - //lock + char target[64]; // "ip:port" + struct sockaddr_in server; + benaphore ben; vint32 refcnt; uint64 req; /* next ID for requests */ int sock; @@ -53,6 +74,8 @@ struct nbd_device *nbd_find_device(const char* name); +KSOCKET_MODULE_DECL; + #pragma mark ==== request manager ==== @@ -68,36 +91,86 @@ return 0; } +status_t nbd_connect(struct nbd_device *dev) +{ + + return B_OK; +} + +status_t nbd_teardown(struct nbd_device *dev) +{ + close(dev->sock); + return B_OK; +} + #pragma mark ==== device hooks ==== static struct nbd_device nbd_devices[MAX_NBDS]; status_t nbd_open(const char *name, uint32 flags, cookie_t **cookie) { + status_t err; struct nbd_device *dev = NULL; (void)name; (void)flags; dev = nbd_find_device(name); if (!dev) return ENOENT; + err = ENOMEM; *cookie = (void*)malloc(sizeof(cookie_t)); - if (*cookie == NULL) { - dprintf("nbd_open : error allocating cookie\n"); + if (*cookie == NULL) goto err0; - } memset(*cookie, 0, sizeof(cookie_t)); (*cookie)->dev = dev; + err = benaphore_lock(&dev->ben); + if (err) + goto err1; + /* */ + if (dev->sock < 0) + err = nbd_connect(dev); + if (err) + goto err2; + dev->refcnt++; + benaphore_unlock(&dev->ben); return B_OK; + +err2: + benaphore_unlock(&dev->ben); +err1: + free(*cookie); err0: - return B_ERROR; + dprintf("nbd_open : error 0x%08lx\n", err); + return err; } -status_t nbd_close(void *cookie) { - (void)cookie; +status_t nbd_close(cookie_t *cookie) { + struct nbd_device *dev = cookie->dev; + status_t err; + + err = benaphore_lock(&dev->ben); + if (err) + return err; + + // XXX: do something ? + + benaphore_unlock(&dev->ben); return B_OK; } status_t nbd_free(cookie_t *cookie) { + struct nbd_device *dev = cookie->dev; + status_t err; + + err = benaphore_lock(&dev->ben); + if (err) + return err; + + if (--dev->refcnt == 0) { + err = nbd_teardown(dev); + } + + benaphore_unlock(&dev->ben); + free(cookie); - return B_OK; + return err; } status_t nbd_control(cookie_t *cookie, uint32 op, void *data, size_t len) { @@ -193,9 +266,26 @@ status_t init_driver (void) { - int i; - // load settings + status_t err; + int i, j; + // XXX: load settings + void *handle; + + err = ksocket_init(); + if (err < B_OK) + return err; + for (i = 0; i < MAX_NBDS; i++) { + memset(nbd_devices[i].target, 0, 64); + err = benaphore_init(&nbd_devices[i].ben, "nbd lock"); + if (err < B_OK) + return err; // XXX + nbd_devices[i].refcnt = 0; + nbd_devices[i].req = 0LL; /* next ID for requests */ + nbd_devices[i].sock = -1; + nbd_devices[i].postoffice = -1; + nbd_devices[i].size = 0LL; + nbd_devices[i].reqs = NULL; nbd_name[i] = malloc(DEVICE_NAME_MAX); if (nbd_name[i] == NULL) break; @@ -203,16 +293,50 @@ // XXX: init nbd_devices[i] } nbd_name[i] = NULL; + + handle = load_driver_settings(DRV); + if (handle) { + for (i = 0; i < MAX_NBDS; i++) { + char keyname[10]; + char *v; + sprintf(keyname, "nbd%d", i); + v = get_driver_parameter(handle, keyname, NULL, NULL); + /* should be "ip:port" */ + // XXX: test + if (v || 0) { + //strncpy(nbd_devices[i].target, v, 64); + //XXX:TEST + //strncpy(nbd_devices[i].target, "127.0.0.1:1337", 64); + //XXX:parse it + nbd_devices[i].server.sin_len = sizeof(struct sockaddr_in); + nbd_devices[i].server.sin_family = AF_INET; + nbd_devices[i].server.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + nbd_devices[i].server.sin_port = htons(1337 + i); + } + } + /*should parse as a tree: + settings = get_driver_settings(handle); + for (i = 0; i < settings->parameter_count; i++) { + + } + */ + + unload_driver_settings(handle); + } + return B_OK; } void uninit_driver (void) { + status_t err; int i; for (i = 0; i < MAX_NBDS; i++) { free(nbd_name[i]); + err = benaphore_destroy(&nbd_devices[i].ben); } + err = ksocket_cleanup(); } const char** From hugosantos at mail.berlios.de Thu May 3 03:18:40 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Thu, 3 May 2007 03:18:40 +0200 Subject: [Haiku-commits] r20989 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/sys Message-ID: <200705030118.l431IemX001295@sheep.berlios.de> Author: hugosantos Date: 2007-05-03 03:18:30 +0200 (Thu, 03 May 2007) New Revision: 20989 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20989&view=rev Added: haiku/trunk/src/libs/compat/freebsd_network/bus.c Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h Log: freebsd compat. layer: resource allocation and interrupt setup Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-03 01:08:36 UTC (rev 20988) +++ haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-03 01:18:30 UTC (rev 20989) @@ -8,6 +8,7 @@ SubDirCcFlags [ FDefines _KERNEL=1 ] ; Library libfreebsd_network.a : + bus.c compat.c device.c mbuf.c Added: haiku/trunk/src/libs/compat/freebsd_network/bus.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-03 01:08:36 UTC (rev 20988) +++ haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-03 01:18:30 UTC (rev 20989) @@ -0,0 +1,124 @@ +/* + * Copyright 2007, Hugo Santos. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Hugo Santos, hugosantos at gmail.com + * + * Some of this code is based on previous work by Marcus Overhagen. + */ + +#include + +#include + +#include +#include +#include + + +struct internal_intr { + driver_intr_t handler; + void *arg; + int irq; +}; + + +/* straight from Marcus' ipro1000 driver */ +struct resource * +bus_alloc_resource(device_t dev, int type, int *rid, unsigned long start, + unsigned long end, unsigned long count, uint32 flags) +{ + switch (type) { + case SYS_RES_IRQ: + { + uint8 res = pci_read_config(dev, PCI_interrupt_line, 1); + if (res == 0 || res == 0xff) + return NULL; + return (struct resource *)(int)res; + } + + case SYS_RES_MEMORY: + { + uint32 res = pci_read_config(dev, *rid, 4) + & PCI_address_memory_32_mask; + uint32 size = 128 * 1024; // TODO get size from BAR + void *virtualAddr; + if (map_mem(&virtualAddr, (void *)res, size, 0, "bus_alloc_resource(MEMORY)") < 0) + return NULL; + return (struct resource *)virtualAddr; + } + + case SYS_RES_IOPORT: + return (struct resource *)(pci_read_config(dev, *rid, 4) + & PCI_address_io_mask); + + default: + return NULL; + } +} + + +int +bus_release_resource(device_t dev, int type, int rid, struct resource *res) +{ + switch (type) { + case SYS_RES_IRQ: + case SYS_RES_IOPORT: + return 0; + + case SYS_RES_MEMORY: + delete_area(area_for(res)); + return 0; + + default: + return B_ERROR; + } +} + + +static int32 +intr_wrapper(void *data) +{ + struct internal_intr *intr = data; + intr->handler(intr->arg); + return 0; +} + + +int +bus_setup_intr(device_t dev, struct resource *res, int flags, + driver_intr_t handler, void *arg, void **cookiep) +{ + struct internal_intr *intr = (struct internal_intr *)malloc( + sizeof(struct internal_intr)); + status_t status; + + if (intr == NULL) + return B_NO_MEMORY; + + intr->handler = handler; + intr->arg = arg; + intr->irq = (int)res; + + status = install_io_interrupt_handler(intr->irq, intr_wrapper, intr, 0); + if (status < B_OK) { + free(intr); + return status; + } + + *cookiep = intr; + + return status; +} + + +int +bus_teardown_intr(device_t dev, struct resource *res, void *arg) +{ + struct internal_intr *intr = arg; + remove_io_interrupt_handler(intr->irq, intr_wrapper, intr); + free(intr); + return 0; +} + Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-03 01:08:36 UTC (rev 20988) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-03 01:18:30 UTC (rev 20989) @@ -111,7 +111,7 @@ int bus_generic_detach(device_t dev); -typedef void driver_intr_t(void *); +typedef void (*driver_intr_t)(void *); struct resource; From hugosantos at mail.berlios.de Thu May 3 04:18:50 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Thu, 3 May 2007 04:18:50 +0200 Subject: [Haiku-commits] r20990 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/net compat/sys Message-ID: <200705030218.l432IodE004213@sheep.berlios.de> Author: hugosantos Date: 2007-05-03 04:18:17 +0200 (Thu, 03 May 2007) New Revision: 20990 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20990&view=rev Added: haiku/trunk/src/libs/compat/freebsd_network/if_media.c Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile haiku/trunk/src/libs/compat/freebsd_network/bus.c haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/compat/net/if.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/malloc.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h haiku/trunk/src/libs/compat/freebsd_network/mbuf.c Log: freebsd compat. layer: added mbuf allocation and if_media support Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-03 01:18:30 UTC (rev 20989) +++ haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-03 02:18:17 UTC (rev 20990) @@ -11,6 +11,7 @@ bus.c compat.c device.c + if_media.c mbuf.c mutex.c ; Modified: haiku/trunk/src/libs/compat/freebsd_network/bus.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-03 01:18:30 UTC (rev 20989) +++ haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-03 02:18:17 UTC (rev 20990) @@ -17,6 +17,9 @@ #include +#define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1)) + + struct internal_intr { driver_intr_t handler; void *arg; @@ -24,6 +27,26 @@ }; +static area_id +map_mem(void **virtualAddr, void *_phy, size_t size, uint32 protection, + const char *name) +{ + uint32 offset = (uint32)_phy & (B_PAGE_SIZE - 1); + void *physicalAddr = (uint8 *)_phy - offset; + area_id area; + + size = ROUNDUP(size + offset, B_PAGE_SIZE); + area = map_physical_memory(name, physicalAddr, size, B_ANY_KERNEL_ADDRESS, + protection, virtualAddr); + if (area < B_OK) + return area; + + *virtualAddr = (uint8 *)(*virtualAddr) + offset; + + return area; +} + + /* straight from Marcus' ipro1000 driver */ struct resource * bus_alloc_resource(device_t dev, int type, int *rid, unsigned long start, Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/net/if.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/net/if.h 2007-05-03 01:18:30 UTC (rev 20989) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/net/if.h 2007-05-03 02:18:17 UTC (rev 20990) @@ -6,6 +6,11 @@ #include /* for timeval */ +#define IF_Kbps(x) ((x) * 1000) +#define IF_Mbps(x) (IF_Kbps((x) * 1000)) +#define IF_Gbps(x) (IF_Mbps((x) * 1000)) + + /* Capabilities that interfaces can advertise. */ #define IFCAP_RXCSUM 0x0001 /* can offload checksum on RX */ #define IFCAP_TXCSUM 0x0002 /* can offload checksum on TX */ Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/malloc.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/malloc.h 2007-05-03 01:18:30 UTC (rev 20989) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/malloc.h 2007-05-03 02:18:17 UTC (rev 20990) @@ -1,8 +1,20 @@ #ifndef _FBSD_COMPAT_SYS_MALLOC_H_ #define _FBSD_COMPAT_SYS_MALLOC_H_ +#include + #define M_NOWAIT 0x0001 #define M_WAITOK 0x0002 #define M_ZERO 0x0100 + +void *_kernel_malloc(size_t size, int flags); +void _kernel_free(void *ptr); + +#define kernel_malloc(size, base, flags) \ + _kernel_malloc(size, flags) + +#define kernel_free( ptr, base) \ + _kernel_free(ptr) + #endif Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h 2007-05-03 01:18:30 UTC (rev 20989) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h 2007-05-03 02:18:17 UTC (rev 20990) @@ -2,12 +2,27 @@ #define _FBSD_COMPAT_SYS_MBUF_H_ #include +#include -struct m_pkthdr { +#define MLEN (MSIZE - sizeof(struct m_hdr)) +#define MHLEN (MSIZE - sizeof(struct pkthdr)) + +#ifdef _KERNEL + +struct m_hdr { + struct mbuf * mh_next; + struct mbuf * mh_nextpkt; + void * mh_data; + int mh_len; + int mh_flags; + short mh_type; +}; + +struct pkthdr { + struct ifnet * rcvif; int len; int csum_flags; uint16_t csum_data; - struct ifnet * rcvif; }; struct m_ext { @@ -16,16 +31,32 @@ }; struct mbuf { - struct mbuf * m_next; - struct mbuf * m_nextpkt; - int m_len; - int m_flags; - void * m_data; - - struct m_pkthdr m_pkthdr; - struct m_ext m_ext; + struct m_hdr m_hdr; + union { + struct { + struct pkthdr MH_pkthdr; + union { + struct m_ext MH_ext; + char MH_databuf[MHLEN]; + } MH_dat; + } MH; + char M_databuf[MLEN]; + } M_dat; }; +#define m_next m_hdr.mh_next +#define m_len m_hdr.mh_len +#define m_data m_hdr.mh_data +#define m_type m_hdr.mh_type +#define m_flags m_hdr.mh_flags +#define m_nextpkt m_hdr.mh_nextpkt +#define m_act m_nextpkt +#define m_pkthdr M_dat.MH.MH_pkthdr +#define m_ext M_dat.MH.MH_dat.MH_ext +#define m_pktdat M_dat.MH.MH_dat.MH_databuf +#define m_dat M_dat.M_databuf + + #define M_DONTWAIT M_NOWAIT #define M_TRYWAIT M_WAITOK #define M_WAIT M_WAITOK @@ -51,3 +82,5 @@ #define mtod(m, type) (type)((m)->m_data) #endif + +#endif Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-03 01:18:30 UTC (rev 20989) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-03 02:18:17 UTC (rev 20990) @@ -74,6 +74,22 @@ } +void * +_kernel_malloc(size_t size, int flags) +{ + // our kernel malloc() is insufficent + + return malloc(size); +} + + +void +_kernel_free(void *ptr) +{ + free(ptr); +} + + status_t init_compat_layer() { Added: haiku/trunk/src/libs/compat/freebsd_network/if_media.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/if_media.c 2007-05-03 01:18:30 UTC (rev 20989) +++ haiku/trunk/src/libs/compat/freebsd_network/if_media.c 2007-05-03 02:18:17 UTC (rev 20990) @@ -0,0 +1,563 @@ +/* $NetBSD: if_media.c,v 1.1 1997/03/17 02:55:15 thorpej Exp $ */ +/* $FreeBSD: src/sys/net/if_media.c,v 1.21.2.1 2006/03/17 20:17:43 glebius Exp $ */ + +/*- + * Copyright (c) 1997 + * Jonathan Stone and Jason R. Thorpe. All rights reserved. + * + * This software is derived from information provided by Matt Thomas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Jonathan Stone + * and Jason R. Thorpe for the NetBSD Project. + * 4. The names of the authors may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * BSD/OS-compatible network interface media selection. + * + * Where it is safe to do so, this code strays slightly from the BSD/OS + * design. Software which uses the API (device drivers, basically) + * shouldn't notice any difference. + * + * Many thanks to Matt Thomas for providing the information necessary + * to implement this interface. + */ + +#include +#include +#include +#include +#include + +#include +#include + +/* + * Compile-time options: + * IFMEDIA_DEBUG: + * turn on implementation-level debug printfs. + * Useful for debugging newly-ported drivers. + */ + +static struct ifmedia_entry *ifmedia_match(struct ifmedia *ifm, + int flags, int mask); + +#ifdef IFMEDIA_DEBUG +int ifmedia_debug = 0; +static void ifmedia_printword(int); +#endif + +/* + * Initialize if_media struct for a specific interface instance. + */ +void +ifmedia_init(ifm, dontcare_mask, change_callback, status_callback) + struct ifmedia *ifm; + int dontcare_mask; + ifm_change_cb_t change_callback; + ifm_stat_cb_t status_callback; +{ + + LIST_INIT(&ifm->ifm_list); + ifm->ifm_cur = NULL; + ifm->ifm_media = 0; + ifm->ifm_mask = dontcare_mask; /* IF don't-care bits */ + ifm->ifm_change = change_callback; + ifm->ifm_status = status_callback; +} + +void +ifmedia_removeall(ifm) + struct ifmedia *ifm; +{ + struct ifmedia_entry *entry; + + for (entry = LIST_FIRST(&ifm->ifm_list); entry; + entry = LIST_FIRST(&ifm->ifm_list)) { + LIST_REMOVE(entry, ifm_list); + kernel_free(entry, M_IFADDR); + } +} + +/* + * Add a media configuration to the list of supported media + * for a specific interface instance. + */ +void +ifmedia_add(ifm, mword, data, aux) + struct ifmedia *ifm; + int mword; + int data; + void *aux; +{ + register struct ifmedia_entry *entry; + +#ifdef IFMEDIA_DEBUG + if (ifmedia_debug) { + if (ifm == NULL) { + printf("ifmedia_add: null ifm\n"); + return; + } + printf("Adding entry for "); + ifmedia_printword(mword); + } +#endif + + entry = kernel_malloc(sizeof(*entry), M_IFADDR, M_NOWAIT); + if (entry == NULL) + panic("ifmedia_add: can't malloc entry"); + + entry->ifm_media = mword; + entry->ifm_data = data; + entry->ifm_aux = aux; + + LIST_INSERT_HEAD(&ifm->ifm_list, entry, ifm_list); +} + +/* + * Add an array of media configurations to the list of + * supported media for a specific interface instance. + */ +void +ifmedia_list_add(ifm, lp, count) + struct ifmedia *ifm; + struct ifmedia_entry *lp; + int count; +{ + int i; + + for (i = 0; i < count; i++) + ifmedia_add(ifm, lp[i].ifm_media, lp[i].ifm_data, + lp[i].ifm_aux); +} + +/* + * Set the default active media. + * + * Called by device-specific code which is assumed to have already + * selected the default media in hardware. We do _not_ call the + * media-change callback. + */ +void +ifmedia_set(ifm, target) + struct ifmedia *ifm; + int target; + +{ + struct ifmedia_entry *match; + + match = ifmedia_match(ifm, target, ifm->ifm_mask); + + if (match == NULL) { + printf("ifmedia_set: no match for 0x%x/0x%x\n", + target, ~ifm->ifm_mask); + panic("ifmedia_set"); + } + ifm->ifm_cur = match; + +#ifdef IFMEDIA_DEBUG + if (ifmedia_debug) { + printf("ifmedia_set: target "); + ifmedia_printword(target); + printf("ifmedia_set: setting to "); + ifmedia_printword(ifm->ifm_cur->ifm_media); + } +#endif +} + +/* + * Device-independent media ioctl support function. + */ +int +ifmedia_ioctl(ifp, ifr, ifm, cmd) + struct ifnet *ifp; + struct ifreq *ifr; + struct ifmedia *ifm; + u_long cmd; +{ +#if 0 + struct ifmedia_entry *match; + struct ifmediareq *ifmr = (struct ifmediareq *) ifr; + int error = 0, sticky; + + if (ifp == NULL || ifr == NULL || ifm == NULL) + return(EINVAL); + + switch (cmd) { + + /* + * Set the current media. + */ + case SIOCSIFMEDIA: + { + struct ifmedia_entry *oldentry; + int oldmedia; + int newmedia = ifr->ifr_media; + + match = ifmedia_match(ifm, newmedia, ifm->ifm_mask); + if (match == NULL) { +#ifdef IFMEDIA_DEBUG + if (ifmedia_debug) { + printf( + "ifmedia_ioctl: no media found for 0x%x\n", + newmedia); + } +#endif + return (ENXIO); + } + + /* + * If no change, we're done. + * XXX Automedia may invole software intervention. + * Keep going in case the the connected media changed. + * Similarly, if best match changed (kernel debugger?). + */ + if ((IFM_SUBTYPE(newmedia) != IFM_AUTO) && + (newmedia == ifm->ifm_media) && + (match == ifm->ifm_cur)) + return 0; + + /* + * We found a match, now make the driver switch to it. + * Make sure to preserve our old media type in case the + * driver can't switch. + */ +#ifdef IFMEDIA_DEBUG + if (ifmedia_debug) { + printf("ifmedia_ioctl: switching %s to ", + ifp->if_xname); + ifmedia_printword(match->ifm_media); + } +#endif + oldentry = ifm->ifm_cur; + oldmedia = ifm->ifm_media; + ifm->ifm_cur = match; + ifm->ifm_media = newmedia; + error = (*ifm->ifm_change)(ifp); + if (error) { + ifm->ifm_cur = oldentry; + ifm->ifm_media = oldmedia; + } + break; + } + + /* + * Get list of available media and current media on interface. + */ + case SIOCGIFMEDIA: + { + struct ifmedia_entry *ep; + int *kptr, count; + int usermax; /* user requested max */ + + kptr = NULL; /* XXX gcc */ + + ifmr->ifm_active = ifmr->ifm_current = ifm->ifm_cur ? + ifm->ifm_cur->ifm_media : IFM_NONE; + ifmr->ifm_mask = ifm->ifm_mask; + ifmr->ifm_status = 0; + (*ifm->ifm_status)(ifp, ifmr); + + count = 0; + usermax = 0; + + /* + * If there are more interfaces on the list, count + * them. This allows the caller to set ifmr->ifm_count + * to 0 on the first call to know how much space to + * allocate. + */ + LIST_FOREACH(ep, &ifm->ifm_list, ifm_list) + usermax++; + + /* + * Don't allow the user to ask for too many + * or a negative number. + */ + if (ifmr->ifm_count > usermax) + ifmr->ifm_count = usermax; + else if (ifmr->ifm_count < 0) + return (EINVAL); + + if (ifmr->ifm_count != 0) { + kptr = (int *)kernel_malloc(ifmr->ifm_count * sizeof(int), + M_TEMP, M_NOWAIT); + + if (kptr == NULL) + return (ENOMEM); + /* + * Get the media words from the interface's list. + */ + ep = LIST_FIRST(&ifm->ifm_list); + for (; ep != NULL && count < ifmr->ifm_count; + ep = LIST_NEXT(ep, ifm_list), count++) + kptr[count] = ep->ifm_media; + + if (ep != NULL) + error = E2BIG; /* oops! */ + } else { + count = usermax; + } + + /* + * We do the copyout on E2BIG, because that's + * just our way of telling userland that there + * are more. This is the behavior I've observed + * under BSD/OS 3.0 + */ + sticky = error; + if ((error == 0 || error == E2BIG) && ifmr->ifm_count != 0) { + error = copyout((caddr_t)kptr, + (caddr_t)ifmr->ifm_ulist, + ifmr->ifm_count * sizeof(int)); + } + + if (error == 0) + error = sticky; + + if (ifmr->ifm_count != 0) + kernel_free(kptr, M_TEMP); + + ifmr->ifm_count = count; + break; + } + + default: + return (EINVAL); + } + + return (error); +#endif + return ENOTSUP; +} + +/* + * Find media entry matching a given ifm word. + * + */ +static struct ifmedia_entry * +ifmedia_match(ifm, target, mask) + struct ifmedia *ifm; + int target; + int mask; +{ + struct ifmedia_entry *match, *next; + + match = NULL; + mask = ~mask; + + LIST_FOREACH(next, &ifm->ifm_list, ifm_list) { + if ((next->ifm_media & mask) == (target & mask)) { +#if defined(IFMEDIA_DEBUG) || defined(DIAGNOSTIC) + if (match) { + printf("ifmedia_match: multiple match for " + "0x%x/0x%x\n", target, mask); + } +#endif + match = next; + } + } + + return match; +} + +/* + * Compute the interface `baudrate' from the media, for the interface + * metrics (used by routing daemons). + */ +static const struct ifmedia_baudrate ifmedia_baudrate_descriptions[] = + IFM_BAUDRATE_DESCRIPTIONS; + +uint64_t +ifmedia_baudrate(int mword) +{ + int i; + + for (i = 0; ifmedia_baudrate_descriptions[i].ifmb_word != 0; i++) { + if ((mword & (IFM_NMASK|IFM_TMASK)) == + ifmedia_baudrate_descriptions[i].ifmb_word) + return (ifmedia_baudrate_descriptions[i].ifmb_baudrate); + } + + /* Not known. */ + return (0); +} + +#ifdef IFMEDIA_DEBUG +struct ifmedia_description ifm_type_descriptions[] = + IFM_TYPE_DESCRIPTIONS; + +struct ifmedia_description ifm_subtype_ethernet_descriptions[] = + IFM_SUBTYPE_ETHERNET_DESCRIPTIONS; + +struct ifmedia_description ifm_subtype_ethernet_option_descriptions[] = + IFM_SUBTYPE_ETHERNET_OPTION_DESCRIPTIONS; + +struct ifmedia_description ifm_subtype_tokenring_descriptions[] = + IFM_SUBTYPE_TOKENRING_DESCRIPTIONS; + +struct ifmedia_description ifm_subtype_tokenring_option_descriptions[] = + IFM_SUBTYPE_TOKENRING_OPTION_DESCRIPTIONS; + +struct ifmedia_description ifm_subtype_fddi_descriptions[] = + IFM_SUBTYPE_FDDI_DESCRIPTIONS; + +struct ifmedia_description ifm_subtype_fddi_option_descriptions[] = + IFM_SUBTYPE_FDDI_OPTION_DESCRIPTIONS; + +struct ifmedia_description ifm_subtype_ieee80211_descriptions[] = + IFM_SUBTYPE_IEEE80211_DESCRIPTIONS; + +struct ifmedia_description ifm_subtype_ieee80211_option_descriptions[] = + IFM_SUBTYPE_IEEE80211_OPTION_DESCRIPTIONS; + +struct ifmedia_description ifm_subtype_ieee80211_mode_descriptions[] = + IFM_SUBTYPE_IEEE80211_MODE_DESCRIPTIONS; + +struct ifmedia_description ifm_subtype_atm_descriptions[] = + IFM_SUBTYPE_ATM_DESCRIPTIONS; + +struct ifmedia_description ifm_subtype_atm_option_descriptions[] = + IFM_SUBTYPE_ATM_OPTION_DESCRIPTIONS; + +struct ifmedia_description ifm_subtype_shared_descriptions[] = + IFM_SUBTYPE_SHARED_DESCRIPTIONS; + +struct ifmedia_description ifm_shared_option_descriptions[] = + IFM_SHARED_OPTION_DESCRIPTIONS; + +struct ifmedia_type_to_subtype { + struct ifmedia_description *subtypes; + struct ifmedia_description *options; + struct ifmedia_description *modes; +}; + +/* must be in the same order as IFM_TYPE_DESCRIPTIONS */ +struct ifmedia_type_to_subtype ifmedia_types_to_subtypes[] = { + { + &ifm_subtype_ethernet_descriptions[0], + &ifm_subtype_ethernet_option_descriptions[0], + NULL, + }, + { + &ifm_subtype_tokenring_descriptions[0], + &ifm_subtype_tokenring_option_descriptions[0], + NULL, + }, + { + &ifm_subtype_fddi_descriptions[0], + &ifm_subtype_fddi_option_descriptions[0], + NULL, + }, + { + &ifm_subtype_ieee80211_descriptions[0], + &ifm_subtype_ieee80211_option_descriptions[0], + &ifm_subtype_ieee80211_mode_descriptions[0] + }, + { + &ifm_subtype_atm_descriptions[0], + &ifm_subtype_atm_option_descriptions[0], + NULL, + }, +}; + +/* + * print a media word. + */ +static void +ifmedia_printword(ifmw) + int ifmw; +{ + struct ifmedia_description *desc; + struct ifmedia_type_to_subtype *ttos; + int seen_option = 0; + + /* Find the top-level interface type. */ + for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes; + desc->ifmt_string != NULL; desc++, ttos++) + if (IFM_TYPE(ifmw) == desc->ifmt_word) + break; + if (desc->ifmt_string == NULL) { + printf("\n"); + return; + } + printf(desc->ifmt_string); + + /* Any mode. */ + for (desc = ttos->modes; desc && desc->ifmt_string != NULL; desc++) + if (IFM_MODE(ifmw) == desc->ifmt_word) { + if (desc->ifmt_string != NULL) + printf(" mode %s", desc->ifmt_string); + break; + } + + /* + * Check for the shared subtype descriptions first, then the + * type-specific ones. + */ + for (desc = ifm_subtype_shared_descriptions; + desc->ifmt_string != NULL; desc++) + if (IFM_SUBTYPE(ifmw) == desc->ifmt_word) + goto got_subtype; + + for (desc = ttos->subtypes; desc->ifmt_string != NULL; desc++) + if (IFM_SUBTYPE(ifmw) == desc->ifmt_word) + break; + if (desc->ifmt_string == NULL) { + printf(" \n"); + return; + } + + got_subtype: + printf(" %s", desc->ifmt_string); + + /* + * Look for shared options. + */ + for (desc = ifm_shared_option_descriptions; + desc->ifmt_string != NULL; desc++) { + if (ifmw & desc->ifmt_word) { + if (seen_option == 0) + printf(" <"); + printf("%s%s", seen_option++ ? "," : "", + desc->ifmt_string); + } + } + + /* + * Look for subtype-specific options. + */ + for (desc = ttos->options; desc->ifmt_string != NULL; desc++) { + if (ifmw & desc->ifmt_word) { + if (seen_option == 0) + printf(" <"); + printf("%s%s", seen_option++ ? "," : "", + desc->ifmt_string); + } + } + printf("%s\n", seen_option ? ">" : ""); +} +#endif /* IFMEDIA_DEBUG */ Modified: haiku/trunk/src/libs/compat/freebsd_network/mbuf.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/mbuf.c 2007-05-03 01:18:30 UTC (rev 20989) +++ haiku/trunk/src/libs/compat/freebsd_network/mbuf.c 2007-05-03 02:18:17 UTC (rev 20990) @@ -24,6 +24,43 @@ static object_cache *sChunkCache; +static void +construct_mbuf(struct mbuf *mb, short type, int flags) +{ + mb->m_next = NULL; + mb->m_nextpkt = NULL; + mb->m_len = 0; + mb->m_flags = flags; + mb->m_type = type; + + if (flags & M_PKTHDR) { + mb->m_data = mb->m_pktdat; + memset(&mb->m_pkthdr, 0, sizeof(mb->m_pkthdr)); + } else { + mb->m_data = mb->m_dat; + } +} + + +struct mbuf * +m_getcl(int how, short type, int flags) +{ + uint32 cacheFlags = 0; + struct mbuf *mb; + + if (how & M_NOWAIT) + cacheFlags = CACHE_DONT_SLEEP; + + mb = (struct mbuf *)object_cache_alloc(sMBufCache, cacheFlags); + if (mb == NULL) + return NULL; + + construct_mbuf(mb, type, flags); + + return mb; +} + + void m_freem(struct mbuf *mp) { From mmu_man at mail.berlios.de Thu May 3 05:37:05 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Thu, 3 May 2007 05:37:05 +0200 Subject: [Haiku-commits] r20991 - haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd Message-ID: <200705030337.l433b5ES008292@sheep.berlios.de> Author: mmu_man Date: 2007-05-03 05:37:04 +0200 (Thu, 03 May 2007) New Revision: 20991 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20991&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c Log: Add debug output. Implement connect/teardown. Added a workaround for BONE wanting to keep locked pages around when connect() fails (TCP teardown-> "trying to delete area in use!"). But doesn't seem to wait long enough. Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-03 02:18:17 UTC (rev 20990) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-03 03:37:04 UTC (rev 20991) @@ -16,10 +16,13 @@ #include #include +#define DEBUG 1 + +/* locking support */ #ifdef __HAIKU__ #include #else -/* wrappers */ +/* wrappers for R5 */ #ifndef _IMPEXP_KERNEL #define _IMPEXP_KERNEL #endif @@ -34,13 +37,21 @@ #include "nbd.h" #define DRV "nbd" -#define D "nbd:" +#define DP "nbd:" #define MAX_NBDS 4 #define DEVICE_PREFIX "disk/virtual/nbd/" -#define DEVICE_FMT DEVICE_PREFIX "%2d/raw" +#define DEVICE_FMT DEVICE_PREFIX "%d/raw" #define DEVICE_NAME_MAX 32 #define MAX_REQ_SIZE (32*1024*1024) +/* debugging */ +#if DEBUG +#define PRINT(a) dprintf a +#define WHICH(dev) ((int)(dev - nbd_devices)) +#else +#define PRINT(a) +#endif + struct nbd_request_entry { struct nbd_request_entry *next; struct nbd_request req; @@ -76,30 +87,100 @@ KSOCKET_MODULE_DECL; +/* HACK: + * In BONE at least, if connect() fails (EINTR or ETIMEDOUT) + * keeps locked pages around (likely a bone_data, + * until TCP gets the last ACK). If that happens, we snooze() + * in unload_driver() to let TCP timeout before the kernel + * tries to delete the image. */ +bool gDelayUnload = false; +#define BONE_TEARDOWN_DELAY 60000000 + #pragma mark ==== request manager ==== #pragma mark ==== nbd handler ==== -int32 postoffice(void *arg) +int32 nbd_postoffice(void *arg) { struct nbd_device *dev = (struct nbd_device *)arg; int sock = dev->sock; + PRINT((DP ">%s()\n", __FUNCTION__)); + PRINT((DP "<%s\n", __FUNCTION__)); return 0; } status_t nbd_connect(struct nbd_device *dev) { + struct nbd_init_packet initpkt; + status_t err; + PRINT((DP ">%s()\n", __FUNCTION__)); + + PRINT((DP " %s: socket()\n", __FUNCTION__)); + err = dev->sock = ksocket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (err == -1 && errno < 0) + err = errno; + if (err < 0) + goto err0; + PRINT((DP " %s: connect()\n", __FUNCTION__)); + err = kconnect(dev->sock, (struct sockaddr *)&dev->server, sizeof(dev->server)); + //err = ENOSYS; + if (err == -1 && errno < 0) + err = errno; + /* HACK: avoid the kernel unlading us with locked pages from TCP */ + if (err) + gDelayUnload = true; + if (err) + goto err1; + + PRINT((DP " %s: recv(initpkt)\n", __FUNCTION__)); + err = krecv(dev->sock, &initpkt, sizeof(initpkt), 0); + if (err == -1 && errno < 0) + err = errno; + if (err < sizeof(initpkt)) + goto err2; + err = EINVAL;//EPROTO; + if (memcmp(initpkt.passwd, NBD_INIT_PASSWD, sizeof(initpkt.passwd))) + goto err3; + if (B_BENDIAN_TO_HOST_INT64(initpkt.magic) != NBD_INIT_MAGIC) + goto err3; + + dev->size = B_BENDIAN_TO_HOST_INT64(initpkt.device_size); + + dprintf(DP " %s: connected, device size %Ld bytes.\n", __FUNCTION__, dev->size); + + err = dev->postoffice = spawn_kernel_thread(nbd_postoffice, "nbd postoffice", B_REAL_TIME_PRIORITY, dev); + if (err < B_OK) + goto err4; + resume_thread(dev->postoffice); + + PRINT((DP "<%s\n", __FUNCTION__)); return B_OK; + +err4: + dev->postoffice = -1; +err3: +err2: +err1: + kclosesocket(dev->sock); + dev->sock = -1; +err0: + dprintf(DP "<%s: error 0x%08lx\n", __FUNCTION__, err); + return err; } status_t nbd_teardown(struct nbd_device *dev) { - close(dev->sock); + status_t err, ret; + PRINT((DP ">%s()\n", __FUNCTION__)); + kshutdown(dev->sock, SHUTDOWN_BOTH); + kclosesocket(dev->sock); + dev->sock = -1; + err = wait_for_thread(dev->postoffice, &ret); return B_OK; } @@ -110,6 +191,7 @@ status_t nbd_open(const char *name, uint32 flags, cookie_t **cookie) { status_t err; struct nbd_device *dev = NULL; + PRINT((DP ">%s(%s, %x, )\n", __FUNCTION__, name, flags)); (void)name; (void)flags; dev = nbd_find_device(name); if (!dev) @@ -137,13 +219,14 @@ err1: free(*cookie); err0: - dprintf("nbd_open : error 0x%08lx\n", err); + dprintf(DP " %s: error 0x%08lx\n", __FUNCTION__, err); return err; } status_t nbd_close(cookie_t *cookie) { struct nbd_device *dev = cookie->dev; status_t err; + PRINT((DP ">%s(%d)\n", __FUNCTION__, WHICH(cookie->dev))); err = benaphore_lock(&dev->ben); if (err) @@ -158,6 +241,7 @@ status_t nbd_free(cookie_t *cookie) { struct nbd_device *dev = cookie->dev; status_t err; + PRINT((DP ">%s(%d)\n", __FUNCTION__, WHICH(cookie->dev))); err = benaphore_lock(&dev->ben); if (err) @@ -174,6 +258,7 @@ } status_t nbd_control(cookie_t *cookie, uint32 op, void *data, size_t len) { + PRINT((DP ">%s(%d, %ul, , %d)\n", __FUNCTION__, WHICH(cookie->dev), op, len)); switch (op) { case B_GET_DEVICE_SIZE: /* this one is broken anyway... */ if (data) { @@ -227,11 +312,13 @@ } status_t nbd_read(cookie_t *cookie, off_t position, void *data, size_t *numbytes) { + PRINT((DP ">%s(%d, %Ld, , )\n", __FUNCTION__, WHICH(cookie->dev), position)); *numbytes = 0; return B_NOT_ALLOWED; } status_t nbd_write(cookie_t *cookie, off_t position, const void *data, size_t *numbytes) { + PRINT((DP ">%s(%d, %Ld, , )\n", __FUNCTION__, WHICH(cookie->dev), position)); (void)cookie; (void)position; (void)data; (void)numbytes; *numbytes = 0; return EIO; @@ -260,6 +347,7 @@ status_t init_hardware (void) { + PRINT((DP ">%s()\n", __FUNCTION__)); return B_OK; } @@ -270,6 +358,7 @@ int i, j; // XXX: load settings void *handle; + PRINT((DP ">%s()\n", __FUNCTION__)); err = ksocket_init(); if (err < B_OK) @@ -290,7 +379,11 @@ if (nbd_name[i] == NULL) break; sprintf(nbd_name[i], DEVICE_FMT, i); - // XXX: init nbd_devices[i] + /* XXX: default init */ + nbd_devices[i].server.sin_len = sizeof(struct sockaddr_in); + nbd_devices[i].server.sin_family = AF_INET; + nbd_devices[i].server.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + nbd_devices[i].server.sin_port = htons(1337 + i); } nbd_name[i] = NULL; @@ -303,7 +396,7 @@ v = get_driver_parameter(handle, keyname, NULL, NULL); /* should be "ip:port" */ // XXX: test - if (v || 0) { + if (v || 1) { //strncpy(nbd_devices[i].target, v, 64); //XXX:TEST //strncpy(nbd_devices[i].target, "127.0.0.1:1337", 64); @@ -332,22 +425,28 @@ { status_t err; int i; + PRINT((DP ">%s()\n", __FUNCTION__)); for (i = 0; i < MAX_NBDS; i++) { free(nbd_name[i]); err = benaphore_destroy(&nbd_devices[i].ben); } err = ksocket_cleanup(); + /* HACK */ + if (gDelayUnload) + snooze(BONE_TEARDOWN_DELAY); } const char** publish_devices() { + PRINT((DP ">%s()\n", __FUNCTION__)); return nbd_name; } device_hooks* find_device(const char* name) { + PRINT((DP ">%s(%s)\n", __FUNCTION__, name)); return &nbd_hooks; } @@ -355,6 +454,7 @@ nbd_find_device(const char* name) { int i; + PRINT((DP ">%s(%s)\n", __FUNCTION__, name)); for (i = 0; i < MAX_NBDS; i++) { if (!strcmp(nbd_name[i], name)) return &nbd_devices[i]; From mmu_man at mail.berlios.de Thu May 3 08:06:11 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Thu, 3 May 2007 08:06:11 +0200 Subject: [Haiku-commits] r20992 - haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd Message-ID: <200705030606.l4366Bhe027529@sheep.berlios.de> Author: mmu_man Date: 2007-05-03 08:06:10 +0200 (Thu, 03 May 2007) New Revision: 20992 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20992&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c Log: Implemented request funcs. Done read(). It's working \o/ Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-03 03:37:04 UTC (rev 20991) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-03 06:06:10 UTC (rev 20992) @@ -54,8 +54,14 @@ struct nbd_request_entry { struct nbd_request_entry *next; - struct nbd_request req; - bool r; /* is read */ + struct nbd_request req; /* net byte order */ + struct nbd_reply reply; /* net byte order */ + sem_id sem; + bool replied; + bool discard; + uint64 handle; + uint32 type; + uint64 from; size_t len; void *buffer; /* write: ptr to passed buffer; read: ptr to malloc()ed extra */ }; @@ -78,10 +84,10 @@ } cookie_t; /* data=NULL on read */ -status_t nbd_alloc_request(struct nbd_device, struct nbd_request_entry **req, size_t len, const char *data); -status_t nbd_post_request(struct nbd_device, uint64 handle, struct nbd_request_entry **req); -status_t nbd_dequeue_request(struct nbd_device, uint64 handle, struct nbd_request_entry **req); -status_t nbd_free_request(struct nbd_device, struct nbd_request_entry *req); +status_t nbd_alloc_request(struct nbd_device *dev, struct nbd_request_entry **req, uint32 type, off_t from, size_t len, const char *data); +status_t nbd_queue_request(struct nbd_device *dev, struct nbd_request_entry *req); +status_t nbd_dequeue_request(struct nbd_device *dev, uint64 handle, struct nbd_request_entry **req); +status_t nbd_free_request(struct nbd_device *dev, struct nbd_request_entry *req); struct nbd_device *nbd_find_device(const char* name); @@ -98,19 +104,191 @@ #pragma mark ==== request manager ==== +status_t nbd_alloc_request(struct nbd_device *dev, struct nbd_request_entry **req, uint32 type, off_t from, size_t len, const char *data) +{ + bool w = (type == NBD_CMD_WRITE); + struct nbd_request_entry *r; + status_t err = EINVAL; + uint64 handle; + PRINT((DP ">%s(%ld, %Ld, %ld)\n", __FUNCTION__, type, from, len)); + + if (type != NBD_CMD_READ && type != NBD_CMD_WRITE && type != NBD_CMD_DISC) + return err; + if (!dev || !req || from < 0) + return err; + + //LOCK + err = benaphore_lock(&dev->ben); + if (err) + return err; + // atomic + handle = dev->req++; + + + //UNLOCK + benaphore_unlock(&dev->ben); + + err = ENOMEM; + r = malloc(sizeof(struct nbd_request_entry) + (w ? 0 : len)); + if (r == NULL) + goto err0; + r->next = NULL; + err = r->sem = create_sem(0, "nbd request sem"); + if (err < 0) + goto err1; + + r->replied = false; + r->discard = false; + r->handle = handle; + r->type = type; + r->from = from; + r->len = len; + + r->req.magic = B_HOST_TO_BENDIAN_INT32(NBD_REQUEST_MAGIC); + r->req.type = B_HOST_TO_BENDIAN_INT32(type); + r->req.handle = B_HOST_TO_BENDIAN_INT64(r->handle); + r->req.from = B_HOST_TO_BENDIAN_INT64(r->from); + r->req.len = B_HOST_TO_BENDIAN_INT32(len); + + r->buffer = w ? data : (((char *)r) + sizeof(struct nbd_request_entry)); + + *req = r; + return B_OK; + +err1: + free(r); +err0: + dprintf(DP " %s: error 0x%08lx\n", __FUNCTION__, err); + return err; +} + +status_t nbd_queue_request(struct nbd_device *dev, struct nbd_request_entry *req) +{ + PRINT((DP ">%s(handle:%Ld)\n", __FUNCTION__, req->handle)); + req->next = dev->reqs; + dev->reqs = req; + return B_OK; +} + +status_t nbd_dequeue_request(struct nbd_device *dev, uint64 handle, struct nbd_request_entry **req) +{ + struct nbd_request_entry *r, *prev; + PRINT((DP ">%s(handle:%Ld)\n", __FUNCTION__, handle)); + r = dev->reqs; + prev = NULL; + while (r && r->handle != handle) { + prev = r; + r = r->next; + } + if (!r) + return ENOENT; + + if (prev) + prev->next = r->next; + else + dev->reqs = r->next; + + *req = r; + return B_OK; +} + +status_t nbd_free_request(struct nbd_device *dev, struct nbd_request_entry *req) +{ + PRINT((DP ">%s(handle:%Ld)\n", __FUNCTION__, req->handle)); + delete_sem(req->sem); + free(req); + return B_OK; +} + + + #pragma mark ==== nbd handler ==== int32 nbd_postoffice(void *arg) { struct nbd_device *dev = (struct nbd_device *)arg; + struct nbd_request_entry *req = NULL; + struct nbd_reply reply; int sock = dev->sock; + status_t err; + const char *reason; PRINT((DP ">%s()\n", __FUNCTION__)); + for (;;) { + reason = "recv"; + err = krecv(dev->sock, &reply, sizeof(reply), 0); + if (err == -1 && errno < 0) + err = errno; + if (err < 0) + goto err; + reason = "recv:size"; + if (err < sizeof(reply)) + err = EINVAL; + if (err < 0) + goto err; + reason = "magic"; + err = EINVAL; + if (B_BENDIAN_TO_HOST_INT32(reply.magic) != NBD_REPLY_MAGIC) + goto err; + + reason = "lock"; + //LOCK + err = benaphore_lock(&dev->ben); + if (err) + goto err; + + reason = "dequeue_request"; + err = nbd_dequeue_request(dev, B_BENDIAN_TO_HOST_INT64(reply.handle), &req); + + //UNLOCK + benaphore_unlock(&dev->ben); + + if (!err && !req) { + dprintf(DP "nbd_dequeue_rquest found NULL!\n"); + err = ENOENT; + } + + if (err == B_OK) { + memcpy(&req->reply, &reply, sizeof(reply)); + if (req->type == NBD_CMD_READ) { + err = 0; + reason = "recv(data)"; + if (reply.error == 0) + err = krecv(dev->sock, req->buffer, req->len, 0); + if (err < 0) + goto err; + /* tell back how much we've got (?) */ + req->len = err; + } else { + if (reply.error) + req->len = 0; + } + + reason = "lock"; + //LOCK + err = benaphore_lock(&dev->ben); + if (err) + goto err; + + // this also must be atomic! + release_sem(req->sem); + req->replied = true; + if (req->discard) + nbd_free_request(dev, req); + + //UNLOCK + benaphore_unlock(&dev->ben); + } + + } - PRINT((DP "<%s\n", __FUNCTION__)); return 0; + +err: + dprintf(DP "%s: %s: error 0x%08lx\n", __FUNCTION__, reason, err); + return err; } status_t nbd_connect(struct nbd_device *dev) @@ -184,6 +362,20 @@ return B_OK; } +status_t nbd_post_request(struct nbd_device *dev, struct nbd_request_entry *req) +{ + status_t err; + PRINT((DP ">%s(handle:%Ld)\n", __FUNCTION__, req->handle)); + + err = ksend(dev->sock, &req->req, sizeof(req->req), 0); + if (err < 0) + return err; + + err = nbd_queue_request(dev, req); + return err; +} + + #pragma mark ==== device hooks ==== static struct nbd_device nbd_devices[MAX_NBDS]; @@ -312,9 +504,70 @@ } status_t nbd_read(cookie_t *cookie, off_t position, void *data, size_t *numbytes) { + struct nbd_device *dev = cookie->dev; + struct nbd_request_entry *req; + status_t err, semerr; PRINT((DP ">%s(%d, %Ld, , )\n", __FUNCTION__, WHICH(cookie->dev), position)); + + if (position < 0) + return EINVAL; + if (!data) + return EINVAL; + + err = nbd_alloc_request(dev, &req, NBD_CMD_READ, position, *numbytes, NULL); + if (err) + goto err0; + + //LOCK + err = benaphore_lock(&dev->ben); + if (err) + goto err1; + + err = nbd_post_request(dev, req); + + //UNLOCK + benaphore_unlock(&dev->ben); + + if (err) + goto err2; + + + semerr = acquire_sem(req->sem); + + //LOCK + err = benaphore_lock(&dev->ben); + if(err) + goto err3; + + /* bad scenarii */ + if (!req->replied) + req->discard = true; + else if (semerr) + nbd_free_request(dev, req); + + //UNLOCK + benaphore_unlock(&dev->ben); + + if (semerr == B_OK) { + *numbytes = req->len; + memcpy(data, req->buffer, req->len); + nbd_free_request(dev, req); + if (*numbytes == 0 && req->reply.error) + return B_ERROR; + return B_OK; + } + *numbytes = 0; - return B_NOT_ALLOWED; + return semerr; + + +err3: +err2: +err1: + nbd_free_request(dev, req); +err0: + *numbytes = 0; + return err; } status_t nbd_write(cookie_t *cookie, off_t position, const void *data, size_t *numbytes) { From mmu_man at mail.berlios.de Thu May 3 08:37:38 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Thu, 3 May 2007 08:37:38 +0200 Subject: [Haiku-commits] r20993 - haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd Message-ID: <200705030637.l436bcOb029233@sheep.berlios.de> Author: mmu_man Date: 2007-05-03 08:37:38 +0200 (Thu, 03 May 2007) New Revision: 20993 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20993&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c Log: 512 as block size. Typo. Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-03 06:06:10 UTC (rev 20992) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-03 06:37:38 UTC (rev 20993) @@ -43,6 +43,7 @@ #define DEVICE_FMT DEVICE_PREFIX "%d/raw" #define DEVICE_NAME_MAX 32 #define MAX_REQ_SIZE (32*1024*1024) +#define BLKSIZE 512 /* debugging */ #if DEBUG @@ -450,7 +451,7 @@ } status_t nbd_control(cookie_t *cookie, uint32 op, void *data, size_t len) { - PRINT((DP ">%s(%d, %ul, , %d)\n", __FUNCTION__, WHICH(cookie->dev), op, len)); + PRINT((DP ">%s(%d, %lu, , %d)\n", __FUNCTION__, WHICH(cookie->dev), op, len)); switch (op) { case B_GET_DEVICE_SIZE: /* this one is broken anyway... */ if (data) { @@ -475,9 +476,9 @@ case B_GET_BIOS_GEOMETRY: if (data) { device_geometry *geom = (device_geometry *)data; - geom->bytes_per_sector = 256; + geom->bytes_per_sector = BLKSIZE; geom->sectors_per_track = 1; - geom->cylinder_count = cookie->dev->size / 256; + geom->cylinder_count = cookie->dev->size / BLKSIZE; geom->head_count = 1; geom->device_type = B_DISK; geom->removable = false; @@ -495,10 +496,11 @@ case B_EJECT_DEVICE: case B_LOAD_MEDIA: - return ENOSYS; + return B_BAD_VALUE; case B_FLUSH_DRIVE_CACHE: /* wait for request list to be empty ? */ + return B_OK; default: - return ENOSYS; + return B_BAD_VALUE; } return B_NOT_ALLOWED; } From axeld at pinc-software.de Thu May 3 10:24:31 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Thu, 03 May 2007 10:24:31 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r20985_-_in_haiku/trunk/src/libs?= =?iso-8859-15?q?=3A_=2E_compat_compat/freebsd=5Fnetwork__compat/freebsd?= =?iso-8859-15?q?=5Fnetwork/compat_compat/freebsd=5Fnetwork/compat/altq__c?= =?iso-8859-15?q?ompat/freebsd=5Fnetwork/compat/dev_compat/freebsd=5Fnetwo?= =?iso-8859-15?q?rk/compat/dev/mii_compat/freebsd=5Fnetwork/compat/dev/ofw?= =?iso-8859-15?q?_compat/freebsd=5Fnetwork/compat/dev/pci_compat/freebsd?= =?iso-8859-15?q?=5Fnetwork/compat/machine_compat/freebsd=5Fnetwork/compat?= =?iso-8859-15?q?/net__compat/freebsd=5Fnetwork/compat/sys?= In-Reply-To: <200705022311.l42NB0Xv003652@sheep.berlios.de> Message-ID: <786923934-BeMail@zon> hugosantos at mail.berlios.de wrote: > Log: > initial work towards a FreeBSD network driver source level > compatibility layer. Nice one! Bye, Axel. From axeld at pinc-software.de Thu May 3 10:30:01 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Thu, 03 May 2007 10:30:01 +0200 CEST Subject: [Haiku-commits] r20982 - haiku/trunk/src/system/kernel/fs In-Reply-To: <20070502235116.1662.6@cs.tu-berlin.de> Message-ID: <1116158975-BeMail@zon> Ingo Weinhold wrote: > > Log: > > devfs now accepts to create directories > > is scanning needed here ? > Out of curiosity, why would one want to create a directory in the > devfs? That question was exactly the reason why I didn't implement it in the first place :-) But Korli could convince me: say you have an application that wants to monitor /dev/input/keyboard/, but there are no keyboards attached, yet. Damn, now I have second thoughts. As soon as you open the directory for traversal, the drivers are scanned, and so /dev/input/keyboard/ will be created for you automatically - since there are drivers that are found in that directory. Only .../usb and .../ps2 won't be created if there are no devices - but the add-on shouldn't care about those specifically, anyway. So I think we may want to remove that possibility again, and just change the input_server accordingly. What do you think, J?r?me? Bye, Axel. From korli at users.berlios.de Thu May 3 10:55:57 2007 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Thu, 3 May 2007 10:55:57 +0200 Subject: [Haiku-commits] r20982 - haiku/trunk/src/system/kernel/fs In-Reply-To: <1116158975-BeMail@zon> References: <20070502235116.1662.6@cs.tu-berlin.de> <1116158975-BeMail@zon> Message-ID: 2007/5/3, Axel D?rfler : > Ingo Weinhold wrote: > > > Log: > > > devfs now accepts to create directories > > > is scanning needed here ? > > Out of curiosity, why would one want to create a directory in the > > devfs? > > That question was exactly the reason why I didn't implement it in the > first place :-) > But Korli could convince me: say you have an application that wants to > monitor /dev/input/keyboard/, but there are no keyboards attached, yet. > > Damn, now I have second thoughts. As soon as you open the directory for > traversal, the drivers are scanned, and so /dev/input/keyboard/ will be > created for you automatically - since there are drivers that are found > in that directory. > Only .../usb and .../ps2 won't be created if there are no devices - but > the add-on shouldn't care about those specifically, anyway. > So I think we may want to remove that possibility again, and just > change the input_server accordingly. What do you think, J?r?me? I'm not sure to follow your reasoning. You'd just put a burden on the userland app : it's a bit difficult to explain someone he has to monitor a parent node to find out that a subdirectory is created, and then nodes in this dir. I like to have the option to keep monitoring created directories, with simplicity. I don't prevent anyone to follow your approach of monitoring a devfs directory, but it shouldn't be the only way to implement it, and the possibility shouldn't be removed. Bye, J?r?me From axeld at pinc-software.de Thu May 3 11:09:27 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Thu, 03 May 2007 11:09:27 +0200 CEST Subject: [Haiku-commits] r20982 - haiku/trunk/src/system/kernel/fs In-Reply-To: Message-ID: <3482707022-BeMail@zon> "J?r?me Duval" wrote: > 2007/5/3, Axel D?rfler : > > Damn, now I have second thoughts. As soon as you open the directory > > for > > traversal, the drivers are scanned, and so /dev/input/keyboard/ > > will be > > created for you automatically - since there are drivers that are > > found > > in that directory. > > Only .../usb and .../ps2 won't be created if there are no devices - > > but > > the add-on shouldn't care about those specifically, anyway. > > So I think we may want to remove that possibility again, and just > > change the input_server accordingly. What do you think, J?r?me? > I'm not sure to follow your reasoning. You'd just put a burden on the > userland app : it's a bit difficult to explain someone he has to > monitor a parent node to find out that a subdirectory is created, and > then nodes in this dir. I like to have the option to keep monitoring > created directories, with simplicity. He wouldn't have to - as I said, the /dev/input/keyboard/ directory will automatically be created as long as it exists It would only prevent to let the server monitor the devices of a specific driver directly - which it shouldn't do in this case, anyway (I consider the hardcoded usb and ps2 paths a bug). > I don't prevent anyone to follow your approach of monitoring a devfs > directory, but it shouldn't be the only way to implement it, and the > possibility shouldn't be removed. Regardless of what I wrote above, I agree with you, since my argumentation has an oversight: if the directory actually doesn't exist yet in either /boot/home/config/add-ons/kernel/drivers/dev/ or /system/ add-ons/kernel/drivers/dev/ no directory is created in /dev, and monitoring that directory would fail - if you wanted to be able to automatically pick up drivers that are installed later (which creates that directory), you would indeed have to monitor a parent directory that doesn't really interest you, which is not what we want. Bye, Axel. From bonefish at cs.tu-berlin.de Thu May 3 12:16:05 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Thu, 03 May 2007 12:16:05 +0200 Subject: [Haiku-commits] r20982 - haiku/trunk/src/system/kernel/fs In-Reply-To: <3482707022-BeMail@zon> References: <3482707022-BeMail@zon> Message-ID: <20070503121605.11614.2@cs.tu-berlin.de> On 2007-05-03 at 11:09:27 [+0200], Axel D?rfler wrote: > "J?r?me Duval" wrote: [...] > > I don't prevent anyone to follow your approach of monitoring a devfs > > directory, but it shouldn't be the only way to implement it, and the > > possibility shouldn't be removed. > > Regardless of what I wrote above, I agree with you, since my > argumentation has an oversight: if the directory actually doesn't exist > yet in either /boot/home/config/add-ons/kernel/drivers/dev/ or /system/ > add-ons/kernel/drivers/dev/ no directory is created in /dev, and > monitoring that directory would fail - if you wanted to be able to > automatically pick up drivers that are installed later (which creates > that directory), you would indeed have to monitor a parent directory > that doesn't really interest you, which is not what we want. I find it a bit weird, that the devfs itself is writable for user applications. Security-wise it's a no-go and we'll have to remove that "feature" at some point in the future anyway. I understand the problem to be solved, but, I think, that's simply not the right solution. IMHO, a reasonable solution is a monitoring helper class that you can tell to watch a directory given by path and it handles all the details. That is optionally, if the directory doesn't exist yet, it watches the nearest ancestor that does exist. The monitoring messages would be filtered, of course, so that the class user is notified only of the events they're actually interested in. CU, Ingo From axeld at pinc-software.de Thu May 3 13:48:43 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Thu, 03 May 2007 13:48:43 +0200 CEST Subject: [Haiku-commits] r20982 - haiku/trunk/src/system/kernel/fs In-Reply-To: <20070503121605.11614.2@cs.tu-berlin.de> Message-ID: <13038748381-BeMail@zon> Ingo Weinhold wrote: > On 2007-05-03 at 11:09:27 [+0200], Axel D?rfler > > wrote: > > "J?r?me Duval" wrote: > [...] > > > I don't prevent anyone to follow your approach of monitoring a > > > devfs > > > directory, but it shouldn't be the only way to implement it, and > > > the > > > possibility shouldn't be removed. > > [...] if you wanted to be able to > > automatically pick up drivers that are installed later (which > > creates > > that directory), you would indeed have to monitor a parent > > directory > > that doesn't really interest you, which is not what we want. > I find it a bit weird, that the devfs itself is writable for user > applications. Security-wise it's a no-go and we'll have to remove > that > "feature" at some point in the future anyway. I understand the > problem to > be solved, but, I think, that's simply not the right solution. It would only be writable for the root user anyway. But in principle, I certainly agree with you :-) > IMHO, a reasonable solution is a monitoring helper class that you can > tell > to watch a directory given by path and it handles all the details. > That is > optionally, if the directory doesn't exist yet, it watches the > nearest > ancestor that does exist. The monitoring messages would be filtered, > of > course, so that the class user is notified only of the events they're > actually interested in. Having something like this would be nice, even though I would prefer if we had a path version of watch_node() that would automatically handle the details in the future (like a "watch all files under /boot/home/ config/"). Anyway, I planned to have a look at the AddOnMonitor stuff in src/kits/ storage (why there, anyway?) and implement this functionality there. But feel free to beat me on it :) Bye, Axel. From revol at free.fr Thu May 3 14:51:58 2007 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Thu, 03 May 2007 14:51:58 +0200 CEST Subject: [Haiku-commits] r20975 - haiku/trunk/build/jam In-Reply-To: <993979469-BeMail@guglielmo> Message-ID: <546393191-BeMail@laptop> > On Thu, 03 May 2007 00:04:20 +0200, Ingo Weinhold said: > > > So at least LLONG_MIN is not defined on your platform when < > > limits.h> > > is > > included. Given that the macro definitions are indented I suspose > > they are > > conditional. Please check, what's going on there. > > B_WILL_DO when I am back at work tomorrow. Date: Fri, 01 Jun 2007 19:07:00 -0300 BRT Are you experimenting IPOT at Google ?? Fran?ois. From bga at bug-br.org.br Thu May 3 14:51:37 2007 From: bga at bug-br.org.br (Bruno Albuquerque) Date: Thu, 03 May 2007 09:51:37 -0300 Subject: [Haiku-commits] r20975 - haiku/trunk/build/jam In-Reply-To: <546393191-BeMail@laptop> References: <546393191-BeMail@laptop> Message-ID: <4639DAD9.1060803@bug-br.org.br> Fran?ois Revol wrote: >>> So at least LLONG_MIN is not defined on your platform when < >>> limits.h> >>> is >>> included. Given that the macro definitions are indented I suspose >>> they are >>> conditional. Please check, what's going on there. >> >> B_WILL_DO when I am back at work tomorrow. > > Date: Fri, 01 Jun 2007 19:07:00 -0300 BRT > > Are you experimenting IPOT at Google ?? It depends, what does IPOT mean and how is it related to the date/time? :) -Bruno From revol at free.fr Thu May 3 15:02:41 2007 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Thu, 03 May 2007 15:02:41 +0200 CEST Subject: [Haiku-commits] r20982 - haiku/trunk/src/system/kernel/fs In-Reply-To: <13038748381-BeMail@zon> Message-ID: <1189113056-BeMail@laptop> > > I find it a bit weird, that the devfs itself is writable for user > > applications. Security-wise it's a no-go and we'll have to remove > > that > > "feature" at some point in the future anyway. I understand the > > problem to > > be solved, but, I think, that's simply not the right solution. > > It would only be writable for the root user anyway. But in principle, > I > certainly agree with you :-) Right, the less the "user" can mess up the better :) > > IMHO, a reasonable solution is a monitoring helper class that you > > can > > tell > > to watch a directory given by path and it handles all the details. > > That is > > optionally, if the directory doesn't exist yet, it watches the > > nearest > > ancestor that does exist. The monitoring messages would be > > filtered, > > of > > course, so that the class user is notified only of the events > > they're > > actually interested in. > > Having something like this would be nice, even though I would prefer > if > we had a path version of watch_node() that would automatically handle > the details in the future (like a "watch all files under /boot/home/ > config/"). How about mirroring the drivers/dev/ tree ? making a dir there would force one being present in /dev. Actually I wonder if BeOS does it. Fran?ois. From revol at free.fr Thu May 3 15:05:22 2007 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Thu, 03 May 2007 15:05:22 +0200 CEST Subject: [Haiku-commits] r20975 - haiku/trunk/build/jam In-Reply-To: <4639DAD9.1060803@bug-br.org.br> Message-ID: <1350286067-BeMail@laptop> > Fran?ois Revol wrote: > > >>> So at least LLONG_MIN is not defined on your platform when < > >>> limits.h> > >>> is > >>> included. Given that the macro definitions are indented I suspose > >>> they are > >>> conditional. Please check, what's going on there. > >> > >> B_WILL_DO when I am back at work tomorrow. > > > > Date: Fri, 01 Jun 2007 19:07:00 -0300 BRT > > > > Are you experimenting IPOT at Google ?? > > It depends, what does IPOT mean and how is it related to the date/ > time? :) A hypothetical quantum physics based IP Over Time protocol :) http://kadreg.free.fr/ipot/ (fr) Fran?ois. From korli at users.berlios.de Thu May 3 15:13:25 2007 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Thu, 3 May 2007 15:13:25 +0200 Subject: [Haiku-commits] r20982 - haiku/trunk/src/system/kernel/fs In-Reply-To: <20070503121605.11614.2@cs.tu-berlin.de> References: <3482707022-BeMail@zon> <20070503121605.11614.2@cs.tu-berlin.de> Message-ID: 2007/5/3, Ingo Weinhold : > > I find it a bit weird, that the devfs itself is writable for user > applications. Security-wise it's a no-go and we'll have to remove that > "feature" at some point in the future anyway. I understand the problem to > be solved, but, I think, that's simply not the right solution. That being said, BeOS is supporting creating directories in devfs :) > > IMHO, a reasonable solution is a monitoring helper class that you can tell > to watch a directory given by path and it handles all the details. That is > optionally, if the directory doesn't exist yet, it watches the nearest > ancestor that does exist. The monitoring messages would be filtered, of > course, so that the class user is notified only of the events they're > actually interested in. BTW I had the same problem when monitoring the ScreenSaver settings file : if it doesn't exist, we need to monitor the directory. Bye, J?r?me From hugosantos at mail.berlios.de Thu May 3 16:14:52 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Thu, 3 May 2007 16:14:52 +0200 Subject: [Haiku-commits] r20994 - in haiku/trunk/src/libs/compat/freebsd_network: . compat compat/machine compat/sys compat/vm Message-ID: <200705031414.l43EEqUf007733@sheep.berlios.de> Author: hugosantos Date: 2007-05-03 16:14:12 +0200 (Thu, 03 May 2007) New Revision: 20994 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20994&view=rev Added: haiku/trunk/src/libs/compat/freebsd_network/busdma_machdep.c haiku/trunk/src/libs/compat/freebsd_network/compat/machine/atomic.h haiku/trunk/src/libs/compat/freebsd_network/compat/vm/ haiku/trunk/src/libs/compat/freebsd_network/compat/vm/vm.h Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile haiku/trunk/src/libs/compat/freebsd_network/bus.c haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/cdefs.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kernel.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/malloc.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/param.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/sysctl.h Log: freebsd compat. layer: added freebsd's busdma implementation. we are still missing MII and the ifp/ether methods. Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-03 06:37:38 UTC (rev 20993) +++ haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-03 14:14:12 UTC (rev 20994) @@ -9,6 +9,7 @@ Library libfreebsd_network.a : bus.c + busdma_machdep.c compat.c device.c if_media.c Modified: haiku/trunk/src/libs/compat/freebsd_network/bus.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-03 06:37:38 UTC (rev 20993) +++ haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-03 14:14:12 UTC (rev 20994) @@ -15,11 +15,21 @@ #include #include #include +#include #define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1)) +struct resource { + int type; + bus_space_tag_t tag; + bus_space_handle_t handle; + + area_id mapped_area; +}; + + struct internal_intr { driver_intr_t handler; void *arg; @@ -47,59 +57,110 @@ } -/* straight from Marcus' ipro1000 driver */ +static int +bus_alloc_irq_resource(device_t dev, struct resource *res) +{ + uint8 irq = pci_read_config(dev, PCI_interrupt_line, 1); + if (irq == 0 || irq == 0xff) + return -1; + + /* XXX */ + res->tag = 0; + res->handle = irq; + + return 0; +} + + +static int +bus_alloc_mem_resource(device_t dev, struct resource *res, int regid) +{ + uint32 addr = pci_read_config(dev, regid, 4) & PCI_address_memory_32_mask; + uint32 size = 128 * 1024; /* XXX */ + void *virtualAddr; + + res->mapped_area = map_mem(&virtualAddr, (void *)addr, size, 0, + "bus_alloc_resource(MEMORY)"); + + if (res->mapped_area < 0) + return -1; + + res->tag = I386_BUS_SPACE_MEM; + res->handle = (bus_space_handle_t)virtualAddr; + return 0; +} + + +static int +bus_alloc_ioport_resource(device_t dev, struct resource *res, int regid) +{ + res->tag = I386_BUS_SPACE_IO; + res->handle = pci_read_config(dev, regid, 4) & PCI_address_io_mask; + return 0; +} + + struct resource * bus_alloc_resource(device_t dev, int type, int *rid, unsigned long start, unsigned long end, unsigned long count, uint32 flags) { - switch (type) { - case SYS_RES_IRQ: - { - uint8 res = pci_read_config(dev, PCI_interrupt_line, 1); - if (res == 0 || res == 0xff) - return NULL; - return (struct resource *)(int)res; - } + struct resource *res; + int result = -1; - case SYS_RES_MEMORY: - { - uint32 res = pci_read_config(dev, *rid, 4) - & PCI_address_memory_32_mask; - uint32 size = 128 * 1024; // TODO get size from BAR - void *virtualAddr; - if (map_mem(&virtualAddr, (void *)res, size, 0, "bus_alloc_resource(MEMORY)") < 0) - return NULL; - return (struct resource *)virtualAddr; - } + if (type != SYS_RES_IRQ && type != SYS_RES_MEMORY + && type != SYS_RES_IOPORT) + return NULL; - case SYS_RES_IOPORT: - return (struct resource *)(pci_read_config(dev, *rid, 4) - & PCI_address_io_mask); + // maybe a local array of resources is enough + res = malloc(sizeof(struct resource)); + if (res == NULL) + return NULL; - default: - return NULL; + if (type == SYS_RES_IRQ) + result = bus_alloc_irq_resource(dev, res); + else if (type == SYS_RES_MEMORY) + result = bus_alloc_mem_resource(dev, res, *rid); + else if (type == SYS_RES_IOPORT) + result = bus_alloc_ioport_resource(dev, res, *rid); + + if (result < 0) { + free(res); + return NULL; } + + res->type = type; + return res; } int bus_release_resource(device_t dev, int type, int rid, struct resource *res) { - switch (type) { - case SYS_RES_IRQ: - case SYS_RES_IOPORT: - return 0; + if (res->type != type) + panic("bus_release_resource: mismatch"); - case SYS_RES_MEMORY: - delete_area(area_for(res)); - return 0; + if (type == SYS_RES_MEMORY) + delete_area(res->mapped_area); - default: - return B_ERROR; - } + free(res); + return 0; } +bus_space_handle_t +rman_get_bushandle(struct resource *res) +{ + return res->handle; +} + + +bus_space_tag_t +rman_get_bustag(struct resource *res) +{ + return res->tag; +} + + static int32 intr_wrapper(void *data) { Added: haiku/trunk/src/libs/compat/freebsd_network/busdma_machdep.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/busdma_machdep.c 2007-05-03 06:37:38 UTC (rev 20993) +++ haiku/trunk/src/libs/compat/freebsd_network/busdma_machdep.c 2007-05-03 14:14:12 UTC (rev 20994) @@ -0,0 +1,1182 @@ +/*- + * Copyright (c) 1997, 1998 Justin T. Gibbs. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/sys/i386/i386/busdma_machdep.c,v 1.74.2.4 2006/10/21 16:26:53 hrs Exp $"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#define MAX_BPAGES 512 + +/* -hugo */ +#define malloc(a, b, c) kernel_malloc(a, b, c) +#define free(a, b) kernel_free(a, b) +#define contigmalloc(a, b, c, d, e, f, g) kernel_contigmalloc(a, b, c, d, e, f, g) +#define contigfree(a, b, c) kernel_contigfree(a, b, c) +#define __unused +void busdma_swi(void); +/* */ + +struct bounce_zone; + +struct bus_dma_tag { + bus_dma_tag_t parent; + bus_size_t alignment; + bus_size_t boundary; + bus_addr_t lowaddr; + bus_addr_t highaddr; + bus_dma_filter_t *filter; + void *filterarg; + bus_size_t maxsize; + u_int nsegments; + bus_size_t maxsegsz; + int flags; + int ref_count; + int map_count; + bus_dma_lock_t *lockfunc; + void *lockfuncarg; + bus_dma_segment_t *segments; + struct bounce_zone *bounce_zone; +}; + +struct bounce_page { + vm_offset_t vaddr; /* kva of bounce buffer */ + bus_addr_t busaddr; /* Physical address */ + vm_offset_t datavaddr; /* kva of client data */ + bus_size_t datacount; /* client data count */ + STAILQ_ENTRY(bounce_page) links; +}; + +int busdma_swi_pending; + +struct bounce_zone { + STAILQ_ENTRY(bounce_zone) links; + STAILQ_HEAD(bp_list, bounce_page) bounce_page_list; + int total_bpages; + int free_bpages; + int reserved_bpages; + int active_bpages; + int total_bounced; + int total_deferred; + bus_size_t alignment; + bus_size_t boundary; + bus_addr_t lowaddr; + char zoneid[8]; + char lowaddrid[20]; + struct sysctl_ctx_list sysctl_tree; + struct sysctl_oid *sysctl_tree_top; +}; + +static struct mtx bounce_lock; +static int total_bpages; +static int busdma_zonecount; +static STAILQ_HEAD(, bounce_zone) bounce_zone_list; + +SYSCTL_NODE(_hw, OID_AUTO, busdma, CTLFLAG_RD, 0, "Busdma parameters"); +SYSCTL_INT(_hw_busdma, OID_AUTO, total_bpages, CTLFLAG_RD, &total_bpages, 0, + "Total bounce pages"); + +struct bus_dmamap { + struct bp_list bpages; + int pagesneeded; + int pagesreserved; + bus_dma_tag_t dmat; + void *buf; /* unmapped buffer pointer */ + bus_size_t buflen; /* unmapped buffer length */ + bus_dmamap_callback_t *callback; + void *callback_arg; + STAILQ_ENTRY(bus_dmamap) links; +}; + +static STAILQ_HEAD(, bus_dmamap) bounce_map_waitinglist; +static STAILQ_HEAD(, bus_dmamap) bounce_map_callbacklist; +static struct bus_dmamap nobounce_dmamap; + +static void init_bounce_pages(void *dummy); +static int alloc_bounce_zone(bus_dma_tag_t dmat); +static int alloc_bounce_pages(bus_dma_tag_t dmat, u_int numpages); +static int reserve_bounce_pages(bus_dma_tag_t dmat, bus_dmamap_t map, + int commit); +static bus_addr_t add_bounce_page(bus_dma_tag_t dmat, bus_dmamap_t map, + vm_offset_t vaddr, bus_size_t size); +static void free_bounce_page(bus_dma_tag_t dmat, struct bounce_page *bpage); +static __inline int run_filter(bus_dma_tag_t dmat, bus_addr_t paddr); + +/* + * Return true if a match is made. + * + * To find a match walk the chain of bus_dma_tag_t's looking for 'paddr'. + * + * If paddr is within the bounds of the dma tag then call the filter callback + * to check for a match, if there is no filter callback then assume a match. + */ +static __inline int +run_filter(bus_dma_tag_t dmat, bus_addr_t paddr) +{ + int retval; + + retval = 0; + + do { + if (((paddr > dmat->lowaddr && paddr <= dmat->highaddr) + || ((paddr & (dmat->alignment - 1)) != 0)) + && (dmat->filter == NULL + || (*dmat->filter)(dmat->filterarg, paddr) != 0)) + retval = 1; + + dmat = dmat->parent; + } while (retval == 0 && dmat != NULL); + return (retval); +} + +/* + * Convenience function for manipulating driver locks from busdma (during + * busdma_swi, for example). Drivers that don't provide their own locks + * should specify &Giant to dmat->lockfuncarg. Drivers that use their own + * non-mutex locking scheme don't have to use this at all. + */ +void +busdma_lock_mutex(void *arg, bus_dma_lock_op_t op) +{ + struct mtx *dmtx; + + dmtx = (struct mtx *)arg; + switch (op) { + case BUS_DMA_LOCK: + mtx_lock(dmtx); + break; + case BUS_DMA_UNLOCK: + mtx_unlock(dmtx); + break; + default: + panic("Unknown operation 0x%x for busdma_lock_mutex!", op); + } +} + +/* + * dflt_lock should never get called. It gets put into the dma tag when + * lockfunc == NULL, which is only valid if the maps that are associated + * with the tag are meant to never be defered. + * XXX Should have a way to identify which driver is responsible here. + */ +static void +dflt_lock(void *arg, bus_dma_lock_op_t op) +{ + panic("driver error: busdma dflt_lock called"); +} + +#define BUS_DMA_COULD_BOUNCE BUS_DMA_BUS3 +#define BUS_DMA_MIN_ALLOC_COMP BUS_DMA_BUS4 +/* + * Allocate a device specific dma_tag. + */ +int +bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, + bus_size_t boundary, bus_addr_t lowaddr, + bus_addr_t highaddr, bus_dma_filter_t *filter, + void *filterarg, bus_size_t maxsize, int nsegments, + bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, + void *lockfuncarg, bus_dma_tag_t *dmat) +{ + bus_dma_tag_t newtag; + int error = 0; + + /* Basic sanity checking */ + if (boundary != 0 && boundary < maxsegsz) + maxsegsz = boundary; + + /* Return a NULL tag on failure */ + *dmat = NULL; + + newtag = (bus_dma_tag_t)malloc(sizeof(*newtag), M_DEVBUF, + M_ZERO | M_NOWAIT); + if (newtag == NULL) { + CTR4(KTR_BUSDMA, "%s returned tag %p tag flags 0x%x error %d", + __func__, newtag, 0, error); + return (ENOMEM); + } + + newtag->parent = parent; + newtag->alignment = alignment; + newtag->boundary = boundary; + newtag->lowaddr = trunc_page((vm_paddr_t)lowaddr) + (PAGE_SIZE - 1); + newtag->highaddr = trunc_page((vm_paddr_t)highaddr) + + (PAGE_SIZE - 1); + newtag->filter = filter; + newtag->filterarg = filterarg; + newtag->maxsize = maxsize; + newtag->nsegments = nsegments; + newtag->maxsegsz = maxsegsz; + newtag->flags = flags; + newtag->ref_count = 1; /* Count ourself */ + newtag->map_count = 0; + if (lockfunc != NULL) { + newtag->lockfunc = lockfunc; + newtag->lockfuncarg = lockfuncarg; + } else { + newtag->lockfunc = dflt_lock; + newtag->lockfuncarg = NULL; + } + newtag->segments = NULL; + + /* Take into account any restrictions imposed by our parent tag */ + if (parent != NULL) { + newtag->lowaddr = MIN(parent->lowaddr, newtag->lowaddr); + newtag->highaddr = MAX(parent->highaddr, newtag->highaddr); + if (newtag->boundary == 0) + newtag->boundary = parent->boundary; + else if (parent->boundary != 0) + newtag->boundary = MIN(parent->boundary, + newtag->boundary); + if (newtag->filter == NULL) { + /* + * Short circuit looking at our parent directly + * since we have encapsulated all of its information + */ + newtag->filter = parent->filter; + newtag->filterarg = parent->filterarg; + newtag->parent = parent->parent; + } + if (newtag->parent != NULL) + atomic_add_int(&parent->ref_count, 1); + } + + if (newtag->lowaddr < ptoa((vm_paddr_t)Maxmem) + || newtag->alignment > 1) + newtag->flags |= BUS_DMA_COULD_BOUNCE; + + if (((newtag->flags & BUS_DMA_COULD_BOUNCE) != 0) && + (flags & BUS_DMA_ALLOCNOW) != 0) { + struct bounce_zone *bz; + + /* Must bounce */ + + if ((error = alloc_bounce_zone(newtag)) != 0) { + free(newtag, M_DEVBUF); + return (error); + } + bz = newtag->bounce_zone; + + if (ptoa(bz->total_bpages) < maxsize) { + int pages; + + pages = atop(maxsize) - bz->total_bpages; + + /* Add pages to our bounce pool */ + if (alloc_bounce_pages(newtag, pages) < pages) + error = ENOMEM; + } + /* Performed initial allocation */ + newtag->flags |= BUS_DMA_MIN_ALLOC_COMP; + } + + if (error != 0) { + free(newtag, M_DEVBUF); + } else { + *dmat = newtag; + } + CTR4(KTR_BUSDMA, "%s returned tag %p tag flags 0x%x error %d", + __func__, newtag, (newtag != NULL ? newtag->flags : 0), error); + return (error); +} + +int +bus_dma_tag_destroy(bus_dma_tag_t dmat) +{ + bus_dma_tag_t dmat_copy; + int error; + + error = 0; + dmat_copy = dmat; + + if (dmat != NULL) { + + if (dmat->map_count != 0) { + error = EBUSY; + goto out; + } + + while (dmat != NULL) { + bus_dma_tag_t parent; + + parent = dmat->parent; + atomic_subtract_int(&dmat->ref_count, 1); + if (dmat->ref_count == 0) { + if (dmat->segments != NULL) + free(dmat->segments, M_DEVBUF); + free(dmat, M_DEVBUF); + /* + * Last reference count, so + * release our reference + * count on our parent. + */ + dmat = parent; + } else + dmat = NULL; + } + } +out: + CTR3(KTR_BUSDMA, "%s tag %p error %d", __func__, dmat_copy, error); + return (error); +} + +/* + * Allocate a handle for mapping from kva/uva/physical + * address space into bus device space. + */ +int +bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp) +{ + int error; + + error = 0; + + if (dmat->segments == NULL) { + dmat->segments = (bus_dma_segment_t *)malloc( + sizeof(bus_dma_segment_t) * dmat->nsegments, M_DEVBUF, + M_NOWAIT); + if (dmat->segments == NULL) { + CTR3(KTR_BUSDMA, "%s: tag %p error %d", + __func__, dmat, ENOMEM); + return (ENOMEM); + } + } + + /* + * Bouncing might be required if the driver asks for an active + * exclusion region, a data alignment that is stricter than 1, and/or + * an active address boundary. + */ + if (dmat->flags & BUS_DMA_COULD_BOUNCE) { + + /* Must bounce */ + struct bounce_zone *bz; + int maxpages; + + if (dmat->bounce_zone == NULL) { + if ((error = alloc_bounce_zone(dmat)) != 0) + return (error); + } + bz = dmat->bounce_zone; + + *mapp = (bus_dmamap_t)malloc(sizeof(**mapp), M_DEVBUF, + M_NOWAIT | M_ZERO); + if (*mapp == NULL) { + CTR3(KTR_BUSDMA, "%s: tag %p error %d", + __func__, dmat, ENOMEM); + return (ENOMEM); + } + + /* Initialize the new map */ + STAILQ_INIT(&((*mapp)->bpages)); + + /* + * Attempt to add pages to our pool on a per-instance + * basis up to a sane limit. + */ + if (dmat->alignment > 1) + maxpages = MAX_BPAGES; + else + maxpages = MIN(MAX_BPAGES, Maxmem -atop(dmat->lowaddr)); + if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0 + || (dmat->map_count > 0 && bz->total_bpages < maxpages)) { + int pages; + + pages = MAX(atop(dmat->maxsize), 1); + pages = MIN(maxpages - bz->total_bpages, pages); + pages = MAX(pages, 1); + if (alloc_bounce_pages(dmat, pages) < pages) + error = ENOMEM; + + if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0) { + if (error == 0) + dmat->flags |= BUS_DMA_MIN_ALLOC_COMP; + } else { + error = 0; + } + } + } else { + *mapp = NULL; + } + if (error == 0) + dmat->map_count++; + CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", + __func__, dmat, dmat->flags, error); + return (error); +} + +/* + * Destroy a handle for mapping from kva/uva/physical + * address space into bus device space. + */ +int +bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map) +{ + if (map != NULL && map != &nobounce_dmamap) { + if (STAILQ_FIRST(&map->bpages) != NULL) { + CTR3(KTR_BUSDMA, "%s: tag %p error %d", + __func__, dmat, EBUSY); + return (EBUSY); + } + free(map, M_DEVBUF); + } + dmat->map_count--; + CTR2(KTR_BUSDMA, "%s: tag %p error 0", __func__, dmat); + return (0); +} + + +/* + * Allocate a piece of memory that can be efficiently mapped into + * bus device space based on the constraints lited in the dma tag. + * A dmamap to for use with dmamap_load is also allocated. + */ +int +bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, + bus_dmamap_t *mapp) +{ + int mflags; + + if (flags & BUS_DMA_NOWAIT) + mflags = M_NOWAIT; + else + mflags = M_WAITOK; + if (flags & BUS_DMA_ZERO) + mflags |= M_ZERO; + + /* If we succeed, no mapping/bouncing will be required */ + *mapp = NULL; + + if (dmat->segments == NULL) { + dmat->segments = (bus_dma_segment_t *)malloc( + sizeof(bus_dma_segment_t) * dmat->nsegments, M_DEVBUF, + M_NOWAIT); + if (dmat->segments == NULL) { + CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", + __func__, dmat, dmat->flags, ENOMEM); + return (ENOMEM); + } + } + + /* + * XXX: + * (dmat->alignment < dmat->maxsize) is just a quick hack; the exact + * alignment guarantees of malloc need to be nailed down, and the + * code below should be rewritten to take that into account. + * + * In the meantime, we'll warn the user if malloc gets it wrong. + */ + if ((dmat->maxsize <= PAGE_SIZE) && + (dmat->alignment < dmat->maxsize) && + dmat->lowaddr >= ptoa((vm_paddr_t)Maxmem)) { + *vaddr = malloc(dmat->maxsize, M_DEVBUF, mflags); + } else { + /* + * XXX Use Contigmalloc until it is merged into this facility + * and handles multi-seg allocations. Nobody is doing + * multi-seg allocations yet though. + * XXX Certain AGP hardware does. + */ + *vaddr = contigmalloc(dmat->maxsize, M_DEVBUF, mflags, + 0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : 1ul, + dmat->boundary); + } + if (*vaddr == NULL) { + CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", + __func__, dmat, dmat->flags, ENOMEM); + return (ENOMEM); + } else if ((uintptr_t)*vaddr & (dmat->alignment - 1)) { + printf("bus_dmamem_alloc failed to align memory properly.\n"); + } + CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", + __func__, dmat, dmat->flags, ENOMEM); + return (0); +} + +/* + * Free a piece of memory and it's allociated dmamap, that was allocated + * via bus_dmamem_alloc. Make the same choice for free/contigfree. + */ +void +bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map) +{ + /* + * dmamem does not need to be bounced, so the map should be + * NULL + */ + if (map != NULL) + panic("bus_dmamem_free: Invalid map freed\n"); + if ((dmat->maxsize <= PAGE_SIZE) && + (dmat->alignment < dmat->maxsize) && + dmat->lowaddr >= ptoa((vm_paddr_t)Maxmem)) + free(vaddr, M_DEVBUF); + else { + contigfree(vaddr, dmat->maxsize, M_DEVBUF); + } + CTR3(KTR_BUSDMA, "%s: tag %p flags 0x%x", __func__, dmat, dmat->flags); +} + +/* + * Utility function to load a linear buffer. lastaddrp holds state + * between invocations (for multiple-buffer loads). segp contains + * the starting segment on entrace, and the ending segment on exit. + * first indicates if this is the first invocation of this function. + */ +static __inline int +_bus_dmamap_load_buffer(bus_dma_tag_t dmat, + bus_dmamap_t map, + void *buf, bus_size_t buflen, + pmap_t pmap, + int flags, + bus_addr_t *lastaddrp, + bus_dma_segment_t *segs, + int *segp, + int first) +{ + bus_size_t sgsize; + bus_addr_t curaddr, lastaddr, baddr, bmask; + vm_offset_t vaddr; + bus_addr_t paddr; + int needbounce = 0; + int seg; + + if (map == NULL) + map = &nobounce_dmamap; + + if ((map != &nobounce_dmamap && map->pagesneeded == 0) + && ((dmat->flags & BUS_DMA_COULD_BOUNCE) != 0)) { + vm_offset_t vendaddr; + + CTR4(KTR_BUSDMA, "lowaddr= %d Maxmem= %d, boundary= %d, " + "alignment= %d", dmat->lowaddr, ptoa((vm_paddr_t)Maxmem), + dmat->boundary, dmat->alignment); + CTR3(KTR_BUSDMA, "map= %p, nobouncemap= %p, pagesneeded= %d", + map, &nobounce_dmamap, map->pagesneeded); + /* + * Count the number of bounce pages + * needed in order to complete this transfer + */ + vaddr = trunc_page((vm_offset_t)buf); + vendaddr = (vm_offset_t)buf + buflen; + + while (vaddr < vendaddr) { + paddr = pmap_kextract(vaddr); + if (run_filter(dmat, paddr) != 0) { + needbounce = 1; + map->pagesneeded++; + } + vaddr += PAGE_SIZE; + } + CTR1(KTR_BUSDMA, "pagesneeded= %d\n", map->pagesneeded); + } + + /* Reserve Necessary Bounce Pages */ + if (map->pagesneeded != 0) { + mtx_lock(&bounce_lock); + if (flags & BUS_DMA_NOWAIT) { + if (reserve_bounce_pages(dmat, map, 0) != 0) { + mtx_unlock(&bounce_lock); + return (ENOMEM); + } + } else { + if (reserve_bounce_pages(dmat, map, 1) != 0) { + /* Queue us for resources */ + map->dmat = dmat; + map->buf = buf; + map->buflen = buflen; + STAILQ_INSERT_TAIL(&bounce_map_waitinglist, + map, links); + mtx_unlock(&bounce_lock); + return (EINPROGRESS); + } + } + mtx_unlock(&bounce_lock); + } + + vaddr = (vm_offset_t)buf; + lastaddr = *lastaddrp; + bmask = ~(dmat->boundary - 1); + + for (seg = *segp; buflen > 0 ; ) { + /* + * Get the physical address for this segment. + */ + if (pmap) + curaddr = pmap_extract(pmap, vaddr); + else + curaddr = pmap_kextract(vaddr); + + /* + * Compute the segment size, and adjust counts. + */ + sgsize = PAGE_SIZE - ((u_long)curaddr & PAGE_MASK); + if (buflen < sgsize) + sgsize = buflen; + + /* + * Make sure we don't cross any boundaries. + */ + if (dmat->boundary > 0) { + baddr = (curaddr + dmat->boundary) & bmask; + if (sgsize > (baddr - curaddr)) + sgsize = (baddr - curaddr); + } + + if (map->pagesneeded != 0 && run_filter(dmat, curaddr)) + curaddr = add_bounce_page(dmat, map, vaddr, sgsize); + + /* + * Insert chunk into a segment, coalescing with + * previous segment if possible. + */ + if (first) { + segs[seg].ds_addr = curaddr; + segs[seg].ds_len = sgsize; + first = 0; + } else { + if (needbounce == 0 && curaddr == lastaddr && + (segs[seg].ds_len + sgsize) <= dmat->maxsegsz && + (dmat->boundary == 0 || + (segs[seg].ds_addr & bmask) == (curaddr & bmask))) + segs[seg].ds_len += sgsize; + else { + if (++seg >= dmat->nsegments) + break; + segs[seg].ds_addr = curaddr; + segs[seg].ds_len = sgsize; + } + } + + lastaddr = curaddr + sgsize; + vaddr += sgsize; + buflen -= sgsize; + } + + *segp = seg; + *lastaddrp = lastaddr; + + /* + * Did we fit? + */ + return (buflen != 0 ? EFBIG : 0); /* XXX better return value here? */ +} + +/* + * Map the buffer buf into bus space using the dmamap map. + */ +int +bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, + bus_size_t buflen, bus_dmamap_callback_t *callback, + void *callback_arg, int flags) +{ + bus_addr_t lastaddr = 0; + int error, nsegs = 0; + + if (map != NULL) { + flags |= BUS_DMA_WAITOK; + map->callback = callback; + map->callback_arg = callback_arg; + } + + error = _bus_dmamap_load_buffer(dmat, map, buf, buflen, NULL, flags, + &lastaddr, dmat->segments, &nsegs, 1); + + CTR5(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d nsegs %d", + __func__, dmat, dmat->flags, error, nsegs + 1); + + if (error == EINPROGRESS) { + return (error); + } + + if (error) + (*callback)(callback_arg, dmat->segments, 0, error); + else + (*callback)(callback_arg, dmat->segments, nsegs + 1, 0); + + /* + * Return ENOMEM to the caller so that it can pass it up the stack. + * This error only happens when NOWAIT is set, so deferal is disabled. + */ + if (error == ENOMEM) + return (error); + + return (0); +} + + +/* + * Like _bus_dmamap_load(), but for mbufs. + */ +int +bus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map, + struct mbuf *m0, + bus_dmamap_callback2_t *callback, void *callback_arg, + int flags) +{ + int nsegs, error; + + M_ASSERTPKTHDR(m0); + + flags |= BUS_DMA_NOWAIT; + nsegs = 0; + error = 0; + if (m0->m_pkthdr.len <= dmat->maxsize) { + int first = 1; + bus_addr_t lastaddr = 0; + struct mbuf *m; + + for (m = m0; m != NULL && error == 0; m = m->m_next) { + if (m->m_len > 0) { + error = _bus_dmamap_load_buffer(dmat, map, + m->m_data, m->m_len, + NULL, flags, &lastaddr, + dmat->segments, &nsegs, first); + first = 0; + } + } + } else { + error = EINVAL; + } + + if (error) { + /* force "no valid mappings" in callback */ + (*callback)(callback_arg, dmat->segments, 0, 0, error); + } else { + (*callback)(callback_arg, dmat->segments, + nsegs+1, m0->m_pkthdr.len, error); + } + CTR5(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d nsegs %d", + __func__, dmat, dmat->flags, error, nsegs + 1); + return (error); +} + +int +bus_dmamap_load_mbuf_sg(bus_dma_tag_t dmat, bus_dmamap_t map, + struct mbuf *m0, bus_dma_segment_t *segs, int *nsegs, + int flags) +{ + int error; + + M_ASSERTPKTHDR(m0); + + flags |= BUS_DMA_NOWAIT; + *nsegs = 0; + error = 0; + if (m0->m_pkthdr.len <= dmat->maxsize) { + int first = 1; + bus_addr_t lastaddr = 0; + struct mbuf *m; + + for (m = m0; m != NULL && error == 0; m = m->m_next) { + if (m->m_len > 0) { + error = _bus_dmamap_load_buffer(dmat, map, [... truncated: 798 lines follow ...] From mmu_man at mail.berlios.de Thu May 3 16:40:42 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Thu, 3 May 2007 16:40:42 +0200 Subject: [Haiku-commits] r20995 - haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd Message-ID: <200705031440.l43Eegv0009379@sheep.berlios.de> Author: mmu_man Date: 2007-05-03 16:40:42 +0200 (Thu, 03 May 2007) New Revision: 20995 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20995&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c Log: (not working) kludge to allow mountign with a single connection in BeOS (mount open()/close() twice). Implement correct settings. Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-03 14:14:12 UTC (rev 20994) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-03 14:40:42 UTC (rev 20995) @@ -18,6 +18,12 @@ #define DEBUG 1 +/* on the first open(), open ourselves for some seconds, + * to avoid trying to reconnect and failing on a 2nd open, + * as it happens with the python server. + */ +//#define MOUNT_KLUDGE + /* locking support */ #ifdef __HAIKU__ #include @@ -68,7 +74,8 @@ }; struct nbd_device { - char target[64]; // "ip:port" + bool valid; + bool readonly; struct sockaddr_in server; benaphore ben; vint32 refcnt; @@ -77,6 +84,9 @@ thread_id postoffice; uint64 size; struct nbd_request_entry *reqs; +#ifdef MOUNT_KLUDGE + int kludge; +#endif }; typedef struct cookie { @@ -103,6 +113,28 @@ bool gDelayUnload = false; #define BONE_TEARDOWN_DELAY 60000000 +#pragma mark ==== support ==== + +// move that to ksocket inlined +static int kinet_aton(const char *in, struct in_addr *addr) +{ + int i; + unsigned long a; + uint32 inaddr = 0L; + const char *p = in; + for (i = 0; i < 4; i++) { + a = strtoul(p, &p, 10); + if (!p) + return -1; + inaddr = (inaddr >> 8) | ((a & 0x0ff) << 24); + *(uint32 *)addr = inaddr; + if (!*p) + return 0; + p++; + } + return 0; +} + #pragma mark ==== request manager ==== status_t nbd_alloc_request(struct nbd_device *dev, struct nbd_request_entry **req, uint32 type, off_t from, size_t len, const char *data) @@ -383,11 +415,15 @@ status_t nbd_open(const char *name, uint32 flags, cookie_t **cookie) { status_t err; + int32 refcnt; +#ifdef MOUNT_KLUDGE + int kfd; +#endif struct nbd_device *dev = NULL; PRINT((DP ">%s(%s, %x, )\n", __FUNCTION__, name, flags)); (void)name; (void)flags; dev = nbd_find_device(name); - if (!dev) + if (!dev || !dev->valid) return ENOENT; err = ENOMEM; *cookie = (void*)malloc(sizeof(cookie_t)); @@ -403,8 +439,23 @@ err = nbd_connect(dev); if (err) goto err2; - dev->refcnt++; + refcnt = dev->refcnt++; +#ifdef MOUNT_KLUDGE + kfd = dev->kludge; + dev->kludge = -1; +#endif benaphore_unlock(&dev->ben); + +#ifdef MOUNT_KLUDGE + if (refcnt == 0) { + char buf[32]; + sprintf(buf, "/dev/%s", name); + dev->kludge = open(buf, O_RDONLY); + } else if (kfd) { + close(kfd); + } +#endif + return B_OK; err2: @@ -419,6 +470,9 @@ status_t nbd_close(cookie_t *cookie) { struct nbd_device *dev = cookie->dev; status_t err; +#ifdef MOUNT_KLUDGE + int kfd = -1; +#endif PRINT((DP ">%s(%d)\n", __FUNCTION__, WHICH(cookie->dev))); err = benaphore_lock(&dev->ben); @@ -426,8 +480,18 @@ return err; // XXX: do something ? +#ifdef MOUNT_KLUDGE + kfd = dev->kludge; + dev->kludge = -1; +#endif benaphore_unlock(&dev->ben); + +#ifdef MOUNT_KLUDGE + if (kfd > -1) { + close(kfd); + } +#endif return B_OK; } @@ -615,12 +679,19 @@ void *handle; PRINT((DP ">%s()\n", __FUNCTION__)); + handle = load_driver_settings(DRV); + if (handle == NULL) + return ENOENT; + // XXX: test for boot args ? + + err = ksocket_init(); if (err < B_OK) return err; for (i = 0; i < MAX_NBDS; i++) { - memset(nbd_devices[i].target, 0, 64); + nbd_devices[i].valid = false; + nbd_devices[i].readonly = false; err = benaphore_init(&nbd_devices[i].ben, "nbd lock"); if (err < B_OK) return err; // XXX @@ -630,48 +701,44 @@ nbd_devices[i].postoffice = -1; nbd_devices[i].size = 0LL; nbd_devices[i].reqs = NULL; +#ifdef MOUNT_KLUDGE + nbd_devices[i].kludge = -1; +#endif nbd_name[i] = malloc(DEVICE_NAME_MAX); if (nbd_name[i] == NULL) break; sprintf(nbd_name[i], DEVICE_FMT, i); - /* XXX: default init */ - nbd_devices[i].server.sin_len = sizeof(struct sockaddr_in); - nbd_devices[i].server.sin_family = AF_INET; - nbd_devices[i].server.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - nbd_devices[i].server.sin_port = htons(1337 + i); } nbd_name[i] = NULL; - handle = load_driver_settings(DRV); - if (handle) { - for (i = 0; i < MAX_NBDS; i++) { - char keyname[10]; - char *v; - sprintf(keyname, "nbd%d", i); - v = get_driver_parameter(handle, keyname, NULL, NULL); - /* should be "ip:port" */ - // XXX: test - if (v || 1) { - //strncpy(nbd_devices[i].target, v, 64); - //XXX:TEST - //strncpy(nbd_devices[i].target, "127.0.0.1:1337", 64); - //XXX:parse it + for (i = 0; i < MAX_NBDS; i++) { + driver_settings *settings = get_driver_settings(handle); + driver_parameter *p; + char keyname[10]; + char *v; + sprintf(keyname, "%d", i); + for (j = 0; j < settings->parameter_count; j++) + if (!strcmp(settings->parameters[j].name, keyname)) + p = &settings->parameters[j]; + if (!p) + continue; + for (j = 0; j < p->parameter_count; j++) { + if (!strcmp(p->parameters[j].name, "readonly")) + nbd_devices[i].readonly = true; + if (!strcmp(p->parameters[j].name, "server")) { + if (p->parameters[j].value_count < 2) + continue; nbd_devices[i].server.sin_len = sizeof(struct sockaddr_in); nbd_devices[i].server.sin_family = AF_INET; - nbd_devices[i].server.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - nbd_devices[i].server.sin_port = htons(1337 + i); + kinet_aton(p->parameters[j].values[0], &nbd_devices[i].server.sin_addr); + nbd_devices[i].server.sin_port = htons(atoi(p->parameters[j].values[1])); + + nbd_devices[i].valid = true; } } - /*should parse as a tree: - settings = get_driver_settings(handle); - for (i = 0; i < settings->parameter_count; i++) { - - } - */ + } - unload_driver_settings(handle); - } - + unload_driver_settings(handle); return B_OK; } From jackburton at mail.berlios.de Thu May 3 16:52:14 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Thu, 3 May 2007 16:52:14 +0200 Subject: [Haiku-commits] r20996 - haiku/trunk/src/servers/app Message-ID: <200705031452.l43EqEgC010387@sheep.berlios.de> Author: jackburton Date: 2007-05-03 16:52:13 +0200 (Thu, 03 May 2007) New Revision: 20996 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20996&view=rev Modified: haiku/trunk/src/servers/app/Jamfile haiku/trunk/src/servers/app/ServerApp.cpp haiku/trunk/src/servers/app/ServerPicture.cpp haiku/trunk/src/servers/app/ServerPicture.h haiku/trunk/src/servers/app/ServerWindow.cpp haiku/trunk/src/servers/app/ViewLayer.cpp Log: ServerPicture now uses a BPositionIO object as internal storage instead of BMallocIO. Added an additional constructor to handle a file. This is in preparation of implementing BView::SetDiskMode(). Modified: haiku/trunk/src/servers/app/Jamfile =================================================================== --- haiku/trunk/src/servers/app/Jamfile 2007-05-03 14:40:42 UTC (rev 20995) +++ haiku/trunk/src/servers/app/Jamfile 2007-05-03 14:52:13 UTC (rev 20996) @@ -1,7 +1,7 @@ SubDir HAIKU_TOP src servers app ; UseLibraryHeaders png zlib ; -UsePrivateHeaders app graphics input interface kernel shared ; +UsePrivateHeaders app graphics input interface kernel shared storage ; UseHeaders [ FDirName $(HAIKU_TOP) src servers app drawing ] ; UseFreeTypeHeaders ; Modified: haiku/trunk/src/servers/app/ServerApp.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerApp.cpp 2007-05-03 14:40:42 UTC (rev 20995) +++ haiku/trunk/src/servers/app/ServerApp.cpp 2007-05-03 14:52:13 UTC (rev 20996) @@ -740,12 +740,8 @@ link.Read(&token); ServerPicture *picture = FindPicture(token); if (picture != NULL) { - fLink.StartMessage(B_OK); - - // TODO: support nested pictures (subpictures) - fLink.Attach(0); // number of subpictures - fLink.Attach(picture->DataLength()); - fLink.Attach(picture->Data(), picture->DataLength()); + picture->ExportData(fLink); + // ExportData() calls StartMessage() already } else fLink.StartMessage(B_ERROR); Modified: haiku/trunk/src/servers/app/ServerPicture.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerPicture.cpp 2007-05-03 14:40:42 UTC (rev 20995) +++ haiku/trunk/src/servers/app/ServerPicture.cpp 2007-05-03 14:52:13 UTC (rev 20996) @@ -17,8 +17,10 @@ #include "WindowLayer.h" #include +#include #include #include +#include #include #include @@ -661,23 +663,61 @@ // ServerPicture ServerPicture::ServerPicture() - :PictureDataWriter(&fData) + : + PictureDataWriter(), + fData(NULL) { fToken = gTokenSpace.NewToken(kPictureToken, this); + fData = new (std::nothrow) BMallocIO(); + + PictureDataWriter::SetTo(fData); } ServerPicture::ServerPicture(const ServerPicture &picture) - :PictureDataWriter(&fData) + : + PictureDataWriter(), + fData(NULL) { fToken = gTokenSpace.NewToken(kPictureToken, this); - fData.Write(picture.Data(), picture.DataLength()); + BMallocIO *mallocIO = new (std::nothrow) BMallocIO(); + if (mallocIO == NULL) + return; + + fData = mallocIO; + + const off_t size = picture.DataLength(); + if (mallocIO->SetSize(size) < B_OK) + return; + + picture.fData->ReadAt(0, const_cast(mallocIO->Buffer()), size); + + PictureDataWriter::SetTo(fData); } +ServerPicture::ServerPicture(const char *fileName, const int32 &offset) + : + PictureDataWriter(), + fData(NULL) +{ + BPrivate::Storage::OffsetFile *file = + new BPrivate::Storage::OffsetFile(new BFile(fileName, B_READ_WRITE), (off_t)offset); + + if (file == NULL || file->InitCheck() != B_OK) + return; + + fData = file; + fToken = gTokenSpace.NewToken(kPictureToken, this); + + PictureDataWriter::SetTo(fData); +} + + ServerPicture::~ServerPicture() { + delete fData; gTokenSpace.RemoveToken(fToken); } @@ -717,11 +757,30 @@ void ServerPicture::Play(ViewLayer *view) { - PicturePlayer player(fData.Buffer(), fData.BufferLength(), NULL); + // TODO: for now: then change PicturePlayer to accept a BPositionIO object + BMallocIO *mallocIO = dynamic_cast(fData); + if (mallocIO == NULL) + return; + + PicturePlayer player(mallocIO->Buffer(), mallocIO->BufferLength(), NULL); player.Play(const_cast(tableEntries), sizeof(tableEntries) / sizeof(void *), view); } +off_t +ServerPicture::DataLength() const +{ + if (fData == NULL) + return 0; + off_t size; + fData->GetSize(&size); + return size; +} + + +#define BUFFER_SIZE 4096 + + status_t ServerPicture::ImportData(BPrivate::LinkReceiver &link) { @@ -733,14 +792,59 @@ int32 size = 0; link.Read(&size); - if (fData.SetSize(size) != B_OK) - return B_ERROR; - // TODO: The best way to do this would be to read the data into - // a temporary buffer, and then use the BMallocIO::Write() method, - // but this way we avoid an extra copy. Unfortunately BMallocIO::Write() - // only accepts a pointer to raw data... - link.Read(const_cast(fData.Buffer()), size); + off_t oldPosition = fData->Position(); + fData->Seek(0, SEEK_SET); + ssize_t toWrite = size; + // TODO: For some reason, this doesn't work. Bug in LinkReceiver ? + /*char buffer[BUFFER_SIZE]; + while (toWrite > 0) { + ssize_t read = link.Read(buffer, toWrite > BUFFER_SIZE ? BUFFER_SIZE : toWrite); + if (read < B_OK) + return (status_t)read; + fData->Write(buffer, read); + toWrite -= read; + }*/ + + char buffer[toWrite]; + link.Read(buffer, toWrite); + fData->Write(buffer, toWrite); + + fData->Seek(oldPosition, SEEK_SET); + return B_OK; } + + +status_t +ServerPicture::ExportData(BPrivate::PortLink &link) +{ + link.StartMessage(B_OK); + + off_t oldPosition = fData->Position(); + fData->Seek(0, SEEK_SET); + + int32 subPicturesCount = 0; + link.Attach(subPicturesCount); + + off_t size = 0; + fData->GetSize(&size); + link.Attach((int32)size); + + ssize_t toWrite = size; + char buffer[BUFFER_SIZE]; + while (toWrite > 0) { + ssize_t read = fData->Read(buffer, toWrite > BUFFER_SIZE ? BUFFER_SIZE : toWrite); + if (read < B_OK) + return (status_t)read; + link.Attach(buffer, read); + toWrite -= read; + } + + fData->Seek(oldPosition, SEEK_SET); + + return B_OK; +} + + Modified: haiku/trunk/src/servers/app/ServerPicture.h =================================================================== --- haiku/trunk/src/servers/app/ServerPicture.h 2007-05-03 14:40:42 UTC (rev 20995) +++ haiku/trunk/src/servers/app/ServerPicture.h 2007-05-03 14:52:13 UTC (rev 20996) @@ -5,6 +5,10 @@ #include +#include + // TODO: For some reason, the forward declaration "class BPrivate::PortLink" causes compiling errors + + class ServerApp; class ViewLayer; class BPrivate::LinkReceiver; @@ -22,20 +26,21 @@ void Play(ViewLayer *view); - const void *Data() const { return fData.Buffer(); } - int32 DataLength() const { return fData.BufferLength(); } + off_t DataLength() const; status_t ImportData(BPrivate::LinkReceiver &link); + status_t ExportData(BPrivate::PortLink &link); private: friend class ServerApp; ServerPicture(); ServerPicture(const ServerPicture &); + ServerPicture(const char *fileName, const int32 &offset); ~ServerPicture(); int32 fToken; - BMallocIO fData; + BPositionIO *fData; // DrawState *fState; }; Modified: haiku/trunk/src/servers/app/ServerWindow.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerWindow.cpp 2007-05-03 14:40:42 UTC (rev 20995) +++ haiku/trunk/src/servers/app/ServerWindow.cpp 2007-05-03 14:52:13 UTC (rev 20996) @@ -2783,7 +2783,6 @@ fDirectWindowData->buffer_info->pixel_format = buffer->ColorSpace(); fDirectWindowData->buffer_info->layout = B_BUFFER_NONINTERLEAVED; fDirectWindowData->buffer_info->orientation = B_BUFFER_TOP_TO_BOTTOM; // TODO - fDirectWindowData->buffer_info->window_bounds = to_clipping_rect(fWindowLayer->Frame()); // TODO: Review this Modified: haiku/trunk/src/servers/app/ViewLayer.cpp =================================================================== --- haiku/trunk/src/servers/app/ViewLayer.cpp 2007-05-03 14:40:42 UTC (rev 20995) +++ haiku/trunk/src/servers/app/ViewLayer.cpp 2007-05-03 14:52:13 UTC (rev 20996) @@ -125,8 +125,6 @@ // if (fWindow && this == fWindow->TopLayer()) // fWindow->SetTopLayer(NULL); -// - // TODO: Don't know yet if we should also delete fPicture if (fCursor) fCursor->Release(); From jackburton at mail.berlios.de Thu May 3 17:15:23 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Thu, 3 May 2007 17:15:23 +0200 Subject: [Haiku-commits] r20997 - haiku/trunk/src/kits/interface Message-ID: <200705031515.l43FFNEa012343@sheep.berlios.de> Author: jackburton Date: 2007-05-03 17:15:23 +0200 (Thu, 03 May 2007) New Revision: 20997 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20997&view=rev Modified: haiku/trunk/src/kits/interface/TextView.cpp Log: Fixed a bug in selection via keyboard (the problem described in bug #716, comment #4) Modified: haiku/trunk/src/kits/interface/TextView.cpp =================================================================== --- haiku/trunk/src/kits/interface/TextView.cpp 2007-05-03 14:52:13 UTC (rev 20996) +++ haiku/trunk/src/kits/interface/TextView.cpp 2007-05-03 15:15:23 UTC (rev 20997) @@ -2861,10 +2861,12 @@ point.y -= height; fClickOffset = OffsetAt(point); if (shiftDown) { - if (fClickOffset >= fSelStart) - selEnd = fClickOffset; - else - selStart = fClickOffset; + if (fClickOffset != currentOffset) { + if (fClickOffset >= fSelStart) + selEnd = fClickOffset; + else + selStart = fClickOffset; + } } break; } @@ -2876,10 +2878,12 @@ point.y += height; fClickOffset = OffsetAt(point); if (shiftDown) { - if (fClickOffset <= fSelEnd) - selStart = fClickOffset; - else - selEnd = fClickOffset; + if (fClickOffset != currentOffset) { + if (fClickOffset <= fSelEnd) + selStart = fClickOffset; + else + selEnd = fClickOffset; + } } break; } From stefano.ceccherini at gmail.com Thu May 3 18:20:48 2007 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Thu, 3 May 2007 18:20:48 +0200 Subject: [Haiku-commits] r20996 - haiku/trunk/src/servers/app In-Reply-To: <200705031452.l43EqEgC010387@sheep.berlios.de> References: <200705031452.l43EqEgC010387@sheep.berlios.de> Message-ID: <894b9700705030920v49beafc0nb8f8d29711d5d82a@mail.gmail.com> 2007/5/3, jackburton at BerliOS : > Author: jackburton > Date: 2007-05-03 16:52:13 +0200 (Thu, 03 May 2007) > New Revision: 20996 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20996&view=rev > > Modified: > haiku/trunk/src/servers/app/Jamfile > haiku/trunk/src/servers/app/ServerApp.cpp > haiku/trunk/src/servers/app/ServerPicture.cpp > haiku/trunk/src/servers/app/ServerPicture.h > haiku/trunk/src/servers/app/ServerWindow.cpp > haiku/trunk/src/servers/app/ViewLayer.cpp > Log: > ServerPicture now uses a BPositionIO object as internal storage instead > of BMallocIO. Added an additional constructor to handle a file. This is > in preparation of implementing BView::SetDiskMode(). > I obviously forgot to commit the new version of PictureDataWriter.cpp/h, thus breaking the build. I'll do that in a moment. Sorry for the trouble. From jackburton at mail.berlios.de Thu May 3 18:34:32 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Thu, 3 May 2007 18:34:32 +0200 Subject: [Haiku-commits] r20998 - in haiku/trunk: headers/private/interface src/kits/interface Message-ID: <200705031634.l43GYWwX024238@sheep.berlios.de> Author: jackburton Date: 2007-05-03 18:34:31 +0200 (Thu, 03 May 2007) New Revision: 20998 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20998&view=rev Modified: haiku/trunk/headers/private/interface/PictureDataWriter.h haiku/trunk/src/kits/interface/PictureDataWriter.cpp Log: completes previous commit. Sorry for breaking the build Modified: haiku/trunk/headers/private/interface/PictureDataWriter.h =================================================================== --- haiku/trunk/headers/private/interface/PictureDataWriter.h 2007-05-03 15:15:23 UTC (rev 20997) +++ haiku/trunk/headers/private/interface/PictureDataWriter.h 2007-05-03 16:34:31 UTC (rev 20998) @@ -18,8 +18,11 @@ class BPositionIO; class PictureDataWriter { public: + PictureDataWriter(); PictureDataWriter(BPositionIO *data); + status_t SetTo(BPositionIO *data); + status_t WriteSetOrigin(const BPoint &point); status_t WriteInvertRect(const BRect &rect); Modified: haiku/trunk/src/kits/interface/PictureDataWriter.cpp =================================================================== --- haiku/trunk/src/kits/interface/PictureDataWriter.cpp 2007-05-03 15:15:23 UTC (rev 20997) +++ haiku/trunk/src/kits/interface/PictureDataWriter.cpp 2007-05-03 16:34:31 UTC (rev 20998) @@ -15,6 +15,13 @@ #include +PictureDataWriter::PictureDataWriter() + : + fData(NULL) +{ +} + + PictureDataWriter::PictureDataWriter(BPositionIO *data) : fData(data) @@ -23,6 +30,14 @@ status_t +PictureDataWriter::SetTo(BPositionIO *data) +{ + fData = data; + return B_OK; +} + + +status_t PictureDataWriter::WriteSetOrigin(const BPoint &point) { BeginOp(B_PIC_SET_ORIGIN); From hugosantos at mail.berlios.de Thu May 3 18:40:41 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Thu, 3 May 2007 18:40:41 +0200 Subject: [Haiku-commits] r20999 - haiku/trunk/src/libs/compat/freebsd_network Message-ID: <200705031640.l43GefmV004840@sheep.berlios.de> Author: hugosantos Date: 2007-05-03 18:40:08 +0200 (Thu, 03 May 2007) New Revision: 20999 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=20999&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/bus.c haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/device.h Log: freebsd compat. layer: a few more symbols, also respect malloc's M_ZERO Modified: haiku/trunk/src/libs/compat/freebsd_network/bus.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-03 16:34:31 UTC (rev 20998) +++ haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-03 16:40:08 UTC (rev 20999) @@ -206,3 +206,12 @@ return 0; } + +int +bus_generic_detach(device_t dev) +{ + /* TODO */ + + return B_ERROR; +} + Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-03 16:34:31 UTC (rev 20998) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-03 16:40:08 UTC (rev 20999) @@ -53,6 +53,20 @@ } +uint16_t +pci_get_subvendor(device_t dev) +{ + return pci_read_config(dev, PCI_subsystem_vendor_id, 2); +} + + +uint16_t +pci_get_subdevice(device_t dev) +{ + return pci_read_config(dev, PCI_subsystem_id, 2); +} + + uint8_t pci_get_revid(device_t dev) { @@ -60,7 +74,23 @@ } +static void +pci_set_command_bit(device_t dev, uint16_t bit) +{ + uint16_t command = pci_read_config(dev, PCI_command, 2); + pci_write_config(dev, PCI_command, command | bit, 2); +} + + int +pci_enable_busmaster(device_t dev) +{ + pci_set_command_bit(dev, PCI_command_master); + return 0; +} + + +int device_printf(device_t dev, const char *format, ...) { char buf[256]; @@ -74,7 +104,46 @@ } +void +device_set_desc(device_t dev, const char *desc) +{ + dev->description = desc; +} + + +const char * +device_get_name(device_t dev) +{ + /* + * if (dev != NULL && dev->devclass) + * return devclass_get_name(dev->devclass); + */ + return NULL; +} + + int +device_get_unit(device_t dev) +{ + return dev->unit; +} + + +const char * +device_get_nameunit(device_t dev) +{ + return dev->nameunit; +} + + +void * +device_get_softc(device_t dev) +{ + return dev->softc; +} + + +int printf(const char *format, ...) { char buf[256]; @@ -99,9 +168,16 @@ void * _kernel_malloc(size_t size, int flags) { - // our kernel malloc() is insufficent + // our kernel malloc() is insufficent, must handle M_WAIT - return malloc(size); + void *ptr = malloc(size); + if (ptr == NULL) + return ptr; + + if (flags & M_ZERO) + memset(ptr, 0, size); + + return ptr; } Modified: haiku/trunk/src/libs/compat/freebsd_network/device.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-03 16:34:31 UTC (rev 20998) +++ haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-03 16:40:08 UTC (rev 20999) @@ -31,6 +31,11 @@ sem_id receive_sem; struct ifnet * ifp; + + int unit; + char nameunit[64]; + const char * description; + void * softc; }; From hugosantos at mail.berlios.de Thu May 3 19:30:11 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Thu, 3 May 2007 19:30:11 +0200 Subject: [Haiku-commits] r21000 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/altq compat/sys Message-ID: <200705031730.l43HUBSB000937@sheep.berlios.de> Author: hugosantos Date: 2007-05-03 19:29:43 +0200 (Thu, 03 May 2007) New Revision: 21000 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21000&view=rev Added: haiku/trunk/src/libs/compat/freebsd_network/if.c Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile haiku/trunk/src/libs/compat/freebsd_network/compat/altq/if_altq.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h Log: freebsd compat. layer: ifnet and ethernet methods. missing MII and callout Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-03 16:40:08 UTC (rev 20999) +++ haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-03 17:29:43 UTC (rev 21000) @@ -12,6 +12,7 @@ busdma_machdep.c compat.c device.c + if.c if_media.c mbuf.c mutex.c Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/altq/if_altq.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/altq/if_altq.h 2007-05-03 16:40:08 UTC (rev 20999) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/altq/if_altq.h 2007-05-03 17:29:43 UTC (rev 21000) @@ -10,6 +10,7 @@ int ifq_len; int ifq_maxlen; + int ifq_drops; struct mtx ifq_mtx; struct mbuf * ifq_drv_head; @@ -25,6 +26,8 @@ #define ALTDQ_REMOVE 1 #define ALTQ_IS_ENABLED(ifq) 0 +#define ALTQ_ENQUEUE(ifr, m, foo, error) \ + do { m_freem(m); error = -1; } while (0) #define ALTQ_DEQUEUE(ifr, m) (m) = NULL #define TBR_IS_ENABLED(ifq) 0 Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h 2007-05-03 16:40:08 UTC (rev 20999) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h 2007-05-03 17:29:43 UTC (rev 21000) @@ -66,6 +66,9 @@ #define M_EXT 0x0001 #define M_PKTHDR 0x0002 +#define M_BCAST 0x0200 +#define M_MCAST 0x0400 + #define CSUM_IP 0x0001 #define CSUM_TCP 0x0002 #define CSUM_UDP 0x0004 Added: haiku/trunk/src/libs/compat/freebsd_network/if.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-03 16:40:08 UTC (rev 20999) +++ haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-03 17:29:43 UTC (rev 21000) @@ -0,0 +1,151 @@ +/* + * Copyright 2007, Hugo Santos. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Hugo Santos, hugosantos at gmail.com + * + * Some of this code is based on previous work by Marcus Overhagen. + */ + +#include "device.h" + +#include +#include + +#include +#include + +#include +#include +#include + +#include + +struct ifnet * +if_alloc(u_char type) +{ + struct ifnet *ifp = _kernel_malloc(sizeof(struct ifnet), M_ZERO); + if (ifp == NULL) + return NULL; + + ifp->if_type = type; + + IF_ADDR_LOCK_INIT(ifp); + return ifp; +} + + +void +if_free(struct ifnet *ifp) +{ + IF_ADDR_LOCK_DESTROY(ifp); + _kernel_free(ifp); +} + + +void +if_initname(struct ifnet *ifp, const char *name, int unit) +{ + ifp->if_dname = name; + ifp->if_dunit = unit; + + /* XXX use a more Haiku friendly name here? */ + snprintf(ifp->if_xname, IFNAMSIZ, "%s%d", name, unit); +} + + +void +if_attach(struct ifnet *ifp) +{ + TAILQ_INIT(&ifp->if_addrhead); + TAILQ_INIT(&ifp->if_prefixhead); + TAILQ_INIT(&ifp->if_multiaddrs); + + mtx_init(&ifp->if_snd.ifq_mtx, ifp->if_xname, NULL, MTX_DEF); +} + + +void +if_detach(struct ifnet *ifp) +{ + mtx_destroy(&ifp->if_snd.ifq_mtx); +} + + +void +if_start(struct ifnet *ifp) +{ +#ifdef IFF_NEEDSGIANT + if (ifp->if_flags & IFF_NEEDSGIANT) + panic("freebsd compat.: unsupported giant requirement"); +#endif + + ifp->if_start(ifp); +} + + +int +ether_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, + struct rtentry *rt0) +{ + int error; + IFQ_HANDOFF(ifp, m, error); + return error; +} + + +static void +ether_input(struct ifnet *ifp, struct mbuf *m) +{ + device_t dev = NULL; /* XXX */ + + IF_ENQUEUE(&dev->receive_queue, m); + release_sem_etc(dev->receive_sem, 1, B_DO_NOT_RESCHEDULE); +} + + +void +ether_ifattach(struct ifnet *ifp, const uint8_t *mac_address) +{ + ifp->if_addrlen = ETHER_ADDR_LEN; + ifp->if_hdrlen = ETHER_HDR_LEN; + if_attach(ifp); + ifp->if_mtu = ETHERMTU; + ifp->if_output = ether_output; + ifp->if_input = ether_input; + ifp->if_resolvemulti = NULL; /* done in the stack */ + + ifp->if_init(ifp->if_softc); +} + + +void +ether_ifdetach(struct ifnet *ifp) +{ + if_detach(ifp); +} + + +int +ether_ioctl(struct ifnet *ifp, int command, caddr_t data) +{ + struct ifreq *ifr = (struct ifreq *)data; + + switch (command) { + case SIOCSIFMTU: + if (ifr->ifr_mtu > ETHERMTU) + return EINVAL; + else + ; + /* need to fix our ifreq to work with C... */ + /* ifp->ifr_mtu = ifr->ifr_mtu; */ + break; + + default: + return EINVAL; + } + + return 0; +} + From jackburton at mail.berlios.de Thu May 3 22:05:48 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Thu, 3 May 2007 22:05:48 +0200 Subject: [Haiku-commits] r21001 - haiku/trunk/src/preferences/menu Message-ID: <200705032005.l43K5m7O015255@sheep.berlios.de> Author: jackburton Date: 2007-05-03 22:05:47 +0200 (Thu, 03 May 2007) New Revision: 21001 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21001&view=rev Modified: haiku/trunk/src/preferences/menu/AutoSettingsMenu.cpp haiku/trunk/src/preferences/menu/AutoSettingsMenu.h haiku/trunk/src/preferences/menu/BitmapMenuItem.cpp haiku/trunk/src/preferences/menu/BitmapMenuItem.h haiku/trunk/src/preferences/menu/ColorWindow.cpp haiku/trunk/src/preferences/menu/ColorWindow.h haiku/trunk/src/preferences/menu/FontMenu.cpp haiku/trunk/src/preferences/menu/FontSizeMenu.cpp haiku/trunk/src/preferences/menu/MenuApp.cpp haiku/trunk/src/preferences/menu/MenuApp.h haiku/trunk/src/preferences/menu/MenuBar.cpp haiku/trunk/src/preferences/menu/MenuBar.h haiku/trunk/src/preferences/menu/MenuSettings.cpp haiku/trunk/src/preferences/menu/MenuWindow.cpp haiku/trunk/src/preferences/menu/MenuWindow.h haiku/trunk/src/preferences/menu/msg.h Log: cleanups, updated copyrights Modified: haiku/trunk/src/preferences/menu/AutoSettingsMenu.cpp =================================================================== --- haiku/trunk/src/preferences/menu/AutoSettingsMenu.cpp 2007-05-03 17:29:43 UTC (rev 21000) +++ haiku/trunk/src/preferences/menu/AutoSettingsMenu.cpp 2007-05-03 20:05:47 UTC (rev 21001) @@ -3,7 +3,7 @@ * Distributed under the terms of the MIT License. * * Authors: - * + * Stefano Ceccherini (stefano.ceccherini at gmail.com) */ Modified: haiku/trunk/src/preferences/menu/AutoSettingsMenu.h =================================================================== --- haiku/trunk/src/preferences/menu/AutoSettingsMenu.h 2007-05-03 17:29:43 UTC (rev 21000) +++ haiku/trunk/src/preferences/menu/AutoSettingsMenu.h 2007-05-03 20:05:47 UTC (rev 21001) @@ -1,10 +1,11 @@ /* - * Copyright 2002-2006, Haiku Inc. All rights reserved. + * Copyright 2002-2007, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: - * + * Stefano Ceccherini (stefano.ceccherini at gmail.com) */ + #ifndef AUTO_SETTINGS_MENU_H #define AUTO_SETTINGS_MENU_H @@ -20,3 +21,4 @@ }; #endif // AUTO_SETTINGS_MENU_H + Modified: haiku/trunk/src/preferences/menu/BitmapMenuItem.cpp =================================================================== --- haiku/trunk/src/preferences/menu/BitmapMenuItem.cpp 2007-05-03 17:29:43 UTC (rev 21000) +++ haiku/trunk/src/preferences/menu/BitmapMenuItem.cpp 2007-05-03 20:05:47 UTC (rev 21001) @@ -1,9 +1,10 @@ /* - * Copyright 2002-2006, Haiku Inc. All rights reserved. + * Copyright 2002-2007, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * + * Stefano Ceccherini (stefano.ceccherini at gmail.com) */ @@ -15,7 +16,7 @@ // BitmapMenuItem class definition BitmapMenuItem::BitmapMenuItem(const char* name, BMessage* message, - BBitmap* bmp, char shortcut, uint32 modifiers) + BBitmap* bmp, char shortcut, uint32 modifiers) : BMenuItem(name, message, shortcut, modifiers), fBitmap(bmp), fName(name) Modified: haiku/trunk/src/preferences/menu/BitmapMenuItem.h =================================================================== --- haiku/trunk/src/preferences/menu/BitmapMenuItem.h 2007-05-03 17:29:43 UTC (rev 21000) +++ haiku/trunk/src/preferences/menu/BitmapMenuItem.h 2007-05-03 20:05:47 UTC (rev 21001) @@ -1,20 +1,19 @@ /* - * Copyright 2002-2006, Haiku Inc. All rights reserved. + * Copyright 2002-2007, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * + * Stefano Ceccherini (stefano.ceccherini at gmail.com) */ + #ifndef BITMAP_MENU_ITEM_H #define BITMAP_MENU_ITEM_H - #include #include class BBitmap; - - class BitmapMenuItem : public BMenuItem { public: BitmapMenuItem(const char* name, BMessage* message, BBitmap* bmp, Modified: haiku/trunk/src/preferences/menu/ColorWindow.cpp =================================================================== --- haiku/trunk/src/preferences/menu/ColorWindow.cpp 2007-05-03 17:29:43 UTC (rev 21000) +++ haiku/trunk/src/preferences/menu/ColorWindow.cpp 2007-05-03 20:05:47 UTC (rev 21001) @@ -59,11 +59,6 @@ } -ColorWindow::~ColorWindow() -{ -} - - void ColorWindow::Quit() { Modified: haiku/trunk/src/preferences/menu/ColorWindow.h =================================================================== --- haiku/trunk/src/preferences/menu/ColorWindow.h 2007-05-03 17:29:43 UTC (rev 21000) +++ haiku/trunk/src/preferences/menu/ColorWindow.h 2007-05-03 20:05:47 UTC (rev 21001) @@ -1,11 +1,13 @@ /* - * Copyright 2002-2006, Haiku Inc. All rights reserved. + * Copyright 2002-2007, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * + * Stefano Ceccherini (stefano.ceccherini at gmail.com) * Vasilis Kaoutsis, kaoutsis at sch.gr */ + #ifndef COLOR_WINDOW_H #define COLOR_WINDOW_H @@ -21,13 +23,12 @@ class ColorWindow : public BWindow { public: ColorWindow(BMessenger owner); - ~ColorWindow(); virtual void Quit(); virtual void MessageReceived(BMessage* message); private: - BColorControl* fColorControl; + BColorControl* fColorControl; BButton* fDefaultButton; BButton* fRevertButton; menu_info fRevertInfo; Modified: haiku/trunk/src/preferences/menu/FontMenu.cpp =================================================================== --- haiku/trunk/src/preferences/menu/FontMenu.cpp 2007-05-03 17:29:43 UTC (rev 21000) +++ haiku/trunk/src/preferences/menu/FontMenu.cpp 2007-05-03 20:05:47 UTC (rev 21001) @@ -1,9 +1,10 @@ /* - * Copyright 2002-2006, Haiku Inc. All rights reserved. + * Copyright 2002-2007, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * + * Stefano Ceccherini (stefano.ceccherini at gmail.com) */ @@ -14,9 +15,7 @@ #include #include -#include - FontMenu::FontMenu() : AutoSettingsMenu("Font", B_ITEMS_IN_COLUMN) { @@ -48,30 +47,32 @@ FontMenu::GetFonts() { int32 numFamilies = count_font_families(); - for ( int32 i = 0; i < numFamilies; i++ ) { - font_family *family = (font_family*)malloc(sizeof(font_family)); + for (int32 i = 0; i < numFamilies; i++) { + font_family family; uint32 flags; - if ( get_font_family(i, family, &flags) == B_OK ) { - BMenu *fontStyleMenu = new BMenu(*family, B_ITEMS_IN_COLUMN); + if (get_font_family(i, &family, &flags) == B_OK) { + BMenu *fontStyleMenu = new BMenu(family, B_ITEMS_IN_COLUMN); fontStyleMenu->SetRadioMode(true); - int32 numStyles = count_font_styles(*family); - for ( int32 j = 0; j < numStyles; j++ ) { - font_style *style = (font_style*)malloc(sizeof(font_style)); - if ( get_font_style(*family, j, style, &flags) == B_OK ) { + int32 numStyles = count_font_styles(family); + for (int32 j = 0; j < numStyles; j++) { + font_style style; + if (get_font_style(family, j, &style, &flags) == B_OK) { BMessage *msg = new BMessage(MENU_FONT_STYLE); - msg->AddPointer("family", family); - msg->AddPointer("style", style); - BMenuItem *fontStyleItem = new BMenuItem(*style, msg, 0, 0); + msg->AddString("family", family); + msg->AddString("style", style); + BMenuItem *fontStyleItem = new BMenuItem(style, msg); fontStyleMenu->AddItem(fontStyleItem); } } + BMessage *msg = new BMessage(MENU_FONT_FAMILY); - msg->AddPointer("family", family); - font_style *style = (font_style*)malloc(sizeof(font_style)); + msg->AddString("family", family); + // if font family selected, we need to change style to // first style - if ( get_font_style(*family, 0, style, &flags) == B_OK ) - msg->AddPointer("style", style); + font_style style; + if (get_font_style(family, 0, &style, &flags) == B_OK) + msg->AddString("style", style); BMenuItem *fontFamily = new BMenuItem(fontStyleMenu, msg); AddItem(fontFamily); } Modified: haiku/trunk/src/preferences/menu/FontSizeMenu.cpp =================================================================== --- haiku/trunk/src/preferences/menu/FontSizeMenu.cpp 2007-05-03 17:29:43 UTC (rev 21000) +++ haiku/trunk/src/preferences/menu/FontSizeMenu.cpp 2007-05-03 20:05:47 UTC (rev 21001) @@ -1,9 +1,10 @@ /* - * Copyright 2002-2006, Haiku Inc. All rights reserved. + * Copyright 2002-2007, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * + * Stefano Ceccherini (stefano.ceccherini at gmail.com) */ @@ -69,3 +70,4 @@ item->SetMarked(true); } + Modified: haiku/trunk/src/preferences/menu/MenuApp.cpp =================================================================== --- haiku/trunk/src/preferences/menu/MenuApp.cpp 2007-05-03 17:29:43 UTC (rev 21000) +++ haiku/trunk/src/preferences/menu/MenuApp.cpp 2007-05-03 20:05:47 UTC (rev 21001) @@ -1,10 +1,10 @@ /* - * Copyright 2002-2006, Haiku Inc. All rights reserved. + * Copyright 2002-2007, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * - * Jack Burton + * Stefano Ceccherini (stefano.ceccherini at gmail.com) * Vasilis Kaoutsis, kaoutsis at sch.gr */ Modified: haiku/trunk/src/preferences/menu/MenuApp.h =================================================================== --- haiku/trunk/src/preferences/menu/MenuApp.h 2007-05-03 17:29:43 UTC (rev 21000) +++ haiku/trunk/src/preferences/menu/MenuApp.h 2007-05-03 20:05:47 UTC (rev 21001) @@ -4,7 +4,7 @@ * * Authors: * - * Jack Burton + * Stefano Ceccherini (stefano.ceccherini at gmail.com) */ #ifndef MENU_APP_H #define MENU_APP_H Modified: haiku/trunk/src/preferences/menu/MenuBar.cpp =================================================================== --- haiku/trunk/src/preferences/menu/MenuBar.cpp 2007-05-03 17:29:43 UTC (rev 21000) +++ haiku/trunk/src/preferences/menu/MenuBar.cpp 2007-05-03 20:05:47 UTC (rev 21001) @@ -1,9 +1,10 @@ /* - * Copyright 2002-2006, Haiku Inc. All rights reserved. + * Copyright 2002-2007, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * + * Stefano Ceccherini (stefano.ceccherini at gmail.com) * Vasilis Kaoutsis, kaoutsis at sch.gr */ Modified: haiku/trunk/src/preferences/menu/MenuBar.h =================================================================== --- haiku/trunk/src/preferences/menu/MenuBar.h 2007-05-03 17:29:43 UTC (rev 21000) +++ haiku/trunk/src/preferences/menu/MenuBar.h 2007-05-03 20:05:47 UTC (rev 21001) @@ -1,9 +1,10 @@ /* - * Copyright 2002-2006, Haiku Inc. All rights reserved. + * Copyright 2002-2007, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * + * Stefano Ceccherini (stefano.ceccherini at gmail.com) */ #ifndef MENU_BAR_H #define MENU_BAR_H @@ -12,8 +13,6 @@ #include class BMenuItem; - - class MenuBar : public BMenuBar { public: MenuBar(); Modified: haiku/trunk/src/preferences/menu/MenuSettings.cpp =================================================================== --- haiku/trunk/src/preferences/menu/MenuSettings.cpp 2007-05-03 17:29:43 UTC (rev 21000) +++ haiku/trunk/src/preferences/menu/MenuSettings.cpp 2007-05-03 20:05:47 UTC (rev 21001) @@ -1,9 +1,10 @@ /* - * Copyright 2002-2006, Haiku Inc. All rights reserved. + * Copyright 2002-2007, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * + * Stefano Ceccherini (stefano.ceccherini at gmail.com) */ Modified: haiku/trunk/src/preferences/menu/MenuWindow.cpp =================================================================== --- haiku/trunk/src/preferences/menu/MenuWindow.cpp 2007-05-03 17:29:43 UTC (rev 21000) +++ haiku/trunk/src/preferences/menu/MenuWindow.cpp 2007-05-03 20:05:47 UTC (rev 21001) @@ -1,9 +1,10 @@ /* - * Copyright 2002-2006, Haiku Inc. All rights reserved. + * Copyright 2002-2007, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * + * Stefano Ceccherini (stefano.ceccherini at gmail.com) * Vasilis Kaoutsis, kaoutsis at sch.gr */ @@ -64,11 +65,6 @@ } -MenuWindow::~MenuWindow() -{ -} - - void MenuWindow::MessageReceived(BMessage *msg) { @@ -96,13 +92,14 @@ case MENU_FONT_STYLE: { fRevert = true; - font_family *family; - msg->FindPointer("family", (void**)&family); - font_style *style; - msg->FindPointer("style", (void**)&style); + const font_family *family; + msg->FindString("family", (const char **)&family); + const font_style *style; + msg->FindString("style", (const char **)&style); + settings->Get(info); - memcpy(info.f_family, family, sizeof(info.f_family)); - memcpy(info.f_style, style, sizeof(info.f_style)); + strlcpy(info.f_family, (const char *)family, B_FONT_FAMILY_LENGTH); + strlcpy(info.f_style, (const char *)style, B_FONT_STYLE_LENGTH); settings->Set(info); Update(); break; @@ -116,14 +113,6 @@ Update(); break; - case MENU_SEP_TYPE: - fRevert = true; - settings->Get(info); - msg->FindInt32("sep", &info.separator); - settings->Set(info); - Update(); - break; - case ALLWAYS_TRIGGERS_MSG: fRevert = true; settings->Get(info); Modified: haiku/trunk/src/preferences/menu/MenuWindow.h =================================================================== --- haiku/trunk/src/preferences/menu/MenuWindow.h 2007-05-03 17:29:43 UTC (rev 21000) +++ haiku/trunk/src/preferences/menu/MenuWindow.h 2007-05-03 20:05:47 UTC (rev 21001) @@ -1,10 +1,12 @@ /* - * Copyright 2002-2006, Haiku Inc. All rights reserved. + * Copyright 2002-2007, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * + * Stefano Ceccherini (stefano.ceccherini at gmail.com) */ + #ifndef MENU_WINDOW_H #define MENU_WINDOW_H @@ -16,13 +18,10 @@ class ColorWindow; class BButton; class MenuBar; - - class MenuWindow : public BWindow { public: MenuWindow(BRect frame); - virtual ~MenuWindow(); - + virtual void MessageReceived(BMessage *message); virtual bool QuitRequested(); Modified: haiku/trunk/src/preferences/menu/msg.h =================================================================== --- haiku/trunk/src/preferences/menu/msg.h 2007-05-03 17:29:43 UTC (rev 21000) +++ haiku/trunk/src/preferences/menu/msg.h 2007-05-03 20:05:47 UTC (rev 21001) @@ -35,7 +35,5 @@ const uint32 MENU_FONT_STYLE = 'mfst'; const uint32 MENU_FONT_SIZE = 'mfsz'; -// seperator -const uint32 MENU_SEP_TYPE = 'mstp'; #endif // MESSAGES_H From korli at mail.berlios.de Thu May 3 22:29:06 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Thu, 3 May 2007 22:29:06 +0200 Subject: [Haiku-commits] r21002 - haiku/trunk/src/add-ons/opengl/mesa_software_renderer Message-ID: <200705032029.l43KT6TK017082@sheep.berlios.de> Author: korli Date: 2007-05-03 22:29:05 +0200 (Thu, 03 May 2007) New Revision: 21002 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21002&view=rev Modified: haiku/trunk/src/add-ons/opengl/mesa_software_renderer/Jamfile haiku/trunk/src/add-ons/opengl/mesa_software_renderer/MesaSoftwareRenderer.cpp Log: added support for B_RGB32 Modified: haiku/trunk/src/add-ons/opengl/mesa_software_renderer/Jamfile =================================================================== --- haiku/trunk/src/add-ons/opengl/mesa_software_renderer/Jamfile 2007-05-03 20:05:47 UTC (rev 21001) +++ haiku/trunk/src/add-ons/opengl/mesa_software_renderer/Jamfile 2007-05-03 20:29:05 UTC (rev 21002) @@ -37,5 +37,5 @@ Addon Mesa\ Software\ Renderer : MesaSoftwareRenderer.cpp - : libGL.so libmesa.a be + : libGL.so libmesa.a /system/lib/libbe.so ; Modified: haiku/trunk/src/add-ons/opengl/mesa_software_renderer/MesaSoftwareRenderer.cpp =================================================================== --- haiku/trunk/src/add-ons/opengl/mesa_software_renderer/MesaSoftwareRenderer.cpp 2007-05-03 20:05:47 UTC (rev 21001) +++ haiku/trunk/src/add-ons/opengl/mesa_software_renderer/MesaSoftwareRenderer.cpp 2007-05-03 20:29:05 UTC (rev 21002) @@ -78,8 +78,8 @@ /***** Read/write spans/arrays of pixels *****/ /**********************************************************************/ -/* 8-bit RGBA */ -#define NAME(PREFIX) PREFIX##_RGBA8 +/* 32-bit RGBA */ +#define NAME(PREFIX) PREFIX##_RGBA32 #define RB_TYPE GLubyte #define SPAN_VARS \ MesaSoftwareRenderer *mr = (MesaSoftwareRenderer *) ctx->DriverCtx; @@ -103,6 +103,25 @@ DST[ACOMP] = SRC[BE_ACOMP] #include "swrast/s_spantemp.h" +/* 32-bit RGB */ +#define NAME(PREFIX) PREFIX##_RGB32 +#define RB_TYPE GLubyte +#define SPAN_VARS \ + MesaSoftwareRenderer *mr = (MesaSoftwareRenderer *) ctx->DriverCtx; +#define INIT_PIXEL_PTR(P, X, Y) \ + GLuint *P = (GLuint *)(((GLubyte **) mr->GetRows())[Y] + (X) * 4) +#define INC_PIXEL_PTR(P) P += 1 +#define STORE_PIXEL(DST, X, Y, VALUE) \ + *DST = ( ((VALUE[RCOMP]) << 16) | \ + ((VALUE[GCOMP]) << 8) | \ + ((VALUE[BCOMP]) ) ) +#define FETCH_PIXEL(DST, SRC) \ + DST[RCOMP] = ((*SRC & 0x00ff0000) >> 16); \ + DST[GCOMP] = ((*SRC & 0x0000ff00) >> 8); \ + DST[BCOMP] = ((*SRC & 0x000000ff)); \ + DST[ACOMP] = 0xff; +#include "swrast/s_spantemp.h" + /* 16-bit RGB */ #define NAME(PREFIX) PREFIX##_RGB16 #define RB_TYPE GLubyte @@ -285,14 +304,23 @@ if (cs != fColorSpace) { switch (cs) { case B_RGBA32: - fRenderBuffer->GetRow = get_row_RGBA8; - fRenderBuffer->GetValues = get_values_RGBA8; - fRenderBuffer->PutRow = put_row_RGBA8; - fRenderBuffer->PutRowRGB = put_row_rgb_RGBA8; - fRenderBuffer->PutMonoRow = put_mono_row_RGBA8; - fRenderBuffer->PutValues = put_values_RGBA8; - fRenderBuffer->PutMonoValues = put_mono_values_RGBA8; + fRenderBuffer->GetRow = get_row_RGBA32; + fRenderBuffer->GetValues = get_values_RGBA32; + fRenderBuffer->PutRow = put_row_RGBA32; + fRenderBuffer->PutRowRGB = put_row_rgb_RGBA32; + fRenderBuffer->PutMonoRow = put_mono_row_RGBA32; + fRenderBuffer->PutValues = put_values_RGBA32; + fRenderBuffer->PutMonoValues = put_mono_values_RGBA32; break; + case B_RGB32: + fRenderBuffer->GetRow = get_row_RGB32; + fRenderBuffer->GetValues = get_values_RGB32; + fRenderBuffer->PutRow = put_row_RGB32; + fRenderBuffer->PutRowRGB = put_row_rgb_RGB32; + fRenderBuffer->PutMonoRow = put_mono_row_RGB32; + fRenderBuffer->PutValues = put_values_RGB32; + fRenderBuffer->PutMonoValues = put_mono_values_RGB32; + break; case B_RGB16: fRenderBuffer->GetRow = get_row_RGB16; fRenderBuffer->GetValues = get_values_RGB16; @@ -303,6 +331,7 @@ fRenderBuffer->PutMonoValues = put_mono_values_RGB16; break; default: + fprintf(stderr, "unsupported screen color space %ld\n", cs); debugger("unsupported OpenGL color space"); break; } From korli at mail.berlios.de Thu May 3 22:30:11 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Thu, 3 May 2007 22:30:11 +0200 Subject: [Haiku-commits] r21003 - haiku/trunk/src/add-ons/opengl/mesa_software_renderer Message-ID: <200705032030.l43KUBd6017221@sheep.berlios.de> Author: korli Date: 2007-05-03 22:30:11 +0200 (Thu, 03 May 2007) New Revision: 21003 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21003&view=rev Modified: haiku/trunk/src/add-ons/opengl/mesa_software_renderer/MesaSoftwareRenderer.cpp Log: clean up Modified: haiku/trunk/src/add-ons/opengl/mesa_software_renderer/MesaSoftwareRenderer.cpp =================================================================== --- haiku/trunk/src/add-ons/opengl/mesa_software_renderer/MesaSoftwareRenderer.cpp 2007-05-03 20:29:05 UTC (rev 21002) +++ haiku/trunk/src/add-ons/opengl/mesa_software_renderer/MesaSoftwareRenderer.cpp 2007-05-03 20:30:11 UTC (rev 21003) @@ -226,27 +226,6 @@ fRenderBuffer->Data = NULL; fRenderBuffer->AllocStorage = RenderbufferStorage; - /*switch (fColorSpace) { - case B_RGBA32: - fRenderBuffer->GetRow = get_row_RGBA8; - fRenderBuffer->GetValues = get_values_RGBA8; - fRenderBuffer->PutRow = put_row_RGBA8; - fRenderBuffer->PutRowRGB = put_row_rgb_RGBA8; - fRenderBuffer->PutMonoRow = put_mono_row_RGBA8; - fRenderBuffer->PutValues = put_values_RGBA8; - fRenderBuffer->PutMonoValues = put_mono_values_RGBA8; - break; - case B_RGB16: - fRenderBuffer->GetRow = get_row_RGB16; - fRenderBuffer->GetValues = get_values_RGB16; - fRenderBuffer->PutRow = put_row_RGB16; - fRenderBuffer->PutRowRGB = put_row_rgb_RGB16; - fRenderBuffer->PutMonoRow = put_mono_row_RGB16; - fRenderBuffer->PutValues = put_values_RGB16; - fRenderBuffer->PutMonoValues = put_mono_values_RGB16; - break; - }*/ - _mesa_add_renderbuffer(fFrameBuffer, BUFFER_FRONT_LEFT, fRenderBuffer); _mesa_add_soft_renderbuffers(fFrameBuffer, From mmu_man at mail.berlios.de Thu May 3 22:38:10 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Thu, 3 May 2007 22:38:10 +0200 Subject: [Haiku-commits] r21004 - haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd Message-ID: <200705032038.l43KcAZc017661@sheep.berlios.de> Author: mmu_man Date: 2007-05-03 22:38:09 +0200 (Thu, 03 May 2007) New Revision: 21004 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21004&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c Log: Only publish configured devices. Implemented write(). Not sure it works as it KDLs here on shutdown :^) Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-03 20:30:11 UTC (rev 21003) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-03 20:38:09 UTC (rev 21004) @@ -403,6 +403,13 @@ err = ksend(dev->sock, &req->req, sizeof(req->req), 0); if (err < 0) return err; + + if (req->type == NBD_CMD_WRITE) + err = ksend(dev->sock, req->buffer, req->len, 0); + if (err < 0) + return err; + else + req->len = err; err = nbd_queue_request(dev, req); return err; @@ -546,7 +553,7 @@ geom->head_count = 1; geom->device_type = B_DISK; geom->removable = false; - geom->read_only = false; // XXX + geom->read_only = cookie->dev->readonly; geom->write_once = false; return B_OK; } @@ -617,10 +624,11 @@ if (semerr == B_OK) { *numbytes = req->len; memcpy(data, req->buffer, req->len); + err = B_OK; + if (*numbytes == 0 && req->reply.error) + err = EIO; nbd_free_request(dev, req); - if (*numbytes == 0 && req->reply.error) - return B_ERROR; - return B_OK; + return err; } *numbytes = 0; @@ -637,15 +645,79 @@ } status_t nbd_write(cookie_t *cookie, off_t position, const void *data, size_t *numbytes) { - PRINT((DP ">%s(%d, %Ld, , )\n", __FUNCTION__, WHICH(cookie->dev), position)); - (void)cookie; (void)position; (void)data; (void)numbytes; + struct nbd_device *dev = cookie->dev; + struct nbd_request_entry *req; + status_t err, semerr; + PRINT((DP ">%s(%d, %Ld, %ld, )\n", __FUNCTION__, WHICH(cookie->dev), position, *numbytes)); + + if (position < 0) + return EINVAL; + if (!data) + return EINVAL; + err = B_NOT_ALLOWED; + if (dev->readonly) + goto err0; + + err = nbd_alloc_request(dev, &req, NBD_CMD_WRITE, position, *numbytes, data); + if (err) + goto err0; + + //LOCK + err = benaphore_lock(&dev->ben); + if (err) + goto err1; + + /* sending request+data must be atomic */ + err = nbd_post_request(dev, req); + + //UNLOCK + benaphore_unlock(&dev->ben); + + if (err) + goto err2; + + + semerr = acquire_sem(req->sem); + + //LOCK + err = benaphore_lock(&dev->ben); + if(err) + goto err3; + + /* bad scenarii */ + if (!req->replied) + req->discard = true; + else if (semerr) + nbd_free_request(dev, req); + + //UNLOCK + benaphore_unlock(&dev->ben); + + if (semerr == B_OK) { + *numbytes = req->len; + err = B_OK; + if (*numbytes == 0 && req->reply.error) + err = EIO; + nbd_free_request(dev, req); + return err; + } + *numbytes = 0; - return EIO; + return semerr; + + +err3: +err2: +err1: + nbd_free_request(dev, req); +err0: + *numbytes = 0; + return err; } device_hooks nbd_hooks={ (device_open_hook)nbd_open, - nbd_close, + (device_close_hook)nbd_close, (device_free_hook)nbd_free, (device_control_hook)nbd_control, (device_read_hook)nbd_read, @@ -659,7 +731,7 @@ #pragma mark ==== driver hooks ==== -static const char *nbd_name[MAX_NBDS+1] = { +static char *nbd_name[MAX_NBDS+1] = { NULL }; @@ -677,6 +749,7 @@ int i, j; // XXX: load settings void *handle; + char **names = nbd_name; PRINT((DP ">%s()\n", __FUNCTION__)); handle = load_driver_settings(DRV); @@ -704,16 +777,12 @@ #ifdef MOUNT_KLUDGE nbd_devices[i].kludge = -1; #endif - nbd_name[i] = malloc(DEVICE_NAME_MAX); - if (nbd_name[i] == NULL) - break; - sprintf(nbd_name[i], DEVICE_FMT, i); + nbd_name[i] = NULL; } - nbd_name[i] = NULL; for (i = 0; i < MAX_NBDS; i++) { - driver_settings *settings = get_driver_settings(handle); - driver_parameter *p; + const driver_settings *settings = get_driver_settings(handle); + driver_parameter *p = NULL; char keyname[10]; char *v; sprintf(keyname, "%d", i); @@ -732,11 +801,16 @@ nbd_devices[i].server.sin_family = AF_INET; kinet_aton(p->parameters[j].values[0], &nbd_devices[i].server.sin_addr); nbd_devices[i].server.sin_port = htons(atoi(p->parameters[j].values[1])); - + dprintf(DP " configured [%d]\n", i); + *(names) = malloc(DEVICE_NAME_MAX); + if (*(names) == NULL) + return ENOMEM; + sprintf(*(names++), DEVICE_FMT, i); nbd_devices[i].valid = true; } } } + *names = NULL; unload_driver_settings(handle); return B_OK; @@ -762,7 +836,7 @@ publish_devices() { PRINT((DP ">%s()\n", __FUNCTION__)); - return nbd_name; + return (const char **)nbd_name; } device_hooks* @@ -778,7 +852,9 @@ int i; PRINT((DP ">%s(%s)\n", __FUNCTION__, name)); for (i = 0; i < MAX_NBDS; i++) { - if (!strcmp(nbd_name[i], name)) + char buf[DEVICE_NAME_MAX]; + sprintf(buf, DEVICE_FMT, i); + if (!strcmp(buf, name)) return &nbd_devices[i]; } return NULL; From stefano.ceccherini at gmail.com Thu May 3 22:45:48 2007 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Thu, 3 May 2007 22:45:48 +0200 Subject: [Haiku-commits] r21002 - haiku/trunk/src/add-ons/opengl/mesa_software_renderer In-Reply-To: <200705032029.l43KT6TK017082@sheep.berlios.de> References: <200705032029.l43KT6TK017082@sheep.berlios.de> Message-ID: <894b9700705031345i7be289b3jda81a475c71b37a1@mail.gmail.com> 2007/5/3, korli at BerliOS : > Author: korli > Date: 2007-05-03 22:29:05 +0200 (Thu, 03 May 2007) > New Revision: 21002 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21002&view=rev > > Modified: > haiku/trunk/src/add-ons/opengl/mesa_software_renderer/Jamfile > haiku/trunk/src/add-ons/opengl/mesa_software_renderer/MesaSoftwareRenderer.cpp > Log: > added support for B_RGB32 > > > Modified: haiku/trunk/src/add-ons/opengl/mesa_software_renderer/Jamfile > =================================================================== > --- haiku/trunk/src/add-ons/opengl/mesa_software_renderer/Jamfile 2007-05-03 20:05:47 UTC (rev 21001) > +++ haiku/trunk/src/add-ons/opengl/mesa_software_renderer/Jamfile 2007-05-03 20:29:05 UTC (rev 21002) > @@ -37,5 +37,5 @@ > > Addon Mesa\ Software\ Renderer : > MesaSoftwareRenderer.cpp > - : libGL.so libmesa.a be > + : libGL.so libmesa.a /system/lib/libbe.so > ; > Korli, I guess this is a typo ? since it breaks the build on non beos systems... From hugosantos at gmail.com Thu May 3 23:17:49 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Thu, 3 May 2007 22:17:49 +0100 Subject: [Haiku-commits] r21004 - haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd In-Reply-To: <200705032038.l43KcAZc017661@sheep.berlios.de> References: <200705032038.l43KcAZc017661@sheep.berlios.de> Message-ID: <9c46321e0705031417q15a74874i4a880aeced862642@mail.gmail.com> > Implemented write(). Not sure it works as it KDLs here on shutdown :^) In Haiku? What is the ticket number? Hugo From mmu_man at mail.berlios.de Thu May 3 23:18:46 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Thu, 3 May 2007 23:18:46 +0200 Subject: [Haiku-commits] r21005 - haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd Message-ID: <200705032118.l43LIkaa024609@sheep.berlios.de> Author: mmu_man Date: 2007-05-03 23:18:45 +0200 (Thu, 03 May 2007) New Revision: 21005 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21005&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/Jamfile haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c Log: Fix building in Haiku Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/Jamfile 2007-05-03 20:38:09 UTC (rev 21004) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/Jamfile 2007-05-03 21:18:45 UTC (rev 21005) @@ -2,15 +2,16 @@ SetSubDirSupportedPlatformsBeOSCompatible ; -#if $(TARGET_PLATFORM) != haiku { -# # Needed for . Unfortunately we also get the other headers there, -# # that we don't really want. -# UsePublicHeaders drivers ; -#} - # not Haiku-specific, ksocket.h also works in BONE. UsePrivateHeaders drivers ; +if $(TARGET_PLATFORM) = haiku { + # lock.h wants debug.h and others. + #UsePrivateHeaders kernel ; + #UsePublicHeaders kernel ; + UsePrivateHeaders [ FDirName kernel ] ; +} + KernelAddon nbd : nbd.c ; Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-03 20:38:09 UTC (rev 21004) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-03 21:18:45 UTC (rev 21005) @@ -9,10 +9,12 @@ * Maps a Network Block Device as virtual partitions. */ +#include #include #include +#include #include -#include +#include #include #include @@ -24,6 +26,12 @@ */ //#define MOUNT_KLUDGE + +/* names, ohh names... */ +#ifndef SHUT_RDWR +#define SHUT_RDWR SHUTDOWN_BOTH +#endif + /* locking support */ #ifdef __HAIKU__ #include @@ -388,7 +396,7 @@ { status_t err, ret; PRINT((DP ">%s()\n", __FUNCTION__)); - kshutdown(dev->sock, SHUTDOWN_BOTH); + kshutdown(dev->sock, SHUT_RDWR); kclosesocket(dev->sock); dev->sock = -1; err = wait_for_thread(dev->postoffice, &ret); @@ -784,7 +792,6 @@ const driver_settings *settings = get_driver_settings(handle); driver_parameter *p = NULL; char keyname[10]; - char *v; sprintf(keyname, "%d", i); for (j = 0; j < settings->parameter_count; j++) if (!strcmp(settings->parameters[j].name, keyname)) @@ -824,7 +831,7 @@ PRINT((DP ">%s()\n", __FUNCTION__)); for (i = 0; i < MAX_NBDS; i++) { free(nbd_name[i]); - err = benaphore_destroy(&nbd_devices[i].ben); + benaphore_destroy(&nbd_devices[i].ben); } err = ksocket_cleanup(); /* HACK */ From hugosantos at mail.berlios.de Thu May 3 23:19:29 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Thu, 3 May 2007 23:19:29 +0200 Subject: [Haiku-commits] r21006 - in haiku/trunk: headers/private/net src/libs/compat/freebsd_network src/libs/compat/freebsd_network/compat/sys Message-ID: <200705032119.l43LJTpH024637@sheep.berlios.de> Author: hugosantos Date: 2007-05-03 23:18:21 +0200 (Thu, 03 May 2007) New Revision: 21006 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21006&view=rev Added: haiku/trunk/src/libs/compat/freebsd_network/callout.c haiku/trunk/src/libs/compat/freebsd_network/mii.c Modified: haiku/trunk/headers/private/net/net_stack.h haiku/trunk/src/libs/compat/freebsd_network/Jamfile haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/compat/sys/callout.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mutex.h haiku/trunk/src/libs/compat/freebsd_network/device.h haiku/trunk/src/libs/compat/freebsd_network/mbuf.c haiku/trunk/src/libs/compat/freebsd_network/mutex.c Log: freebsd compat. layer: added mii placeholders, callout implementation. Modified: haiku/trunk/headers/private/net/net_stack.h =================================================================== --- haiku/trunk/headers/private/net/net_stack.h 2007-05-03 21:18:45 UTC (rev 21005) +++ haiku/trunk/headers/private/net/net_stack.h 2007-05-03 21:18:21 UTC (rev 21006) @@ -14,6 +14,16 @@ #define NET_STACK_MODULE_NAME "network/stack/v1" + +struct net_address_module_info; +struct net_protocol_module_info; + +struct net_buffer; +struct net_device; +struct net_domain; +struct net_socket; +struct net_timer; + struct net_fifo { benaphore lock; sem_id notify; Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-03 21:18:45 UTC (rev 21005) +++ haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-03 21:18:21 UTC (rev 21006) @@ -10,10 +10,12 @@ Library libfreebsd_network.a : bus.c busdma_machdep.c + callout.c compat.c device.c if.c if_media.c mbuf.c + mii.c mutex.c ; Added: haiku/trunk/src/libs/compat/freebsd_network/callout.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/callout.c 2007-05-03 21:18:45 UTC (rev 21005) +++ haiku/trunk/src/libs/compat/freebsd_network/callout.c 2007-05-03 21:18:21 UTC (rev 21006) @@ -0,0 +1,64 @@ +/* + * Copyright 2007, Hugo Santos. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Hugo Santos, hugosantos at gmail.com + */ + +#include "device.h" + +#include + + +static void +handle_callout(struct net_timer *timer, void *data) +{ + struct callout *c = data; + struct mtx *c_mtx = c->c_mtx; + + if (c_mtx) + mtx_lock(c_mtx); + + /* FreeBSD 6.2 uses THREAD_NO_SLEEPING/THREAD_SLEEPING_OK when calling the + * callback */ + + c->c_func(c->c_arg); + + if (c_mtx) + mtx_unlock(c_mtx); +} + + +void +callout_init_mtx(struct callout *c, struct mtx *mtx, int flags) +{ + gStack->init_timer(&c->c_timer, handle_callout, c); + + c->c_arg = NULL; + c->c_func = NULL; + c->c_mtx = mtx; + c->c_flags = flags; +} + + +int +callout_reset(struct callout *c, int when, void (*func)(void *), void *arg) +{ + int canceled = gStack->cancel_timer(&c->c_timer) ? 1 : 0; + + c->c_func = func; + c->c_arg = arg; + + gStack->set_timer(&c->c_timer, when); + + return canceled; +} + + +int +_callout_stop_safe(struct callout *c, int safe) +{ + return gStack->cancel_timer(&c->c_timer) ? 1 : 0; +} + Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/callout.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/callout.h 2007-05-03 21:18:45 UTC (rev 21005) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/callout.h 2007-05-03 21:18:21 UTC (rev 21006) @@ -1,90 +1,36 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)callout.h 8.2 (Berkeley) 1/21/94 - * $FreeBSD: src/sys/sys/callout.h,v 1.28.2.1 2005/09/12 13:43:34 glebius Exp $ - */ +#ifndef _FBSD_COMPAT_SYS_CALLOUT_H_ +#define _FBSD_COMPAT_SYS_CALLOUT_H_ -#ifndef _SYS_CALLOUT_H_ -#define _SYS_CALLOUT_H_ +#include +#include #include -struct mtx; -SLIST_HEAD(callout_list, callout); -TAILQ_HEAD(callout_tailq, callout); - struct callout { - union { - SLIST_ENTRY(callout) sle; - TAILQ_ENTRY(callout) tqe; - } c_links; - int c_time; /* ticks to the event */ - void *c_arg; /* function argument */ - void (*c_func)(void *); /* function to call */ - struct mtx *c_mtx; /* mutex to lock */ - int c_flags; /* state of this entry */ + struct net_timer c_timer; + void * c_arg; + void (*c_func)(void *); + struct mtx * c_mtx; + int c_flags; }; -#define CALLOUT_LOCAL_ALLOC 0x0001 /* was allocated from callfree */ -#define CALLOUT_ACTIVE 0x0002 /* callout is currently active */ -#define CALLOUT_PENDING 0x0004 /* callout is waiting for timeout */ -#define CALLOUT_MPSAFE 0x0008 /* callout handler is mp safe */ -#define CALLOUT_RETURNUNLOCKED 0x0010 /* handler returns with mtx unlocked */ -struct callout_handle { - struct callout *callout; -}; +void callout_init_mtx(struct callout *, struct mtx *, int); +int callout_reset(struct callout *, int, void (*)(void *), void *); -#ifdef _KERNEL -extern struct callout_list callfree; -extern struct callout *callout; -extern int ncallout; -extern struct callout_tailq *callwheel; -extern int callwheelsize, callwheelbits, callwheelmask, softticks; -extern struct mtx callout_lock; - -#define callout_active(c) ((c)->c_flags & CALLOUT_ACTIVE) -#define callout_deactivate(c) ((c)->c_flags &= ~CALLOUT_ACTIVE) #define callout_drain(c) _callout_stop_safe(c, 1) -void callout_init(struct callout *, int); -void callout_init_mtx(struct callout *, struct mtx *, int); -#define callout_pending(c) ((c)->c_flags & CALLOUT_PENDING) -int callout_reset(struct callout *, int, void (*)(void *), void *); #define callout_stop(c) _callout_stop_safe(c, 0) int _callout_stop_safe(struct callout *, int); -#endif -#endif /* _SYS_CALLOUT_H_ */ +static inline void +callout_init(struct callout *c, int mpsafe) +{ + if (mpsafe) + callout_init_mtx(c, NULL, 0); + else + callout_init_mtx(c, &Giant, 0); +} + +#endif Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h 2007-05-03 21:18:45 UTC (rev 21005) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h 2007-05-03 21:18:21 UTC (rev 21006) @@ -4,15 +4,15 @@ #include #include -#define MLEN (MSIZE - sizeof(struct m_hdr)) -#define MHLEN (MSIZE - sizeof(struct pkthdr)) +#define MLEN ((int)(MSIZE - sizeof(struct m_hdr))) +#define MHLEN ((int)(MSIZE - sizeof(struct pkthdr))) #ifdef _KERNEL struct m_hdr { struct mbuf * mh_next; struct mbuf * mh_nextpkt; - void * mh_data; + caddr_t mh_data; int mh_len; int mh_flags; short mh_type; @@ -28,6 +28,7 @@ struct m_ext { void * ext_buf; unsigned int ext_size; + int ext_type; }; struct mbuf { @@ -66,6 +67,9 @@ #define M_EXT 0x0001 #define M_PKTHDR 0x0002 +#define EXT_CLUSTER 1 +#define EXT_PACKET 3 + #define M_BCAST 0x0200 #define M_MCAST 0x0400 @@ -80,8 +84,17 @@ struct mbuf *m_getcl(int how, short type, int flags); void m_freem(struct mbuf *mbuf); +struct mbuf *m_free(struct mbuf *m); struct mbuf *m_defrag(struct mbuf *m, int); +u_int m_length(struct mbuf *m, struct mbuf **last); +u_int m_fixhdr(struct mbuf *m); +void m_cat(struct mbuf *m, struct mbuf *n); +void m_copydata(const struct mbuf *m, int off, int len, caddr_t cp); + +struct mbuf *m_get(int how, short type); +struct mbuf *m_gethdr(int how, short type); + #define mtod(m, type) (type)((m)->m_data) /* Check if the supplied mbuf has a packet header, or else panic. */ Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mutex.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mutex.h 2007-05-03 21:18:45 UTC (rev 21005) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mutex.h 2007-05-03 21:18:21 UTC (rev 21006) @@ -46,6 +46,6 @@ void mtx_init(struct mtx *m, const char *name, const char *type, int opts); void mtx_destroy(struct mtx *m); -extern struct mutex Giant; +extern struct mtx Giant; #endif Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-03 21:18:45 UTC (rev 21005) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-03 21:18:21 UTC (rev 21006) @@ -21,6 +21,7 @@ status_t init_compat_layer(void); +struct net_stack_module_info *gStack; pci_module_info *gPci; uint32_t @@ -144,6 +145,13 @@ int +device_delete_child(device_t dev, device_t child) +{ + return -1; +} + + +int printf(const char *format, ...) { char buf[256]; @@ -222,6 +230,7 @@ } module_dependency module_dependencies[] = { + {NET_STACK_MODULE_NAME, (module_info **)&gStack}, {B_PCI_MODULE_NAME, (module_info **)&gPci}, {} }; Modified: haiku/trunk/src/libs/compat/freebsd_network/device.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-03 21:18:45 UTC (rev 21005) +++ haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-03 21:18:21 UTC (rev 21006) @@ -15,6 +15,8 @@ #include #include +#include + #include #include #include @@ -45,6 +47,7 @@ }; +extern struct net_stack_module_info *gStack; extern pci_module_info *gPci; #endif Modified: haiku/trunk/src/libs/compat/freebsd_network/mbuf.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/mbuf.c 2007-05-03 21:18:45 UTC (rev 21005) +++ haiku/trunk/src/libs/compat/freebsd_network/mbuf.c 2007-05-03 21:18:21 UTC (rev 21006) @@ -6,14 +6,22 @@ * Hugo Santos, hugosantos at gmail.com * * Some of this code is based on previous work by Marcus Overhagen. + * + * `m_defrag' and friends are straight from FreeBSD 6.2. */ #include +#include #include #include +#include +#define MBUF_CHECKSLEEP(how) do { } while (0) +#define MBTOM(how) (how) + + status_t init_mbufs(void); void uninit_mbufs(void); @@ -24,7 +32,17 @@ static object_cache *sChunkCache; -static void +static int +m_to_oc_flags(int how) +{ + if (how & M_NOWAIT) + return CACHE_DONT_SLEEP; + + return 0; +} + + +static int construct_mbuf(struct mbuf *mb, short type, int flags) { mb->m_next = NULL; @@ -36,22 +54,75 @@ if (flags & M_PKTHDR) { mb->m_data = mb->m_pktdat; memset(&mb->m_pkthdr, 0, sizeof(mb->m_pkthdr)); + /* SLIST_INIT(&m->m_pkthdr.tags); */ } else { mb->m_data = mb->m_dat; } + + return 0; } +static int +construct_ext_mbuf(struct mbuf *mb, int how) +{ + mb->m_ext.ext_buf = object_cache_alloc(sChunkCache, m_to_oc_flags(how)); + if (mb->m_ext.ext_buf == NULL) + return B_NO_MEMORY; + + mb->m_data = mb->m_ext.ext_buf; + mb->m_flags |= M_EXT; + /* mb->m_ext.ext_free = NULL; */ + /* mb->m_ext.ext_args = NULL; */ + mb->m_ext.ext_size = MCLBYTES; + mb->m_ext.ext_type = EXT_CLUSTER; + /* mb->m_ext.ref_cnt = NULL; */ + + return 0; +} + + +static int +construct_pkt_mbuf(int how, struct mbuf *mb, short type, int flags) +{ + construct_mbuf(mb, type, flags); + if (construct_ext_mbuf(mb, how) < 0) + return -1; + mb->m_ext.ext_type = EXT_PACKET; + return 0; +} + + +static void +destruct_pkt_mbuf(struct mbuf *mb) +{ + object_cache_free(sChunkCache, mb->m_ext.ext_buf); + mb->m_ext.ext_buf = NULL; +} + + struct mbuf * m_getcl(int how, short type, int flags) { - uint32 cacheFlags = 0; - struct mbuf *mb; + struct mbuf *mb = + (struct mbuf *)object_cache_alloc(sMBufCache, m_to_oc_flags(how)); + if (mb == NULL) + return NULL; - if (how & M_NOWAIT) - cacheFlags = CACHE_DONT_SLEEP; + if (construct_pkt_mbuf(how, mb, type, flags) < 0) { + object_cache_free(sMBufCache, mb); + return NULL; + } - mb = (struct mbuf *)object_cache_alloc(sMBufCache, cacheFlags); + return mb; +} + + +static struct mbuf * +_m_get(int how, short type, int flags) +{ + struct mbuf *mb = + (struct mbuf *)object_cache_alloc(sMBufCache, m_to_oc_flags(how)); if (mb == NULL) return NULL; @@ -61,31 +132,249 @@ } +struct mbuf * +m_get(int how, short type) +{ + return _m_get(how, type, 0); +} + + +struct mbuf * +m_gethdr(int how, short type) +{ + return _m_get(how, type, M_PKTHDR); +} + + void -m_freem(struct mbuf *mp) +m_freem(struct mbuf *mb) { - struct mbuf *next = mp; + while (mb) + mb = m_free(mb); +} - do { - mp = next; - next = next->m_next; - if (mp->m_flags & M_EXT) - object_cache_free(sChunkCache, mp->m_ext.ext_buf); - object_cache_free(sMBufCache, mp); - } while (next); +static void +mb_free_ext(struct mbuf *m) +{ + /* + if (m->m_ext.ref_count != NULL) + panic("unsupported"); + */ + + if (m->m_ext.ext_type == EXT_PACKET) + destruct_pkt_mbuf(m); + else if (m->m_ext.ext_type == EXT_CLUSTER) { + object_cache_free(sChunkCache, m->m_ext.ext_buf); + m->m_ext.ext_buf = NULL; + } else + panic("unknown type"); + + object_cache_free(sMBufCache, m); } +struct mbuf * +m_free(struct mbuf *m) +{ + struct mbuf *next = m->m_next; + + if (m->m_flags & M_EXT) + mb_free_ext(m); + else + object_cache_free(sMBufCache, m); + + return next; +} + + +/* + * Copy data from an mbuf chain starting "off" bytes from the beginning, + * continuing for "len" bytes, into the indicated buffer. + */ +void +m_copydata(const struct mbuf *m, int off, int len, caddr_t cp) +{ + u_int count; + + KASSERT(off >= 0, ("m_copydata, negative off %d", off)); + KASSERT(len >= 0, ("m_copydata, negative len %d", len)); + while (off > 0) { + KASSERT(m != NULL, ("m_copydata, offset > size of mbuf chain")); + if (off < m->m_len) + break; + off -= m->m_len; + m = m->m_next; + } + while (len > 0) { + KASSERT(m != NULL, ("m_copydata, length > size of mbuf chain")); + count = min(m->m_len - off, len); + bcopy(mtod(m, caddr_t) + off, cp, count); + len -= count; + cp += count; + off = 0; + m = m->m_next; + } +} + + +/* + * Concatenate mbuf chain n to m. + * Both chains must be of the same type (e.g. MT_DATA). + * Any m_pkthdr is not updated. + */ +void +m_cat(struct mbuf *m, struct mbuf *n) +{ + while (m->m_next) + m = m->m_next; + while (n) { + if (m->m_flags & M_EXT || + m->m_data + m->m_len + n->m_len >= &m->m_dat[MLEN]) { + /* just join the two chains */ + m->m_next = n; + return; + } + /* splat the data from one into the other */ + bcopy(mtod(n, caddr_t), mtod(m, caddr_t) + m->m_len, + (u_int)n->m_len); + m->m_len += n->m_len; + n = m_free(n); + } +} + + +u_int +m_length(struct mbuf *m0, struct mbuf **last) +{ + struct mbuf *m; + u_int len; + + len = 0; + for (m = m0; m != NULL; m = m->m_next) { + len += m->m_len; + if (m->m_next == NULL) + break; + } + if (last != NULL) + *last = m; + return (len); +} + + +u_int +m_fixhdr(struct mbuf *m0) +{ + u_int len; + + len = m_length(m0, NULL); + m0->m_pkthdr.len = len; + return (len); +} + + +static int +m_tag_copy_chain(struct mbuf *to, struct mbuf *from, int how) +{ + return 1; +} + + +/* + * Duplicate "from"'s mbuf pkthdr in "to". + * "from" must have M_PKTHDR set, and "to" must be empty. + * In particular, this does a deep copy of the packet tags. + */ +static int +m_dup_pkthdr(struct mbuf *to, struct mbuf *from, int how) +{ + MBUF_CHECKSLEEP(how); + /* to->m_flags = (from->m_flags & M_COPYFLAGS) | (to->m_flags & M_EXT); */ + to->m_flags = (to->m_flags & M_EXT); + if ((to->m_flags & M_EXT) == 0) + to->m_data = to->m_pktdat; + to->m_pkthdr = from->m_pkthdr; + /* SLIST_INIT(&to->m_pkthdr.tags); */ + return (m_tag_copy_chain(to, from, MBTOM(how))); +} + + +/* + * Defragment a mbuf chain, returning the shortest possible + * chain of mbufs and clusters. If allocation fails and + * this cannot be completed, NULL will be returned, but + * the passed in chain will be unchanged. Upon success, + * the original chain will be freed, and the new chain + * will be returned. + * + * If a non-packet header is passed in, the original + * mbuf (chain?) will be returned unharmed. + */ +struct mbuf * +m_defrag(struct mbuf *m0, int how) +{ + struct mbuf *m_new = NULL, *m_final = NULL; + int progress = 0, length; + + MBUF_CHECKSLEEP(how); + if (!(m0->m_flags & M_PKTHDR)) + return (m0); + + m_fixhdr(m0); /* Needed sanity check */ + + if (m0->m_pkthdr.len > MHLEN) + m_final = m_getcl(how, MT_DATA, M_PKTHDR); + else + m_final = m_gethdr(how, MT_DATA); + + if (m_final == NULL) + goto nospace; + + if (m_dup_pkthdr(m_final, m0, how) == 0) + goto nospace; + + m_new = m_final; + + while (progress < m0->m_pkthdr.len) { + length = m0->m_pkthdr.len - progress; + if (length > MCLBYTES) + length = MCLBYTES; + + if (m_new == NULL) { + if (length > MLEN) + m_new = m_getcl(how, MT_DATA, 0); + else + m_new = m_get(how, MT_DATA); + if (m_new == NULL) + goto nospace; + } + + m_copydata(m0, progress, length, mtod(m_new, caddr_t)); + progress += length; + m_new->m_len = length; + if (m_new != m_final) + m_cat(m_final, m_new); + m_new = NULL; + } + + m_freem(m0); + m0 = m_final; + return (m0); +nospace: + if (m_final) + m_freem(m_final); + return (NULL); +} + + status_t init_mbufs() { - sMBufCache = create_object_cache("mbufs", sizeof(struct mbuf), 8, NULL, - NULL, NULL); + sMBufCache = create_object_cache("mbufs", MSIZE, 8, NULL, NULL, NULL); if (sMBufCache == NULL) return B_NO_MEMORY; - sChunkCache = create_object_cache("mbuf chunks", CHUNK_SIZE, 0, NULL, NULL, + sChunkCache = create_object_cache("mbuf chunks", MCLBYTES, 0, NULL, NULL, NULL); if (sChunkCache == NULL) { delete_object_cache(sMBufCache); Added: haiku/trunk/src/libs/compat/freebsd_network/mii.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/mii.c 2007-05-03 21:18:45 UTC (rev 21005) +++ haiku/trunk/src/libs/compat/freebsd_network/mii.c 2007-05-03 21:18:21 UTC (rev 21006) @@ -0,0 +1,40 @@ +/* + * Copyright 2007, Hugo Santos. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Hugo Santos, hugosantos at gmail.com + */ + +#include "device.h" + +#include + +#include +#include + + +int +mii_phy_probe(device_t dev, device_t *miiDev, ifm_change_cb_t change, + ifm_stat_cb_t stat) +{ + return -1; +} + + +void +mii_tick(struct mii_data *data) +{ +} + +int +mii_mediachg(struct mii_data *data) +{ + return -1; +} + + +void +mii_pollstat(struct mii_data *data) +{ +} Modified: haiku/trunk/src/libs/compat/freebsd_network/mutex.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/mutex.c 2007-05-03 21:18:45 UTC (rev 21005) +++ haiku/trunk/src/libs/compat/freebsd_network/mutex.c 2007-05-03 21:18:21 UTC (rev 21006) @@ -17,7 +17,7 @@ // these methods are bit unfriendly, a bit too much panic() around -struct mutex Giant; +struct mtx Giant; void From hugosantos at mail.berlios.de Thu May 3 23:42:53 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Thu, 3 May 2007 23:42:53 +0200 Subject: [Haiku-commits] r21007 - in haiku/trunk/src/add-ons/kernel/drivers/network: . fxp fxp/dev fxp/dev/fxp Message-ID: <200705032142.l43Lgr2G026204@sheep.berlios.de> Author: hugosantos Date: 2007-05-03 23:42:09 +0200 (Thu, 03 May 2007) New Revision: 21007 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21007&view=rev Added: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/ haiku/trunk/src/add-ons/kernel/drivers/network/fxp/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/ haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/ haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/if_fxp.c haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/if_fxpreg.h haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/if_fxpvar.h haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/rcvbundl.h Modified: haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile Log: Added FreeBSD's 6.2 fxp driver (Intel Pro Express 100) to the source tree (original source, no modifications). It already builds and links but it is still a bit far from working. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile 2007-05-03 21:18:21 UTC (rev 21006) +++ haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile 2007-05-03 21:42:09 UTC (rev 21007) @@ -12,5 +12,7 @@ SubInclude HAIKU_TOP src add-ons kernel drivers network vlance ; SubInclude HAIKU_TOP src add-ons kernel drivers network wb840 ; +SubInclude HAIKU_TOP src add-ons kernel drivers network fxp ; + SubIncludeGPL HAIKU_TOP src add-ons kernel drivers network bcm440x ; SubIncludeGPL HAIKU_TOP src add-ons kernel drivers network bcm570x ; Added: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/fxp/Jamfile 2007-05-03 21:18:21 UTC (rev 21006) +++ haiku/trunk/src/add-ons/kernel/drivers/network/fxp/Jamfile 2007-05-03 21:42:09 UTC (rev 21007) @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network fxp ; + +SubInclude HAIKU_TOP src add-ons kernel drivers network fxp dev ; Added: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/Jamfile 2007-05-03 21:18:21 UTC (rev 21006) +++ haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/Jamfile 2007-05-03 21:42:09 UTC (rev 21007) @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network fxp dev ; + +SubInclude HAIKU_TOP src add-ons kernel drivers network fxp dev fxp ; Added: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/Jamfile 2007-05-03 21:18:21 UTC (rev 21006) +++ haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/Jamfile 2007-05-03 21:42:09 UTC (rev 21007) @@ -0,0 +1,16 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network fxp dev fxp ; + +SubDirCcFlags -Wall ; + +UsePrivateHeaders kernel net ; + +UseHeaders [ FDirName $(SUBDIR) .. .. ] : true ; +UseHeaders [ FDirName $(HAIKU_TOP) src libs compat freebsd_network compat ] : true ; + +SubDirCcFlags [ FDefines _KERNEL=1 ] ; + +KernelAddon fxp : + if_fxp.c + : libfreebsd_network.a + ; + Added: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/if_fxp.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/if_fxp.c 2007-05-03 21:18:21 UTC (rev 21006) +++ haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/if_fxp.c 2007-05-03 21:42:09 UTC (rev 21007) @@ -0,0 +1,2713 @@ +/*- + * Copyright (c) 1995, David Greenman + * Copyright (c) 2001 Jonathan Lemon + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include +__FBSDID("$FreeBSD: src/sys/dev/fxp/if_fxp.c,v 1.240.2.10.2.1 2006/11/20 16:21:12 rink Exp $"); + +/* + * Intel EtherExpress Pro/100B PCI Fast Ethernet driver + */ + +#ifdef HAVE_KERNEL_OPTION_HEADERS +#include "opt_device_polling.h" +#endif + +#include +#include +#include +#include + /* #include */ +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include /* for DELAY */ + +#include +#include + +#ifdef FXP_IP_CSUM_WAR +#include +#include +#include +#include +#endif + +#include +#include /* for PCIM_CMD_xxx */ + +#include +#include + +#include +#include +#include + +MODULE_DEPEND(fxp, pci, 1, 1, 1); +MODULE_DEPEND(fxp, ether, 1, 1, 1); +MODULE_DEPEND(fxp, miibus, 1, 1, 1); +#include "miibus_if.h" + +/* + * NOTE! On the Alpha, we have an alignment constraint. The + * card DMAs the packet immediately following the RFA. However, + * the first thing in the packet is a 14-byte Ethernet header. + * This means that the packet is misaligned. To compensate, + * we actually offset the RFA 2 bytes into the cluster. This + * alignes the packet after the Ethernet header at a 32-bit + * boundary. HOWEVER! This means that the RFA is misaligned! + */ +#define RFA_ALIGNMENT_FUDGE 2 + +/* + * Set initial transmit threshold at 64 (512 bytes). This is + * increased by 64 (512 bytes) at a time, to maximum of 192 + * (1536 bytes), if an underrun occurs. + */ +static int tx_threshold = 64; + +/* + * The configuration byte map has several undefined fields which + * must be one or must be zero. Set up a template for these bits + * only, (assuming a 82557 chip) leaving the actual configuration + * to fxp_init. + * + * See struct fxp_cb_config for the bit definitions. + */ +static u_char fxp_cb_config_template[] = { + 0x0, 0x0, /* cb_status */ + 0x0, 0x0, /* cb_command */ + 0x0, 0x0, 0x0, 0x0, /* link_addr */ + 0x0, /* 0 */ + 0x0, /* 1 */ + 0x0, /* 2 */ + 0x0, /* 3 */ + 0x0, /* 4 */ + 0x0, /* 5 */ + 0x32, /* 6 */ + 0x0, /* 7 */ + 0x0, /* 8 */ + 0x0, /* 9 */ + 0x6, /* 10 */ + 0x0, /* 11 */ + 0x0, /* 12 */ + 0x0, /* 13 */ + 0xf2, /* 14 */ + 0x48, /* 15 */ + 0x0, /* 16 */ + 0x40, /* 17 */ + 0xf0, /* 18 */ + 0x0, /* 19 */ + 0x3f, /* 20 */ + 0x5 /* 21 */ +}; + +struct fxp_ident { + uint16_t devid; + int16_t revid; /* -1 matches anything */ + char *name; +}; + +/* + * Claim various Intel PCI device identifiers for this driver. The + * sub-vendor and sub-device field are extensively used to identify + * particular variants, but we don't currently differentiate between + * them. + */ +static struct fxp_ident fxp_ident_table[] = { + { 0x1029, -1, "Intel 82559 PCI/CardBus Pro/100" }, + { 0x1030, -1, "Intel 82559 Pro/100 Ethernet" }, + { 0x1031, -1, "Intel 82801CAM (ICH3) Pro/100 VE Ethernet" }, + { 0x1032, -1, "Intel 82801CAM (ICH3) Pro/100 VE Ethernet" }, + { 0x1033, -1, "Intel 82801CAM (ICH3) Pro/100 VM Ethernet" }, + { 0x1034, -1, "Intel 82801CAM (ICH3) Pro/100 VM Ethernet" }, + { 0x1035, -1, "Intel 82801CAM (ICH3) Pro/100 Ethernet" }, + { 0x1036, -1, "Intel 82801CAM (ICH3) Pro/100 Ethernet" }, + { 0x1037, -1, "Intel 82801CAM (ICH3) Pro/100 Ethernet" }, + { 0x1038, -1, "Intel 82801CAM (ICH3) Pro/100 VM Ethernet" }, + { 0x1039, -1, "Intel 82801DB (ICH4) Pro/100 VE Ethernet" }, + { 0x103A, -1, "Intel 82801DB (ICH4) Pro/100 Ethernet" }, + { 0x103B, -1, "Intel 82801DB (ICH4) Pro/100 VM Ethernet" }, + { 0x103C, -1, "Intel 82801DB (ICH4) Pro/100 Ethernet" }, + { 0x103D, -1, "Intel 82801DB (ICH4) Pro/100 VE Ethernet" }, + { 0x103E, -1, "Intel 82801DB (ICH4) Pro/100 VM Ethernet" }, + { 0x1050, -1, "Intel 82801BA (D865) Pro/100 VE Ethernet" }, + { 0x1051, -1, "Intel 82562ET (ICH5/ICH5R) Pro/100 VE Ethernet" }, + { 0x1059, -1, "Intel 82551QM Pro/100 M Mobile Connection" }, + { 0x1064, -1, "Intel 82562EZ (ICH6)" }, + { 0x1065, -1, "Intel 82562ET/EZ/GT/GZ PRO/100 VE Ethernet" }, + { 0x1068, -1, "Intel 82801FBM (ICH6-M) Pro/100 VE Ethernet" }, + { 0x1069, -1, "Intel 82562EM/EX/GX Pro/100 Ethernet" }, + { 0x1092, -1, "Intel Pro/100 VE Network Connection" }, + { 0x1093, -1, "Intel Pro/100 VM Network Connection" }, + { 0x1094, -1, "Intel Pro/100 946GZ (ICH7) Network Connection" }, + { 0x1209, -1, "Intel 82559ER Embedded 10/100 Ethernet" }, + { 0x1229, 0x01, "Intel 82557 Pro/100 Ethernet" }, + { 0x1229, 0x02, "Intel 82557 Pro/100 Ethernet" }, + { 0x1229, 0x03, "Intel 82557 Pro/100 Ethernet" }, + { 0x1229, 0x04, "Intel 82558 Pro/100 Ethernet" }, + { 0x1229, 0x05, "Intel 82558 Pro/100 Ethernet" }, + { 0x1229, 0x06, "Intel 82559 Pro/100 Ethernet" }, + { 0x1229, 0x07, "Intel 82559 Pro/100 Ethernet" }, + { 0x1229, 0x08, "Intel 82559 Pro/100 Ethernet" }, + { 0x1229, 0x09, "Intel 82559ER Pro/100 Ethernet" }, + { 0x1229, 0x0c, "Intel 82550 Pro/100 Ethernet" }, + { 0x1229, 0x0d, "Intel 82550 Pro/100 Ethernet" }, + { 0x1229, 0x0e, "Intel 82550 Pro/100 Ethernet" }, + { 0x1229, 0x0f, "Intel 82551 Pro/100 Ethernet" }, + { 0x1229, 0x10, "Intel 82551 Pro/100 Ethernet" }, + { 0x1229, -1, "Intel 82557/8/9 Pro/100 Ethernet" }, + { 0x2449, -1, "Intel 82801BA/CAM (ICH2/3) Pro/100 Ethernet" }, + { 0x27dc, -1, "Intel 82801GB (ICH7) 10/100 Ethernet" }, + { 0, -1, NULL }, +}; + +#ifdef FXP_IP_CSUM_WAR +#define FXP_CSUM_FEATURES (CSUM_IP | CSUM_TCP | CSUM_UDP) +#else +#define FXP_CSUM_FEATURES (CSUM_TCP | CSUM_UDP) +#endif + +static int fxp_probe(device_t dev); +static int fxp_attach(device_t dev); +static int fxp_detach(device_t dev); +static int fxp_shutdown(device_t dev); +static int fxp_suspend(device_t dev); +static int fxp_resume(device_t dev); + +static void fxp_intr(void *xsc); +static void fxp_intr_body(struct fxp_softc *sc, struct ifnet *ifp, + uint8_t statack, int count); +static void fxp_init(void *xsc); +static void fxp_init_body(struct fxp_softc *sc); +static void fxp_tick(void *xsc); +static void fxp_start(struct ifnet *ifp); +static void fxp_start_body(struct ifnet *ifp); +static int fxp_encap(struct fxp_softc *sc, struct mbuf *m_head); +static void fxp_stop(struct fxp_softc *sc); +static void fxp_release(struct fxp_softc *sc); +static int fxp_ioctl(struct ifnet *ifp, u_long command, + caddr_t data); +static void fxp_watchdog(struct ifnet *ifp); +static int fxp_add_rfabuf(struct fxp_softc *sc, + struct fxp_rx *rxp); +static int fxp_mc_addrs(struct fxp_softc *sc); +static void fxp_mc_setup(struct fxp_softc *sc); +static uint16_t fxp_eeprom_getword(struct fxp_softc *sc, int offset, + int autosize); +static void fxp_eeprom_putword(struct fxp_softc *sc, int offset, + uint16_t data); +static void fxp_autosize_eeprom(struct fxp_softc *sc); +static void fxp_read_eeprom(struct fxp_softc *sc, u_short *data, + int offset, int words); +static void fxp_write_eeprom(struct fxp_softc *sc, u_short *data, + int offset, int words); +static int fxp_ifmedia_upd(struct ifnet *ifp); +static void fxp_ifmedia_sts(struct ifnet *ifp, + struct ifmediareq *ifmr); +static int fxp_serial_ifmedia_upd(struct ifnet *ifp); +static void fxp_serial_ifmedia_sts(struct ifnet *ifp, + struct ifmediareq *ifmr); +static volatile int fxp_miibus_readreg(device_t dev, int phy, int reg); +static void fxp_miibus_writereg(device_t dev, int phy, int reg, + int value); +static void fxp_load_ucode(struct fxp_softc *sc); +static int sysctl_int_range(SYSCTL_HANDLER_ARGS, + int low, int high); +static int sysctl_hw_fxp_bundle_max(SYSCTL_HANDLER_ARGS); +static int sysctl_hw_fxp_int_delay(SYSCTL_HANDLER_ARGS); +static void fxp_scb_wait(struct fxp_softc *sc); +static void fxp_scb_cmd(struct fxp_softc *sc, int cmd); +static void fxp_dma_wait(struct fxp_softc *sc, + volatile uint16_t *status, bus_dma_tag_t dmat, + bus_dmamap_t map); + +static device_method_t fxp_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, fxp_probe), + DEVMETHOD(device_attach, fxp_attach), + DEVMETHOD(device_detach, fxp_detach), + DEVMETHOD(device_shutdown, fxp_shutdown), + DEVMETHOD(device_suspend, fxp_suspend), + DEVMETHOD(device_resume, fxp_resume), + + /* MII interface */ + DEVMETHOD(miibus_readreg, fxp_miibus_readreg), + DEVMETHOD(miibus_writereg, fxp_miibus_writereg), + + { 0, 0 } +}; + +static driver_t fxp_driver = { + "fxp", + fxp_methods, + sizeof(struct fxp_softc), +}; + +static devclass_t fxp_devclass; + +DRIVER_MODULE(fxp, pci, fxp_driver, fxp_devclass, 0, 0); +DRIVER_MODULE(fxp, cardbus, fxp_driver, fxp_devclass, 0, 0); +DRIVER_MODULE(miibus, fxp, miibus_driver, miibus_devclass, 0, 0); + +/* + * Wait for the previous command to be accepted (but not necessarily + * completed). + */ +static void +fxp_scb_wait(struct fxp_softc *sc) +{ + union { + uint16_t w; + uint8_t b[2]; + } flowctl; + int i = 10000; + + while (CSR_READ_1(sc, FXP_CSR_SCB_COMMAND) && --i) + DELAY(2); + if (i == 0) { + flowctl.b[0] = CSR_READ_1(sc, FXP_CSR_FLOWCONTROL); + flowctl.b[1] = CSR_READ_1(sc, FXP_CSR_FLOWCONTROL + 1); + device_printf(sc->dev, "SCB timeout: 0x%x 0x%x 0x%x 0x%x\n", + CSR_READ_1(sc, FXP_CSR_SCB_COMMAND), + CSR_READ_1(sc, FXP_CSR_SCB_STATACK), + CSR_READ_1(sc, FXP_CSR_SCB_RUSCUS), flowctl.w); + } +} + +static void +fxp_scb_cmd(struct fxp_softc *sc, int cmd) +{ + + if (cmd == FXP_SCB_COMMAND_CU_RESUME && sc->cu_resume_bug) { + CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_CB_COMMAND_NOP); + fxp_scb_wait(sc); + } + CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, cmd); +} + +static void +fxp_dma_wait(struct fxp_softc *sc, volatile uint16_t *status, + bus_dma_tag_t dmat, bus_dmamap_t map) +{ + int i = 10000; + + bus_dmamap_sync(dmat, map, BUS_DMASYNC_POSTREAD); + while (!(le16toh(*status) & FXP_CB_STATUS_C) && --i) { + DELAY(2); + bus_dmamap_sync(dmat, map, BUS_DMASYNC_POSTREAD); + } + if (i == 0) + device_printf(sc->dev, "DMA timeout\n"); +} + +/* + * Return identification string if this device is ours. + */ +static int +fxp_probe(device_t dev) +{ + uint16_t devid; + uint8_t revid; + struct fxp_ident *ident; + + if (pci_get_vendor(dev) == FXP_VENDORID_INTEL) { + devid = pci_get_device(dev); + revid = pci_get_revid(dev); + for (ident = fxp_ident_table; ident->name != NULL; ident++) { + if (ident->devid == devid && + (ident->revid == revid || ident->revid == -1)) { + device_set_desc(dev, ident->name); + return (BUS_PROBE_DEFAULT); + } + } + } + return (ENXIO); +} + +static void +fxp_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error) +{ + uint32_t *addr; + + if (error) + return; + + KASSERT(nseg == 1, ("too many DMA segments, %d should be 1", nseg)); + addr = arg; + *addr = segs->ds_addr; +} + +static int +fxp_attach(device_t dev) +{ + struct fxp_softc *sc; + struct fxp_cb_tx *tcbp; + struct fxp_tx *txp; + struct fxp_rx *rxp; + struct ifnet *ifp; + uint32_t val; + uint16_t data, myea[ETHER_ADDR_LEN / 2]; + u_char eaddr[ETHER_ADDR_LEN]; + int i, rid, m1, m2, prefer_iomap; + int error; + + error = 0; + sc = device_get_softc(dev); + sc->dev = dev; + mtx_init(&sc->sc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, + MTX_DEF); + callout_init_mtx(&sc->stat_ch, &sc->sc_mtx, 0); + ifmedia_init(&sc->sc_media, 0, fxp_serial_ifmedia_upd, + fxp_serial_ifmedia_sts); + + ifp = sc->ifp = if_alloc(IFT_ETHER); + if (ifp == NULL) { + device_printf(dev, "can not if_alloc()\n"); + error = ENOSPC; + goto fail; + } + + /* + * Enable bus mastering. + */ + pci_enable_busmaster(dev); + val = pci_read_config(dev, PCIR_COMMAND, 2); + + /* + * Figure out which we should try first - memory mapping or i/o mapping? + * We default to memory mapping. Then we accept an override from the + * command line. Then we check to see which one is enabled. + */ + m1 = PCIM_CMD_MEMEN; + m2 = PCIM_CMD_PORTEN; + prefer_iomap = 0; + if (resource_int_value(device_get_name(dev), device_get_unit(dev), + "prefer_iomap", &prefer_iomap) == 0 && prefer_iomap != 0) { + m1 = PCIM_CMD_PORTEN; + m2 = PCIM_CMD_MEMEN; + } + + sc->rtp = (m1 == PCIM_CMD_MEMEN)? SYS_RES_MEMORY : SYS_RES_IOPORT; + sc->rgd = (m1 == PCIM_CMD_MEMEN)? FXP_PCI_MMBA : FXP_PCI_IOBA; + sc->mem = bus_alloc_resource_any(dev, sc->rtp, &sc->rgd, RF_ACTIVE); + if (sc->mem == NULL) { + sc->rtp = + (m2 == PCIM_CMD_MEMEN)? SYS_RES_MEMORY : SYS_RES_IOPORT; + sc->rgd = (m2 == PCIM_CMD_MEMEN)? FXP_PCI_MMBA : FXP_PCI_IOBA; + sc->mem = bus_alloc_resource_any(dev, sc->rtp, &sc->rgd, + RF_ACTIVE); + } + + if (!sc->mem) { + error = ENXIO; + goto fail; + } + if (bootverbose) { + device_printf(dev, "using %s space register mapping\n", + sc->rtp == SYS_RES_MEMORY? "memory" : "I/O"); + } + + sc->sc_st = rman_get_bustag(sc->mem); + sc->sc_sh = rman_get_bushandle(sc->mem); + + /* + * Allocate our interrupt. + */ + rid = 0; + sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, + RF_SHAREABLE | RF_ACTIVE); + if (sc->irq == NULL) { + device_printf(dev, "could not map interrupt\n"); + error = ENXIO; + goto fail; + } + + /* + * Reset to a stable state. + */ + CSR_WRITE_4(sc, FXP_CSR_PORT, FXP_PORT_SELECTIVE_RESET); + DELAY(10); + + /* + * Find out how large of an SEEPROM we have. + */ + fxp_autosize_eeprom(sc); + + /* + * Find out the chip revision; lump all 82557 revs together. + */ + fxp_read_eeprom(sc, &data, 5, 1); + if ((data >> 8) == 1) + sc->revision = FXP_REV_82557; + else + sc->revision = pci_get_revid(dev); + + /* + * Determine whether we must use the 503 serial interface. + */ + fxp_read_eeprom(sc, &data, 6, 1); + if (sc->revision == FXP_REV_82557 && (data & FXP_PHY_DEVICE_MASK) != 0 + && (data & FXP_PHY_SERIAL_ONLY)) + sc->flags |= FXP_FLAG_SERIAL_MEDIA; + + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "int_delay", CTLTYPE_INT | CTLFLAG_RW, + &sc->tunable_int_delay, 0, sysctl_hw_fxp_int_delay, "I", + "FXP driver receive interrupt microcode bundling delay"); + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "bundle_max", CTLTYPE_INT | CTLFLAG_RW, + &sc->tunable_bundle_max, 0, sysctl_hw_fxp_bundle_max, "I", + "FXP driver receive interrupt microcode bundle size limit"); + SYSCTL_ADD_INT(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "rnr", CTLFLAG_RD, &sc->rnr, 0, + "FXP RNR events"); + SYSCTL_ADD_INT(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "noflow", CTLFLAG_RW, &sc->tunable_noflow, 0, + "FXP flow control disabled"); + + /* + * Pull in device tunables. + */ + sc->tunable_int_delay = TUNABLE_INT_DELAY; + sc->tunable_bundle_max = TUNABLE_BUNDLE_MAX; + sc->tunable_noflow = 1; + (void) resource_int_value(device_get_name(dev), device_get_unit(dev), + "int_delay", &sc->tunable_int_delay); + (void) resource_int_value(device_get_name(dev), device_get_unit(dev), + "bundle_max", &sc->tunable_bundle_max); + (void) resource_int_value(device_get_name(dev), device_get_unit(dev), + "noflow", &sc->tunable_noflow); + sc->rnr = 0; + + /* + * Enable workarounds for certain chip revision deficiencies. + * + * Systems based on the ICH2/ICH2-M chip from Intel, and possibly + * some systems based a normal 82559 design, have a defect where + * the chip can cause a PCI protocol violation if it receives + * a CU_RESUME command when it is entering the IDLE state. The + * workaround is to disable Dynamic Standby Mode, so the chip never + * deasserts CLKRUN#, and always remains in an active state. + * + * See Intel 82801BA/82801BAM Specification Update, Errata #30. + */ + i = pci_get_device(dev); + if (i == 0x2449 || (i > 0x1030 && i < 0x1039) || + sc->revision >= FXP_REV_82559_A0) { + fxp_read_eeprom(sc, &data, 10, 1); + if (data & 0x02) { /* STB enable */ + uint16_t cksum; + int i; + + device_printf(dev, + "Disabling dynamic standby mode in EEPROM\n"); + data &= ~0x02; + fxp_write_eeprom(sc, &data, 10, 1); + device_printf(dev, "New EEPROM ID: 0x%x\n", data); + cksum = 0; + for (i = 0; i < (1 << sc->eeprom_size) - 1; i++) { + fxp_read_eeprom(sc, &data, i, 1); + cksum += data; + } + i = (1 << sc->eeprom_size) - 1; + cksum = 0xBABA - cksum; + fxp_read_eeprom(sc, &data, i, 1); + fxp_write_eeprom(sc, &cksum, i, 1); + device_printf(dev, + "EEPROM checksum @ 0x%x: 0x%x -> 0x%x\n", + i, data, cksum); +#if 1 + /* + * If the user elects to continue, try the software + * workaround, as it is better than nothing. + */ + sc->flags |= FXP_FLAG_CU_RESUME_BUG; +#endif + } + } + + /* + * If we are not a 82557 chip, we can enable extended features. + */ + if (sc->revision != FXP_REV_82557) { + /* + * If MWI is enabled in the PCI configuration, and there + * is a valid cacheline size (8 or 16 dwords), then tell + * the board to turn on MWI. + */ + if (val & PCIM_CMD_MWRICEN && + pci_read_config(dev, PCIR_CACHELNSZ, 1) != 0) + sc->flags |= FXP_FLAG_MWI_ENABLE; + + /* turn on the extended TxCB feature */ + sc->flags |= FXP_FLAG_EXT_TXCB; + + /* enable reception of long frames for VLAN */ + sc->flags |= FXP_FLAG_LONG_PKT_EN; + } else { + /* a hack to get long VLAN frames on a 82557 */ + sc->flags |= FXP_FLAG_SAVE_BAD; + } + + /* + * Enable use of extended RFDs and TCBs for 82550 + * and later chips. Note: we need extended TXCB support + * too, but that's already enabled by the code above. + * Be careful to do this only on the right devices. + */ + if (sc->revision == FXP_REV_82550 || sc->revision == FXP_REV_82550_C || + sc->revision == FXP_REV_82551_E || sc->revision == FXP_REV_82551_F + || sc->revision == FXP_REV_82551_10) { + sc->rfa_size = sizeof (struct fxp_rfa); + sc->tx_cmd = FXP_CB_COMMAND_IPCBXMIT; + sc->flags |= FXP_FLAG_EXT_RFA; + } else { + sc->rfa_size = sizeof (struct fxp_rfa) - FXP_RFAX_LEN; + sc->tx_cmd = FXP_CB_COMMAND_XMIT; + } + + /* + * Allocate DMA tags and DMA safe memory. + */ + sc->maxtxseg = FXP_NTXSEG; + if (sc->flags & FXP_FLAG_EXT_RFA) + sc->maxtxseg--; + error = bus_dma_tag_create(NULL, 2, 0, BUS_SPACE_MAXADDR_32BIT, + BUS_SPACE_MAXADDR, NULL, NULL, MCLBYTES * sc->maxtxseg, + sc->maxtxseg, MCLBYTES, 0, busdma_lock_mutex, &Giant, + &sc->fxp_mtag); + if (error) { + device_printf(dev, "could not allocate dma tag\n"); + goto fail; + } + + error = bus_dma_tag_create(NULL, 4, 0, BUS_SPACE_MAXADDR_32BIT, + BUS_SPACE_MAXADDR, NULL, NULL, sizeof(struct fxp_stats), 1, + sizeof(struct fxp_stats), 0, busdma_lock_mutex, &Giant, + &sc->fxp_stag); + if (error) { + device_printf(dev, "could not allocate dma tag\n"); + goto fail; + } + + error = bus_dmamem_alloc(sc->fxp_stag, (void **)&sc->fxp_stats, + BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sc->fxp_smap); + if (error) + goto fail; + error = bus_dmamap_load(sc->fxp_stag, sc->fxp_smap, sc->fxp_stats, + sizeof(struct fxp_stats), fxp_dma_map_addr, &sc->stats_addr, 0); + if (error) { + device_printf(dev, "could not map the stats buffer\n"); + goto fail; + } + + error = bus_dma_tag_create(NULL, 4, 0, BUS_SPACE_MAXADDR_32BIT, + BUS_SPACE_MAXADDR, NULL, NULL, FXP_TXCB_SZ, 1, + FXP_TXCB_SZ, 0, busdma_lock_mutex, &Giant, &sc->cbl_tag); + if (error) { + device_printf(dev, "could not allocate dma tag\n"); + goto fail; + } + + error = bus_dmamem_alloc(sc->cbl_tag, (void **)&sc->fxp_desc.cbl_list, + BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sc->cbl_map); + if (error) + goto fail; + + error = bus_dmamap_load(sc->cbl_tag, sc->cbl_map, + sc->fxp_desc.cbl_list, FXP_TXCB_SZ, fxp_dma_map_addr, + &sc->fxp_desc.cbl_addr, 0); + if (error) { + device_printf(dev, "could not map DMA memory\n"); + goto fail; + } + + error = bus_dma_tag_create(NULL, 4, 0, BUS_SPACE_MAXADDR_32BIT, + BUS_SPACE_MAXADDR, NULL, NULL, sizeof(struct fxp_cb_mcs), 1, + sizeof(struct fxp_cb_mcs), 0, busdma_lock_mutex, &Giant, + &sc->mcs_tag); + if (error) { + device_printf(dev, "could not allocate dma tag\n"); + goto fail; + } + + error = bus_dmamem_alloc(sc->mcs_tag, (void **)&sc->mcsp, + BUS_DMA_NOWAIT, &sc->mcs_map); + if (error) + goto fail; + error = bus_dmamap_load(sc->mcs_tag, sc->mcs_map, sc->mcsp, + sizeof(struct fxp_cb_mcs), fxp_dma_map_addr, &sc->mcs_addr, 0); + if (error) { + device_printf(dev, "can't map the multicast setup command\n"); + goto fail; + } + + /* + * Pre-allocate the TX DMA maps and setup the pointers to + * the TX command blocks. + */ + txp = sc->fxp_desc.tx_list; + tcbp = sc->fxp_desc.cbl_list; + for (i = 0; i < FXP_NTXCB; i++) { + txp[i].tx_cb = tcbp + i; + error = bus_dmamap_create(sc->fxp_mtag, 0, &txp[i].tx_map); + if (error) { + device_printf(dev, "can't create DMA map for TX\n"); + goto fail; + } + } + error = bus_dmamap_create(sc->fxp_mtag, 0, &sc->spare_map); + if (error) { + device_printf(dev, "can't create spare DMA map\n"); + goto fail; + } + + /* + * Pre-allocate our receive buffers. + */ + sc->fxp_desc.rx_head = sc->fxp_desc.rx_tail = NULL; + for (i = 0; i < FXP_NRFABUFS; i++) { + rxp = &sc->fxp_desc.rx_list[i]; + error = bus_dmamap_create(sc->fxp_mtag, 0, &rxp->rx_map); + if (error) { + device_printf(dev, "can't create DMA map for RX\n"); + goto fail; + } + if (fxp_add_rfabuf(sc, rxp) != 0) { + error = ENOMEM; + goto fail; + } + } + + /* + * Read MAC address. + */ + fxp_read_eeprom(sc, myea, 0, 3); + eaddr[0] = myea[0] & 0xff; + eaddr[1] = myea[0] >> 8; + eaddr[2] = myea[1] & 0xff; + eaddr[3] = myea[1] >> 8; + eaddr[4] = myea[2] & 0xff; + eaddr[5] = myea[2] >> 8; + if (bootverbose) { + device_printf(dev, "PCI IDs: %04x %04x %04x %04x %04x\n", + pci_get_vendor(dev), pci_get_device(dev), + pci_get_subvendor(dev), pci_get_subdevice(dev), + pci_get_revid(dev)); + fxp_read_eeprom(sc, &data, 10, 1); + device_printf(dev, "Dynamic Standby mode is %s\n", + data & 0x02 ? "enabled" : "disabled"); + } + + /* + * If this is only a 10Mbps device, then there is no MII, and + * the PHY will use a serial interface instead. + * + * The Seeq 80c24 AutoDUPLEX(tm) Ethernet Interface Adapter + * doesn't have a programming interface of any sort. The + * media is sensed automatically based on how the link partner + * is configured. This is, in essence, manual configuration. + */ + if (sc->flags & FXP_FLAG_SERIAL_MEDIA) { + ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL); + ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_MANUAL); + } else { + if (mii_phy_probe(dev, &sc->miibus, fxp_ifmedia_upd, + fxp_ifmedia_sts)) { + device_printf(dev, "MII without any PHY!\n"); + error = ENXIO; + goto fail; + } + } + + if_initname(ifp, device_get_name(dev), device_get_unit(dev)); + ifp->if_init = fxp_init; + ifp->if_softc = sc; + ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; + ifp->if_ioctl = fxp_ioctl; + ifp->if_start = fxp_start; + ifp->if_watchdog = fxp_watchdog; + + ifp->if_capabilities = ifp->if_capenable = 0; + + /* Enable checksum offload for 82550 or better chips */ + if (sc->flags & FXP_FLAG_EXT_RFA) { + ifp->if_hwassist = FXP_CSUM_FEATURES; + ifp->if_capabilities |= IFCAP_HWCSUM; + ifp->if_capenable |= IFCAP_HWCSUM; + } + +#ifdef DEVICE_POLLING + /* Inform the world we support polling. */ + ifp->if_capabilities |= IFCAP_POLLING; +#endif + + /* + * Attach the interface. + */ + ether_ifattach(ifp, eaddr); + + /* + * Tell the upper layer(s) we support long frames. + * Must appear after the call to ether_ifattach() because + * ether_ifattach() sets ifi_hdrlen to the default value. + */ + ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header); + ifp->if_capabilities |= IFCAP_VLAN_MTU; + ifp->if_capenable |= IFCAP_VLAN_MTU; /* the hw bits already set */ + + /* + * Let the system queue as many packets as we have available + * TX descriptors. + */ + IFQ_SET_MAXLEN(&ifp->if_snd, FXP_NTXCB - 1); + ifp->if_snd.ifq_drv_maxlen = FXP_NTXCB - 1; + IFQ_SET_READY(&ifp->if_snd); + + /* + * Hook our interrupt after all initialization is complete. + */ + error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE, + fxp_intr, sc, &sc->ih); + if (error) { + device_printf(dev, "could not setup irq\n"); + ether_ifdetach(sc->ifp); + goto fail; + } + +fail: + if (error) + fxp_release(sc); + return (error); +} + +/* + * Release all resources. The softc lock should not be held and the + * interrupt should already be torn down. + */ +static void +fxp_release(struct fxp_softc *sc) +{ + struct fxp_rx *rxp; + struct fxp_tx *txp; + int i; + + FXP_LOCK_ASSERT(sc, MA_NOTOWNED); + KASSERT(sc->ih == NULL, + ("fxp_release() called with intr handle still active")); + if (sc->miibus) + device_delete_child(sc->dev, sc->miibus); + bus_generic_detach(sc->dev); + ifmedia_removeall(&sc->sc_media); + if (sc->fxp_desc.cbl_list) { + bus_dmamap_unload(sc->cbl_tag, sc->cbl_map); + bus_dmamem_free(sc->cbl_tag, sc->fxp_desc.cbl_list, + sc->cbl_map); + } + if (sc->fxp_stats) { + bus_dmamap_unload(sc->fxp_stag, sc->fxp_smap); + bus_dmamem_free(sc->fxp_stag, sc->fxp_stats, sc->fxp_smap); + } + if (sc->mcsp) { + bus_dmamap_unload(sc->mcs_tag, sc->mcs_map); + bus_dmamem_free(sc->mcs_tag, sc->mcsp, sc->mcs_map); + } + if (sc->irq) + bus_release_resource(sc->dev, SYS_RES_IRQ, 0, sc->irq); + if (sc->mem) + bus_release_resource(sc->dev, sc->rtp, sc->rgd, sc->mem); + if (sc->fxp_mtag) { + for (i = 0; i < FXP_NRFABUFS; i++) { + rxp = &sc->fxp_desc.rx_list[i]; + if (rxp->rx_mbuf != NULL) { + bus_dmamap_sync(sc->fxp_mtag, rxp->rx_map, + BUS_DMASYNC_POSTREAD); + bus_dmamap_unload(sc->fxp_mtag, rxp->rx_map); + m_freem(rxp->rx_mbuf); + } + bus_dmamap_destroy(sc->fxp_mtag, rxp->rx_map); + } + bus_dmamap_destroy(sc->fxp_mtag, sc->spare_map); + for (i = 0; i < FXP_NTXCB; i++) { + txp = &sc->fxp_desc.tx_list[i]; + if (txp->tx_mbuf != NULL) { + bus_dmamap_sync(sc->fxp_mtag, txp->tx_map, + BUS_DMASYNC_POSTWRITE); + bus_dmamap_unload(sc->fxp_mtag, txp->tx_map); + m_freem(txp->tx_mbuf); + } + bus_dmamap_destroy(sc->fxp_mtag, txp->tx_map); + } + bus_dma_tag_destroy(sc->fxp_mtag); + } + if (sc->fxp_stag) + bus_dma_tag_destroy(sc->fxp_stag); + if (sc->cbl_tag) + bus_dma_tag_destroy(sc->cbl_tag); + if (sc->mcs_tag) + bus_dma_tag_destroy(sc->mcs_tag); + if (sc->ifp) + if_free(sc->ifp); + + mtx_destroy(&sc->sc_mtx); +} + +/* + * Detach interface. + */ +static int +fxp_detach(device_t dev) +{ + struct fxp_softc *sc = device_get_softc(dev); + +#ifdef DEVICE_POLLING + if (sc->ifp->if_capenable & IFCAP_POLLING) + ether_poll_deregister(sc->ifp); +#endif + + FXP_LOCK(sc); + sc->suspended = 1; /* Do same thing as we do for suspend */ + /* + * Stop DMA and drop transmit queue, but disable interrupts first. + */ + CSR_WRITE_1(sc, FXP_CSR_SCB_INTRCNTL, FXP_SCB_INTR_DISABLE); + fxp_stop(sc); + FXP_UNLOCK(sc); + callout_drain(&sc->stat_ch); + + /* + * Close down routes etc. + */ + ether_ifdetach(sc->ifp); + + /* + * Unhook interrupt before dropping lock. This is to prevent + * races with fxp_intr(). + */ + bus_teardown_intr(sc->dev, sc->irq, sc->ih); + sc->ih = NULL; + + /* Release our allocated resources. */ + fxp_release(sc); + return (0); +} + +/* + * Device shutdown routine. Called at system shutdown after sync. The [... truncated: 3732 lines follow ...] From axeld at mail.berlios.de Fri May 4 08:57:27 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 4 May 2007 08:57:27 +0200 Subject: [Haiku-commits] r21008 - in haiku/trunk: headers/private/net src/add-ons/kernel/network/devices/ethernet src/add-ons/kernel/network/devices/loopback src/add-ons/kernel/network/stack Message-ID: <200705040657.l446vR9D015003@sheep.berlios.de> Author: axeld Date: 2007-05-04 08:57:26 +0200 (Fri, 04 May 2007) New Revision: 21008 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21008&view=rev Modified: haiku/trunk/headers/private/net/net_device.h haiku/trunk/src/add-ons/kernel/network/devices/ethernet/ethernet.cpp haiku/trunk/src/add-ons/kernel/network/devices/loopback/loopback.cpp haiku/trunk/src/add-ons/kernel/network/stack/datalink.cpp Log: Renamed net_device::{add|rem}_multi() to {add|remove}_multicast for consistency and clarity. Modified: haiku/trunk/headers/private/net/net_device.h =================================================================== --- haiku/trunk/headers/private/net/net_device.h 2007-05-03 21:42:09 UTC (rev 21007) +++ haiku/trunk/headers/private/net/net_device.h 2007-05-04 06:57:26 UTC (rev 21008) @@ -55,8 +55,10 @@ status_t (*set_promiscuous)(struct net_device *device, bool promiscuous); status_t (*set_media)(struct net_device *device, uint32 media); - status_t (*add_multi)(struct net_device *device, const sockaddr *); - status_t (*rem_multi)(struct net_device *device, const sockaddr *); + status_t (*add_multicast)(struct net_device *device, + const sockaddr *address); + status_t (*remove_multicast)(struct net_device *device, + const sockaddr *address); }; #endif // NET_DEVICE_H Modified: haiku/trunk/src/add-ons/kernel/network/devices/ethernet/ethernet.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/devices/ethernet/ethernet.cpp 2007-05-03 21:42:09 UTC (rev 21007) +++ haiku/trunk/src/add-ons/kernel/network/devices/ethernet/ethernet.cpp 2007-05-04 06:57:26 UTC (rev 21008) @@ -380,7 +380,7 @@ status_t -ethernet_add_multi(struct net_device *_device, const sockaddr *_address) +ethernet_add_multicast(struct net_device *_device, const sockaddr *_address) { ethernet_device *device = (ethernet_device *)_device; @@ -396,7 +396,7 @@ status_t -ethernet_rem_multi(struct net_device *_device, const sockaddr *_address) +ethernet_remove_multicast(struct net_device *_device, const sockaddr *_address) { ethernet_device *device = (ethernet_device *)_device; @@ -477,8 +477,8 @@ ethernet_set_mtu, ethernet_set_promiscuous, ethernet_set_media, - ethernet_add_multi, - ethernet_rem_multi, + ethernet_add_multicast, + ethernet_remove_multicast, }; module_info *modules[] = { Modified: haiku/trunk/src/add-ons/kernel/network/devices/loopback/loopback.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/devices/loopback/loopback.cpp 2007-05-03 21:42:09 UTC (rev 21007) +++ haiku/trunk/src/add-ons/kernel/network/devices/loopback/loopback.cpp 2007-05-04 06:57:26 UTC (rev 21008) @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -193,14 +193,14 @@ status_t -loopback_add_multi(net_device *device, const sockaddr *address) +loopback_add_multicast(net_device *device, const sockaddr *address) { return B_OK; } status_t -loopback_rem_multi(net_device *device, const sockaddr *address) +loopback_remove_multicast(net_device *device, const sockaddr *address) { return B_OK; } @@ -236,8 +236,8 @@ loopback_set_mtu, loopback_set_promiscuous, loopback_set_media, - loopback_add_multi, - loopback_rem_multi, + loopback_add_multicast, + loopback_remove_multicast, }; module_info *modules[] = { Modified: haiku/trunk/src/add-ons/kernel/network/stack/datalink.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/stack/datalink.cpp 2007-05-03 21:42:09 UTC (rev 21007) +++ haiku/trunk/src/add-ons/kernel/network/stack/datalink.cpp 2007-05-04 06:57:26 UTC (rev 21008) @@ -4,6 +4,7 @@ * * Authors: * Axel D?rfler, axeld at pinc-software.de + * Hugo Santos, hugosantos at gmail.com */ @@ -804,7 +805,8 @@ const sockaddr *address) { interface_protocol *protocol = (interface_protocol *)_protocol; - return protocol->device_module->add_multi(protocol->device, address); + + return protocol->device_module->add_multicast(protocol->device, address); } @@ -813,7 +815,9 @@ const sockaddr *address) { interface_protocol *protocol = (interface_protocol *)_protocol; - return protocol->device_module->rem_multi(protocol->device, address); + + return protocol->device_module->remove_multicast(protocol->device, + address); } From revol at free.fr Fri May 4 09:05:31 2007 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Fri, 04 May 2007 09:05:31 +0200 CEST Subject: [Haiku-commits] =?windows-1252?q?r21004_-_haiku/trunk/src/add-ons?= =?windows-1252?q?/kernel/drivers/disk/virtual/nbd?= In-Reply-To: <9c46321e0705031417q15a74874i4a880aeced862642@mail.gmail.com> Message-ID: <1081156376-BeMail@laptop> > > Implemented write(). Not sure it works as it KDLs here on shutdown > > :^) > > In Haiku? What is the ticket number? In Zeta, didn't try on Haiku yet. Btw, it builds but not when DEBUG=1, lock.h wants to include loads of stuff like arch_debugger_something.h... anyone has a fix for that ? Fran?ois. From axeld at pinc-software.de Fri May 4 09:02:03 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Fri, 04 May 2007 09:02:03 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r20947_-_in_haiku/trunk=3A_header?= =?iso-8859-15?q?s/private/net_src/add-ons/kernel/network/devices/ethernet?= =?iso-8859-15?q?_src/add-ons/kernel/network/devices/loopback_src/add-ons/?= =?iso-8859-15?q?kernel/network/stack?= In-Reply-To: <9c46321e0705011705u7b23f1d9g91c31426ac0acaa@mail.gmail.com> Message-ID: <2121975194-BeMail@zon> "Hugo Santos" wrote: > I tend to agree with Rob Pike on this: > ``Length is not a virtue in a name; clarity of expression is.'' [1] While the quote alone looks good, having read the link, I can only say: Rob Pike has no place within Haiku. I used to come from a similar direction, but I learnt for the better. Just read old code and you'll see the difference. > There is a single caller to both add_multi and rem_multi, and they > are called join_multicast and leave_multicast. Whoever is reading the > code can understand those fine -- including people who might develop > new device modules. Driver developer's will have to use > ETHER_ADDMULTI/ETHER_REMMULTI anyway. I've renamed them now add_multicast() and remove_multicast() - this is more consistent with {join|leave}_multicast() in the datalink protocol, and is also much clearer than add_multi(). > From previous discussions it seems the core developers prefer a > more > Java-ish approach to programming, if i may say so. And by that i mean > longer names and more objects. I prefer a more traditional C++ > approach i guess, with a bit of Rob Pike in the mix (oh the irony), > with clarity over verbosity (less letters to read, more efficiency -- > i.e. "ctx" vs. "context") and concepts vs. objects (more templates -- > a la STL, less Java). Java has generics which is more or less the same thing as templates. Anyway, I agree that verbosity is not a good idea, but we're far from it (unlike AGMS, right? ;-)). You'll get used to it, too, I'm sure. Bye, Axel. From korli at users.berlios.de Fri May 4 09:38:20 2007 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Fri, 4 May 2007 09:38:20 +0200 Subject: [Haiku-commits] r21002 - haiku/trunk/src/add-ons/opengl/mesa_software_renderer In-Reply-To: <894b9700705031345i7be289b3jda81a475c71b37a1@mail.gmail.com> References: <200705032029.l43KT6TK017082@sheep.berlios.de> <894b9700705031345i7be289b3jda81a475c71b37a1@mail.gmail.com> Message-ID: 2007/5/3, Stefano Ceccherini : > 2007/5/3, korli at BerliOS : > > Author: korli > > Date: 2007-05-03 22:29:05 +0200 (Thu, 03 May 2007) > > New Revision: 21002 > > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21002&view=rev > > > > Modified: > > haiku/trunk/src/add-ons/opengl/mesa_software_renderer/Jamfile > > haiku/trunk/src/add-ons/opengl/mesa_software_renderer/MesaSoftwareRenderer.cpp > > Log: > > added support for B_RGB32 > > > > > > Modified: haiku/trunk/src/add-ons/opengl/mesa_software_renderer/Jamfile > > =================================================================== > > --- haiku/trunk/src/add-ons/opengl/mesa_software_renderer/Jamfile 2007-05-03 20:05:47 UTC (rev 21001) > > +++ haiku/trunk/src/add-ons/opengl/mesa_software_renderer/Jamfile 2007-05-03 20:29:05 UTC (rev 21002) > > @@ -37,5 +37,5 @@ > > > > Addon Mesa\ Software\ Renderer : > > MesaSoftwareRenderer.cpp > > - : libGL.so libmesa.a be > > + : libGL.so libmesa.a /system/lib/libbe.so > > ; > > > > Korli, I guess this is a typo ? since it breaks the build on non beos systems... oh Sorry, it wasn't to be changed. Please revert the Jamfile for me (I could do it tonight). Bye, J?r?me From bonefish at mail.berlios.de Fri May 4 09:39:02 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Fri, 4 May 2007 09:39:02 +0200 Subject: [Haiku-commits] r21009 - haiku/trunk/src/add-ons/opengl/mesa_software_renderer Message-ID: <200705040739.l447d2DW017916@sheep.berlios.de> Author: bonefish Date: 2007-05-04 09:39:01 +0200 (Fri, 04 May 2007) New Revision: 21009 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21009&view=rev Modified: haiku/trunk/src/add-ons/opengl/mesa_software_renderer/Jamfile Log: Unbreak the build. No idea what that was supposed to mean. No Jamfile (exceptions might be obscure ones in src/tests/...) should directly refer to anything outside of the build system. Modified: haiku/trunk/src/add-ons/opengl/mesa_software_renderer/Jamfile =================================================================== --- haiku/trunk/src/add-ons/opengl/mesa_software_renderer/Jamfile 2007-05-04 06:57:26 UTC (rev 21008) +++ haiku/trunk/src/add-ons/opengl/mesa_software_renderer/Jamfile 2007-05-04 07:39:01 UTC (rev 21009) @@ -37,5 +37,5 @@ Addon Mesa\ Software\ Renderer : MesaSoftwareRenderer.cpp - : libGL.so libmesa.a /system/lib/libbe.so + : libGL.so libmesa.a be ; From axeld at mail.berlios.de Fri May 4 09:49:58 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 4 May 2007 09:49:58 +0200 Subject: [Haiku-commits] r21010 - in haiku/trunk: build/jam headers/private/graphics/matrox headers/private/graphics/neomagic headers/private/graphics/nvidia src/add-ons/accelerants/matrox src/add-ons/accelerants/neomagic src/add-ons/accelerants/nvidia src/add-ons/accelerants/radeon src/add-ons/kernel/drivers/graphics/intel_extreme src/add-ons/kernel/drivers/graphics/matrox src/add-ons/kernel/drivers/graphics/neomagic src/add-ons/kernel/drivers/graphics/nvidia src/add-ons/kernel/drivers/graphics/radeon Message-ID: <200705040749.l447nw5E018588@sheep.berlios.de> Author: axeld Date: 2007-05-04 09:49:53 +0200 (Fri, 04 May 2007) New Revision: 21010 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21010&view=rev Added: haiku/trunk/src/add-ons/kernel/drivers/graphics/matrox/matrox.settings haiku/trunk/src/add-ons/kernel/drivers/graphics/neomagic/neomagic.settings haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia/nvidia.settings Removed: haiku/trunk/src/add-ons/kernel/drivers/graphics/matrox/mga.settings haiku/trunk/src/add-ons/kernel/drivers/graphics/neomagic/nm.settings haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia/nv.settings Modified: haiku/trunk/build/jam/HaikuImage haiku/trunk/headers/private/graphics/matrox/DriverInterface.h haiku/trunk/headers/private/graphics/neomagic/DriverInterface.h haiku/trunk/headers/private/graphics/nvidia/DriverInterface.h haiku/trunk/src/add-ons/accelerants/matrox/Jamfile haiku/trunk/src/add-ons/accelerants/matrox/Overlay.c haiku/trunk/src/add-ons/accelerants/neomagic/Jamfile haiku/trunk/src/add-ons/accelerants/nvidia/Jamfile haiku/trunk/src/add-ons/accelerants/radeon/Jamfile haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/driver.cpp haiku/trunk/src/add-ons/kernel/drivers/graphics/matrox/Jamfile haiku/trunk/src/add-ons/kernel/drivers/graphics/neomagic/Jamfile haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia/Jamfile haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia/driver.c haiku/trunk/src/add-ons/kernel/drivers/graphics/radeon/Jamfile Log: * Renamed nv.driver to "nvidia", nm.driver to "neomagic", and mga.driver to "matrox"; also renamed their accelerants and settings files accordingly. * Added Mandelbrot and GLDirectMode as demo applications. * Moved CortexAddOnHost to /bin. Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2007-05-04 07:39:01 UTC (rev 21009) +++ haiku/trunk/build/jam/HaikuImage 2007-05-04 07:49:53 UTC (rev 21010) @@ -22,6 +22,7 @@ BEOS_BIN = "[" addattr alert arp basename bc beep bzip2 cat cardctl catattr chgrp chmod chop chown cksum clear clockconfig cmp comm compress cp copyattr + $(X86_ONLY)CortexAddOnHost csplit ctags cut date dc dd desklink df diff diff3 dircolors dirname driveinfo dstcheck du dump_cis dump_cisreg echo eject env error expand expr factor false fdinfo ffm find finddir fmt fold fortune frcode ftp funzip gawk @@ -44,7 +45,7 @@ BEOS_APPS = Terminal Expander People ShowImage Pulse ProcessController SoundRecorder Magnify DiskProbe AboutHaiku StyledEdit Installer Workspaces - $(X86_ONLY)Cortex $(X86_ONLY)CortexAddOnHost MediaPlayer DeskCalc MidiPlayer + $(X86_ONLY)Cortex MediaPlayer DeskCalc MidiPlayer Icon-O-Matic Mail CDPlayer NetworkStatus TV ; BEOS_PREFERENCES = Appearance Backgrounds DataTranslations E-mail FileTypes @@ -52,7 +53,7 @@ Time VirtualMemory ; BEOS_DEMOS = BitmapDrawing Chart Clock FontDemo $(X86_ONLY)GLTeapot PictureTest - Playground + Playground Mandelbrot GLDirectMode ; BEOS_SYSTEM_LIB = libbe.so $(HAIKU_LIBSTDC++) libmedia.so libtracker.so libtranslation.so libnetwork.so libdebug.so libbsd.so libmail.so @@ -70,8 +71,8 @@ #BEOS_NETWORK_PPP = ipcp modem pap pppoe ; BEOS_NETWORK_PROTOCOLS = ipv4 tcp udp icmp ; -BEOS_ADD_ONS_ACCELERANTS = $(X86_ONLY)radeon.accelerant $(X86_ONLY)nv.accelerant - $(X86_ONLY)mga.accelerant $(X86_ONLY)nm.accelerant +BEOS_ADD_ONS_ACCELERANTS = $(X86_ONLY)radeon.accelerant $(X86_ONLY)nvidia.accelerant + $(X86_ONLY)matrox.accelerant $(X86_ONLY)neomagic.accelerant $(X86_ONLY)intel_extreme.accelerant vesa.accelerant #$(X86_ONLY)vmware.accelerant ; @@ -103,8 +104,8 @@ ; BEOS_ADD_ONS_SCREENSAVERS = Haiku IFS ; BEOS_ADD_ONS_DRIVERS_AUDIO = auich auvia emuxki ; -BEOS_ADD_ONS_DRIVERS_GRAPHICS = $(X86_ONLY)radeon.driver $(X86_ONLY)nv.driver - $(X86_ONLY)nm.driver $(X86_ONLY)mga.driver $(X86_ONLY)intel_extreme vesa +BEOS_ADD_ONS_DRIVERS_GRAPHICS = $(X86_ONLY)radeon $(X86_ONLY)nvidia + $(X86_ONLY)neomagic $(X86_ONLY)matrox $(X86_ONLY)intel_extreme vesa #$(X86_ONLY)vmware ; BEOS_ADD_ONS_DRIVERS_MIDI = emuxki ; Modified: haiku/trunk/headers/private/graphics/matrox/DriverInterface.h =================================================================== --- haiku/trunk/headers/private/graphics/matrox/DriverInterface.h 2007-05-04 07:39:01 UTC (rev 21009) +++ haiku/trunk/headers/private/graphics/matrox/DriverInterface.h 2007-05-04 07:49:53 UTC (rev 21010) @@ -17,7 +17,7 @@ #include #include -#define DRIVER_PREFIX "mga" // apsed +#define DRIVER_PREFIX "matrox" // apsed #define DEVICE_FORMAT "%04x_%04x_%02x%02x%02x" // apsed /* Modified: haiku/trunk/headers/private/graphics/neomagic/DriverInterface.h =================================================================== --- haiku/trunk/headers/private/graphics/neomagic/DriverInterface.h 2007-05-04 07:39:01 UTC (rev 21009) +++ haiku/trunk/headers/private/graphics/neomagic/DriverInterface.h 2007-05-04 07:49:53 UTC (rev 21010) @@ -15,7 +15,7 @@ #include #include -#define DRIVER_PREFIX "nm" // apsed +#define DRIVER_PREFIX "neomagic" /* Internal driver state (also for sharing info between driver and accelerant) Modified: haiku/trunk/headers/private/graphics/nvidia/DriverInterface.h =================================================================== --- haiku/trunk/headers/private/graphics/nvidia/DriverInterface.h 2007-05-04 07:39:01 UTC (rev 21009) +++ haiku/trunk/headers/private/graphics/nvidia/DriverInterface.h 2007-05-04 07:49:53 UTC (rev 21010) @@ -18,7 +18,7 @@ #include #include "AGP.h" -#define DRIVER_PREFIX "nv" // apsed +#define DRIVER_PREFIX "nvidia" // apsed #define DEVICE_FORMAT "%04x_%04x_%02x%02x%02x" // apsed /* Modified: haiku/trunk/src/add-ons/accelerants/matrox/Jamfile =================================================================== --- haiku/trunk/src/add-ons/accelerants/matrox/Jamfile 2007-05-04 07:39:01 UTC (rev 21009) +++ haiku/trunk/src/add-ons/accelerants/matrox/Jamfile 2007-05-04 07:49:53 UTC (rev 21010) @@ -6,7 +6,7 @@ UsePrivateHeaders [ FDirName graphics matrox ] ; UseHeaders [ FDirName $(SUBDIR) engine ] ; -Addon mga.accelerant : +Addon matrox.accelerant : Cursor.c EngineManagment.c GetAccelerantHook.c @@ -21,9 +21,9 @@ ; Package haiku-matrox-cvs : - mga.accelerant : + matrox.accelerant : boot home config add-ons accelerants ; -Depends mga.accelerant : mga.driver ; +Depends matrox.accelerant : matrox ; SubInclude HAIKU_TOP src add-ons accelerants matrox engine ; Modified: haiku/trunk/src/add-ons/accelerants/matrox/Overlay.c =================================================================== --- haiku/trunk/src/add-ons/accelerants/matrox/Overlay.c 2007-05-04 07:39:01 UTC (rev 21009) +++ haiku/trunk/src/add-ons/accelerants/matrox/Overlay.c 2007-05-04 07:49:53 UTC (rev 21010) @@ -238,7 +238,7 @@ /* NOTE to app programmers: * For testing app behaviour regarding workspace switches or screen prefs changes to settings * that do not have enough cardRAM left for allocation of overlay bitmaps, you need a card with - * a low amount of RAM. Or you can set in the file mga.settings for example: + * a low amount of RAM. Or you can set in the file matrox.settings for example: * memory 8 #8Mb RAM on card * and reboot (this simulates 8Mb RAM on the card). * @@ -332,7 +332,7 @@ /* NOTE to app programmers: * For testing app behaviour regarding workspace switches or screen prefs changes to settings * that do not have enough cardRAM left for allocation of overlay bitmaps, you need a card with - * a low amount of RAM. Or you can set in the file mga.settings for example: + * a low amount of RAM. Or you can set in the file matrox.settings for example: * memory 8 #8Mb RAM on card * and reboot (this simulates 8Mb RAM on the card). * Modified: haiku/trunk/src/add-ons/accelerants/neomagic/Jamfile =================================================================== --- haiku/trunk/src/add-ons/accelerants/neomagic/Jamfile 2007-05-04 07:39:01 UTC (rev 21009) +++ haiku/trunk/src/add-ons/accelerants/neomagic/Jamfile 2007-05-04 07:49:53 UTC (rev 21010) @@ -6,7 +6,7 @@ UsePrivateHeaders [ FDirName graphics neomagic ] ; UseHeaders [ FDirName $(SUBDIR) engine ] ; -Addon nm.accelerant : +Addon neomagic.accelerant : Acceleration.c Cursor.c EngineManagment.c @@ -22,9 +22,9 @@ ; Package haiku-neomagic-cvs : - nm.accelerant : + neomagic.accelerant : boot home config add-ons accelerants ; -Depends nm.accelerant : nm.driver ; +Depends neomagic.accelerant : neomagic ; SubInclude HAIKU_TOP src add-ons accelerants neomagic engine ; Modified: haiku/trunk/src/add-ons/accelerants/nvidia/Jamfile =================================================================== --- haiku/trunk/src/add-ons/accelerants/nvidia/Jamfile 2007-05-04 07:39:01 UTC (rev 21009) +++ haiku/trunk/src/add-ons/accelerants/nvidia/Jamfile 2007-05-04 07:49:53 UTC (rev 21010) @@ -6,7 +6,7 @@ UsePrivateHeaders [ FDirName graphics nvidia ] ; UseHeaders [ FDirName $(SUBDIR) engine ] ; -Addon nv.accelerant : +Addon nvidia.accelerant : Acceleration.c Cursor.c EngineManagment.c @@ -22,9 +22,9 @@ ; Package haiku-nvidia-cvs : - nv.accelerant : + nvidia.accelerant : boot home config add-ons accelerants ; -Depends nv.accelerant : nv.driver ; +Depends nvidia.accelerant : nvidia ; SubInclude HAIKU_TOP src add-ons accelerants nvidia engine ; Modified: haiku/trunk/src/add-ons/accelerants/radeon/Jamfile =================================================================== --- haiku/trunk/src/add-ons/accelerants/radeon/Jamfile 2007-05-04 07:39:01 UTC (rev 21009) +++ haiku/trunk/src/add-ons/accelerants/radeon/Jamfile 2007-05-04 07:49:53 UTC (rev 21010) @@ -40,4 +40,4 @@ radeon.accelerant : boot home config add-ons accelerants ; -Depends radeon.accelerant : radeon.driver ; +Depends radeon.accelerant : radeon ; Modified: haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/driver.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/driver.cpp 2007-05-04 07:39:01 UTC (rev 21009) +++ haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/driver.cpp 2007-05-04 07:49:53 UTC (rev 21010) @@ -42,7 +42,7 @@ {0x2572, INTEL_TYPE_8xx | INTEL_TYPE_85x, "i865G"}, {0x3582, INTEL_TYPE_8xx | INTEL_TYPE_85x, "i855G"}, -#if 0 +#if 1 {0x2792, INTEL_TYPE_9xx, "i910"}, {0x258a, INTEL_TYPE_9xx, "i915"}, {0x2582, INTEL_TYPE_9xx, "i915G"}, Modified: haiku/trunk/src/add-ons/kernel/drivers/graphics/matrox/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/graphics/matrox/Jamfile 2007-05-04 07:39:01 UTC (rev 21009) +++ haiku/trunk/src/add-ons/kernel/drivers/graphics/matrox/Jamfile 2007-05-04 07:49:53 UTC (rev 21010) @@ -5,17 +5,16 @@ UsePrivateHeaders graphics ; UsePrivateHeaders [ FDirName graphics matrox ] ; -KernelAddon mga.driver : +KernelAddon matrox : driver.c ; Package haiku-matrox-cvs : README.html UPDATE.html ; Package haiku-matrox-cvs : - mga.driver : + matrox : boot home config add-ons kernel drivers bin ; -PackageDriverSymLink haiku-matrox-cvs : graphics mga.driver ; +PackageDriverSymLink haiku-matrox-cvs : graphics matrox ; Package haiku-matrox-cvs : - mga.settings : + matrox.settings : boot home config settings kernel drivers ; - Copied: haiku/trunk/src/add-ons/kernel/drivers/graphics/matrox/matrox.settings (from rev 21007, haiku/trunk/src/add-ons/kernel/drivers/graphics/matrox/mga.settings) Deleted: haiku/trunk/src/add-ons/kernel/drivers/graphics/matrox/mga.settings Modified: haiku/trunk/src/add-ons/kernel/drivers/graphics/neomagic/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/graphics/neomagic/Jamfile 2007-05-04 07:39:01 UTC (rev 21009) +++ haiku/trunk/src/add-ons/kernel/drivers/graphics/neomagic/Jamfile 2007-05-04 07:49:53 UTC (rev 21010) @@ -5,17 +5,17 @@ UsePrivateHeaders graphics ; UsePrivateHeaders [ FDirName graphics neomagic ] ; -KernelAddon nm.driver : +KernelAddon neomagic : driver.c ; Package haiku-neomagic-cvs : README.html UPDATE.html ; Package haiku-neomagic-cvs : - nm.driver : + neomagic : boot home config add-ons kernel drivers bin ; -PackageDriverSymLink haiku-neomagic-cvs : graphics nm.driver ; +PackageDriverSymLink haiku-neomagic-cvs : graphics neomagic ; Package haiku-neomagic-cvs : - nm.settings : + neomagic.settings : boot home config settings kernel drivers ; Copied: haiku/trunk/src/add-ons/kernel/drivers/graphics/neomagic/neomagic.settings (from rev 21007, haiku/trunk/src/add-ons/kernel/drivers/graphics/neomagic/nm.settings) =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/graphics/neomagic/nm.settings 2007-05-03 21:42:09 UTC (rev 21007) +++ haiku/trunk/src/add-ons/kernel/drivers/graphics/neomagic/neomagic.settings 2007-05-04 07:49:53 UTC (rev 21010) @@ -0,0 +1,49 @@ +# Settings file for the neomagic driver and accelerant +# +# This file should be moved to the directory +# ~/config/settings/kernel/drivers/ +# + +# neomagic parameters +# accelerant "neomagic.accelerant" + +# nm.accelerant parameters +usebios true # if true rely on bios to coldstart the card instead of driver (not functional) +#memory 2048 # in Kb, override builtin memory size detection +hardcursor true # if true use on-chip cursor capabilities +#logmask 0x00000000 # nothing logged, except errors, is default +#logmask 0x80000000 # log card physical features +#logmask 0x80000000 # log following mask +#logmask 0x08000604 # log overlay use in full +#logmask 0xffffffff # log everything +dumprom false # dump bios rom in ~/neomagic.rom + +#--------- that's all. + + +#logmask setup info: +#log level select: +#logmask 0x0000000x # lowest digit: bitmask to select logging level. + +#log modules select: +#logmask 0xxxxxxxx0 # highest 7 digits: bitmask to select individual modules to log. + +#log modules: +#logmask 0x00000200 # engine: bes +#logmask 0x00000400 # overlay +#logmask 0x00000800 # engine: support +#logmask 0x00002000 # engine: info +#logmask 0x00008000 # engine: general +#logmask 0x00010000 # engine: dac +#logmask 0x00040000 # engine: crtc +#logmask 0x00080000 # engine: acc +#logmask 0x00200000 # set displaymode +#logmask 0x00400000 # propose displaymode +#logmask 0x00800000 # init accelerant +#logmask 0x01000000 # get timing constraints +#logmask 0x02000000 # get mode info +#logmask 0x04000000 # get device info +#logmask 0x08000000 # get accelerant hook +#logmask 0x10000000 # engine management +#logmask 0x20000000 # cursor +#logmask 0x40000000 # acceleration Deleted: haiku/trunk/src/add-ons/kernel/drivers/graphics/neomagic/nm.settings Modified: haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia/Jamfile 2007-05-04 07:39:01 UTC (rev 21009) +++ haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia/Jamfile 2007-05-04 07:49:53 UTC (rev 21010) @@ -5,17 +5,17 @@ UsePrivateHeaders graphics ; UsePrivateHeaders [ FDirName graphics nvidia ] ; -KernelAddon nv.driver : +KernelAddon nvidia : driver.c ; Package haiku-nvidia-cvs : README.html UPDATE.html ; Package haiku-nvidia-cvs : - nv.driver : + nvidia : boot home config add-ons kernel drivers bin ; -PackageDriverSymLink haiku-nvidia-cvs : graphics nv.driver ; +PackageDriverSymLink haiku-nvidia-cvs : graphics nvidia ; Package haiku-nvidia-cvs : - nv.settings : + nvidia.settings : boot home config settings kernel drivers ; Modified: haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia/driver.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia/driver.c 2007-05-04 07:39:01 UTC (rev 21009) +++ haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia/driver.c 2007-05-04 07:49:53 UTC (rev 21010) @@ -7,30 +7,22 @@ Rudolf Cornelissen 3/2002-4/2006. */ -/* standard kernel driver stuff */ + +#include "AGP.h" +#include "DriverInterface.h" +#include "nv_macros.h" + +#include #include #include #include #include #include -#include -#include // for strtoXX -#include "AGP.h" -/* this is for the standardized portion of the driver API */ -/* currently only one operation is defined: B_GET_ACCELERANT_SIGNATURE */ -#include - -/* this is for sprintf() */ +#include #include - -/* this is for string compares */ #include -/* The private interface between the accelerant and the kernel driver. */ -#include "DriverInterface.h" -#include "nv_macros.h" - #define get_pci(o, s) (*pci_bus->read_pci_config)(pcii->bus, pcii->device, pcii->function, (o), (s)) #define set_pci(o, s, v) (*pci_bus->write_pci_config)(pcii->bus, pcii->device, pcii->function, (o), (s), (v)) @@ -42,7 +34,7 @@ #endif /* Tell the kernel what revision of the driver API we support */ -int32 api_version = B_CUR_DRIVER_API_VERSION; // apsed, was 2, is 2 in R5 +int32 api_version = B_CUR_DRIVER_API_VERSION; /* these structures are private to the kernel driver */ typedef struct device_info device_info; @@ -70,12 +62,12 @@ } DeviceData; /* prototypes for our private functions */ -static status_t open_hook (const char* name, uint32 flags, void** cookie); -static status_t close_hook (void* dev); -static status_t free_hook (void* dev); -static status_t read_hook (void* dev, off_t pos, void* buf, size_t* len); -static status_t write_hook (void* dev, off_t pos, const void* buf, size_t* len); -static status_t control_hook (void* dev, uint32 msg, void *buf, size_t len); +static status_t open_hook(const char* name, uint32 flags, void** cookie); +static status_t close_hook(void* dev); +static status_t free_hook(void* dev); +static status_t read_hook(void* dev, off_t pos, void* buf, size_t* len); +static status_t write_hook(void* dev, off_t pos, const void* buf, size_t* len); +static status_t control_hook(void* dev, uint32 msg, void *buf, size_t len); static status_t map_device(device_info *di); static void unmap_device(device_info *di); static void probe_devices(void); @@ -363,7 +355,7 @@ {0x0000, NULL} }; -static nv_settings current_settings = { // see comments in nv.settings +static nv_settings sSettings = { // see comments in nvidia.settings /* for driver */ DRIVER_PREFIX ".accelerant", "none", // primary @@ -386,7 +378,9 @@ 0, // ram_clk }; -static void dumprom (void *rom, uint32 size, pci_info pcii) + +static void +dumprom(void *rom, uint32 size, pci_info pcii) { int fd; uint32 cnt; @@ -406,19 +400,25 @@ close (fd); } -/* return 1 if vblank interrupt has occured */ -static int caused_vbi_crtc1(vuint32 * regs) + +/*! return 1 if vblank interrupt has occured */ +static int +caused_vbi_crtc1(vuint32 * regs) { return (NV_REG32(NV32_CRTC_INTS) & 0x00000001); } -/* clear the vblank interrupt */ -static void clear_vbi_crtc1(vuint32 * regs) + +/*! clear the vblank interrupt */ +static void +clear_vbi_crtc1(vuint32 * regs) { NV_REG32(NV32_CRTC_INTS) = 0x00000001; } -static void enable_vbi_crtc1(vuint32 * regs) + +static void +enable_vbi_crtc1(vuint32 * regs) { /* clear the vblank interrupt */ NV_REG32(NV32_CRTC_INTS) = 0x00000001; @@ -428,7 +428,9 @@ NV_REG32(NV32_MAIN_INTE) = 0x00000001; } -static void disable_vbi_crtc1(vuint32 * regs) + +static void +disable_vbi_crtc1(vuint32 * regs) { /* disable nVidia interrupt source vblank */ NV_REG32(NV32_CRTC_INTE) &= 0xfffffffe; @@ -436,19 +438,25 @@ NV_REG32(NV32_CRTC_INTS) = 0x00000001; } -/* return 1 if vblank interrupt has occured */ -static int caused_vbi_crtc2(vuint32 * regs) + +/*! return 1 if vblank interrupt has occured */ +static int +caused_vbi_crtc2(vuint32 * regs) { return (NV_REG32(NV32_CRTC2_INTS) & 0x00000001); } -/* clear the vblank interrupt */ -static void clear_vbi_crtc2(vuint32 * regs) + +/*! clear the vblank interrupt */ +static void +clear_vbi_crtc2(vuint32 * regs) { NV_REG32(NV32_CRTC2_INTS) = 0x00000001; } -static void enable_vbi_crtc2(vuint32 * regs) + +static void +enable_vbi_crtc2(vuint32 * regs) { /* clear the vblank interrupt */ NV_REG32(NV32_CRTC2_INTS) = 0x00000001; @@ -458,7 +466,9 @@ NV_REG32(NV32_MAIN_INTE) = 0x00000001; } -static void disable_vbi_crtc2(vuint32 * regs) + +static void +disable_vbi_crtc2(vuint32 * regs) { /* disable nVidia interrupt source vblank */ NV_REG32(NV32_CRTC2_INTE) &= 0xfffffffe; @@ -466,13 +476,15 @@ NV_REG32(NV32_CRTC2_INTS) = 0x00000001; } + //fixme: //dangerous code, on singlehead cards better not try accessing secondary head //registers (card might react in unpredictable ways, though there's only a small //chance we actually run into this). //fix requires (some) card recognition code to be moved from accelerant to //kerneldriver... -static void disable_vbi_all(vuint32 * regs) +static void +disable_vbi_all(vuint32 * regs) { /* disable nVidia interrupt source vblank */ NV_REG32(NV32_CRTC_INTE) &= 0xfffffffe; @@ -488,177 +500,9 @@ NV_REG32(NV32_MAIN_INTE) = 0x00000000; } -/* - init_hardware() - Returns B_OK if one is - found, otherwise returns B_ERROR so the driver will be unloaded. -*/ -status_t -init_hardware(void) { - long pci_index = 0; - pci_info pcii; - bool found_one = false; - - /* choke if we can't find the PCI bus */ - if (get_module(B_PCI_MODULE_NAME, (module_info **)&pci_bus) != B_OK) - return B_ERROR; - /* choke if we can't find the ISA bus */ - if (get_module(B_ISA_MODULE_NAME, (module_info **)&isa_bus) != B_OK) - { - put_module(B_PCI_MODULE_NAME); - return B_ERROR; - } - - /* while there are more pci devices */ - while ((*pci_bus->get_nth_pci_info)(pci_index, &pcii) == B_NO_ERROR) { - int vendor = 0; - - /* if we match a supported vendor */ - while (SupportedDevices[vendor].vendor) { - if (SupportedDevices[vendor].vendor == pcii.vendor_id) { - uint16 *devices = SupportedDevices[vendor].devices; - /* while there are more supported devices */ - while (*devices) { - /* if we match a supported device */ - if (*devices == pcii.device_id ) { - - found_one = true; - goto done; - } - /* next supported device */ - devices++; - } - } - vendor++; - } - /* next pci_info struct, please */ - pci_index++; - } - -done: - /* put away the module manager */ - put_module(B_PCI_MODULE_NAME); - return (found_one ? B_OK : B_ERROR); -} - -status_t -init_driver(void) { - void *settings_handle; - - // get driver/accelerant settings, apsed - settings_handle = load_driver_settings (DRIVER_PREFIX ".settings"); - if (settings_handle != NULL) { - const char *item; - char *end; - uint32 value; - - // for driver - item = get_driver_parameter (settings_handle, "accelerant", "", ""); - if ((strlen (item) > 0) && (strlen (item) < sizeof (current_settings.accelerant) - 1)) { - strcpy (current_settings.accelerant, item); - } - item = get_driver_parameter (settings_handle, "primary", "", ""); - if ((strlen (item) > 0) && (strlen (item) < sizeof (current_settings.primary) - 1)) { - strcpy (current_settings.primary, item); - } - current_settings.dumprom = get_driver_boolean_parameter (settings_handle, "dumprom", false, false); - - // for accelerant - item = get_driver_parameter (settings_handle, "logmask", "0x00000000", "0x00000000"); - value = strtoul (item, &end, 0); - if (*end == '\0') current_settings.logmask = value; - - item = get_driver_parameter (settings_handle, "memory", "0", "0"); - value = strtoul (item, &end, 0); - if (*end == '\0') current_settings.memory = value; - - item = get_driver_parameter (settings_handle, "tv_output", "0", "0"); - value = strtoul (item, &end, 0); - if (*end == '\0') current_settings.tv_output = value; - - current_settings.hardcursor = get_driver_boolean_parameter (settings_handle, "hardcursor", false, false); - current_settings.usebios = get_driver_boolean_parameter (settings_handle, "usebios", false, false); - current_settings.switchhead = get_driver_boolean_parameter (settings_handle, "switchhead", false, false); - current_settings.force_pci = get_driver_boolean_parameter (settings_handle, "force_pci", false, false); - current_settings.unhide_fw = get_driver_boolean_parameter (settings_handle, "unhide_fw", false, false); - current_settings.pgm_panel = get_driver_boolean_parameter (settings_handle, "pgm_panel", false, false); - current_settings.dma_acc = get_driver_boolean_parameter (settings_handle, "dma_acc", false, false); - current_settings.vga_on_tv = get_driver_boolean_parameter (settings_handle, "vga_on_tv", false, false); - current_settings.force_sync = get_driver_boolean_parameter (settings_handle, "force_sync", false, false); - current_settings.force_ws = get_driver_boolean_parameter (settings_handle, "force_ws", false, false); - - item = get_driver_parameter (settings_handle, "gpu_clk", "0", "0"); - value = strtoul (item, &end, 0); - if (*end == '\0') current_settings.gpu_clk = value; - - item = get_driver_parameter (settings_handle, "ram_clk", "0", "0"); - value = strtoul (item, &end, 0); - if (*end == '\0') current_settings.ram_clk = value; - - unload_driver_settings (settings_handle); - } - - /* get a handle for the pci bus */ - if (get_module(B_PCI_MODULE_NAME, (module_info **)&pci_bus) != B_OK) - return B_ERROR; - - /* get a handle for the isa bus */ - if (get_module(B_ISA_MODULE_NAME, (module_info **)&isa_bus) != B_OK) - { - put_module(B_PCI_MODULE_NAME); - return B_ERROR; - } - - /* get a handle for the agp bus if it exists */ - get_module(B_AGP_MODULE_NAME, (module_info **)&agp_bus); - - /* driver private data */ - pd = (DeviceData *)calloc(1, sizeof(DeviceData)); - if (!pd) { - put_module(B_PCI_MODULE_NAME); - return B_ERROR; - } - /* initialize the benaphore */ - INIT_BEN(pd->kernel); - /* find all of our supported devices */ - probe_devices(); - return B_OK; -} - -const char ** -publish_devices(void) { - /* return the list of supported devices */ - return (const char **)pd->device_names; -} - -device_hooks * -find_device(const char *name) { - int index = 0; - while (pd->device_names[index]) { - if (strcmp(name, pd->device_names[index]) == 0) - return &graphics_device_hooks; - index++; - } - return NULL; - -} - -void uninit_driver(void) { - - /* free the driver data */ - DELETE_BEN(pd->kernel); - free(pd); - pd = NULL; - - /* put the pci module away */ - put_module(B_PCI_MODULE_NAME); - put_module(B_ISA_MODULE_NAME); - - /* put the agp module away if it's there */ - if (agp_bus) put_module(B_AGP_MODULE_NAME); -} - -static status_t map_device(device_info *di) +static status_t +map_device(device_info *di) { char buffer[B_OS_NAME_LENGTH]; /*memory for device name*/ shared_info *si = di->si; @@ -735,8 +579,7 @@ //having the ROM mapped on PCI and PCIe cards. Falling back to fetching from ISA //legacy space will get us into trouble if we aren't the primary graphics card!! //(as legacy space always has the primary card's ROM 'mapped'!) - if (tmpUlong) - { + if (tmpUlong) { /* ROM was assigned an adress, so enable ROM decoding - see PCI standard */ tmpUlong |= 0x00000001; set_pci(PCI_rom_base, 4, tmpUlong); @@ -751,35 +594,24 @@ ); /* check if we got the BIOS and signature (might fail on laptops..) */ - if (rom_area >= 0) - { - if ((rom_temp[0] != 0x55) || (rom_temp[1] != 0xaa)) - { + if (rom_area >= 0) { + if ((rom_temp[0] != 0x55) || (rom_temp[1] != 0xaa)) { /* apparantly no ROM is mapped here */ delete_area(rom_area); rom_area = -1; /* force using ISA legacy map as fall-back */ tmpUlong = 0x00000000; } - } - else - { + } else { /* mapping failed: force using ISA legacy map as fall-back */ tmpUlong = 0x00000000; } } - if (!tmpUlong) - { + if (!tmpUlong) { /* ROM was not assigned an adress, fetch it from ISA legacy memory map! */ - rom_area = map_physical_memory( - buffer, - (void *)0x000c0000, - 65536, - B_ANY_KERNEL_ADDRESS, - B_READ_AREA, - (void **)&(rom_temp) - ); + rom_area = map_physical_memory(buffer, (void *)0x000c0000, + 65536, B_ANY_KERNEL_ADDRESS, B_READ_AREA, (void **)&(rom_temp)); } /* if mapping ROM to vmem failed then clean up and pass on error */ @@ -789,11 +621,13 @@ return rom_area; } - /* dump ROM to file if selected in nv.settings + /* dump ROM to file if selected in nvidia.settings * (ROM always fits in 64Kb: checked TNT1 - FX5950) */ - if (current_settings.dumprom) dumprom (rom_temp, 65536, di->pcii); + if (sSettings.dumprom) + dumprom(rom_temp, 65536, di->pcii); + /* make a copy of ROM for future reference */ - memcpy (si->rom_mirror, rom_temp, 65536); + memcpy(si->rom_mirror, rom_temp, 65536); /* disable ROM decoding - this is defined in the PCI standard, and delete the area */ tmpUlong = get_pci(PCI_rom_base, 4); @@ -810,8 +644,7 @@ di->pcii.bus, di->pcii.device, di->pcii.function); /* map the framebuffer into vmem, using Write Combining*/ - si->fb_area = map_physical_memory( - buffer, + si->fb_area = map_physical_memory(buffer, /* WARNING: Nvidia needs to map framebuffer as viewed from PCI space! */ (void *) di->pcii.u.h0.base_registers_pci[frame_buffer], di->pcii.u.h0.base_register_sizes[frame_buffer], @@ -821,8 +654,7 @@ /*if failed with write combining try again without*/ if (si->fb_area < 0) { - si->fb_area = map_physical_memory( - buffer, + si->fb_area = map_physical_memory(buffer, /* WARNING: Nvidia needs to map framebuffer as viewed from PCI space! */ (void *) di->pcii.u.h0.base_registers_pci[frame_buffer], di->pcii.u.h0.base_register_sizes[frame_buffer], @@ -830,26 +662,29 @@ B_READ_AREA | B_WRITE_AREA, &(si->framebuffer)); } - + /* if there was an error, delete our other areas and pass on error*/ - if (si->fb_area < 0) - { + if (si->fb_area < 0) { delete_area(si->regs_area); si->regs_area = -1; return si->fb_area; } -//fixme: retest for card coldstart and PCI/virt_mem mapping!! + + //fixme: retest for card coldstart and PCI/virt_mem mapping!! /* remember the DMA address of the frame buffer for BDirectWindow?? purposes */ si->framebuffer_pci = (void *) di->pcii.u.h0.base_registers_pci[frame_buffer]; // remember settings for use here and in accelerant - si->settings = current_settings; + si->settings = sSettings; /* in any case, return the result */ return si->fb_area; } -static void unmap_device(device_info *di) { + +static void +unmap_device(device_info *di) +{ shared_info *si = di->si; uint32 tmpUlong; pci_info *pcii = &(di->pcii); @@ -859,23 +694,29 @@ tmpUlong &= 0xfffffffc; set_pci(PCI_command, 4, tmpUlong); /* delete the areas */ - if (si->regs_area >= 0) delete_area(si->regs_area); - if (si->fb_area >= 0) delete_area(si->fb_area); + if (si->regs_area >= 0) + delete_area(si->regs_area); + if (si->fb_area >= 0) + delete_area(si->fb_area); si->regs_area = si->fb_area = -1; si->framebuffer = NULL; di->regs = NULL; } -static void probe_devices(void) { + +static void +probe_devices(void) +{ uint32 pci_index = 0; uint32 count = 0; device_info *di = pd->di; char tmp_name[B_OS_NAME_LENGTH]; /* while there are more pci devices */ - while ((count < MAX_DEVICES) && ((*pci_bus->get_nth_pci_info)(pci_index, &(di->pcii)) == B_NO_ERROR)) { + while (count < MAX_DEVICES + && (*pci_bus->get_nth_pci_info)(pci_index, &(di->pcii)) == B_OK) { int vendor = 0; - + /* if we match a supported vendor */ while (SupportedDevices[vendor].vendor) { if (SupportedDevices[vendor].vendor == di->pcii.vendor_id) { @@ -890,9 +731,9 @@ di->pcii.bus, di->pcii.device, di->pcii.function); /* tweak the exported name to show first in the alphabetically ordered /dev/ * hierarchy folder, so the system will use it as primary adaptor if requested - * via nv.settings. */ - if (strcmp(tmp_name, current_settings.primary) == 0) - sprintf(tmp_name, "-%s", current_settings.primary); + * via nvidia.settings. */ + if (strcmp(tmp_name, sSettings.primary) == 0) + sprintf(tmp_name, "-%s", sSettings.primary); /* add /dev/ hierarchy path */ sprintf(di->name, "graphics/%s", tmp_name); /* remember the name */ @@ -926,7 +767,10 @@ pd->device_names[pd->count] = NULL; } -static uint32 thread_interrupt_work(int32 *flags, vuint32 *regs, shared_info *si) { + +static uint32 +thread_interrupt_work(int32 *flags, vuint32 *regs, shared_info *si) +{ uint32 handled = B_HANDLED_INTERRUPT; /* release the vblank semaphore */ if (si->vblank >= 0) { @@ -939,6 +783,7 @@ return handled; } + static int32 nv_interrupt(void *data) { @@ -956,23 +801,18 @@ /* was it a VBI? */ /* note: si->ps.secondary_head was cleared by kerneldriver earlier! (at least) */ - if (si->ps.secondary_head) - { + if (si->ps.secondary_head) { //fixme: //rewrite once we use one driver instance 'per head' (instead of 'per card') - if (caused_vbi_crtc1(regs) || caused_vbi_crtc2(regs)) - { + if (caused_vbi_crtc1(regs) || caused_vbi_crtc2(regs)) { /* clear the interrupt(s) */ clear_vbi_crtc1(regs); clear_vbi_crtc2(regs); /* release the semaphore */ handled = thread_interrupt_work(flags, regs, si); } - } - else - { - if (caused_vbi_crtc1(regs)) - { + } else { + if (caused_vbi_crtc1(regs)) { /* clear the interrupt */ clear_vbi_crtc1(regs); /* release the semaphore */ @@ -987,7 +827,13 @@ return handled; } -static status_t open_hook (const char* name, uint32 flags, void** cookie) { + +// #pragma mark - device hooks + + +static status_t +open_hook(const char* name, uint32 flags, void** cookie) +{ int32 index = 0; device_info *di; shared_info *si; @@ -1001,7 +847,9 @@ /* find the device name in the list of devices */ /* we're never passed a name we didn't publish */ - while (pd->device_names[index] && (strcmp(name, pd->device_names[index]) != 0)) index++; + while (pd->device_names[index] + && (strcmp(name, pd->device_names[index]) != 0)) + index++; /* for convienience */ di = &(pd->di[index]); @@ -1203,41 +1051,34 @@ return result; } -/* ---------- - read_hook - does nothing, gracefully ------ */ + static status_t -read_hook (void* dev, off_t pos, void* buf, size_t* len) +read_hook(void* dev, off_t pos, void* buf, size_t* len) { *len = 0; return B_NOT_ALLOWED; } -/* ---------- - write_hook - does nothing, gracefully ------ */ [... truncated: 430 lines follow ...] From bonefish at mail.berlios.de Fri May 4 09:59:48 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Fri, 4 May 2007 09:59:48 +0200 Subject: [Haiku-commits] r21011 - haiku/trunk/headers/posix Message-ID: <200705040759.l447xmKl019109@sheep.berlios.de> Author: bonefish Date: 2007-05-04 09:59:47 +0200 (Fri, 04 May 2007) New Revision: 21011 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21011&view=rev Modified: haiku/trunk/headers/posix/size_t.h Log: Removed kludge that was only necessary for building the old bfs_shell. Modified: haiku/trunk/headers/posix/size_t.h =================================================================== --- haiku/trunk/headers/posix/size_t.h 2007-05-04 07:49:53 UTC (rev 21010) +++ haiku/trunk/headers/posix/size_t.h 2007-05-04 07:59:47 UTC (rev 21011) @@ -1,20 +1,7 @@ #ifndef _SIZE_T_H_ #define _SIZE_T_H_ -/* - * XXX serious hack that doesn't really solve the problem. - * As of right now, some versions of the toolchain expect size_t to - * be unsigned long (newer ones than 2.95.2 and beos), and the older - * ones need it to be unsigned int. It's an actual failure when - * operator new is declared. This will have to be resolved in the future. - */ - -#ifdef __BEOS__ typedef unsigned long size_t; typedef signed long ssize_t; -#else -typedef unsigned int size_t; -typedef signed int ssize_t; -#endif #endif /* _SIZE_T_H_ */ From bonefish at cs.tu-berlin.de Fri May 4 10:21:24 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Fri, 04 May 2007 10:21:24 +0200 Subject: [Haiku-commits] r20982 - haiku/trunk/src/system/kernel/fs In-Reply-To: <13038748381-BeMail@zon> References: <13038748381-BeMail@zon> Message-ID: <20070504102124.1040.1@cs.tu-berlin.de> On 2007-05-03 at 13:48:43 [+0200], Axel D?rfler wrote: > Ingo Weinhold wrote: > > On 2007-05-03 at 11:09:27 [+0200], Axel D?rfler > > > wrote: > > > "J?r?me Duval" wrote: > > [...] > > > > I don't prevent anyone to follow your approach of monitoring a > > > > devfs > > > > directory, but it shouldn't be the only way to implement it, and > > > > the > > > > possibility shouldn't be removed. > > > [...] if you wanted to be able to > > > automatically pick up drivers that are installed later (which > > > creates > > > that directory), you would indeed have to monitor a parent > > > directory > > > that doesn't really interest you, which is not what we want. > > I find it a bit weird, that the devfs itself is writable for user > > applications. Security-wise it's a no-go and we'll have to remove > > that > > "feature" at some point in the future anyway. I understand the > > problem to > > be solved, but, I think, that's simply not the right solution. > > It would only be writable for the root user anyway. But in principle, I > certainly agree with you :-) If only root programs -- the input server would probably be one -- need to monitor devices, that would at least solve the security problem. I'm nevertheless uncomfortable with having a read-only feature (node monitoring) require write operations. > > IMHO, a reasonable solution is a monitoring helper class that you can > > tell > > to watch a directory given by path and it handles all the details. > > That is > > optionally, if the directory doesn't exist yet, it watches the > > nearest > > ancestor that does exist. The monitoring messages would be filtered, > > of > > course, so that the class user is notified only of the events they're > > actually interested in. > > Having something like this would be nice, even though I would prefer if > we had a path version of watch_node() that would automatically handle > the details in the future (like a "watch all files under /boot/home/ > config/"). That would be nice, though it's also quite a bit more expensive (memory- and CPU-wise) than ordinary node monitoring. > Anyway, I planned to have a look at the AddOnMonitor stuff in src/kits/ > storage (why there, anyway?) and implement this functionality there. > But feel free to beat me on it :) No worries, I won't beat you. :-P CU, Ingo From bonefish at mail.berlios.de Fri May 4 11:55:32 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Fri, 4 May 2007 11:55:32 +0200 Subject: [Haiku-commits] r21012 - haiku/trunk/build/jam Message-ID: <200705040955.l449tW2h028029@sheep.berlios.de> Author: bonefish Date: 2007-05-04 11:55:31 +0200 (Fri, 04 May 2007) New Revision: 21012 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21012&view=rev Modified: haiku/trunk/build/jam/BuildSetup Log: Get more features on glibc host platforms, among those ISO C 99 definitions (like LLONG_{MIN,MAX}). Modified: haiku/trunk/build/jam/BuildSetup =================================================================== --- haiku/trunk/build/jam/BuildSetup 2007-05-04 07:59:47 UTC (rev 21011) +++ haiku/trunk/build/jam/BuildSetup 2007-05-04 09:55:31 UTC (rev 21012) @@ -478,10 +478,9 @@ HOST_DEFINES += __POWERPC__ ; } - # Supposing this is a glibc platform, let's try to get large file support - HOST_DEFINES += - _LARGEFILE_SOURCE _LARGEFILE64_SOURCE _FILE_OFFSET_BITS=64 - ; + # Supposing this is a glibc platform, let's try to get features like large + # file support, ISO C 99 definitions, etc. + HOST_DEFINES += _GNU_SOURCE ; # On Linux with xattr support we can use it for our attribute emulation, # which is somewhat more robust. From hugosantos at gmail.com Fri May 4 12:52:16 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Fri, 4 May 2007 11:52:16 +0100 Subject: [Haiku-commits] r20947 - in haiku/trunk: headers/private/net src/add-ons/kernel/network/devices/ethernet src/add-ons/kernel/network/devices/loopback src/add-ons/kernel/network/stack In-Reply-To: <2121975194-BeMail@zon> References: <9c46321e0705011705u7b23f1d9g91c31426ac0acaa@mail.gmail.com> <2121975194-BeMail@zon> Message-ID: <9c46321e0705040352g84bc312pd62170e967cf9f12@mail.gmail.com> On 5/4/07, Axel D?rfler wrote: > "Hugo Santos" wrote: > > I tend to agree with Rob Pike on this: > > ``Length is not a virtue in a name; clarity of expression is.'' [1] > > While the quote alone looks good, having read the link, I can only say: > Rob Pike has no place within Haiku. > I used to come from a similar direction, but I learnt for the better. > Just read old code and you'll see the difference. I didn't say that Rob Pike has a place within Haiku, that even sounds wrong. I have a lot of respect from him, but i don't agree fully with him on every point. I only pointed to Pike style because i didn't want to leave a quote without proper reference. > I've renamed them now add_multicast() and remove_multicast() - this is > more consistent with {join|leave}_multicast() in the datalink protocol, > and is also much clearer than add_multi(). Well.. if it was that critical you could have told me so privately and i would have changed it myself as i've changed other stuff. I might have forgotten something in the past, as i usually end up coding new stuff or fixing bugs, but if the issues are pointed i fix them. You don't see me changing other people's code for 'clarity' without fixing bugs or introducing/using new code. Anyway... > Java has generics which is more or less the same thing as templates. > Anyway, I agree that verbosity is not a good idea, but we're far from > it (unlike AGMS, right? ;-)). > You'll get used to it, too, I'm sure. I know Java has generics, that's not the point. The point is that the fact Java only recently added generics, a lot of the original APIs use an explicit object to implement functionality. Anyway, no point continuing this discussion. There's nothing to get used to besides Haiku's coding style, which i try to follow. Hugo From axeld at pinc-software.de Fri May 4 13:10:16 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Fri, 04 May 2007 13:10:16 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r20947_-_in_haiku/trunk=3A_header?= =?iso-8859-15?q?s/private/net_src/add-ons/kernel/network/devices/ethernet?= =?iso-8859-15?q?_src/add-ons/kernel/network/devices/loopback_src/add-ons/?= =?iso-8859-15?q?kernel/network/stack?= In-Reply-To: <9c46321e0705040352g84bc312pd62170e967cf9f12@mail.gmail.com> Message-ID: <17014746248-BeMail@zon> "Hugo Santos" wrote: > On 5/4/07, Axel D?rfler wrote: > > I've renamed them now add_multicast() and remove_multicast() - this > > is > > more consistent with {join|leave}_multicast() in the datalink > > protocol, > > and is also much clearer than add_multi(). > Well.. if it was that critical you could have told me so privately > and i would have changed it myself as i've changed other stuff. I > might have forgotten something in the past, as i usually end up > coding > new stuff or fixing bugs, but if the issues are pointed i fix them. Since I am usually the one insisting on a consistent coding style and naming, I also don't mind doing the appropriate changes. If you prefer to do them yourself, that's okay, too; but sometimes it's just simpler and faster to just do the changes directly. So I take the opportunity and remind you of renaming the TCP timestamp variables :-) > You don't see me changing other people's code for 'clarity' without > fixing bugs or introducing/using new code. Anyway... You changed a lot of working code for clarity, already (ie. by using your hashtable, protocol/socket base class, etc.) - and that's perfectly okay, too. It's called refactoring and usually improves the code ;-) Also, it makes sense to divide refactoring and bug errr code writing in separate commits to make it simpler to check that the refactoring didn't break anything. > > Java has generics which is more or less the same thing as > > templates. > > Anyway, I agree that verbosity is not a good idea, but we're far > > from > > it (unlike AGMS, right? ;-)). > > You'll get used to it, too, I'm sure. > I know Java has generics, that's not the point. The point is that > the fact Java only recently added generics, a lot of the original > APIs > use an explicit object to implement functionality. Anyway, no point Usually interfaces which C++ doesn't have, but at least all the enumeration classes have generic versions now. > continuing this discussion. There's nothing to get used to besides > Haiku's coding style, which i try to follow. Coding and naming style, apparently ;-) BTW I would also suggest renaming fxp to ipro100 - for clarity; there is no reason to duplicate the useless FreeBSD driver naming style. Bye, Axel. From hugosantos at mail.berlios.de Fri May 4 13:27:07 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Fri, 4 May 2007 13:27:07 +0200 Subject: [Haiku-commits] r21013 - in haiku/trunk/src: add-ons/kernel/drivers/network/fxp/dev/fxp libs/compat/freebsd_network libs/compat/freebsd_network/compat/sys Message-ID: <200705041127.l44BR79w014945@sheep.berlios.de> Author: hugosantos Date: 2007-05-04 13:26:37 +0200 (Fri, 04 May 2007) New Revision: 21013 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21013&view=rev Added: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/glue.c Modified: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/Jamfile haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/mii.c Log: freebsd compat. layer: some initial glue code Modified: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/Jamfile 2007-05-04 09:55:31 UTC (rev 21012) +++ haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/Jamfile 2007-05-04 11:26:37 UTC (rev 21013) @@ -11,6 +11,7 @@ KernelAddon fxp : if_fxp.c + glue.c : libfreebsd_network.a ; Added: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/glue.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/glue.c 2007-05-04 09:55:31 UTC (rev 21012) +++ haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/glue.c 2007-05-04 11:26:37 UTC (rev 21013) @@ -0,0 +1,3 @@ +#include + +HAIKU_FBSD_DRIVER_GLUE(fxp, pci) Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-04 09:55:31 UTC (rev 21012) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-04 11:26:37 UTC (rev 21013) @@ -133,10 +133,22 @@ driver_intr_t handler, void *arg, void **cookiep); int bus_teardown_intr(device_t dev, struct resource *r, void *cookie); -#define BUS_PROBE_DEFAULT -20 +#define BUS_PROBE_DEFAULT 20 -#define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) +#define DRIVER_MODULE_NAME(name, busname) \ + __fbsd_##name##busname +driver_t *__fbsd_driver(void); + +#define HAIKU_FBSD_DRIVER_GLUE(name, busname) \ + driver_t *__fbsd_driver() { \ + extern driver_t *DRIVER_MODULE_NAME(name, busname); \ + return DRIVER_MODULE_NAME(name, busname); \ + } + +#define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) \ + driver_t *DRIVER_MODULE_NAME(name, busname) = &(driver) + const char *device_get_name(device_t dev); const char *device_get_nameunit(device_t dev); int device_get_unit(device_t dev); Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-04 09:55:31 UTC (rev 21012) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-04 11:26:37 UTC (rev 21013) @@ -11,11 +11,21 @@ #include "device.h" #include +#include #include #include +#define MAX_DEVICES 8 + + +int32 api_version = B_CUR_DRIVER_API_VERSION; + + +static char *sDevNameList[MAX_DEVICES + 1]; + + static status_t compat_open(const char *name, uint32 flags, void **cookie) { @@ -70,7 +80,7 @@ IF_DEQUEUE(&dev->receive_queue, mb); } while (mb == NULL); - len = min_c(max_c(mb->m_len, 0), *numBytes); + len = min_c(max_c((size_t)mb->m_len, 0), *numBytes); // TODO we need something that cna join various chunks memcpy(buf, mtod(mb, const void *), len); @@ -94,3 +104,75 @@ { return B_ERROR; } + + +static device_hooks sDeviceHooks = { + compat_open, + compat_close, + compat_free, + compat_control, + compat_read, + compat_write, +}; + + +static int +_device_probe(device_t dev) +{ + device_method_t *methods = __fbsd_driver()->methods; + int i; + + for (i = 0; methods[i].name != NULL; i++) { + if (!strcmp(methods[i].name, "device_probe")) + return methods[i].method(dev); + } + + panic("fsbd compat layer: method missing, device_probe"); + return -1; +} + + +status_t +init_hardware() +{ + struct device fakeDevice; + pci_info info; + int i; + + memset(&fakeDevice, 0, sizeof(struct device)); + fakeDevice.pciInfo = &info; + + for (i = 0; gPci->get_nth_pci_info(i, &info) == B_OK; i++) { + if (_device_probe(&fakeDevice) >= 0) + return B_OK; + } + + return B_ERROR; +} + + +status_t +init_driver() +{ + return B_ERROR; +} + + +void +uninit_driver() +{ +} + + +const char ** +publish_devices() +{ + return (const char **)sDevNameList; +} + + +device_hooks * +find_device(const char *name) +{ + return &sDeviceHooks; +} Modified: haiku/trunk/src/libs/compat/freebsd_network/mii.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/mii.c 2007-05-04 09:55:31 UTC (rev 21012) +++ haiku/trunk/src/libs/compat/freebsd_network/mii.c 2007-05-04 11:26:37 UTC (rev 21013) @@ -14,6 +14,11 @@ #include +driver_t miibus_driver = { + "mii", +}; + + int mii_phy_probe(device_t dev, device_t *miiDev, ifm_change_cb_t change, ifm_stat_cb_t stat) From hugosantos at mail.berlios.de Fri May 4 13:27:32 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Fri, 4 May 2007 13:27:32 +0200 Subject: [Haiku-commits] r21015 - in haiku/trunk/src/add-ons/kernel/drivers/network: . fxp fxp/dev fxp/dev/fxp ipro100 ipro100/dev ipro100/dev/fxp Message-ID: <200705041127.l44BRWaK014996@sheep.berlios.de> Author: hugosantos Date: 2007-05-04 13:27:11 +0200 (Fri, 04 May 2007) New Revision: 21015 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21015&view=rev Added: haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/ haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/ haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/fxp/ haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/fxp/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/fxp/glue.c haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/fxp/if_fxp.c haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/fxp/if_fxpreg.h haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/fxp/if_fxpvar.h haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/fxp/rcvbundl.h Removed: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/glue.c haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/if_fxp.c haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/if_fxpreg.h haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/if_fxpvar.h haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/rcvbundl.h Modified: haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile Log: renamed fxp to ipro100. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile 2007-05-04 11:27:00 UTC (rev 21014) +++ haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile 2007-05-04 11:27:11 UTC (rev 21015) @@ -12,7 +12,7 @@ SubInclude HAIKU_TOP src add-ons kernel drivers network vlance ; SubInclude HAIKU_TOP src add-ons kernel drivers network wb840 ; -SubInclude HAIKU_TOP src add-ons kernel drivers network fxp ; +SubInclude HAIKU_TOP src add-ons kernel drivers network ipro100 ; SubIncludeGPL HAIKU_TOP src add-ons kernel drivers network bcm440x ; SubIncludeGPL HAIKU_TOP src add-ons kernel drivers network bcm570x ; Deleted: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/Jamfile Deleted: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/Jamfile Deleted: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/Jamfile Deleted: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/glue.c Deleted: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/if_fxp.c Deleted: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/if_fxpreg.h Deleted: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/if_fxpvar.h Deleted: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/rcvbundl.h Added: haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/Jamfile 2007-05-04 11:27:00 UTC (rev 21014) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/Jamfile 2007-05-04 11:27:11 UTC (rev 21015) @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network ipro100 ; + +SubInclude HAIKU_TOP src add-ons kernel drivers network ipro100 dev ; Added: haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/Jamfile 2007-05-04 11:27:00 UTC (rev 21014) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/Jamfile 2007-05-04 11:27:11 UTC (rev 21015) @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network ipro100 dev ; + +SubInclude HAIKU_TOP src add-ons kernel drivers network ipro100 dev fxp ; Copied: haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/fxp/Jamfile (from rev 21014, haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/Jamfile) =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/Jamfile 2007-05-04 11:27:00 UTC (rev 21014) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/fxp/Jamfile 2007-05-04 11:27:11 UTC (rev 21015) @@ -0,0 +1,17 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network ipro100 dev fxp ; + +SubDirCcFlags -Wall ; + +UsePrivateHeaders kernel net ; + +UseHeaders [ FDirName $(SUBDIR) .. .. ] : true ; +UseHeaders [ FDirName $(HAIKU_TOP) src libs compat freebsd_network compat ] : true ; + +SubDirCcFlags [ FDefines _KERNEL=1 ] ; + +KernelAddon ipro100 : + if_fxp.c + glue.c + : libfreebsd_network.a + ; + Copied: haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/fxp/glue.c (from rev 21014, haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/glue.c) =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/glue.c 2007-05-04 11:27:00 UTC (rev 21014) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/fxp/glue.c 2007-05-04 11:27:11 UTC (rev 21015) @@ -0,0 +1,3 @@ +#include + +HAIKU_FBSD_DRIVER_GLUE(fxp, pci) Copied: haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/fxp/if_fxp.c (from rev 21014, haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/if_fxp.c) =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/fxp/dev/fxp/if_fxp.c 2007-05-04 11:27:00 UTC (rev 21014) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/fxp/if_fxp.c 2007-05-04 11:27:11 UTC (rev 21015) @@ -0,0 +1,2713 @@ +/*- + * Copyright (c) 1995, David Greenman + * Copyright (c) 2001 Jonathan Lemon + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include +__FBSDID("$FreeBSD: src/sys/dev/fxp/if_fxp.c,v 1.240.2.10.2.1 2006/11/20 16:21:12 rink Exp $"); + +/* + * Intel EtherExpress Pro/100B PCI Fast Ethernet driver + */ + +#ifdef HAVE_KERNEL_OPTION_HEADERS +#include "opt_device_polling.h" +#endif + +#include +#include +#include +#include + /* #include */ +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include /* for DELAY */ + +#include +#include + +#ifdef FXP_IP_CSUM_WAR +#include +#include +#include +#include +#endif + +#include +#include /* for PCIM_CMD_xxx */ + +#include +#include + +#include +#include +#include + +MODULE_DEPEND(fxp, pci, 1, 1, 1); +MODULE_DEPEND(fxp, ether, 1, 1, 1); +MODULE_DEPEND(fxp, miibus, 1, 1, 1); +#include "miibus_if.h" + +/* + * NOTE! On the Alpha, we have an alignment constraint. The + * card DMAs the packet immediately following the RFA. However, + * the first thing in the packet is a 14-byte Ethernet header. + * This means that the packet is misaligned. To compensate, + * we actually offset the RFA 2 bytes into the cluster. This + * alignes the packet after the Ethernet header at a 32-bit + * boundary. HOWEVER! This means that the RFA is misaligned! + */ +#define RFA_ALIGNMENT_FUDGE 2 + +/* + * Set initial transmit threshold at 64 (512 bytes). This is + * increased by 64 (512 bytes) at a time, to maximum of 192 + * (1536 bytes), if an underrun occurs. + */ +static int tx_threshold = 64; + +/* + * The configuration byte map has several undefined fields which + * must be one or must be zero. Set up a template for these bits + * only, (assuming a 82557 chip) leaving the actual configuration + * to fxp_init. + * + * See struct fxp_cb_config for the bit definitions. + */ +static u_char fxp_cb_config_template[] = { + 0x0, 0x0, /* cb_status */ + 0x0, 0x0, /* cb_command */ + 0x0, 0x0, 0x0, 0x0, /* link_addr */ + 0x0, /* 0 */ + 0x0, /* 1 */ + 0x0, /* 2 */ + 0x0, /* 3 */ + 0x0, /* 4 */ + 0x0, /* 5 */ + 0x32, /* 6 */ + 0x0, /* 7 */ + 0x0, /* 8 */ + 0x0, /* 9 */ + 0x6, /* 10 */ + 0x0, /* 11 */ + 0x0, /* 12 */ + 0x0, /* 13 */ + 0xf2, /* 14 */ + 0x48, /* 15 */ + 0x0, /* 16 */ + 0x40, /* 17 */ + 0xf0, /* 18 */ + 0x0, /* 19 */ + 0x3f, /* 20 */ + 0x5 /* 21 */ +}; + +struct fxp_ident { + uint16_t devid; + int16_t revid; /* -1 matches anything */ + char *name; +}; + +/* + * Claim various Intel PCI device identifiers for this driver. The + * sub-vendor and sub-device field are extensively used to identify + * particular variants, but we don't currently differentiate between + * them. + */ +static struct fxp_ident fxp_ident_table[] = { + { 0x1029, -1, "Intel 82559 PCI/CardBus Pro/100" }, + { 0x1030, -1, "Intel 82559 Pro/100 Ethernet" }, + { 0x1031, -1, "Intel 82801CAM (ICH3) Pro/100 VE Ethernet" }, + { 0x1032, -1, "Intel 82801CAM (ICH3) Pro/100 VE Ethernet" }, + { 0x1033, -1, "Intel 82801CAM (ICH3) Pro/100 VM Ethernet" }, + { 0x1034, -1, "Intel 82801CAM (ICH3) Pro/100 VM Ethernet" }, + { 0x1035, -1, "Intel 82801CAM (ICH3) Pro/100 Ethernet" }, + { 0x1036, -1, "Intel 82801CAM (ICH3) Pro/100 Ethernet" }, + { 0x1037, -1, "Intel 82801CAM (ICH3) Pro/100 Ethernet" }, + { 0x1038, -1, "Intel 82801CAM (ICH3) Pro/100 VM Ethernet" }, + { 0x1039, -1, "Intel 82801DB (ICH4) Pro/100 VE Ethernet" }, + { 0x103A, -1, "Intel 82801DB (ICH4) Pro/100 Ethernet" }, + { 0x103B, -1, "Intel 82801DB (ICH4) Pro/100 VM Ethernet" }, + { 0x103C, -1, "Intel 82801DB (ICH4) Pro/100 Ethernet" }, + { 0x103D, -1, "Intel 82801DB (ICH4) Pro/100 VE Ethernet" }, + { 0x103E, -1, "Intel 82801DB (ICH4) Pro/100 VM Ethernet" }, + { 0x1050, -1, "Intel 82801BA (D865) Pro/100 VE Ethernet" }, + { 0x1051, -1, "Intel 82562ET (ICH5/ICH5R) Pro/100 VE Ethernet" }, + { 0x1059, -1, "Intel 82551QM Pro/100 M Mobile Connection" }, + { 0x1064, -1, "Intel 82562EZ (ICH6)" }, + { 0x1065, -1, "Intel 82562ET/EZ/GT/GZ PRO/100 VE Ethernet" }, + { 0x1068, -1, "Intel 82801FBM (ICH6-M) Pro/100 VE Ethernet" }, + { 0x1069, -1, "Intel 82562EM/EX/GX Pro/100 Ethernet" }, + { 0x1092, -1, "Intel Pro/100 VE Network Connection" }, + { 0x1093, -1, "Intel Pro/100 VM Network Connection" }, + { 0x1094, -1, "Intel Pro/100 946GZ (ICH7) Network Connection" }, + { 0x1209, -1, "Intel 82559ER Embedded 10/100 Ethernet" }, + { 0x1229, 0x01, "Intel 82557 Pro/100 Ethernet" }, + { 0x1229, 0x02, "Intel 82557 Pro/100 Ethernet" }, + { 0x1229, 0x03, "Intel 82557 Pro/100 Ethernet" }, + { 0x1229, 0x04, "Intel 82558 Pro/100 Ethernet" }, + { 0x1229, 0x05, "Intel 82558 Pro/100 Ethernet" }, + { 0x1229, 0x06, "Intel 82559 Pro/100 Ethernet" }, + { 0x1229, 0x07, "Intel 82559 Pro/100 Ethernet" }, + { 0x1229, 0x08, "Intel 82559 Pro/100 Ethernet" }, + { 0x1229, 0x09, "Intel 82559ER Pro/100 Ethernet" }, + { 0x1229, 0x0c, "Intel 82550 Pro/100 Ethernet" }, + { 0x1229, 0x0d, "Intel 82550 Pro/100 Ethernet" }, + { 0x1229, 0x0e, "Intel 82550 Pro/100 Ethernet" }, + { 0x1229, 0x0f, "Intel 82551 Pro/100 Ethernet" }, + { 0x1229, 0x10, "Intel 82551 Pro/100 Ethernet" }, + { 0x1229, -1, "Intel 82557/8/9 Pro/100 Ethernet" }, + { 0x2449, -1, "Intel 82801BA/CAM (ICH2/3) Pro/100 Ethernet" }, + { 0x27dc, -1, "Intel 82801GB (ICH7) 10/100 Ethernet" }, + { 0, -1, NULL }, +}; + +#ifdef FXP_IP_CSUM_WAR +#define FXP_CSUM_FEATURES (CSUM_IP | CSUM_TCP | CSUM_UDP) +#else +#define FXP_CSUM_FEATURES (CSUM_TCP | CSUM_UDP) +#endif + +static int fxp_probe(device_t dev); +static int fxp_attach(device_t dev); +static int fxp_detach(device_t dev); +static int fxp_shutdown(device_t dev); +static int fxp_suspend(device_t dev); +static int fxp_resume(device_t dev); + +static void fxp_intr(void *xsc); +static void fxp_intr_body(struct fxp_softc *sc, struct ifnet *ifp, + uint8_t statack, int count); +static void fxp_init(void *xsc); +static void fxp_init_body(struct fxp_softc *sc); +static void fxp_tick(void *xsc); +static void fxp_start(struct ifnet *ifp); +static void fxp_start_body(struct ifnet *ifp); +static int fxp_encap(struct fxp_softc *sc, struct mbuf *m_head); +static void fxp_stop(struct fxp_softc *sc); +static void fxp_release(struct fxp_softc *sc); +static int fxp_ioctl(struct ifnet *ifp, u_long command, + caddr_t data); +static void fxp_watchdog(struct ifnet *ifp); +static int fxp_add_rfabuf(struct fxp_softc *sc, + struct fxp_rx *rxp); +static int fxp_mc_addrs(struct fxp_softc *sc); +static void fxp_mc_setup(struct fxp_softc *sc); +static uint16_t fxp_eeprom_getword(struct fxp_softc *sc, int offset, + int autosize); +static void fxp_eeprom_putword(struct fxp_softc *sc, int offset, + uint16_t data); +static void fxp_autosize_eeprom(struct fxp_softc *sc); +static void fxp_read_eeprom(struct fxp_softc *sc, u_short *data, + int offset, int words); +static void fxp_write_eeprom(struct fxp_softc *sc, u_short *data, + int offset, int words); +static int fxp_ifmedia_upd(struct ifnet *ifp); +static void fxp_ifmedia_sts(struct ifnet *ifp, + struct ifmediareq *ifmr); +static int fxp_serial_ifmedia_upd(struct ifnet *ifp); +static void fxp_serial_ifmedia_sts(struct ifnet *ifp, + struct ifmediareq *ifmr); +static volatile int fxp_miibus_readreg(device_t dev, int phy, int reg); +static void fxp_miibus_writereg(device_t dev, int phy, int reg, + int value); +static void fxp_load_ucode(struct fxp_softc *sc); +static int sysctl_int_range(SYSCTL_HANDLER_ARGS, + int low, int high); +static int sysctl_hw_fxp_bundle_max(SYSCTL_HANDLER_ARGS); +static int sysctl_hw_fxp_int_delay(SYSCTL_HANDLER_ARGS); +static void fxp_scb_wait(struct fxp_softc *sc); +static void fxp_scb_cmd(struct fxp_softc *sc, int cmd); +static void fxp_dma_wait(struct fxp_softc *sc, + volatile uint16_t *status, bus_dma_tag_t dmat, + bus_dmamap_t map); + +static device_method_t fxp_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, fxp_probe), + DEVMETHOD(device_attach, fxp_attach), + DEVMETHOD(device_detach, fxp_detach), + DEVMETHOD(device_shutdown, fxp_shutdown), + DEVMETHOD(device_suspend, fxp_suspend), + DEVMETHOD(device_resume, fxp_resume), + + /* MII interface */ + DEVMETHOD(miibus_readreg, fxp_miibus_readreg), + DEVMETHOD(miibus_writereg, fxp_miibus_writereg), + + { 0, 0 } +}; + +static driver_t fxp_driver = { + "fxp", + fxp_methods, + sizeof(struct fxp_softc), +}; + +static devclass_t fxp_devclass; + +DRIVER_MODULE(fxp, pci, fxp_driver, fxp_devclass, 0, 0); +DRIVER_MODULE(fxp, cardbus, fxp_driver, fxp_devclass, 0, 0); +DRIVER_MODULE(miibus, fxp, miibus_driver, miibus_devclass, 0, 0); + +/* + * Wait for the previous command to be accepted (but not necessarily + * completed). + */ +static void +fxp_scb_wait(struct fxp_softc *sc) +{ + union { + uint16_t w; + uint8_t b[2]; + } flowctl; + int i = 10000; + + while (CSR_READ_1(sc, FXP_CSR_SCB_COMMAND) && --i) + DELAY(2); + if (i == 0) { + flowctl.b[0] = CSR_READ_1(sc, FXP_CSR_FLOWCONTROL); + flowctl.b[1] = CSR_READ_1(sc, FXP_CSR_FLOWCONTROL + 1); + device_printf(sc->dev, "SCB timeout: 0x%x 0x%x 0x%x 0x%x\n", + CSR_READ_1(sc, FXP_CSR_SCB_COMMAND), + CSR_READ_1(sc, FXP_CSR_SCB_STATACK), + CSR_READ_1(sc, FXP_CSR_SCB_RUSCUS), flowctl.w); + } +} + +static void +fxp_scb_cmd(struct fxp_softc *sc, int cmd) +{ + + if (cmd == FXP_SCB_COMMAND_CU_RESUME && sc->cu_resume_bug) { + CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_CB_COMMAND_NOP); + fxp_scb_wait(sc); + } + CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, cmd); +} + +static void +fxp_dma_wait(struct fxp_softc *sc, volatile uint16_t *status, + bus_dma_tag_t dmat, bus_dmamap_t map) +{ + int i = 10000; + + bus_dmamap_sync(dmat, map, BUS_DMASYNC_POSTREAD); + while (!(le16toh(*status) & FXP_CB_STATUS_C) && --i) { + DELAY(2); + bus_dmamap_sync(dmat, map, BUS_DMASYNC_POSTREAD); + } + if (i == 0) + device_printf(sc->dev, "DMA timeout\n"); +} + +/* + * Return identification string if this device is ours. + */ +static int +fxp_probe(device_t dev) +{ + uint16_t devid; + uint8_t revid; + struct fxp_ident *ident; + + if (pci_get_vendor(dev) == FXP_VENDORID_INTEL) { + devid = pci_get_device(dev); + revid = pci_get_revid(dev); + for (ident = fxp_ident_table; ident->name != NULL; ident++) { + if (ident->devid == devid && + (ident->revid == revid || ident->revid == -1)) { + device_set_desc(dev, ident->name); + return (BUS_PROBE_DEFAULT); + } + } + } + return (ENXIO); +} + +static void +fxp_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error) +{ + uint32_t *addr; + + if (error) + return; + + KASSERT(nseg == 1, ("too many DMA segments, %d should be 1", nseg)); + addr = arg; + *addr = segs->ds_addr; +} + +static int +fxp_attach(device_t dev) +{ + struct fxp_softc *sc; + struct fxp_cb_tx *tcbp; + struct fxp_tx *txp; + struct fxp_rx *rxp; + struct ifnet *ifp; + uint32_t val; + uint16_t data, myea[ETHER_ADDR_LEN / 2]; + u_char eaddr[ETHER_ADDR_LEN]; + int i, rid, m1, m2, prefer_iomap; + int error; + + error = 0; + sc = device_get_softc(dev); + sc->dev = dev; + mtx_init(&sc->sc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, + MTX_DEF); + callout_init_mtx(&sc->stat_ch, &sc->sc_mtx, 0); + ifmedia_init(&sc->sc_media, 0, fxp_serial_ifmedia_upd, + fxp_serial_ifmedia_sts); + + ifp = sc->ifp = if_alloc(IFT_ETHER); + if (ifp == NULL) { + device_printf(dev, "can not if_alloc()\n"); + error = ENOSPC; + goto fail; + } + + /* + * Enable bus mastering. + */ + pci_enable_busmaster(dev); + val = pci_read_config(dev, PCIR_COMMAND, 2); + + /* + * Figure out which we should try first - memory mapping or i/o mapping? + * We default to memory mapping. Then we accept an override from the + * command line. Then we check to see which one is enabled. + */ + m1 = PCIM_CMD_MEMEN; + m2 = PCIM_CMD_PORTEN; + prefer_iomap = 0; + if (resource_int_value(device_get_name(dev), device_get_unit(dev), + "prefer_iomap", &prefer_iomap) == 0 && prefer_iomap != 0) { + m1 = PCIM_CMD_PORTEN; + m2 = PCIM_CMD_MEMEN; + } + + sc->rtp = (m1 == PCIM_CMD_MEMEN)? SYS_RES_MEMORY : SYS_RES_IOPORT; + sc->rgd = (m1 == PCIM_CMD_MEMEN)? FXP_PCI_MMBA : FXP_PCI_IOBA; + sc->mem = bus_alloc_resource_any(dev, sc->rtp, &sc->rgd, RF_ACTIVE); + if (sc->mem == NULL) { + sc->rtp = + (m2 == PCIM_CMD_MEMEN)? SYS_RES_MEMORY : SYS_RES_IOPORT; + sc->rgd = (m2 == PCIM_CMD_MEMEN)? FXP_PCI_MMBA : FXP_PCI_IOBA; + sc->mem = bus_alloc_resource_any(dev, sc->rtp, &sc->rgd, + RF_ACTIVE); + } + + if (!sc->mem) { + error = ENXIO; + goto fail; + } + if (bootverbose) { + device_printf(dev, "using %s space register mapping\n", + sc->rtp == SYS_RES_MEMORY? "memory" : "I/O"); + } + + sc->sc_st = rman_get_bustag(sc->mem); + sc->sc_sh = rman_get_bushandle(sc->mem); + + /* + * Allocate our interrupt. + */ + rid = 0; + sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, + RF_SHAREABLE | RF_ACTIVE); + if (sc->irq == NULL) { + device_printf(dev, "could not map interrupt\n"); + error = ENXIO; + goto fail; + } + + /* + * Reset to a stable state. + */ + CSR_WRITE_4(sc, FXP_CSR_PORT, FXP_PORT_SELECTIVE_RESET); + DELAY(10); + + /* + * Find out how large of an SEEPROM we have. + */ + fxp_autosize_eeprom(sc); + + /* + * Find out the chip revision; lump all 82557 revs together. + */ + fxp_read_eeprom(sc, &data, 5, 1); + if ((data >> 8) == 1) + sc->revision = FXP_REV_82557; + else + sc->revision = pci_get_revid(dev); + + /* + * Determine whether we must use the 503 serial interface. + */ + fxp_read_eeprom(sc, &data, 6, 1); + if (sc->revision == FXP_REV_82557 && (data & FXP_PHY_DEVICE_MASK) != 0 + && (data & FXP_PHY_SERIAL_ONLY)) + sc->flags |= FXP_FLAG_SERIAL_MEDIA; + + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "int_delay", CTLTYPE_INT | CTLFLAG_RW, + &sc->tunable_int_delay, 0, sysctl_hw_fxp_int_delay, "I", + "FXP driver receive interrupt microcode bundling delay"); + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "bundle_max", CTLTYPE_INT | CTLFLAG_RW, + &sc->tunable_bundle_max, 0, sysctl_hw_fxp_bundle_max, "I", + "FXP driver receive interrupt microcode bundle size limit"); + SYSCTL_ADD_INT(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "rnr", CTLFLAG_RD, &sc->rnr, 0, + "FXP RNR events"); + SYSCTL_ADD_INT(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "noflow", CTLFLAG_RW, &sc->tunable_noflow, 0, + "FXP flow control disabled"); + + /* + * Pull in device tunables. + */ + sc->tunable_int_delay = TUNABLE_INT_DELAY; + sc->tunable_bundle_max = TUNABLE_BUNDLE_MAX; + sc->tunable_noflow = 1; + (void) resource_int_value(device_get_name(dev), device_get_unit(dev), + "int_delay", &sc->tunable_int_delay); + (void) resource_int_value(device_get_name(dev), device_get_unit(dev), + "bundle_max", &sc->tunable_bundle_max); + (void) resource_int_value(device_get_name(dev), device_get_unit(dev), + "noflow", &sc->tunable_noflow); + sc->rnr = 0; + + /* + * Enable workarounds for certain chip revision deficiencies. + * + * Systems based on the ICH2/ICH2-M chip from Intel, and possibly + * some systems based a normal 82559 design, have a defect where + * the chip can cause a PCI protocol violation if it receives + * a CU_RESUME command when it is entering the IDLE state. The + * workaround is to disable Dynamic Standby Mode, so the chip never + * deasserts CLKRUN#, and always remains in an active state. + * + * See Intel 82801BA/82801BAM Specification Update, Errata #30. + */ + i = pci_get_device(dev); + if (i == 0x2449 || (i > 0x1030 && i < 0x1039) || + sc->revision >= FXP_REV_82559_A0) { + fxp_read_eeprom(sc, &data, 10, 1); + if (data & 0x02) { /* STB enable */ + uint16_t cksum; + int i; + + device_printf(dev, + "Disabling dynamic standby mode in EEPROM\n"); + data &= ~0x02; + fxp_write_eeprom(sc, &data, 10, 1); + device_printf(dev, "New EEPROM ID: 0x%x\n", data); + cksum = 0; + for (i = 0; i < (1 << sc->eeprom_size) - 1; i++) { + fxp_read_eeprom(sc, &data, i, 1); + cksum += data; + } + i = (1 << sc->eeprom_size) - 1; + cksum = 0xBABA - cksum; + fxp_read_eeprom(sc, &data, i, 1); + fxp_write_eeprom(sc, &cksum, i, 1); + device_printf(dev, + "EEPROM checksum @ 0x%x: 0x%x -> 0x%x\n", + i, data, cksum); +#if 1 + /* + * If the user elects to continue, try the software + * workaround, as it is better than nothing. + */ + sc->flags |= FXP_FLAG_CU_RESUME_BUG; +#endif + } + } + + /* + * If we are not a 82557 chip, we can enable extended features. + */ + if (sc->revision != FXP_REV_82557) { + /* + * If MWI is enabled in the PCI configuration, and there + * is a valid cacheline size (8 or 16 dwords), then tell + * the board to turn on MWI. + */ + if (val & PCIM_CMD_MWRICEN && + pci_read_config(dev, PCIR_CACHELNSZ, 1) != 0) + sc->flags |= FXP_FLAG_MWI_ENABLE; + + /* turn on the extended TxCB feature */ + sc->flags |= FXP_FLAG_EXT_TXCB; + + /* enable reception of long frames for VLAN */ + sc->flags |= FXP_FLAG_LONG_PKT_EN; + } else { + /* a hack to get long VLAN frames on a 82557 */ + sc->flags |= FXP_FLAG_SAVE_BAD; + } + + /* + * Enable use of extended RFDs and TCBs for 82550 + * and later chips. Note: we need extended TXCB support + * too, but that's already enabled by the code above. + * Be careful to do this only on the right devices. + */ + if (sc->revision == FXP_REV_82550 || sc->revision == FXP_REV_82550_C || + sc->revision == FXP_REV_82551_E || sc->revision == FXP_REV_82551_F + || sc->revision == FXP_REV_82551_10) { + sc->rfa_size = sizeof (struct fxp_rfa); + sc->tx_cmd = FXP_CB_COMMAND_IPCBXMIT; + sc->flags |= FXP_FLAG_EXT_RFA; + } else { + sc->rfa_size = sizeof (struct fxp_rfa) - FXP_RFAX_LEN; + sc->tx_cmd = FXP_CB_COMMAND_XMIT; + } + + /* + * Allocate DMA tags and DMA safe memory. + */ + sc->maxtxseg = FXP_NTXSEG; + if (sc->flags & FXP_FLAG_EXT_RFA) + sc->maxtxseg--; + error = bus_dma_tag_create(NULL, 2, 0, BUS_SPACE_MAXADDR_32BIT, + BUS_SPACE_MAXADDR, NULL, NULL, MCLBYTES * sc->maxtxseg, + sc->maxtxseg, MCLBYTES, 0, busdma_lock_mutex, &Giant, + &sc->fxp_mtag); + if (error) { + device_printf(dev, "could not allocate dma tag\n"); + goto fail; + } + + error = bus_dma_tag_create(NULL, 4, 0, BUS_SPACE_MAXADDR_32BIT, + BUS_SPACE_MAXADDR, NULL, NULL, sizeof(struct fxp_stats), 1, + sizeof(struct fxp_stats), 0, busdma_lock_mutex, &Giant, + &sc->fxp_stag); + if (error) { + device_printf(dev, "could not allocate dma tag\n"); + goto fail; + } + + error = bus_dmamem_alloc(sc->fxp_stag, (void **)&sc->fxp_stats, + BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sc->fxp_smap); + if (error) + goto fail; + error = bus_dmamap_load(sc->fxp_stag, sc->fxp_smap, sc->fxp_stats, + sizeof(struct fxp_stats), fxp_dma_map_addr, &sc->stats_addr, 0); + if (error) { + device_printf(dev, "could not map the stats buffer\n"); + goto fail; + } + + error = bus_dma_tag_create(NULL, 4, 0, BUS_SPACE_MAXADDR_32BIT, + BUS_SPACE_MAXADDR, NULL, NULL, FXP_TXCB_SZ, 1, + FXP_TXCB_SZ, 0, busdma_lock_mutex, &Giant, &sc->cbl_tag); + if (error) { + device_printf(dev, "could not allocate dma tag\n"); + goto fail; + } + + error = bus_dmamem_alloc(sc->cbl_tag, (void **)&sc->fxp_desc.cbl_list, + BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sc->cbl_map); + if (error) + goto fail; + + error = bus_dmamap_load(sc->cbl_tag, sc->cbl_map, + sc->fxp_desc.cbl_list, FXP_TXCB_SZ, fxp_dma_map_addr, + &sc->fxp_desc.cbl_addr, 0); + if (error) { + device_printf(dev, "could not map DMA memory\n"); + goto fail; + } + + error = bus_dma_tag_create(NULL, 4, 0, BUS_SPACE_MAXADDR_32BIT, + BUS_SPACE_MAXADDR, NULL, NULL, sizeof(struct fxp_cb_mcs), 1, + sizeof(struct fxp_cb_mcs), 0, busdma_lock_mutex, &Giant, + &sc->mcs_tag); + if (error) { + device_printf(dev, "could not allocate dma tag\n"); + goto fail; + } + + error = bus_dmamem_alloc(sc->mcs_tag, (void **)&sc->mcsp, + BUS_DMA_NOWAIT, &sc->mcs_map); + if (error) + goto fail; + error = bus_dmamap_load(sc->mcs_tag, sc->mcs_map, sc->mcsp, + sizeof(struct fxp_cb_mcs), fxp_dma_map_addr, &sc->mcs_addr, 0); + if (error) { + device_printf(dev, "can't map the multicast setup command\n"); + goto fail; + } + + /* + * Pre-allocate the TX DMA maps and setup the pointers to + * the TX command blocks. + */ + txp = sc->fxp_desc.tx_list; + tcbp = sc->fxp_desc.cbl_list; + for (i = 0; i < FXP_NTXCB; i++) { + txp[i].tx_cb = tcbp + i; + error = bus_dmamap_create(sc->fxp_mtag, 0, &txp[i].tx_map); + if (error) { + device_printf(dev, "can't create DMA map for TX\n"); + goto fail; + } + } + error = bus_dmamap_create(sc->fxp_mtag, 0, &sc->spare_map); + if (error) { + device_printf(dev, "can't create spare DMA map\n"); + goto fail; + } + + /* + * Pre-allocate our receive buffers. + */ + sc->fxp_desc.rx_head = sc->fxp_desc.rx_tail = NULL; + for (i = 0; i < FXP_NRFABUFS; i++) { + rxp = &sc->fxp_desc.rx_list[i]; + error = bus_dmamap_create(sc->fxp_mtag, 0, &rxp->rx_map); + if (error) { + device_printf(dev, "can't create DMA map for RX\n"); + goto fail; + } + if (fxp_add_rfabuf(sc, rxp) != 0) { + error = ENOMEM; + goto fail; + } + } + + /* + * Read MAC address. + */ + fxp_read_eeprom(sc, myea, 0, 3); + eaddr[0] = myea[0] & 0xff; + eaddr[1] = myea[0] >> 8; + eaddr[2] = myea[1] & 0xff; + eaddr[3] = myea[1] >> 8; + eaddr[4] = myea[2] & 0xff; + eaddr[5] = myea[2] >> 8; + if (bootverbose) { + device_printf(dev, "PCI IDs: %04x %04x %04x %04x %04x\n", + pci_get_vendor(dev), pci_get_device(dev), + pci_get_subvendor(dev), pci_get_subdevice(dev), + pci_get_revid(dev)); + fxp_read_eeprom(sc, &data, 10, 1); + device_printf(dev, "Dynamic Standby mode is %s\n", + data & 0x02 ? "enabled" : "disabled"); + } + + /* + * If this is only a 10Mbps device, then there is no MII, and + * the PHY will use a serial interface instead. + * + * The Seeq 80c24 AutoDUPLEX(tm) Ethernet Interface Adapter + * doesn't have a programming interface of any sort. The + * media is sensed automatically based on how the link partner + * is configured. This is, in essence, manual configuration. + */ + if (sc->flags & FXP_FLAG_SERIAL_MEDIA) { + ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL); + ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_MANUAL); + } else { + if (mii_phy_probe(dev, &sc->miibus, fxp_ifmedia_upd, + fxp_ifmedia_sts)) { + device_printf(dev, "MII without any PHY!\n"); + error = ENXIO; + goto fail; + } + } + + if_initname(ifp, device_get_name(dev), device_get_unit(dev)); + ifp->if_init = fxp_init; + ifp->if_softc = sc; + ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; + ifp->if_ioctl = fxp_ioctl; + ifp->if_start = fxp_start; + ifp->if_watchdog = fxp_watchdog; + + ifp->if_capabilities = ifp->if_capenable = 0; + + /* Enable checksum offload for 82550 or better chips */ + if (sc->flags & FXP_FLAG_EXT_RFA) { + ifp->if_hwassist = FXP_CSUM_FEATURES; + ifp->if_capabilities |= IFCAP_HWCSUM; + ifp->if_capenable |= IFCAP_HWCSUM; + } + +#ifdef DEVICE_POLLING + /* Inform the world we support polling. */ + ifp->if_capabilities |= IFCAP_POLLING; +#endif + + /* + * Attach the interface. + */ + ether_ifattach(ifp, eaddr); + + /* + * Tell the upper layer(s) we support long frames. + * Must appear after the call to ether_ifattach() because + * ether_ifattach() sets ifi_hdrlen to the default value. + */ + ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header); + ifp->if_capabilities |= IFCAP_VLAN_MTU; + ifp->if_capenable |= IFCAP_VLAN_MTU; /* the hw bits already set */ + + /* + * Let the system queue as many packets as we have available + * TX descriptors. + */ + IFQ_SET_MAXLEN(&ifp->if_snd, FXP_NTXCB - 1); + ifp->if_snd.ifq_drv_maxlen = FXP_NTXCB - 1; + IFQ_SET_READY(&ifp->if_snd); + + /* + * Hook our interrupt after all initialization is complete. + */ + error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE, + fxp_intr, sc, &sc->ih); + if (error) { + device_printf(dev, "could not setup irq\n"); + ether_ifdetach(sc->ifp); + goto fail; + } + +fail: + if (error) + fxp_release(sc); + return (error); +} + +/* + * Release all resources. The softc lock should not be held and the + * interrupt should already be torn down. + */ +static void +fxp_release(struct fxp_softc *sc) +{ + struct fxp_rx *rxp; + struct fxp_tx *txp; + int i; + + FXP_LOCK_ASSERT(sc, MA_NOTOWNED); + KASSERT(sc->ih == NULL, + ("fxp_release() called with intr handle still active")); + if (sc->miibus) + device_delete_child(sc->dev, sc->miibus); + bus_generic_detach(sc->dev); + ifmedia_removeall(&sc->sc_media); + if (sc->fxp_desc.cbl_list) { + bus_dmamap_unload(sc->cbl_tag, sc->cbl_map); + bus_dmamem_free(sc->cbl_tag, sc->fxp_desc.cbl_list, + sc->cbl_map); + } + if (sc->fxp_stats) { + bus_dmamap_unload(sc->fxp_stag, sc->fxp_smap); + bus_dmamem_free(sc->fxp_stag, sc->fxp_stats, sc->fxp_smap); + } + if (sc->mcsp) { + bus_dmamap_unload(sc->mcs_tag, sc->mcs_map); + bus_dmamem_free(sc->mcs_tag, sc->mcsp, sc->mcs_map); + } + if (sc->irq) + bus_release_resource(sc->dev, SYS_RES_IRQ, 0, sc->irq); + if (sc->mem) + bus_release_resource(sc->dev, sc->rtp, sc->rgd, sc->mem); + if (sc->fxp_mtag) { + for (i = 0; i < FXP_NRFABUFS; i++) { + rxp = &sc->fxp_desc.rx_list[i]; + if (rxp->rx_mbuf != NULL) { + bus_dmamap_sync(sc->fxp_mtag, rxp->rx_map, + BUS_DMASYNC_POSTREAD); + bus_dmamap_unload(sc->fxp_mtag, rxp->rx_map); + m_freem(rxp->rx_mbuf); + } + bus_dmamap_destroy(sc->fxp_mtag, rxp->rx_map); + } + bus_dmamap_destroy(sc->fxp_mtag, sc->spare_map); + for (i = 0; i < FXP_NTXCB; i++) { + txp = &sc->fxp_desc.tx_list[i]; + if (txp->tx_mbuf != NULL) { + bus_dmamap_sync(sc->fxp_mtag, txp->tx_map, + BUS_DMASYNC_POSTWRITE); + bus_dmamap_unload(sc->fxp_mtag, txp->tx_map); + m_freem(txp->tx_mbuf); + } + bus_dmamap_destroy(sc->fxp_mtag, txp->tx_map); + } + bus_dma_tag_destroy(sc->fxp_mtag); + } + if (sc->fxp_stag) + bus_dma_tag_destroy(sc->fxp_stag); + if (sc->cbl_tag) + bus_dma_tag_destroy(sc->cbl_tag); + if (sc->mcs_tag) + bus_dma_tag_destroy(sc->mcs_tag); + if (sc->ifp) + if_free(sc->ifp); + + mtx_destroy(&sc->sc_mtx); +} + +/* + * Detach interface. + */ +static int +fxp_detach(device_t dev) +{ + struct fxp_softc *sc = device_get_softc(dev); + +#ifdef DEVICE_POLLING + if (sc->ifp->if_capenable & IFCAP_POLLING) + ether_poll_deregister(sc->ifp); +#endif + + FXP_LOCK(sc); + sc->suspended = 1; /* Do same thing as we do for suspend */ [... truncated: 3759 lines follow ...] From hugosantos at mail.berlios.de Fri May 4 13:27:11 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Fri, 4 May 2007 13:27:11 +0200 Subject: [Haiku-commits] r21014 - haiku/trunk/src/add-ons/kernel/network/protocols/tcp Message-ID: <200705041127.l44BRBlJ014963@sheep.berlios.de> Author: hugosantos Date: 2007-05-04 13:27:00 +0200 (Fri, 04 May 2007) New Revision: 21014 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21014&view=rev Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.cpp haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.h Log: renamed TCP's TSval/TSecr Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp 2007-05-04 11:26:37 UTC (rev 21013) +++ haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp 2007-05-04 11:27:00 UTC (rev 21014) @@ -236,7 +236,7 @@ fRoundTripTime(TCP_INITIAL_RTT / kTimestampFactor), fRoundTripDeviation(TCP_INITIAL_RTT / kTimestampFactor), fRetransmitTimeout(TCP_INITIAL_RTT), - fReceivedTSval(0), + fReceivedTimestamp(0), fCongestionWindow(0), fSlowStartThreshold(0), fState(CLOSED), @@ -1120,8 +1120,8 @@ if ((fOptions & TCP_NOOPT) == 0) { if (fFlags & FLAG_OPTION_TIMESTAMP) { segment.options |= TCP_HAS_TIMESTAMPS; - segment.TSecr = fReceivedTSval; - segment.TSval = tcp_now(); + segment.TimestampReply = fReceivedTimestamp; + segment.TimestampValue = tcp_now(); } if ((segment.flags & TCP_FLAG_SYNCHRONIZE) @@ -1579,7 +1579,7 @@ if ((fLastAcknowledgeSent >= sequence && fLastAcknowledgeSent < (sequence + segmentLength))) - fReceivedTSval = segment.TSval; + fReceivedTimestamp = segment.TimestampValue; } } @@ -1650,7 +1650,7 @@ if (segment.options & TCP_HAS_TIMESTAMPS) { fFlags |= FLAG_OPTION_TIMESTAMP; - fReceivedTSval = segment.TSval; + fReceivedTimestamp = segment.TimestampValue; } else fFlags &= ~FLAG_OPTION_TIMESTAMP; } @@ -1715,7 +1715,7 @@ // this ACK acknowledged data if (segment.options & TCP_HAS_TIMESTAMPS) - _UpdateSRTT(tcp_diff_timestamp(segment.TSecr)); + _UpdateSRTT(tcp_diff_timestamp(segment.TimestampReply)); else { // TODO Fallback to RFC 793 type estimation } Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h 2007-05-04 11:26:37 UTC (rev 21013) +++ haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h 2007-05-04 11:27:00 UTC (rev 21014) @@ -162,7 +162,7 @@ int32 fRoundTripDeviation; bigtime_t fRetransmitTimeout; - uint32 fReceivedTSval; + uint32 fReceivedTimestamp; uint32 fCongestionWindow; uint32 fSlowStartThreshold; Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.cpp 2007-05-04 11:26:37 UTC (rev 21013) +++ haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.cpp 2007-05-04 11:27:00 UTC (rev 21014) @@ -134,9 +134,9 @@ bump_option(option, length); option->kind = TCP_OPTION_TIMESTAMP; option->length = 10; - option->timestamp.TSval = htonl(segment.TSval); + option->timestamp.TimestampValue = htonl(segment.TimestampValue); // TSecr is opaque to us, we send it as we received it. - option->timestamp.TSecr = segment.TSecr; + option->timestamp.TimestampReply = segment.TimestampReply; bump_option(option, length); } @@ -307,8 +307,9 @@ case TCP_OPTION_TIMESTAMP: if (option->length == 10 && (size - 10) >= 0) { segment.options |= TCP_HAS_TIMESTAMPS; - segment.TSval = option->timestamp.TSval; - segment.TSecr = ntohl(option->timestamp.TSecr); + segment.TimestampValue = option->timestamp.TimestampValue; + segment.TimestampReply = + ntohl(option->timestamp.TimestampReply); } break; case TCP_OPTION_SACK_PERMITTED: Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.h =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.h 2007-05-04 11:26:37 UTC (rev 21013) +++ haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.h 2007-05-04 11:27:00 UTC (rev 21014) @@ -118,8 +118,8 @@ uint8 window_shift; uint16 max_segment_size; struct { - uint32 TSval; - uint32 TSecr; + uint32 TimestampValue; + uint32 TimestampReply; } timestamp; tcp_sack sack[0]; }; @@ -161,8 +161,8 @@ uint8 window_shift; uint16 max_segment_size; - uint32 TSval; - uint32 TSecr; + uint32 TimestampValue; + uint32 TimestampReply; tcp_sack *sacks; int sack_count; From hugosantos at gmail.com Fri May 4 13:38:25 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Fri, 4 May 2007 12:38:25 +0100 Subject: [Haiku-commits] r20947 - in haiku/trunk: headers/private/net src/add-ons/kernel/network/devices/ethernet src/add-ons/kernel/network/devices/loopback src/add-ons/kernel/network/stack In-Reply-To: <17014746248-BeMail@zon> References: <9c46321e0705040352g84bc312pd62170e967cf9f12@mail.gmail.com> <17014746248-BeMail@zon> Message-ID: <9c46321e0705040438s33099852w3bbaabc098f99d8f@mail.gmail.com> On 5/4/07, Axel D?rfler wrote: > Since I am usually the one insisting on a consistent coding style and > naming, I also don't mind doing the appropriate changes. If you prefer > to do them yourself, that's okay, too; but sometimes it's just simpler > and faster to just do the changes directly. I just don't see the point of wasting time doing these changes in cases where the code isn't old and is not obscure. > So I take the opportunity and remind you of renaming the TCP timestamp > variables :-) I had forgotten about those, i have changed them now. > > You don't see me changing other people's code for 'clarity' without > > fixing bugs or introducing/using new code. Anyway... > > You changed a lot of working code for clarity, already (ie. by using > your hashtable, protocol/socket base class, etc.) - and that's > perfectly okay, too. > It's called refactoring and usually improves the code ;-) You point it out neatly, i tried to refactor code, not changing names for clarity. I tried to introduce type-safe helper classes and containers, and then rewrote code to use them. With the hope that it will prevents errors and reduces the amount of duplicate code. > BTW I would also suggest renaming fxp to ipro100 - for clarity; there > is no reason to duplicate the useless FreeBSD driver naming style. > Done. Hugo From axeld at pinc-software.de Fri May 4 13:58:44 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Fri, 04 May 2007 13:58:44 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r21014_-_haiku/trunk/src/add-ons/?= =?iso-8859-15?q?kernel/network/protocols/tcp?= In-Reply-To: <200705041127.l44BRBlJ014963@sheep.berlios.de> Message-ID: <19922997895-BeMail@zon> hugosantos at mail.berlios.de wrote: > uint16 max_segment_size; > struct { > - uint32 TSval; > - uint32 TSecr; > + uint32 TimestampValue; > + uint32 TimestampReply; > } timestamp; > tcp_sack sack[0]; > }; > @@ -161,8 +161,8 @@ > uint8 window_shift; > uint16 max_segment_size; > > - uint32 TSval; > - uint32 TSecr; > + uint32 TimestampValue; > + uint32 TimestampReply; Thanks for the changes, but since these are member of structs, the correct naming would be: timestamp_value and timestamp_reply in both cases. Bye, Axel. From axeld at pinc-software.de Fri May 4 14:04:38 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Fri, 04 May 2007 14:04:38 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r20947_-_in_haiku/trunk=3A_header?= =?iso-8859-15?q?s/private/net_src/add-ons/kernel/network/devices/ethernet?= =?iso-8859-15?q?_src/add-ons/kernel/network/devices/loopback_src/add-ons/?= =?iso-8859-15?q?kernel/network/stack?= In-Reply-To: <9c46321e0705040438s33099852w3bbaabc098f99d8f@mail.gmail.com> Message-ID: <20276658389-BeMail@zon> "Hugo Santos" wrote: > On 5/4/07, Axel D?rfler wrote: > > Since I am usually the one insisting on a consistent coding style > > and > > naming, I also don't mind doing the appropriate changes. If you > > prefer > > to do them yourself, that's okay, too; but sometimes it's just > > simpler > > and faster to just do the changes directly. > I just don't see the point of wasting time doing these changes in > cases where the code isn't old and is not obscure. It costs you the same amount of time to change them as it costs me (or even more if you don't get it right on first try ;-)). This case was more important since it was part of the API. > > You changed a lot of working code for clarity, already (ie. by > > using > > your hashtable, protocol/socket base class, etc.) - and that's > > perfectly okay, too. > > It's called refactoring and usually improves the code ;-) > You point it out neatly, i tried to refactor code, not changing > names for clarity. I tried to introduce type-safe helper classes and > containers, and then rewrote code to use them. With the hope that it > will prevents errors and reduces the amount of duplicate code. Actually, both things are part of the refactoring process. Anyway, I will ask you next time, if you prefer to do the changes yourself :-) > > BTW I would also suggest renaming fxp to ipro100 - for clarity; > > there > > is no reason to duplicate the useless FreeBSD driver naming style. > Done. Thanks! Bye, Axel. From hugosantos at mail.berlios.de Fri May 4 14:04:47 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Fri, 4 May 2007 14:04:47 +0200 Subject: [Haiku-commits] r21016 - haiku/trunk/src/add-ons/kernel/network/protocols/tcp Message-ID: <200705041204.l44C4lYO017347@sheep.berlios.de> Author: hugosantos Date: 2007-05-04 14:04:34 +0200 (Fri, 04 May 2007) New Revision: 21016 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21016&view=rev Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.cpp haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.h Log: use a appropriate naming for structure fields. Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp 2007-05-04 11:27:11 UTC (rev 21015) +++ haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp 2007-05-04 12:04:34 UTC (rev 21016) @@ -1120,8 +1120,8 @@ if ((fOptions & TCP_NOOPT) == 0) { if (fFlags & FLAG_OPTION_TIMESTAMP) { segment.options |= TCP_HAS_TIMESTAMPS; - segment.TimestampReply = fReceivedTimestamp; - segment.TimestampValue = tcp_now(); + segment.timestamp_reply = fReceivedTimestamp; + segment.timestamp_value = tcp_now(); } if ((segment.flags & TCP_FLAG_SYNCHRONIZE) @@ -1579,7 +1579,7 @@ if ((fLastAcknowledgeSent >= sequence && fLastAcknowledgeSent < (sequence + segmentLength))) - fReceivedTimestamp = segment.TimestampValue; + fReceivedTimestamp = segment.timestamp_value; } } @@ -1650,7 +1650,7 @@ if (segment.options & TCP_HAS_TIMESTAMPS) { fFlags |= FLAG_OPTION_TIMESTAMP; - fReceivedTimestamp = segment.TimestampValue; + fReceivedTimestamp = segment.timestamp_value; } else fFlags &= ~FLAG_OPTION_TIMESTAMP; } @@ -1715,7 +1715,7 @@ // this ACK acknowledged data if (segment.options & TCP_HAS_TIMESTAMPS) - _UpdateSRTT(tcp_diff_timestamp(segment.TimestampReply)); + _UpdateSRTT(tcp_diff_timestamp(segment.timestamp_reply)); else { // TODO Fallback to RFC 793 type estimation } Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.cpp 2007-05-04 11:27:11 UTC (rev 21015) +++ haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.cpp 2007-05-04 12:04:34 UTC (rev 21016) @@ -134,9 +134,9 @@ bump_option(option, length); option->kind = TCP_OPTION_TIMESTAMP; option->length = 10; - option->timestamp.TimestampValue = htonl(segment.TimestampValue); + option->timestamp.timestamp_value = htonl(segment.timestamp_value); // TSecr is opaque to us, we send it as we received it. - option->timestamp.TimestampReply = segment.TimestampReply; + option->timestamp.timestamp_reply = segment.timestamp_reply; bump_option(option, length); } @@ -307,9 +307,9 @@ case TCP_OPTION_TIMESTAMP: if (option->length == 10 && (size - 10) >= 0) { segment.options |= TCP_HAS_TIMESTAMPS; - segment.TimestampValue = option->timestamp.TimestampValue; - segment.TimestampReply = - ntohl(option->timestamp.TimestampReply); + segment.timestamp_value = option->timestamp.timestamp_value; + segment.timestamp_reply = + ntohl(option->timestamp.timestamp_reply); } break; case TCP_OPTION_SACK_PERMITTED: Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.h =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.h 2007-05-04 11:27:11 UTC (rev 21015) +++ haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.h 2007-05-04 12:04:34 UTC (rev 21016) @@ -118,8 +118,8 @@ uint8 window_shift; uint16 max_segment_size; struct { - uint32 TimestampValue; - uint32 TimestampReply; + uint32 timestamp_value; + uint32 timestamp_reply; } timestamp; tcp_sack sack[0]; }; @@ -161,8 +161,8 @@ uint8 window_shift; uint16 max_segment_size; - uint32 TimestampValue; - uint32 TimestampReply; + uint32 timestamp_value; + uint32 timestamp_reply; tcp_sack *sacks; int sack_count; From hugosantos at gmail.com Fri May 4 14:08:04 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Fri, 4 May 2007 13:08:04 +0100 Subject: [Haiku-commits] r20947 - in haiku/trunk: headers/private/net src/add-ons/kernel/network/devices/ethernet src/add-ons/kernel/network/devices/loopback src/add-ons/kernel/network/stack In-Reply-To: <20276658389-BeMail@zon> References: <9c46321e0705040438s33099852w3bbaabc098f99d8f@mail.gmail.com> <20276658389-BeMail@zon> Message-ID: <9c46321e0705040508m6d32ec92hee1b6a387f6e371@mail.gmail.com> On 5/4/07, Axel D?rfler wrote: > Anyway, I will ask you next time, if you prefer to do the changes > yourself :-) Just to make it clearer, i don't mind you changing code i submit at all, specially if you are fixing something i broke. It was just that this single commit seemed a bit pointless. But moving along. Hugo From hugosantos at mail.berlios.de Fri May 4 16:22:51 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Fri, 4 May 2007 16:22:51 +0200 Subject: [Haiku-commits] r21017 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/sys Message-ID: <200705041422.l44EMpQN029793@sheep.berlios.de> Author: hugosantos Date: 2007-05-04 16:22:35 +0200 (Fri, 04 May 2007) New Revision: 21017 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21017&view=rev Added: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h haiku/trunk/src/libs/compat/freebsd_network/device.c Log: freebsd compat. layer: now the glue code properly references the required methods so we have proper linkage with gcc 4 Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-04 12:04:34 UTC (rev 21016) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-04 14:22:35 UTC (rev 21017) @@ -6,6 +6,8 @@ #include #include +#include + // TODO per platform, these are x86 typedef uint32_t bus_addr_t; typedef uint32_t bus_size_t; @@ -85,26 +87,6 @@ } -typedef struct device *device_t; -typedef struct devclass *devclass_t; - -typedef int (*device_method_signature_t)(device_t dev); - -struct device_method { - const char *name; - device_method_signature_t method; -}; - -typedef struct device_method device_method_t; - -#define DEVMETHOD(name, func) { #name, (device_method_signature_t)func } - -typedef struct { - const char *name; - device_method_t *methods; - size_t size; -} driver_t; - enum intr_type { INTR_TYPE_NET = 4, INTR_MPSAFE = 512, @@ -133,22 +115,6 @@ driver_intr_t handler, void *arg, void **cookiep); int bus_teardown_intr(device_t dev, struct resource *r, void *cookie); -#define BUS_PROBE_DEFAULT 20 - -#define DRIVER_MODULE_NAME(name, busname) \ - __fbsd_##name##busname - -driver_t *__fbsd_driver(void); - -#define HAIKU_FBSD_DRIVER_GLUE(name, busname) \ - driver_t *__fbsd_driver() { \ - extern driver_t *DRIVER_MODULE_NAME(name, busname); \ - return DRIVER_MODULE_NAME(name, busname); \ - } - -#define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) \ - driver_t *DRIVER_MODULE_NAME(name, busname) = &(driver) - const char *device_get_name(device_t dev); const char *device_get_nameunit(device_t dev); int device_get_unit(device_t dev); Added: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-04 12:04:34 UTC (rev 21016) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-04 14:22:35 UTC (rev 21017) @@ -0,0 +1,71 @@ +/* + * Copyright 2007, Hugo Santos. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Hugo Santos, hugosantos at gmail.com + */ +#ifndef _FBSD_COMPAT_SYS_HAIKU_MODULE_H_ +#define _FBSD_COMPAT_SYS_HAIKU_MODULE_H_ + +#include /* for device_hooks */ + +typedef struct device *device_t; +typedef struct devclass *devclass_t; + +typedef int (*device_method_signature_t)(device_t dev); + +struct device_method { + const char *name; + device_method_signature_t method; +}; + +typedef struct device_method device_method_t; + +#define DEVMETHOD(name, func) { #name, (device_method_signature_t)func } + +typedef struct { + const char *name; + device_method_t *methods; + size_t size; +} driver_t; + +#define BUS_PROBE_DEFAULT 20 + +#define DRIVER_MODULE_NAME(name, busname) \ + __fbsd_##name##busname + +status_t _fbsd_init_hardware(driver_t *); +status_t _fbsd_init_driver(driver_t *); +void _fbsd_uninit_driver(driver_t *); + +/* we define the driver methods with HAIKU_FBSD_DRIVER_GLUE to + * force the rest of the stuff to be linked back with the driver. + * While gcc 2.95 packs everything from the static library onto + * the final binary, gcc 4.x rightfuly doesn't. */ + +#define HAIKU_FBSD_DRIVER_GLUE(name, busname) \ + extern char *gDevNameList[]; \ + extern device_hooks gDeviceHooks; \ + extern driver_t *DRIVER_MODULE_NAME(name, busname); \ + int32 api_version = B_CUR_DRIVER_API_VERSION; \ + status_t init_hardware() \ + { \ + return _fbsd_init_hardware(DRIVER_MODULE_NAME(name, busname)); \ + } \ + status_t init_driver() \ + { \ + return _fbsd_init_driver(DRIVER_MODULE_NAME(name, busname)); \ + } \ + void uninit_driver() \ + { \ + _fbsd_uninit_driver(DRIVER_MODULE_NAME(name, busname)); \ + } \ + const char **publish_devices() { return (const char **)gDevNameList; } \ + device_hooks *find_device(const char *name) { return &gDeviceHooks; } + +#define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) \ + driver_t *DRIVER_MODULE_NAME(name, busname) = &(driver) + + +#endif Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-04 12:04:34 UTC (rev 21016) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-04 14:22:35 UTC (rev 21017) @@ -13,19 +13,17 @@ #include #include -#include +#include + #include #define MAX_DEVICES 8 -int32 api_version = B_CUR_DRIVER_API_VERSION; +char *gDevNameList[MAX_DEVICES + 1]; -static char *sDevNameList[MAX_DEVICES + 1]; - - static status_t compat_open(const char *name, uint32 flags, void **cookie) { @@ -106,7 +104,7 @@ } -static device_hooks sDeviceHooks = { +device_hooks gDeviceHooks = { compat_open, compat_close, compat_free, @@ -116,34 +114,29 @@ }; -static int -_device_probe(device_t dev) -{ - device_method_t *methods = __fbsd_driver()->methods; - int i; - - for (i = 0; methods[i].name != NULL; i++) { - if (!strcmp(methods[i].name, "device_probe")) - return methods[i].method(dev); - } - - panic("fsbd compat layer: method missing, device_probe"); - return -1; -} - - status_t -init_hardware() +_fbsd_init_hardware(driver_t *driver) { + device_method_signature_t probe = NULL; struct device fakeDevice; pci_info info; int i; + for (i = 0; probe == NULL && driver->methods[i].name != NULL; i++) { + if (strcmp(driver->methods[i].name, "device_probe") == 0) + probe = driver->methods[i].method; + } + + if (probe == NULL) { + dprintf("_fbsd_init_hardware: driver has no device_probe method.\n"); + return B_ERROR; + } + memset(&fakeDevice, 0, sizeof(struct device)); fakeDevice.pciInfo = &info; for (i = 0; gPci->get_nth_pci_info(i, &info) == B_OK; i++) { - if (_device_probe(&fakeDevice) >= 0) + if (probe(&fakeDevice) >= 0) return B_OK; } @@ -152,27 +145,13 @@ status_t -init_driver() +_fbsd_init_driver(driver_t *driver) { return B_ERROR; } void -uninit_driver() +_fbsd_uninit_driver(driver_t *driver) { } - - -const char ** -publish_devices() -{ - return (const char **)sDevNameList; -} - - -device_hooks * -find_device(const char *name) -{ - return &sDeviceHooks; -} From mmu_man at mail.berlios.de Fri May 4 16:33:49 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Fri, 4 May 2007 16:33:49 +0200 Subject: [Haiku-commits] r21018 - haiku/trunk/src/add-ons/kernel/drivers/disk Message-ID: <200705041433.l44EXn18031017@sheep.berlios.de> Author: mmu_man Date: 2007-05-04 16:33:49 +0200 (Fri, 04 May 2007) New Revision: 21018 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21018&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/Jamfile Log: Hook virtual/ to the build Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/Jamfile 2007-05-04 14:22:35 UTC (rev 21017) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/Jamfile 2007-05-04 14:33:49 UTC (rev 21018) @@ -2,3 +2,4 @@ SubInclude HAIKU_TOP src add-ons kernel drivers disk scsi ; SubInclude HAIKU_TOP src add-ons kernel drivers disk acpi_loader ; +SubInclude HAIKU_TOP src add-ons kernel drivers disk virtual ; From mmu_man at mail.berlios.de Fri May 4 16:35:01 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Fri, 4 May 2007 16:35:01 +0200 Subject: [Haiku-commits] r21019 - in haiku/trunk/src/add-ons/kernel/drivers/disk/virtual: fmap nbd Message-ID: <200705041435.l44EZ1xI031090@sheep.berlios.de> Author: mmu_man Date: 2007-05-04 16:35:01 +0200 (Fri, 04 May 2007) New Revision: 21019 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21019&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/fmap/fmap.c haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c Log: Add api_version. Moved #define DEBUG after the lock.h include, as it wants to find lots of header I'm too lazy to track. Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/fmap/fmap.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/fmap/fmap.c 2007-05-04 14:33:49 UTC (rev 21018) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/fmap/fmap.c 2007-05-04 14:35:01 UTC (rev 21019) @@ -16,6 +16,8 @@ #define MAX_FMAPS 4 #define DEVNAME_FMT "disk/virtual/fmap/%2d" +int32 api_version = B_CUR_DRIVER_API_VERSION; + status_t init_hardware (void) { Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-04 14:33:49 UTC (rev 21018) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c 2007-05-04 14:35:01 UTC (rev 21019) @@ -18,7 +18,7 @@ #include #include -#define DEBUG 1 +//#define DEBUG 1 /* on the first open(), open ourselves for some seconds, * to avoid trying to reconnect and failing on a 2nd open, @@ -48,6 +48,8 @@ #define benaphore_unlock UNLOCK #endif +#define DEBUG 1 + #include "nbd.h" #define DRV "nbd" @@ -736,9 +738,10 @@ NULL }; - #pragma mark ==== driver hooks ==== +int32 api_version = B_CUR_DRIVER_API_VERSION; + static char *nbd_name[MAX_NBDS+1] = { NULL }; From axeld at pinc-software.de Fri May 4 16:43:23 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Fri, 04 May 2007 16:43:23 +0200 CEST Subject: [Haiku-commits] r20982 - haiku/trunk/src/system/kernel/fs In-Reply-To: <20070504102124.1040.1@cs.tu-berlin.de> Message-ID: <29801091907-BeMail@zon> Ingo Weinhold wrote: > > Having something like this would be nice, even though I would > > prefer if > > we had a path version of watch_node() that would automatically > > handle > > the details in the future (like a "watch all files under /boot/home > > / > > config/"). > That would be nice, though it's also quite a bit more expensive > (memory- > and CPU-wise) than ordinary node monitoring. Definitely, but it wouldn't matter wether we do the actual work in the kernel or in the userland. > > Anyway, I planned to have a look at the AddOnMonitor stuff in src/ > > kits/ > > storage (why there, anyway?) and implement this functionality > > there. > > But feel free to beat me on it :) > No worries, I won't beat you. :-P Do we prefer a watch_path()/stop_watching_path() API, or a BPathMonitor class? I went for the latter for now, but we could change that to the former without too much effort. Bye, Axel. From bonefish at cs.tu-berlin.de Fri May 4 17:28:58 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Fri, 04 May 2007 17:28:58 +0200 Subject: [Haiku-commits] r20982 - haiku/trunk/src/system/kernel/fs In-Reply-To: <29801091907-BeMail@zon> References: <29801091907-BeMail@zon> Message-ID: <20070504172858.1149.3@cs.tu-berlin.de> On 2007-05-04 at 16:43:23 [+0200], Axel D?rfler wrote: > Ingo Weinhold wrote: > > > Having something like this would be nice, even though I would > > > prefer if > > > we had a path version of watch_node() that would automatically > > > handle > > > the details in the future (like a "watch all files under /boot/home > > > / > > > config/"). > > That would be nice, though it's also quite a bit more expensive > > (memory- > > and CPU-wise) than ordinary node monitoring. > > Definitely, but it wouldn't matter wether we do the actual work in the > kernel or in the userland. Kernel resources are generally more valuable, though. So unless there are actual advantages I'd keep things in userland. > > > Anyway, I planned to have a look at the AddOnMonitor stuff in src/ > > > kits/ > > > storage (why there, anyway?) and implement this functionality > > > there. > > > But feel free to beat me on it :) > > No worries, I won't beat you. :-P > > Do we prefer a watch_path()/stop_watching_path() API, or a BPathMonitor > class? > I went for the latter for now, but we could change that to the former > without too much effort. I like a C++ class better, too. CU, Ingo From axeld at mail.berlios.de Fri May 4 18:02:04 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 4 May 2007 18:02:04 +0200 Subject: [Haiku-commits] r21020 - in haiku/trunk: headers/private/storage src/kits/storage Message-ID: <200705041602.l44G24b0005021@sheep.berlios.de> Author: axeld Date: 2007-05-04 18:02:04 +0200 (Fri, 04 May 2007) New Revision: 21020 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21020&view=rev Added: haiku/trunk/headers/private/storage/PathMonitor.h haiku/trunk/src/kits/storage/PathMonitor.cpp Log: * Implemented PathMonitor class - untested, but compiles. * The API is just a proposal at this time, please comment. Added: haiku/trunk/headers/private/storage/PathMonitor.h =================================================================== --- haiku/trunk/headers/private/storage/PathMonitor.h 2007-05-04 14:35:01 UTC (rev 21019) +++ haiku/trunk/headers/private/storage/PathMonitor.h 2007-05-04 16:02:04 UTC (rev 21020) @@ -0,0 +1,40 @@ +/* + * Copyright 2007, Haiku Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _PATH_MONITOR_H +#define _PATH_MONITOR_H + + +#include + + +// additional flags (combined with those in NodeMonitor.h) +#define B_WATCH_FILES_ONLY 0x0100 +#define B_WATCH_RECURSIVELY 0x0200 + +#define B_PATH_MONITOR '_PMN' + +namespace BPrivate { + +class PathHandler; + +class BPathMonitor { + public: + BPathMonitor(); + BPathMonitor(const char* path, uint32 flags, BMessenger target); + ~BPathMonitor(); + + status_t InitCheck() const; + status_t SetTo(const char* path, uint32 flags, BMessenger target); + status_t SetTarget(BMessenger target); + void Unset(); + + private: + PathHandler* fHandler; + status_t fStatus; +}; + +} // namespace BPrivate + +#endif // _PATH_MONITOR_H Added: haiku/trunk/src/kits/storage/PathMonitor.cpp =================================================================== --- haiku/trunk/src/kits/storage/PathMonitor.cpp 2007-05-04 14:35:01 UTC (rev 21019) +++ haiku/trunk/src/kits/storage/PathMonitor.cpp 2007-05-04 16:02:04 UTC (rev 21020) @@ -0,0 +1,493 @@ +/* + * Copyright 2007, Haiku Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Axel D?rfler, axeld at pinc-software.de + */ + + +#include + +#include +#include +#include +#include +#include +#include + +#include + +using namespace BPrivate; +using namespace std; + + +#define WATCH_NODE_FLAG_MASK 0x00ff + +typedef set DirectorySet; + +namespace BPrivate { + +class PathHandler : public BHandler { + public: + PathHandler(const char* path, uint32 flags, BMessenger target); + virtual ~PathHandler(); + + status_t InitCheck() const; + void SetTarget(BMessenger target); + void Quit(); + + virtual void MessageReceived(BMessage* message); + + private: + bool _IsContained(const node_ref& nodeRef) const; + bool _IsContained(BEntry& entry) const; + bool _HasDirectory(const node_ref& nodeRef) const; + void _NotifyTarget(BMessage* message) const; + status_t _AddDirectory(BEntry& entry); + status_t _RemoveDirectory(const node_ref& nodeRef); + status_t _RemoveDirectory(BEntry& entry); + + BPath fPath; + int32 fPathLength; + BMessenger fTarget; + uint32 fFlags; + status_t fStatus; + bool fOwnsLooper; + DirectorySet fDirectories; +}; + +} + + +static status_t +set_entry(node_ref& nodeRef, const char* name, BEntry& entry) +{ + entry_ref ref; + ref.device = nodeRef.device; + ref.directory = nodeRef.node; + + status_t status = ref.set_name(name); + if (status != B_OK) + return status; + + return entry.SetTo(&ref, true); +} + + +bool +operator<(const node_ref& a, const node_ref& b) +{ + if (a.device < b.device) + return true; + if (a.device == b.device && a.node < b.node) + return true; + + return false; +} + + +// #pragma mark - + + +PathHandler::PathHandler(const char* path, uint32 flags, BMessenger target) + : BHandler(path), + fPath(path, NULL, true), + fTarget(target), + fFlags(flags), + fOwnsLooper(false) +{ + fPathLength = strlen(fPath.Path()); + + BPath first(path); + node_ref nodeRef; + + while (true) { + // try to find the first part of the path that exists + BDirectory directory; + fStatus = directory.SetTo(first.Path()); + if (fStatus == B_OK) { + fStatus = directory.GetNodeRef(&nodeRef); + if (fStatus == B_OK) + break; + } + + if (first.GetParent(&first) != B_OK) { + fStatus = B_ERROR; + break; + } + } + + if (fStatus < B_OK) + return; + + if (be_app != NULL) { + be_app->AddHandler(this); + } else { + // TODO: only have a single global looper! + BLooper* looper = new BLooper("PathMonitor looper"); + looper->Run(); + looper->AddHandler(this); + fOwnsLooper = true; + } + + fStatus = watch_node(&nodeRef, flags & WATCH_NODE_FLAG_MASK, this); +} + + +PathHandler::~PathHandler() +{ +} + + +status_t +PathHandler::InitCheck() const +{ + return fStatus; +} + + +void +PathHandler::SetTarget(BMessenger target) +{ + fTarget = target; +} + + +void +PathHandler::Quit() +{ + BMessenger me(this); + me.SendMessage(B_QUIT_REQUESTED); +} + + +void +PathHandler::MessageReceived(BMessage* message) +{ + switch (message->what) { + case B_NODE_MONITOR: + { + int32 opcode; + if (message->FindInt32("opcode", &opcode) != B_OK) + return; + + switch (opcode) { + case B_ENTRY_CREATED: + { + const char* name; + node_ref nodeRef; + if (message->FindInt32("device", &nodeRef.device) != B_OK + || message->FindInt64("directory", &nodeRef.node) != B_OK + || message->FindString("name", &name) != B_OK) + break; + + BEntry entry; + if (set_entry(nodeRef, name, entry) != B_OK) + break; + + bool notify = true; + + if (entry.IsDirectory()) { + // a new directory to watch for us + if (_AddDirectory(entry) != B_OK + || (fFlags & B_WATCH_FILES_ONLY) != 0) + notify = false; + } + + if (notify && _IsContained(entry)) { + message->AddBool("added", true); + _NotifyTarget(message); + } + break; + } + + case B_ENTRY_MOVED: + { + // has the entry been moved into a monitored directory or has + // it been removed from one? + const char* name; + node_ref nodeRef; + uint64 fromNode; + uint64 node; + if (message->FindInt32("device", &nodeRef.device) != B_OK + || message->FindInt64("to directory", &nodeRef.node) != B_OK + || message->FindInt64("from directory", (int64 *)&fromNode) != B_OK + || message->FindInt64("node", (int64 *)&node) != B_OK + || message->FindString("name", &name) != B_OK) + break; + + BEntry entry; + if (set_entry(nodeRef, name, entry) != B_OK) + break; + + bool wasAdded = false; + bool wasRemoved = false; + bool notify = true; + + if (_HasDirectory(nodeRef)) { + // something has been added to our watched directories + + // test, if the source directory is one of ours as well + nodeRef.node = fromNode; + bool hasFromDirectory = _HasDirectory(nodeRef); + + if (entry.IsDirectory()) { + if (!hasFromDirectory) { + // there is a new directory to watch for us + _AddDirectory(entry); + wasAdded = true; + } + if ((fFlags & B_WATCH_FILES_ONLY) != 0) + notify = false; + } else if (!hasFromDirectory) { + // file has been added + wasAdded = true; + } + } else { + // and entry has been removed from our directories + wasRemoved = true; + + if (entry.IsDirectory()) { + _RemoveDirectory(entry); + if ((fFlags & B_WATCH_FILES_ONLY) != 0) + notify = false; + } + } + + if (notify && _IsContained(entry)) { + if (wasAdded) + message->AddBool("added", true); + if (wasRemoved) + message->AddBool("removed", true); + + _NotifyTarget(message); + } + break; + } + + case B_ENTRY_REMOVED: + { + node_ref nodeRef; + uint64 directoryNode; + if (message->FindInt32("device", &nodeRef.device) != B_OK + || message->FindInt64("directory", (int64 *)&directoryNode) != B_OK + || message->FindInt64("node", &nodeRef.node) != B_OK) + break; + + bool notify = true; + + if (_HasDirectory(nodeRef)) { + // the directory has been removed, so we remove it as well + _RemoveDirectory(nodeRef); + if ((fFlags & B_WATCH_FILES_ONLY) != 0) + notify = false; + } + + nodeRef.node = directoryNode; + if (notify && _IsContained(nodeRef)) { + message->AddBool("removed", true); + _NotifyTarget(message); + } + break; + } + + default: + _NotifyTarget(message); + break; + } + break; + } + + case B_QUIT_REQUESTED: + { + BLooper* looper = Looper(); + + stop_watching(this); + looper->RemoveHandler(this); + delete this; + + if (fOwnsLooper) + looper->Quit(); + return; + } + + default: + BHandler::MessageReceived(message); + break; + } +} + + +bool +PathHandler::_IsContained(const node_ref& nodeRef) const +{ + BDirectory directory(&nodeRef); + if (directory.InitCheck() != B_OK) + return false; + + BEntry entry; + if (directory.GetEntry(&entry) != B_OK) + return false; + + return _IsContained(entry); +} + + +bool +PathHandler::_IsContained(BEntry& entry) const +{ + BPath path; + if (entry.GetPath(&path) != B_OK) + return false; + + return strncmp(path.Path(), fPath.Path(), fPathLength) == 0; +} + + +bool +PathHandler::_HasDirectory(const node_ref& nodeRef) const +{ + DirectorySet::const_iterator iterator = fDirectories.find(nodeRef); + return iterator != fDirectories.end(); +} + + +void +PathHandler::_NotifyTarget(BMessage* message) const +{ + BMessage update(*message); + update.what = B_PATH_MONITOR; + fTarget.SendMessage(&update); +} + + +status_t +PathHandler::_AddDirectory(BEntry& entry) +{ + node_ref nodeRef; + status_t status = entry.GetNodeRef(&nodeRef); + if (status != B_OK) + return status; + + // check if we are already know this directory + + if (_HasDirectory(nodeRef)) + return B_OK; + + uint32 flags; + if (_IsContained(entry)) + flags = fFlags & WATCH_NODE_FLAG_MASK; + else + flags = B_WATCH_DIRECTORY; + + status = watch_node(&nodeRef, flags, this); + if (status != B_OK) + return status; + + fDirectories.insert(nodeRef); + +#if 0 + BEntry parent; + if (entry.GetParent(&parent) == B_OK + && !_IsContained(parent)) { + // TODO: remove parent from watched directories + } +#endif + return B_OK; +} + + +status_t +PathHandler::_RemoveDirectory(const node_ref& nodeRef) +{ + DirectorySet::iterator iterator = fDirectories.find(nodeRef); + if (iterator == fDirectories.end()) + return B_ENTRY_NOT_FOUND; + + fDirectories.erase(iterator); + return B_OK; +} + + +status_t +PathHandler::_RemoveDirectory(BEntry& entry) +{ + node_ref nodeRef; + status_t status = entry.GetNodeRef(&nodeRef); + if (status != B_OK) + return status; + + return _RemoveDirectory(nodeRef); +} + + +// #pragma mark - + + +BPathMonitor::BPathMonitor() + : + fHandler(NULL), + fStatus(B_NO_INIT) +{ +} + + +BPathMonitor::BPathMonitor(const char* path, uint32 flags, BMessenger target) + : + fHandler(NULL), + fStatus(B_NO_INIT) +{ + SetTo(path, flags, target); +} + + +BPathMonitor::~BPathMonitor() +{ + Unset(); +} + + +status_t +BPathMonitor::InitCheck() const +{ + return fStatus; +} + + +status_t +BPathMonitor::SetTo(const char* path, uint32 flags, BMessenger target) +{ + Unset(); + + fHandler = new PathHandler(path, flags, target); + status_t status = fHandler->InitCheck(); + if (status < B_OK) + Unset(); + + return fStatus = status; +} + + +status_t +BPathMonitor::SetTarget(BMessenger target) +{ + if (fStatus < B_OK) + return B_NO_INIT; + + fHandler->SetTarget(target); + return B_OK; +} + + +void +BPathMonitor::Unset() +{ + if (fHandler != NULL) { + fHandler->Quit(); + fHandler = NULL; + } + fStatus = B_NO_INIT; +} + +//} // namespace BPrivate From axeld at pinc-software.de Fri May 4 18:06:19 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Fri, 04 May 2007 18:06:19 +0200 CEST Subject: [Haiku-commits] r20982 - haiku/trunk/src/system/kernel/fs In-Reply-To: <20070504172858.1149.3@cs.tu-berlin.de> Message-ID: <34777160651-BeMail@zon> Ingo Weinhold wrote: > Kernel resources are generally more valuable, though. So unless there > are > actual advantages I'd keep things in userland. True enough. > > Do we prefer a watch_path()/stop_watching_path() API, or a > > BPathMonitor > > class? > > I went for the latter for now, but we could change that to the > > former > > without too much effort. > I like a C++ class better, too. Wait until you've seen it ;-) See r21020 as an API proposal, feel free to comment. In the current implementation, B_WATCH_RECURSIVELY is ignored (it always works recursively right now, and maybe there is little reason to include this flag). It sends B_PATH_MONITOR messages that have the same fields as the usual node monitor message, plus "added" and "removed" in case files were added or removed into the watched space (I currently don't test if the formerly known parent directory is actually contained in the search path). I'll start testing and fixing the bugs as soon as we've agreed on an API :-) Bye, Axel. From axeld at mail.berlios.de Fri May 4 18:59:24 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 4 May 2007 18:59:24 +0200 Subject: [Haiku-commits] r21021 - in haiku/trunk: headers/os/storage src/kits/storage Message-ID: <200705041659.l44GxO5u016287@sheep.berlios.de> Author: axeld Date: 2007-05-04 18:59:23 +0200 (Fri, 04 May 2007) New Revision: 21021 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21021&view=rev Modified: haiku/trunk/headers/os/storage/Statable.h haiku/trunk/src/kits/storage/Statable.cpp Log: Added virtual desctructor to calm down GCC 4. Modified: haiku/trunk/headers/os/storage/Statable.h =================================================================== --- haiku/trunk/headers/os/storage/Statable.h 2007-05-04 16:02:04 UTC (rev 21020) +++ haiku/trunk/headers/os/storage/Statable.h 2007-05-04 16:59:23 UTC (rev 21021) @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. + * Copyright 2002-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _STATABLE_H @@ -17,6 +17,8 @@ class BStatable { public: + virtual ~BStatable(); + virtual status_t GetStat(struct stat *st) const = 0; bool IsFile() const; Modified: haiku/trunk/src/kits/storage/Statable.cpp =================================================================== --- haiku/trunk/src/kits/storage/Statable.cpp 2007-05-04 16:02:04 UTC (rev 21020) +++ haiku/trunk/src/kits/storage/Statable.cpp 2007-05-04 16:59:23 UTC (rev 21021) @@ -1,7 +1,12 @@ -//---------------------------------------------------------------------- -// This software is part of the Haiku distribution and is covered -// by the MIT license. -//--------------------------------------------------------------------- +/* + * Copyright 2002-2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Tyler Dauwalder + * Ingo Weinhold, bonefish at users.sf.net + */ + /*! \file Statable.cpp BStatable implementation. @@ -14,6 +19,12 @@ #include + +BStatable::~BStatable() +{ +} + + /*! \fn status_t GetStat(struct stat *st) const \brief Returns the stat stucture for the node. \param st the stat structure to be filled in. From axeld at mail.berlios.de Fri May 4 19:00:14 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 4 May 2007 19:00:14 +0200 Subject: [Haiku-commits] r21022 - haiku/trunk/src/apps/mandelbrot Message-ID: <200705041700.l44H0E8N016939@sheep.berlios.de> Author: axeld Date: 2007-05-04 19:00:07 +0200 (Fri, 04 May 2007) New Revision: 21022 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21022&view=rev Added: haiku/trunk/src/apps/mandelbrot/Mandelbrot.cpp Removed: haiku/trunk/src/apps/mandelbrot/main.cpp Modified: haiku/trunk/src/apps/mandelbrot/Jamfile Log: * Fixed build under GCC 4, thanks to Ioan Molnar! * Minor cleanup. Modified: haiku/trunk/src/apps/mandelbrot/Jamfile =================================================================== --- haiku/trunk/src/apps/mandelbrot/Jamfile 2007-05-04 16:59:23 UTC (rev 21021) +++ haiku/trunk/src/apps/mandelbrot/Jamfile 2007-05-04 17:00:07 UTC (rev 21022) @@ -4,8 +4,7 @@ AddSubDirSupportedPlatforms libbe_test ; Application Mandelbrot : - main.cpp + Mandelbrot.cpp tsb.cpp : be : Mandelbrot.rdef ; - Copied: haiku/trunk/src/apps/mandelbrot/Mandelbrot.cpp (from rev 21007, haiku/trunk/src/apps/mandelbrot/main.cpp) =================================================================== --- haiku/trunk/src/apps/mandelbrot/main.cpp 2007-05-03 21:42:09 UTC (rev 21007) +++ haiku/trunk/src/apps/mandelbrot/Mandelbrot.cpp 2007-05-04 17:00:07 UTC (rev 21022) @@ -0,0 +1,201 @@ +/* + Copyright 1993-1999, Be Incorporated. All Rights Reserved. + This file may be used under the terms of the Be Sample Code License. +*/ + +#include "tsb.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + +/* Those are the menu item id's of the main window */ +#define P1 0x60 +#define P2 0x61 +#define P3 0x62 +#define P4 0x63 + +class TMainWindow : public BWindow { + public: + TMainWindow(BRect bound, char* name, window_type type, + long flags); + virtual ~TMainWindow(); + + virtual void MessageReceived(BMessage* message); + virtual void FrameResized(float width, float height); + virtual bool QuitRequested(); + + void UpdateScrollBars(); + + private: + TShowBit* fView; +}; + + +TMainWindow::TMainWindow(BRect bound, char* name, window_type type, long flags) + : BWindow(bound, name, type, flags) +{ + BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 1000, 15), "MB"); + BMenuItem* item; + BMenu* menu; + + menu = new BMenu("File"); + menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q')); + menuBar->AddItem(menu); + + menu = new BMenu("Palette"); + menu->AddItem(new BMenuItem("Palette1", new BMessage(P1))); + menu->AddItem(new BMenuItem("Palette2", new BMessage(P2))); + menu->AddItem(item = new BMenuItem("Palette3", new BMessage(P3))); + menu->AddItem(new BMenuItem("Palette4", new BMessage(P4))); + menuBar->AddItem(menu); + + item->SetMarked(true); + menu->SetRadioMode(true); + + menu = new BMenu("Iterations"); + menu->AddItem(new BMenuItem("128", new BMessage(128))); + menu->AddItem(item = new BMenuItem("256", new BMessage(256))); + menu->AddItem(new BMenuItem("384", new BMessage(384))); + menu->AddItem(new BMenuItem("512", new BMessage(512))); + menu->AddItem(new BMenuItem("768", new BMessage(768))); + menu->AddItem(new BMenuItem("1024", new BMessage(1024))); + menuBar->AddItem(menu); + + item->SetMarked(true); + menu->SetRadioMode(true); + + AddChild(menuBar); + float barHeight = menuBar->Bounds().Height(); + + fView = new TShowBit(BRect(0, barHeight + 1, 188 - B_V_SCROLL_BAR_WIDTH, + 188 - B_H_SCROLL_BAR_HEIGHT), B_FOLLOW_ALL | B_WILL_DRAW); + BScrollView *scrollView = new BScrollView("scroll view", fView, + B_FOLLOW_ALL, B_WILL_DRAW, true, true, B_NO_BORDER); + AddChild(scrollView); + + SetSizeLimits(80, size_x + 13, 80 + 20, size_y + barHeight + 1 + 13); + ResizeTo(size_x + 13, size_y + barHeight + 1 + 13); + SetPulseRate(150000); + UpdateScrollBars(); +} + + +TMainWindow::~TMainWindow() +{ +} + + +void +TMainWindow::UpdateScrollBars() +{ + BScrollView* scrollview; + BScrollBar* scrollbar; + BRect visible_extent; + BRect total_extent; + BRect bound; + BRect my_bounds; + long max; + + Lock(); + if ((scrollview = (BScrollView*)FindView("scroll view"))) { + bound.Set(0, 0, size_x, size_y); + my_bounds = Bounds(); + + visible_extent = bound & my_bounds; + total_extent = bound | my_bounds; + + scrollbar = scrollview->ScrollBar(B_HORIZONTAL); + max = (long) (bound.Width() - my_bounds.Width()); + if (max < 0) + max = 0; + scrollbar->SetRange(0, max); + scrollbar->SetProportion(visible_extent.Width() / total_extent.Width()); + + scrollbar = scrollview->ScrollBar(B_VERTICAL); + max = (long) (bound.Height() - my_bounds.Height()); + if (max < 0) + max = 0; + scrollbar->SetRange(0, max); + scrollbar->SetProportion(visible_extent.Height() / total_extent.Height()); + } + Unlock(); +} + + +void +TMainWindow::FrameResized(float, float) +{ + UpdateScrollBars(); +} + + +bool +TMainWindow::QuitRequested() +{ + if (fView->busy) { + fView->exit_now = true; + PostMessage(B_QUIT_REQUESTED); + return false; + } + + be_app->PostMessage(B_QUIT_REQUESTED); + return true; +} + + +void +TMainWindow::MessageReceived(BMessage* message) +{ + switch (message->what) { + case P1: + case P2: + case P3: + case P4: + fView->set_palette(message->what - P1); + break; + + case 128: + case 256: + case 384: + case 512: + case 768: + case 1024: + fView->set_iter(message->what); + break; + + default: + BWindow::MessageReceived(message); + break; + } +} + + +// #pragma mark - + + +int +main(int, char**) +{ + BApplication* app = new BApplication("application/x-vnd.Be-MAND"); + + BWindow* window = new TMainWindow(BRect(100, 100, 288, 288), "Mandelbrot", + B_DOCUMENT_WINDOW, B_WILL_ACCEPT_FIRST_CLICK); + window->Show(); + + app->Run(); + delete app; + return 0; +} Deleted: haiku/trunk/src/apps/mandelbrot/main.cpp From bonefish at cs.tu-berlin.de Fri May 4 20:02:18 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Fri, 04 May 2007 20:02:18 +0200 Subject: [Haiku-commits] r21021 - in haiku/trunk: headers/os/storage src/kits/storage In-Reply-To: <200705041659.l44GxO5u016287@sheep.berlios.de> References: <200705041659.l44GxO5u016287@sheep.berlios.de> Message-ID: <20070504200218.1429.4@cs.tu-berlin.de> On 2007-05-04 at 18:59:24 [+0200], axeld at BerliOS wrote: > Author: axeld > Date: 2007-05-04 18:59:23 +0200 (Fri, 04 May 2007) > New Revision: 21021 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21021&view=rev > > Modified: > haiku/trunk/headers/os/storage/Statable.h > haiku/trunk/src/kits/storage/Statable.cpp > Log: > Added virtual desctructor to calm down GCC 4. Er, binary compatibility? CU, Ingo From hugosantos at gmail.com Fri May 4 20:18:52 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Fri, 4 May 2007 19:18:52 +0100 Subject: [Haiku-commits] r21021 - in haiku/trunk: headers/os/storage src/kits/storage In-Reply-To: <20070504200218.1429.4@cs.tu-berlin.de> References: <200705041659.l44GxO5u016287@sheep.berlios.de> <20070504200218.1429.4@cs.tu-berlin.de> Message-ID: <9c46321e0705041118t7cb643c6n47e4e4c816071991@mail.gmail.com> I was going to suggest this some time ago, but eventually forgot. Stating the obvious -- this destructor should be around a #ifdef compiler not gcc 2.95. I think there are a couple of other cases that would help reduce gcc 4 warnings as well, i'll report them when i get them again. I assume we don't care about binary compatibility when gcc != 2.95 is involved? Hugo On 5/4/07, Ingo Weinhold wrote: > > On 2007-05-04 at 18:59:24 [+0200], axeld at BerliOS > wrote: > > Author: axeld > > Date: 2007-05-04 18:59:23 +0200 (Fri, 04 May 2007) > > New Revision: 21021 > > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21021&view=rev > > > > Modified: > > haiku/trunk/headers/os/storage/Statable.h > > haiku/trunk/src/kits/storage/Statable.cpp > > Log: > > Added virtual desctructor to calm down GCC 4. > > Er, binary compatibility? > > CU, Ingo > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From bonefish at cs.tu-berlin.de Fri May 4 20:32:17 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Fri, 04 May 2007 20:32:17 +0200 Subject: [Haiku-commits] r21021 - in haiku/trunk: headers/os/storage src/kits/storage In-Reply-To: <9c46321e0705041118t7cb643c6n47e4e4c816071991@mail.gmail.com> References: <200705041659.l44GxO5u016287@sheep.berlios.de> <20070504200218.1429.4@cs.tu-berlin.de> <9c46321e0705041118t7cb643c6n47e4e4c816071991@mail.gmail.com> Message-ID: <20070504203217.1539.5@cs.tu-berlin.de> On 2007-05-04 at 20:18:52 [+0200], Hugo Santos wrote: > I was going to suggest this some time ago, but eventually forgot. > Stating the obvious -- this destructor should be around a #ifdef > compiler not gcc 2.95. I think there are a couple of other cases that > would help reduce gcc 4 warnings as well, i'll report them when i get > them again. I assume we don't care about binary compatibility when gcc > != 2.95 is involved? Well, there is nothing to be compatible with in the first place in this case. :-) CU, Ingo From korli at mail.berlios.de Fri May 4 20:31:34 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Fri, 4 May 2007 20:31:34 +0200 Subject: [Haiku-commits] r21023 - haiku/trunk/build/jam Message-ID: <200705041831.l44IVY80002234@sheep.berlios.de> Author: korli Date: 2007-05-04 20:31:33 +0200 (Fri, 04 May 2007) New Revision: 21023 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21023&view=rev Modified: haiku/trunk/build/jam/HaikuImage Log: avoids building libGL.so for ppc Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2007-05-04 17:00:07 UTC (rev 21022) +++ haiku/trunk/build/jam/HaikuImage 2007-05-04 18:31:33 UTC (rev 21023) @@ -53,7 +53,7 @@ Time VirtualMemory ; BEOS_DEMOS = BitmapDrawing Chart Clock FontDemo $(X86_ONLY)GLTeapot PictureTest - Playground Mandelbrot GLDirectMode + Playground Mandelbrot $(X86_ONLY)GLDirectMode ; BEOS_SYSTEM_LIB = libbe.so $(HAIKU_LIBSTDC++) libmedia.so libtracker.so libtranslation.so libnetwork.so libdebug.so libbsd.so libmail.so From hugosantos at mail.berlios.de Fri May 4 20:43:45 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Fri, 4 May 2007 20:43:45 +0200 Subject: [Haiku-commits] r21024 - haiku/trunk/src/add-ons/kernel/network/protocols/tcp Message-ID: <200705041843.l44Ihjug003278@sheep.berlios.de> Author: hugosantos Date: 2007-05-04 20:43:30 +0200 (Fri, 04 May 2007) New Revision: 21024 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21024&view=rev Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h Log: fixed a race condition in TCP's WaitList Wait/Signal that was preventing Connect() from awake when it should. Reported by Francois Revol. Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp 2007-05-04 18:31:33 UTC (rev 21023) +++ haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp 2007-05-04 18:43:30 UTC (rev 21024) @@ -171,6 +171,7 @@ WaitList::WaitList(const char *name) { + fCondition = 0; fSem = create_sem(0, name); } @@ -192,11 +193,17 @@ WaitList::Wait(RecursiveLocker &locker, bigtime_t timeout, bool wakeNext) { locker.Unlock(); - status_t status = acquire_sem_etc(fSem, 1, B_ABSOLUTE_TIMEOUT - | B_CAN_INTERRUPT, timeout); + + status_t status = B_OK; + + while (status == B_OK && !atomic_test_and_set(&fCondition, 0, 1)) + status = acquire_sem_etc(fSem, 1, B_ABSOLUTE_TIMEOUT | B_CAN_INTERRUPT, + timeout); + locker.Lock(); - if (wakeNext && status == B_OK) + if (status == B_OK && wakeNext) Signal(); + return status; } @@ -204,8 +211,8 @@ void WaitList::Signal() { - release_sem_etc(fSem, 1, B_DO_NOT_RESCHEDULE - | B_RELEASE_IF_WAITING_ONLY); + atomic_or(&fCondition, 1); + release_sem_etc(fSem, 1, B_DO_NOT_RESCHEDULE | B_RELEASE_IF_WAITING_ONLY); } @@ -418,7 +425,8 @@ } status = _WaitForEstablished(locker, absolute_timeout(timeout)); - TRACE(" Connect(): Connection complete: %s", strerror(status)); + TRACE(" Connect(): Connection complete: %s (timeout was %llu)", + strerror(status), timeout); return posix_error(status); } Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h 2007-05-04 18:31:33 UTC (rev 21023) +++ haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h 2007-05-04 18:43:30 UTC (rev 21024) @@ -36,6 +36,7 @@ void Signal(); private: + int32 fCondition; sem_id fSem; }; From bonefish at cs.tu-berlin.de Fri May 4 20:50:28 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Fri, 04 May 2007 20:50:28 +0200 Subject: [Haiku-commits] r21020 - in haiku/trunk: headers/private/storage src/kits/storage In-Reply-To: <200705041602.l44G24b0005021@sheep.berlios.de> References: <200705041602.l44G24b0005021@sheep.berlios.de> Message-ID: <20070504205028.1478.6@cs.tu-berlin.de> On 2007-05-04 at 18:02:04 [+0200], axeld at BerliOS wrote: > Author: axeld > Date: 2007-05-04 18:02:04 +0200 (Fri, 04 May 2007) > New Revision: 21020 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21020&view=rev > > Added: > haiku/trunk/headers/private/storage/PathMonitor.h > haiku/trunk/src/kits/storage/PathMonitor.cpp > Log: > * Implemented PathMonitor class - untested, but compiles. > * The API is just a proposal at this time, please comment. At any rate I'd align it with the other watching service APIs and provide the usual StartWatching()/StopWatching() methods. The SetTarget() method is superfluous, IMHO. ATM, the Be API features three flavors of watching service APIs: 1. BClipboard/BRoster(/BDiskDeviceRoster): One can register/unregister any number of watchers and the deletion of the object doesn't unregister them. 2. BMimeType: Start/StopWatching() are static. So the effect is pretty similar to 1. 3. BVolumeRoster: There's only one watcher max per object. Deletion of the object unregisters the watcher. Your proposal would fall into category 3. However, if it is a common case that more than one path is watched, style 1. or 2. might be better, though, since it seems quite unhandy to keep several objects around, just because one wants to watch more than one path. On the other hand, there'd be little value added by the object then. So one would probably go with 2. and make the class not instantiable, or just turn it into a namespace. So much for favoring a class over functions ... ;-) CU, Ingo From axeld at pinc-software.de Fri May 4 21:27:45 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Fri, 04 May 2007 21:27:45 +0200 CEST Subject: [Haiku-commits] r21021 - in haiku/trunk: headers/os/storage src/kits/storage In-Reply-To: <20070504200218.1429.4@cs.tu-berlin.de> Message-ID: <46863103586-BeMail@zon> Ingo Weinhold wrote: > > Log: > > Added virtual desctructor to calm down GCC 4. > Er, binary compatibility? Oh, I thought the destructor would actually be generated automatically when it was missing - I was worried, but accidently only checked sizeof(BStatable) :-) So we either need to do what Hugo suggests (ifdefs), or remove a virtual slot. Too bad :/ Bye, Axel. From jackburton at mail.berlios.de Fri May 4 22:52:30 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Fri, 4 May 2007 22:52:30 +0200 Subject: [Haiku-commits] r21025 - haiku/trunk/src/kits/opengl Message-ID: <200705042052.l44KqU1Y013675@sheep.berlios.de> Author: jackburton Date: 2007-05-04 22:52:30 +0200 (Fri, 04 May 2007) New Revision: 21025 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21025&view=rev Modified: haiku/trunk/src/kits/opengl/GLView.cpp Log: use the already available BLocker instead of atomic_add and a semaphore Modified: haiku/trunk/src/kits/opengl/GLView.cpp =================================================================== --- haiku/trunk/src/kits/opengl/GLView.cpp 2007-05-04 18:43:30 UTC (rev 21024) +++ haiku/trunk/src/kits/opengl/GLView.cpp 2007-05-04 20:52:30 UTC (rev 21025) @@ -45,9 +45,7 @@ direct_buffer_info *direct_info; bool direct_connected; bool enable_direct_mode; - sem_id draw_sem; - int32 draw_lock; - + glview_direct_info(); ~glview_direct_info(); }; @@ -374,10 +372,7 @@ if (!info || !info->enable_direct_mode) return; - if (atomic_add(&info->draw_lock, 1) > 0) { - while (acquire_sem(info->draw_sem) == B_INTERRUPTED) - ; - } + m_drawLock.Lock(); } @@ -389,8 +384,7 @@ if (!info || !info->enable_direct_mode) return; - if (atomic_add(&info->draw_lock, -1) > 1) - release_sem(info->draw_sem); + m_drawLock.Unlock(); } @@ -551,14 +545,11 @@ direct_info = (direct_buffer_info *)calloc(1, B_PAGE_SIZE); direct_connected = false; enable_direct_mode = false; - draw_sem = create_sem(0, "glview_draw_sem"); - draw_lock = 0; } glview_direct_info::~glview_direct_info() { free(direct_info); - delete_sem(draw_sem); } From hugosantos at mail.berlios.de Sat May 5 02:47:39 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Sat, 5 May 2007 02:47:39 +0200 Subject: [Haiku-commits] r21026 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/dev/pci compat/net compat/sys Message-ID: <200705050047.l450ldj3017990@sheep.berlios.de> Author: hugosantos Date: 2007-05-05 02:47:20 +0200 (Sat, 05 May 2007) New Revision: 21026 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21026&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcireg.h haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcivar.h haiku/trunk/src/libs/compat/freebsd_network/compat/net/if.h haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_var.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kernel.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mutex.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/param.h haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/if.c haiku/trunk/src/libs/compat/freebsd_network/mbuf.c Log: freebsd compat. layer: a few more methods, preparing for pcnet Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcireg.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcireg.h 2007-05-04 20:52:30 UTC (rev 21025) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcireg.h 2007-05-05 00:47:20 UTC (rev 21026) @@ -11,4 +11,7 @@ #define PCIM_CMD_MEMEN 0x0002 #define PCIM_CMD_MWRICEN 0x0010 +#define PCIR_BARS 0x10 +#define PCIR_BAR(x) (PCIR_BARS + (x) * 4) + #endif Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcivar.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcivar.h 2007-05-04 20:52:30 UTC (rev 21025) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcivar.h 2007-05-05 00:47:20 UTC (rev 21026) @@ -4,6 +4,7 @@ #include int pci_enable_busmaster(device_t dev); +int pci_enable_io(device_t dev, int reg); uint32_t pci_get_devid(device_t dev); void pci_set_intpin(device_t dev, uint8_t pin); Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/net/if.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/net/if.h 2007-05-04 20:52:30 UTC (rev 21025) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/net/if.h 2007-05-05 00:47:20 UTC (rev 21026) @@ -28,6 +28,14 @@ #define IFF_LINK0 0x40000 +#define LINK_STATE_UNKNOWN 0 +#define LINK_STATE_DOWN 1 +#define LINK_STATE_UP 2 + + +#define IFQ_MAXLEN 50 + + struct ifmediareq { char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */ int ifm_current; /* current media options */ Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_var.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_var.h 2007-05-04 20:52:30 UTC (rev 21025) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_var.h 2007-05-05 00:47:20 UTC (rev 21026) @@ -86,6 +86,8 @@ #include +#include /* for sockaddr_dl */ + TAILQ_HEAD(ifnethead, ifnet); /* we use TAILQs so that the order of */ TAILQ_HEAD(ifaddrhead, ifaddr); /* instantiation is preserved in the list */ TAILQ_HEAD(ifprefixhead, ifprefix); @@ -180,6 +182,9 @@ struct task if_starttask; /* task for IFF_NEEDSGIANT */ struct task if_linktask; /* task for link change events */ struct mtx if_addr_mtx; /* mutex to protect address lists */ + + /* Haiku additions */ + struct sockaddr_dl if_lladdr; }; typedef void if_init_f_t(void *); @@ -657,8 +662,7 @@ void if_register_com_alloc(u_char type, if_com_alloc_t *a, if_com_free_t *f); void if_deregister_com_alloc(u_char type); -#define IF_LLADDR(ifp) \ - LLADDR((struct sockaddr_dl *) ifaddr_byindex((ifp)->if_index)->ifa_addr) +#define IF_LLADDR(ifp) LLADDR(&ifp->if_lladdr) #ifdef DEVICE_POLLING enum poll_cmd { POLL_ONLY, POLL_AND_CHECK_STATUS }; Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-04 20:52:30 UTC (rev 21025) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-05 00:47:20 UTC (rev 21026) @@ -87,6 +87,20 @@ } +#define BUS_SPACE_BARRIER_READ 1 +#define BUS_SPACE_BARRIER_WRITE 2 + +static inline void +bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset, bus_size_t len, int flags) +{ + if (flags & BUS_SPACE_BARRIER_READ) + __asm__ __volatile__ ("lock; addl $0,0(%%esp)" : : : "memory"); + else + __asm__ __volatile__ ("" : : : "memory"); +} + + enum intr_type { INTR_TYPE_NET = 4, INTR_MPSAFE = 512, Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-04 20:52:30 UTC (rev 21025) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-05 00:47:20 UTC (rev 21026) @@ -15,6 +15,12 @@ typedef int (*device_method_signature_t)(device_t dev); +typedef int device_probe_t(device_t dev); +typedef int device_attach_t(device_t dev); +typedef int device_detach_t(device_t dev); +typedef int device_resume_t(device_t dev); +typedef int device_suspend_t(device_t dev); + struct device_method { const char *name; device_method_signature_t method; @@ -22,7 +28,7 @@ typedef struct device_method device_method_t; -#define DEVMETHOD(name, func) { #name, (device_method_signature_t)func } +#define DEVMETHOD(name, func) { #name, (device_method_signature_t)&func } typedef struct { const char *name; @@ -30,6 +36,7 @@ size_t size; } driver_t; +#define BUS_PROBE_LOW_PRIORITY 10 #define BUS_PROBE_DEFAULT 20 #define DRIVER_MODULE_NAME(name, busname) \ @@ -39,15 +46,18 @@ status_t _fbsd_init_driver(driver_t *); void _fbsd_uninit_driver(driver_t *); +extern const char gDriverName[]; + /* we define the driver methods with HAIKU_FBSD_DRIVER_GLUE to * force the rest of the stuff to be linked back with the driver. * While gcc 2.95 packs everything from the static library onto * the final binary, gcc 4.x rightfuly doesn't. */ -#define HAIKU_FBSD_DRIVER_GLUE(name, busname) \ +#define HAIKU_FBSD_DRIVER_GLUE(publicname, name, busname) \ extern char *gDevNameList[]; \ extern device_hooks gDeviceHooks; \ extern driver_t *DRIVER_MODULE_NAME(name, busname); \ + const char gDriverName[] = #publicname; \ int32 api_version = B_CUR_DRIVER_API_VERSION; \ status_t init_hardware() \ { \ @@ -64,6 +74,9 @@ const char **publish_devices() { return (const char **)gDevNameList; } \ device_hooks *find_device(const char *name) { return &gDeviceHooks; } +#define DEFINE_CLASS_0(name, driver, methods, size) \ + driver_t driver = { #name, methods, size } + #define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) \ driver_t *DRIVER_MODULE_NAME(name, busname) = &(driver) Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kernel.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kernel.h 2007-05-04 20:52:30 UTC (rev 21025) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kernel.h 2007-05-05 00:47:20 UTC (rev 21026) @@ -28,7 +28,8 @@ #define SYSINIT(uniquifier, subsystem, order, func, ident) \ struct __system_init __init_##uniquifier = { func } -#define __printflike(a, b) __attribute__ ((format (__printf__, a, b))) +#define __packed __attribute__ ((packed)) +#define __printflike(a, b) __attribute__ ((format (__printf__, a, b))) int printf(const char *format, ...) __printflike(1, 2); Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h 2007-05-04 20:52:30 UTC (rev 21025) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h 2007-05-05 00:47:20 UTC (rev 21026) @@ -7,6 +7,8 @@ #define MLEN ((int)(MSIZE - sizeof(struct m_hdr))) #define MHLEN ((int)(MSIZE - sizeof(struct pkthdr))) +#define MINCLSIZE (MHLEN + 1) + #ifdef _KERNEL struct m_hdr { @@ -82,6 +84,10 @@ #define CSUM_PSEUDO_HDR 0x0800 #define CSUM_DELAY_DATA (CSUM_TCP | CSUM_UDP) +#define MGET(m, how, type) ((m) = m_get((how), (type))) +#define MGETHDR(m, how, type) ((m) = m_gethdr((how), (type))) +#define MCLGET(m, how) m_clget((m), (how)) + struct mbuf *m_getcl(int how, short type, int flags); void m_freem(struct mbuf *mbuf); struct mbuf *m_free(struct mbuf *m); @@ -94,6 +100,7 @@ struct mbuf *m_get(int how, short type); struct mbuf *m_gethdr(int how, short type); +void m_clget(struct mbuf *m, int how); #define mtod(m, type) (type)((m)->m_data) Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mutex.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mutex.h 2007-05-04 20:52:30 UTC (rev 21025) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mutex.h 2007-05-05 00:47:20 UTC (rev 21026) @@ -43,6 +43,13 @@ } +static inline int mtx_initialized(struct mtx *mtx) +{ + /* XXX */ + return 1; +} + + void mtx_init(struct mtx *m, const char *name, const char *type, int opts); void mtx_destroy(struct mtx *m); Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/param.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/param.h 2007-05-04 20:52:30 UTC (rev 21025) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/param.h 2007-05-05 00:47:20 UTC (rev 21026) @@ -30,4 +30,7 @@ #define MCLBYTES (1 << MCLSHIFT) +#define ALIGN_BYTES (sizeof(int) - 1) +#define ALIGN(x) ((((unsigned)x) + ALIGN_BYTES) & ~ALIGN_BYTES) + #endif Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-04 20:52:30 UTC (rev 21025) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-05 00:47:20 UTC (rev 21026) @@ -14,6 +14,7 @@ #include +#include #include #include @@ -92,6 +93,34 @@ int +pci_enable_io(device_t dev, int space) +{ + /* adapted from FreeBSD's pci_enable_io_method */ + uint16_t command; + int bit = 0; + + switch (space) { + case SYS_RES_IOPORT: + bit = PCI_command_io; + break; + case SYS_RES_MEMORY: + bit = PCI_command_memory; + break; + default: + return EINVAL; + } + + pci_set_command_bit(dev, bit); + if (pci_read_config(dev, PCI_command, 2) & bit) + return 0; + + device_printf(dev, "pci_enable_io(%d) failed.\n", space); + + return ENXIO; +} + + +int device_printf(device_t dev, const char *format, ...) { char buf[256]; @@ -100,7 +129,7 @@ vsnprintf(buf, sizeof(buf), format, vl); va_end(vl); - dprintf("[...] %s", buf); + dprintf("[%s...] %s", gDriverName, buf); return 0; } @@ -165,6 +194,21 @@ } +int +ffs(int value) +{ + int i = 1; + + if (value == 0) + return 0; + + for (; !(value & 1); i++) + value >>= 1; + + return i; +} + + int resource_int_value(const char *name, int unit, const char *resname, int *result) { Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-04 20:52:30 UTC (rev 21025) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-05 00:47:20 UTC (rev 21026) @@ -122,13 +122,18 @@ pci_info info; int i; + dprintf("%s: init_hardware(%p)\n", gDriverName, driver); + + if (get_module(B_PCI_MODULE_NAME, (module_info **)&gPci) < B_OK) + return B_ERROR; + for (i = 0; probe == NULL && driver->methods[i].name != NULL; i++) { if (strcmp(driver->methods[i].name, "device_probe") == 0) probe = driver->methods[i].method; } if (probe == NULL) { - dprintf("_fbsd_init_hardware: driver has no device_probe method.\n"); + dprintf("%s: driver has no device_probe method.\n", gDriverName); return B_ERROR; } @@ -136,10 +141,17 @@ fakeDevice.pciInfo = &info; for (i = 0; gPci->get_nth_pci_info(i, &info) == B_OK; i++) { - if (probe(&fakeDevice) >= 0) + if (probe(&fakeDevice) >= 0) { + dprintf("%s, found %s at %i\n", gDriverName, + fakeDevice.description, i); + put_module(B_PCI_MODULE_NAME); return B_OK; + } } + dprintf("%s: no hardware found.\n", gDriverName); + put_module(B_PCI_MODULE_NAME); + return B_ERROR; } @@ -147,6 +159,8 @@ status_t _fbsd_init_driver(driver_t *driver) { + dprintf("%s: init_driver(%p)\n", gDriverName, driver); + return B_ERROR; } @@ -154,4 +168,5 @@ void _fbsd_uninit_driver(driver_t *driver) { + dprintf("%s: uninit_driver(%p)\n", gDriverName, driver); } Modified: haiku/trunk/src/libs/compat/freebsd_network/if.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-04 20:52:30 UTC (rev 21025) +++ haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-05 00:47:20 UTC (rev 21026) @@ -86,6 +86,33 @@ int +if_printf(struct ifnet *ifp, const char *format, ...) +{ + char buf[256]; + va_list vl; + va_start(vl, format); + vsnprintf(buf, sizeof(buf), format, vl); + va_end(vl); + + dprintf("[%s] %s", ifp->if_xname, buf); + return 0; +} + + +void +if_link_state_change(struct ifnet *ifp, int link_state) +{ + if (ifp->if_link_state == link_state) + return; + + ifp->if_link_state = link_state; + + /* XXX */ + /* wake network stack's link state sem */ +} + + +int ether_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct rtentry *rt0) { @@ -116,6 +143,9 @@ ifp->if_input = ether_input; ifp->if_resolvemulti = NULL; /* done in the stack */ + ifp->if_lladdr.sdl_family = AF_LINK; + memcpy(IF_LLADDR(ifp), mac_address, ETHER_ADDR_LEN); + ifp->if_init(ifp->if_softc); } @@ -127,6 +157,80 @@ } +#if 0 +/* + * This is for reference. We have a table-driven version + * of the little-endian crc32 generator, which is faster + * than the double-loop. + */ +uint32_t +ether_crc32_le(const uint8_t *buf, size_t len) +{ + size_t i; + uint32_t crc; + int bit; + uint8_t data; + + crc = 0xffffffff; /* initial value */ + + for (i = 0; i < len; i++) { + for (data = *buf++, bit = 0; bit < 8; bit++, data >>= 1) + carry = (crc ^ data) & 1; + crc >>= 1; + if (carry) + crc = (crc ^ ETHER_CRC_POLY_LE); + } + + return (crc); +} +#else +uint32_t +ether_crc32_le(const uint8_t *buf, size_t len) +{ + static const uint32_t crctab[] = { + 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, + 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, + 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, + 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c + }; + size_t i; + uint32_t crc; + + crc = 0xffffffff; /* initial value */ + + for (i = 0; i < len; i++) { + crc ^= buf[i]; + crc = (crc >> 4) ^ crctab[crc & 0xf]; + crc = (crc >> 4) ^ crctab[crc & 0xf]; + } + + return (crc); +} +#endif + +uint32_t +ether_crc32_be(const uint8_t *buf, size_t len) +{ + size_t i; + uint32_t crc, carry; + int bit; + uint8_t data; + + crc = 0xffffffff; /* initial value */ + + for (i = 0; i < len; i++) { + for (data = *buf++, bit = 0; bit < 8; bit++, data >>= 1) { + carry = ((crc & 0x80000000) ? 1 : 0) ^ (data & 0x01); + crc <<= 1; + if (carry) + crc = (crc ^ ETHER_CRC_POLY_BE) | carry; + } + } + + return (crc); +} + + int ether_ioctl(struct ifnet *ifp, int command, caddr_t data) { Modified: haiku/trunk/src/libs/compat/freebsd_network/mbuf.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/mbuf.c 2007-05-04 20:52:30 UTC (rev 21025) +++ haiku/trunk/src/libs/compat/freebsd_network/mbuf.c 2007-05-05 00:47:20 UTC (rev 21026) @@ -147,6 +147,15 @@ void +m_clget(struct mbuf *m, int how) +{ + m->m_ext.ext_buf = NULL; + /* called checks for errors by looking for M_EXT */ + construct_ext_mbuf(m, how); +} + + +void m_freem(struct mbuf *mb) { while (mb) From hugosantos at mail.berlios.de Sat May 5 02:47:54 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Sat, 5 May 2007 02:47:54 +0200 Subject: [Haiku-commits] r21027 - in haiku/trunk/src/add-ons/kernel/drivers/network: . pcnet pcnet/dev pcnet/dev/le Message-ID: <200705050047.l450lsZH018021@sheep.berlios.de> Author: hugosantos Date: 2007-05-05 02:47:39 +0200 (Sat, 05 May 2007) New Revision: 21027 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21027&view=rev Added: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am7990.c haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am79900.c haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am79900reg.h haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am79900var.h haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am7990reg.h haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am7990var.h haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/if_le_ledma.c haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/if_le_pci.c haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/lance.c haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/lancereg.h haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/lancevar.h Modified: haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile Log: Added FreeBSD 6.2's PCNET driver (original source, no modifications). It's what i'm using to develop and test the compat. layer right now, since it's one of the possibly devices VMWare emulates. although probe() already works, there's still a lot of work ahead. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile 2007-05-05 00:47:20 UTC (rev 21026) +++ haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile 2007-05-05 00:47:39 UTC (rev 21027) @@ -12,7 +12,9 @@ SubInclude HAIKU_TOP src add-ons kernel drivers network vlance ; SubInclude HAIKU_TOP src add-ons kernel drivers network wb840 ; +# FreeBSD 6.2 drivers SubInclude HAIKU_TOP src add-ons kernel drivers network ipro100 ; +SubInclude HAIKU_TOP src add-ons kernel drivers network pcnet ; SubIncludeGPL HAIKU_TOP src add-ons kernel drivers network bcm440x ; SubIncludeGPL HAIKU_TOP src add-ons kernel drivers network bcm570x ; Added: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/Jamfile 2007-05-05 00:47:20 UTC (rev 21026) +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/Jamfile 2007-05-05 00:47:39 UTC (rev 21027) @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network pcnet ; + +SubInclude HAIKU_TOP src add-ons kernel drivers network pcnet dev ; Added: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/Jamfile 2007-05-05 00:47:20 UTC (rev 21026) +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/Jamfile 2007-05-05 00:47:39 UTC (rev 21027) @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network pcnet dev ; + +SubInclude HAIKU_TOP src add-ons kernel drivers network pcnet dev le ; Added: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/Jamfile 2007-05-05 00:47:20 UTC (rev 21026) +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/Jamfile 2007-05-05 00:47:39 UTC (rev 21027) @@ -0,0 +1,20 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network pcnet dev le ; + +SubDirCcFlags -Wall ; + +UsePrivateHeaders kernel net ; + +UseHeaders [ FDirName $(SUBDIR) .. .. ] : true ; +UseHeaders [ FDirName $(HAIKU_TOP) src libs compat freebsd_network compat ] : true ; + +SubDirCcFlags [ FDefines _KERNEL=1 ] ; + +KernelAddon pcnet : + am7990.c + am79900.c + if_le_pci.c + lance.c + glue.c + : libfreebsd_network.a + ; + Added: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am7990.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am7990.c 2007-05-05 00:47:20 UTC (rev 21026) +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am7990.c 2007-05-05 00:47:39 UTC (rev 21027) @@ -0,0 +1,627 @@ +/* $NetBSD: am7990.c,v 1.68 2005/12/11 12:21:25 christos Exp $ */ + +/*- + * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace + * Simulation Facility, NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Ralph Campbell and Rick Macklem. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)if_le.c 8.2 (Berkeley) 11/16/93 + */ + +#include +__FBSDID("$FreeBSD: src/sys/dev/le/am7990.c,v 1.1.2.3 2006/06/18 15:43:18 marius Exp $"); + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +static void am7990_meminit(struct lance_softc *); +static void am7990_rint(struct lance_softc *); +static void am7990_tint(struct lance_softc *); +static void am7990_start_locked(struct lance_softc *sc); + +#ifdef LEDEBUG +static void am7990_recv_print(struct lance_softc *, int); +static void am7990_xmit_print(struct lance_softc *, int); +#endif + +int +am7990_config(struct am7990_softc *sc, const char* name, int unit) +{ + int error, mem; + + sc->lsc.sc_meminit = am7990_meminit; + sc->lsc.sc_start_locked = am7990_start_locked; + + error = lance_config(&sc->lsc, name, unit); + if (error != 0) + return (error); + + mem = 0; + sc->lsc.sc_initaddr = mem; + mem += sizeof(struct leinit); + sc->lsc.sc_rmdaddr = mem; + mem += sizeof(struct lermd) * sc->lsc.sc_nrbuf; + sc->lsc.sc_tmdaddr = mem; + mem += sizeof(struct letmd) * sc->lsc.sc_ntbuf; + sc->lsc.sc_rbufaddr = mem; + mem += LEBLEN * sc->lsc.sc_nrbuf; + sc->lsc.sc_tbufaddr = mem; + mem += LEBLEN * sc->lsc.sc_ntbuf; + + if (mem > sc->lsc.sc_memsize) + panic("%s: memsize", __func__); + + lance_attach(&sc->lsc); + + return (0); +} + +void +am7990_detach(struct am7990_softc *sc) +{ + + lance_detach(&sc->lsc); +} + +/* + * Set up the initialization block and the descriptor rings. + */ +static void +am7990_meminit(struct lance_softc *sc) +{ + struct ifnet *ifp = sc->sc_ifp; + struct leinit init; + struct lermd rmd; + struct letmd tmd; + u_long a; + int bix; + + LE_LOCK_ASSERT(sc, MA_OWNED); + + if (ifp->if_flags & IFF_PROMISC) + init.init_mode = LE_MODE_NORMAL | LE_MODE_PROM; + else + init.init_mode = LE_MODE_NORMAL; + + init.init_padr[0] = (sc->sc_enaddr[1] << 8) | sc->sc_enaddr[0]; + init.init_padr[1] = (sc->sc_enaddr[3] << 8) | sc->sc_enaddr[2]; + init.init_padr[2] = (sc->sc_enaddr[5] << 8) | sc->sc_enaddr[4]; + lance_setladrf(sc, init.init_ladrf); + + sc->sc_last_rd = 0; + sc->sc_first_td = sc->sc_last_td = sc->sc_no_td = 0; + + a = sc->sc_addr + LE_RMDADDR(sc, 0); + init.init_rdra = a; + init.init_rlen = (a >> 16) | ((ffs(sc->sc_nrbuf) - 1) << 13); + + a = sc->sc_addr + LE_TMDADDR(sc, 0); + init.init_tdra = a; + init.init_tlen = (a >> 16) | ((ffs(sc->sc_ntbuf) - 1) << 13); + + (*sc->sc_copytodesc)(sc, &init, LE_INITADDR(sc), sizeof(init)); + + /* + * Set up receive ring descriptors. + */ + for (bix = 0; bix < sc->sc_nrbuf; bix++) { + a = sc->sc_addr + LE_RBUFADDR(sc, bix); + rmd.rmd0 = a; + rmd.rmd1_hadr = a >> 16; + rmd.rmd1_bits = LE_R1_OWN; + rmd.rmd2 = -LEBLEN | LE_XMD2_ONES; + rmd.rmd3 = 0; + (*sc->sc_copytodesc)(sc, &rmd, LE_RMDADDR(sc, bix), + sizeof(rmd)); + } + + /* + * Set up transmit ring descriptors. + */ + for (bix = 0; bix < sc->sc_ntbuf; bix++) { + a = sc->sc_addr + LE_TBUFADDR(sc, bix); + tmd.tmd0 = a; + tmd.tmd1_hadr = a >> 16; + tmd.tmd1_bits = 0; + tmd.tmd2 = LE_XMD2_ONES; + tmd.tmd3 = 0; + (*sc->sc_copytodesc)(sc, &tmd, LE_TMDADDR(sc, bix), + sizeof(tmd)); + } +} + +static void +am7990_rint(struct lance_softc *sc) +{ + struct ifnet *ifp = sc->sc_ifp; + struct mbuf *m; + struct lermd rmd; + int bix, rp; +#if defined(LANCE_REVC_BUG) + struct ether_header *eh; + /* Make sure this is short-aligned, for ether_cmp(). */ + static uint16_t bcast_enaddr[3] = { ~0, ~0, ~0 }; +#endif + + bix = sc->sc_last_rd; + + /* Process all buffers with valid data. */ + for (;;) { + rp = LE_RMDADDR(sc, bix); + (*sc->sc_copyfromdesc)(sc, &rmd, rp, sizeof(rmd)); + + if (rmd.rmd1_bits & LE_R1_OWN) + break; + + m = NULL; + if ((rmd.rmd1_bits & (LE_R1_ERR | LE_R1_STP | LE_R1_ENP)) != + (LE_R1_STP | LE_R1_ENP)) { + if (rmd.rmd1_bits & LE_R1_ERR) { +#ifdef LEDEBUG + if (rmd.rmd1_bits & LE_R1_ENP) { + if ((rmd.rmd1_bits & LE_R1_OFLO) == 0) { + if (rmd.rmd1_bits & LE_R1_FRAM) + if_printf(ifp, + "framing error\n"); + if (rmd.rmd1_bits & LE_R1_CRC) + if_printf(ifp, + "crc mismatch\n"); + } + } else + if (rmd.rmd1_bits & LE_R1_OFLO) + if_printf(ifp, "overflow\n"); +#endif + if (rmd.rmd1_bits & LE_R1_BUFF) + if_printf(ifp, + "receive buffer error\n"); + } else if ((rmd.rmd1_bits & (LE_R1_STP | LE_R1_ENP)) != + (LE_R1_STP | LE_R1_ENP)) + if_printf(ifp, "dropping chained buffer\n"); + } else { +#ifdef LEDEBUG + if (sc->sc_flags & LE_DEBUG) + am7990_recv_print(sc, bix); +#endif + /* Pull the packet off the interface. */ + m = lance_get(sc, LE_RBUFADDR(sc, bix), + (int)rmd.rmd3 - ETHER_CRC_LEN); + } + + rmd.rmd1_bits = LE_R1_OWN; + rmd.rmd2 = -LEBLEN | LE_XMD2_ONES; + rmd.rmd3 = 0; + (*sc->sc_copytodesc)(sc, &rmd, rp, sizeof(rmd)); + + if (++bix == sc->sc_nrbuf) + bix = 0; + + if (m != NULL) { + ifp->if_ipackets++; + +#ifdef LANCE_REVC_BUG + /* + * The old LANCE (Rev. C) chips have a bug which + * causes garbage to be inserted in front of the + * received packet. The workaround is to ignore + * packets with an invalid destination address + * (garbage will usually not match). + * Of course, this precludes multicast support... + */ + eh = mtod(m, struct ether_header *); + if (ether_cmp(eh->ether_dhost, sc->sc_enaddr) && + ether_cmp(eh->ether_dhost, bcast_enaddr)) { + m_freem(m); + continue; + } +#endif + + /* Pass the packet up. */ + LE_UNLOCK(sc); + (*ifp->if_input)(ifp, m); + LE_LOCK(sc); + } else + ifp->if_ierrors++; + } + + sc->sc_last_rd = bix; +} + +static void +am7990_tint(struct lance_softc *sc) +{ + struct ifnet *ifp = sc->sc_ifp; + struct letmd tmd; + int bix; + + bix = sc->sc_first_td; + + for (;;) { + if (sc->sc_no_td <= 0) + break; + + (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, bix), + sizeof(tmd)); + +#ifdef LEDEBUG + if (sc->sc_flags & LE_DEBUG) + if_printf(ifp, "trans tmd: " + "ladr %04x, hadr %02x, flags %02x, " + "bcnt %04x, mcnt %04x\n", + tmd.tmd0, tmd.tmd1_hadr, tmd.tmd1_bits, + tmd.tmd2, tmd.tmd3); +#endif + + if (tmd.tmd1_bits & LE_T1_OWN) + break; + + ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; + + if (tmd.tmd1_bits & LE_T1_ERR) { + if (tmd.tmd3 & LE_T3_BUFF) + if_printf(ifp, "transmit buffer error\n"); + else if (tmd.tmd3 & LE_T3_UFLO) + if_printf(ifp, "underflow\n"); + if (tmd.tmd3 & (LE_T3_BUFF | LE_T3_UFLO)) { + lance_init_locked(sc); + return; + } + if (tmd.tmd3 & LE_T3_LCAR) { + if (sc->sc_flags & LE_CARRIER) + if_link_state_change(ifp, + LINK_STATE_DOWN); + sc->sc_flags &= ~LE_CARRIER; + if (sc->sc_nocarrier) + (*sc->sc_nocarrier)(sc); + else + if_printf(ifp, "lost carrier\n"); + } + if (tmd.tmd3 & LE_T3_LCOL) + ifp->if_collisions++; + if (tmd.tmd3 & LE_T3_RTRY) { +#ifdef LEDEBUG + if_printf(ifp, "excessive collisions, tdr %d\n", + tmd.tmd3 & LE_T3_TDR_MASK); +#endif + ifp->if_collisions += 16; + } + ifp->if_oerrors++; + } else { + if (tmd.tmd1_bits & LE_T1_ONE) + ifp->if_collisions++; + else if (tmd.tmd1_bits & LE_T1_MORE) + /* Real number is unknown. */ + ifp->if_collisions += 2; + ifp->if_opackets++; + } + + if (++bix == sc->sc_ntbuf) + bix = 0; + + --sc->sc_no_td; + } + + sc->sc_first_td = bix; + + ifp->if_timer = sc->sc_no_td > 0 ? 5 : 0; +} + +/* + * Controller interrupt + */ +void +am7990_intr(void *arg) +{ + struct lance_softc *sc = arg; + struct ifnet *ifp = sc->sc_ifp; + uint16_t isr; + + LE_LOCK(sc); + + if (sc->sc_hwintr && (*sc->sc_hwintr)(sc) == -1) { + ifp->if_ierrors++; + lance_init_locked(sc); + LE_UNLOCK(sc); + return; + } + + isr = (*sc->sc_rdcsr)(sc, LE_CSR0); +#if defined(LEDEBUG) && LEDEBUG > 1 + if (sc->sc_flags & LE_DEBUG) + if_printf(ifp, "%s: entering with isr=%04x\n", __func__, isr); +#endif + if ((isr & LE_C0_INTR) == 0) { + LE_UNLOCK(sc); + return; + } + + /* + * Clear interrupt source flags and turn off interrupts. If we + * don't clear these flags before processing their sources we + * could completely miss some interrupt events as the NIC can + * change these flags while we're in this handler. We turn off + * interrupts so we don't get another RX interrupt while still + * processing the previous one in ifp->if_input() with the + * driver lock dropped. + */ + (*sc->sc_wrcsr)(sc, LE_CSR0, isr & ~(LE_C0_INEA | LE_C0_TDMD | + LE_C0_STOP | LE_C0_STRT | LE_C0_INIT)); + + if (isr & LE_C0_ERR) { + if (isr & LE_C0_BABL) { +#ifdef LEDEBUG + if_printf(ifp, "babble\n"); +#endif + ifp->if_oerrors++; + } +#if 0 + if (isr & LE_C0_CERR) { + if_printf(ifp, "collision error\n"); + ifp->if_collisions++; + } +#endif + if (isr & LE_C0_MISS) { +#ifdef LEDEBUG + if_printf(ifp, "missed packet\n"); +#endif + ifp->if_ierrors++; + } + if (isr & LE_C0_MERR) { + if_printf(ifp, "memory error\n"); + lance_init_locked(sc); + LE_UNLOCK(sc); + return; + } + } + + if ((isr & LE_C0_RXON) == 0) { + if_printf(ifp, "receiver disabled\n"); + ifp->if_ierrors++; + lance_init_locked(sc); + LE_UNLOCK(sc); + return; + } + if ((isr & LE_C0_TXON) == 0) { + if_printf(ifp, "transmitter disabled\n"); + ifp->if_oerrors++; + lance_init_locked(sc); + LE_UNLOCK(sc); + return; + } + + /* + * Pretend we have carrier; if we don't this will be cleared shortly. + */ + if (!(sc->sc_flags & LE_CARRIER)) + if_link_state_change(ifp, LINK_STATE_UP); + sc->sc_flags |= LE_CARRIER; + + if (isr & LE_C0_RINT) + am7990_rint(sc); + if (isr & LE_C0_TINT) + am7990_tint(sc); + + /* Enable interrupts again. */ + (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA); + + if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) + am7990_start_locked(sc); + + LE_UNLOCK(sc); +} + +/* + * Set up output on interface. + * Get another datagram to send off of the interface queue, and map it to the + * interface before starting the output. + */ +static void +am7990_start_locked(struct lance_softc *sc) +{ + struct ifnet *ifp = sc->sc_ifp; + struct letmd tmd; + struct mbuf *m; + int bix, enq, len, rp; + + LE_LOCK_ASSERT(sc, MA_OWNED); + + if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != + IFF_DRV_RUNNING) + return; + + bix = sc->sc_last_td; + enq = 0; + + for (; sc->sc_no_td < sc->sc_ntbuf && + !IFQ_DRV_IS_EMPTY(&ifp->if_snd);) { + rp = LE_TMDADDR(sc, bix); + (*sc->sc_copyfromdesc)(sc, &tmd, rp, sizeof(tmd)); + + if (tmd.tmd1_bits & LE_T1_OWN) { + ifp->if_drv_flags |= IFF_DRV_OACTIVE; + if_printf(ifp, + "missing buffer, no_td = %d, last_td = %d\n", + sc->sc_no_td, sc->sc_last_td); + } + + IFQ_DRV_DEQUEUE(&ifp->if_snd, m); + if (m == 0) + break; + + /* + * If BPF is listening on this interface, let it see the packet + * before we commit it to the wire. + */ + BPF_MTAP(ifp, m); + + /* + * Copy the mbuf chain into the transmit buffer. + */ + len = lance_put(sc, LE_TBUFADDR(sc, bix), m); + +#ifdef LEDEBUG + if (len > ETHERMTU + ETHER_HDR_LEN) + if_printf(ifp, "packet length %d\n", len); +#endif + + /* + * Init transmit registers, and set transmit start flag. + */ + tmd.tmd1_bits = LE_T1_OWN | LE_T1_STP | LE_T1_ENP; + tmd.tmd2 = -len | LE_XMD2_ONES; + tmd.tmd3 = 0; + + (*sc->sc_copytodesc)(sc, &tmd, rp, sizeof(tmd)); + +#ifdef LEDEBUG + if (sc->sc_flags & LE_DEBUG) + am7990_xmit_print(sc, bix); +#endif + + (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_TDMD); + enq++; + + if (++bix == sc->sc_ntbuf) + bix = 0; + + if (++sc->sc_no_td == sc->sc_ntbuf) { + ifp->if_drv_flags |= IFF_DRV_OACTIVE; + break; + } + } + + sc->sc_last_td = bix; + + if (enq > 0) + ifp->if_timer = 5; +} + +#ifdef LEDEBUG +static void +am7990_recv_print(struct lance_softc *sc, int no) +{ + struct ifnet *ifp = sc->sc_ifp; + struct ether_header eh; + struct lermd rmd; + uint16_t len; + + (*sc->sc_copyfromdesc)(sc, &rmd, LE_RMDADDR(sc, no), sizeof(rmd)); + len = rmd.rmd3; + if_printf(ifp, "receive buffer %d, len = %d\n", no, len); + if_printf(ifp, "status %04x\n", (*sc->sc_rdcsr)(sc, LE_CSR0)); + if_printf(ifp, + "ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n", + rmd.rmd0, rmd.rmd1_hadr, rmd.rmd1_bits, rmd.rmd2, rmd.rmd3); + if (len - ETHER_CRC_LEN >= sizeof(eh)) { + (*sc->sc_copyfrombuf)(sc, &eh, LE_RBUFADDR(sc, no), sizeof(eh)); + if_printf(ifp, "dst %s", ether_sprintf(eh.ether_dhost)); + printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost), + ntohs(eh.ether_type)); + } +} + +static void +am7990_xmit_print(struct lance_softc *sc, int no) +{ + struct ifnet *ifp = sc->sc_ifp; + struct ether_header eh; + struct letmd tmd; + uint16_t len; + + (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, no), sizeof(tmd)); + len = -tmd.tmd2; + if_printf(ifp, "transmit buffer %d, len = %d\n", no, len); + if_printf(ifp, "status %04x\n", (*sc->sc_rdcsr)(sc, LE_CSR0)); + if_printf(ifp, + "ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n", + tmd.tmd0, tmd.tmd1_hadr, tmd.tmd1_bits, tmd.tmd2, tmd.tmd3); + if (len >= sizeof(eh)) { + (*sc->sc_copyfrombuf)(sc, &eh, LE_TBUFADDR(sc, no), sizeof(eh)); + if_printf(ifp, "dst %s", ether_sprintf(eh.ether_dhost)); + printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost), + ntohs(eh.ether_type)); + } +} +#endif /* LEDEBUG */ Added: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am79900.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am79900.c 2007-05-05 00:47:20 UTC (rev 21026) +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am79900.c 2007-05-05 00:47:39 UTC (rev 21027) @@ -0,0 +1,664 @@ +/* $NetBSD: am79900.c,v 1.17 2005/12/24 20:27:29 perry Exp $ */ + +/*- + * Copyright (c) 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Ralph Campbell and Rick Macklem. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)if_le.c 8.2 (Berkeley) 11/16/93 + */ + +/*- + * Copyright (c) 1998 + * Matthias Drochner. All rights reserved. + * Copyright (c) 1995 Charles M. Hannum. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Ralph Campbell and Rick Macklem. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)if_le.c 8.2 (Berkeley) 11/16/93 + */ + +#include +__FBSDID("$FreeBSD: src/sys/dev/le/am79900.c,v 1.1.2.3 2006/06/18 15:43:18 marius Exp $"); + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +static void am79900_meminit(struct lance_softc *); +static void am79900_rint(struct lance_softc *); +static void am79900_tint(struct lance_softc *); +static void am79900_start_locked(struct lance_softc *sc); + +#ifdef LEDEBUG +static void am79900_recv_print(struct lance_softc *, int); +static void am79900_xmit_print(struct lance_softc *, int); +#endif + +int +am79900_config(struct am79900_softc *sc, const char* name, int unit) +{ + int error, mem; + + sc->lsc.sc_meminit = am79900_meminit; + sc->lsc.sc_start_locked = am79900_start_locked; + + error = lance_config(&sc->lsc, name, unit); + if (error != 0) + return (error); + + mem = 0; + sc->lsc.sc_initaddr = mem; + mem += sizeof(struct leinit); + sc->lsc.sc_rmdaddr = mem; + mem += sizeof(struct lermd) * sc->lsc.sc_nrbuf; + sc->lsc.sc_tmdaddr = mem; + mem += sizeof(struct letmd) * sc->lsc.sc_ntbuf; + sc->lsc.sc_rbufaddr = mem; + mem += LEBLEN * sc->lsc.sc_nrbuf; + sc->lsc.sc_tbufaddr = mem; + mem += LEBLEN * sc->lsc.sc_ntbuf; + + if (mem > sc->lsc.sc_memsize) + panic("%s: memsize", __func__); + + lance_attach(&sc->lsc); + + return (0); +} + +void +am79900_detach(struct am79900_softc *sc) +{ + + lance_detach(&sc->lsc); +} + +/* + * Set up the initialization block and the descriptor rings. + */ +static void +am79900_meminit(struct lance_softc *sc) +{ + struct ifnet *ifp = sc->sc_ifp; + struct leinit init; + struct lermd rmd; + struct letmd tmd; + u_long a; + int bix; + + LE_LOCK_ASSERT(sc, MA_OWNED); + + if (ifp->if_flags & IFF_PROMISC) + init.init_mode = LE_HTOLE32(LE_MODE_NORMAL | LE_MODE_PROM); + else + init.init_mode = LE_HTOLE32(LE_MODE_NORMAL); + + init.init_mode |= LE_HTOLE32(((ffs(sc->sc_ntbuf) - 1) << 28) | + ((ffs(sc->sc_nrbuf) - 1) << 20)); + + init.init_padr[0] = LE_HTOLE32(sc->sc_enaddr[0] | + (sc->sc_enaddr[1] << 8) | (sc->sc_enaddr[2] << 16) | + (sc->sc_enaddr[3] << 24)); + init.init_padr[1] = LE_HTOLE32(sc->sc_enaddr[4] | + (sc->sc_enaddr[5] << 8)); + lance_setladrf(sc, init.init_ladrf); + + sc->sc_last_rd = 0; + sc->sc_first_td = sc->sc_last_td = sc->sc_no_td = 0; + + a = sc->sc_addr + LE_RMDADDR(sc, 0); + init.init_rdra = LE_HTOLE32(a); + + a = sc->sc_addr + LE_TMDADDR(sc, 0); + init.init_tdra = LE_HTOLE32(a); + + (*sc->sc_copytodesc)(sc, &init, LE_INITADDR(sc), sizeof(init)); + + /* + * Set up receive ring descriptors. + */ + for (bix = 0; bix < sc->sc_nrbuf; bix++) { + a = sc->sc_addr + LE_RBUFADDR(sc, bix); + rmd.rmd0 = LE_HTOLE32(a); + rmd.rmd1 = LE_HTOLE32(LE_R1_OWN | LE_R1_ONES | + (-LEBLEN & 0xfff)); + rmd.rmd2 = 0; + rmd.rmd3 = 0; + (*sc->sc_copytodesc)(sc, &rmd, LE_RMDADDR(sc, bix), + sizeof(rmd)); + } + + /* + * Set up transmit ring descriptors. + */ + for (bix = 0; bix < sc->sc_ntbuf; bix++) { + a = sc->sc_addr + LE_TBUFADDR(sc, bix); + tmd.tmd0 = LE_HTOLE32(a); + tmd.tmd1 = LE_HTOLE32(LE_T1_ONES); + tmd.tmd2 = 0; + tmd.tmd3 = 0; + (*sc->sc_copytodesc)(sc, &tmd, LE_TMDADDR(sc, bix), + sizeof(tmd)); + } +} + +static inline void +am79900_rint(struct lance_softc *sc) +{ + struct ifnet *ifp = sc->sc_ifp; + struct mbuf *m; + struct lermd rmd; + uint32_t rmd1; + int bix, rp; +#if defined(__i386__) && !defined(PC98) + struct ether_header *eh; +#endif + + bix = sc->sc_last_rd; + + /* Process all buffers with valid data. */ + for (;;) { + rp = LE_RMDADDR(sc, bix); + (*sc->sc_copyfromdesc)(sc, &rmd, rp, sizeof(rmd)); + + rmd1 = LE_LE32TOH(rmd.rmd1); + if (rmd1 & LE_R1_OWN) + break; + + m = NULL; + if ((rmd1 & (LE_R1_ERR | LE_R1_STP | LE_R1_ENP)) != + (LE_R1_STP | LE_R1_ENP)){ + if (rmd1 & LE_R1_ERR) { +#ifdef LEDEBUG + if (rmd1 & LE_R1_ENP) { + if ((rmd1 & LE_R1_OFLO) == 0) { + if (rmd1 & LE_R1_FRAM) + if_printf(ifp, + "framing error\n"); + if (rmd1 & LE_R1_CRC) + if_printf(ifp, + "crc mismatch\n"); + } + } else + if (rmd1 & LE_R1_OFLO) + if_printf(ifp, "overflow\n"); +#endif + if (rmd1 & LE_R1_BUFF) + if_printf(ifp, + "receive buffer error\n"); + } else if ((rmd1 & (LE_R1_STP | LE_R1_ENP)) != + (LE_R1_STP | LE_R1_ENP)) + if_printf(ifp, "dropping chained buffer\n"); + } else { [... truncated: 3577 lines follow ...] From hugosantos at mail.berlios.de Sat May 5 04:19:53 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Sat, 5 May 2007 04:19:53 +0200 Subject: [Haiku-commits] r21028 - haiku/trunk/src/libs/compat/freebsd_network Message-ID: <200705050219.l452Jrrp023411@sheep.berlios.de> Author: hugosantos Date: 2007-05-05 04:19:44 +0200 (Sat, 05 May 2007) New Revision: 21028 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21028&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/device.h Log: freebsd compat. layer: use m_defrag to get a contiguous mbuf when read()ing. also added write() and a partial control(). Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-05 00:47:39 UTC (rev 21027) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-05 02:19:44 UTC (rev 21028) @@ -28,16 +28,16 @@ uint32_t pci_read_config(device_t dev, int offset, int size) { - return gPci->read_pci_config(dev->pciInfo->bus, dev->pciInfo->device, - dev->pciInfo->function, offset, size); + return gPci->read_pci_config(dev->pciInfo.bus, dev->pciInfo.device, + dev->pciInfo.function, offset, size); } void pci_write_config(device_t dev, int offset, uint32_t value, int size) { - gPci->write_pci_config(dev->pciInfo->bus, dev->pciInfo->device, - dev->pciInfo->function, offset, size, value); + gPci->write_pci_config(dev->pciInfo.bus, dev->pciInfo.device, + dev->pciInfo.function, offset, size, value); } Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-05 00:47:39 UTC (rev 21027) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-05 02:19:44 UTC (rev 21028) @@ -12,10 +12,12 @@ #include #include +#include #include #include +#include #define MAX_DEVICES 8 @@ -57,16 +59,15 @@ struct mbuf *mb; size_t len; - if (atomic_or(&dev->flags, 0) & DEVICE_CLOSED) + if (dev->flags & DEVICE_CLOSED) return B_INTERRUPTED; - if (atomic_or(&dev->flags, 0) & DEVICE_NON_BLOCK) + if (dev->flags & DEVICE_NON_BLOCK) semFlags |= B_RELATIVE_TIMEOUT; - do { status = acquire_sem_etc(dev->receive_sem, 1, semFlags, 0); - if (atomic_or(&dev->flags, 0) & DEVICE_CLOSED) + if (dev->flags & DEVICE_CLOSED) return B_INTERRUPTED; if (status == B_WOULD_BLOCK) { @@ -80,7 +81,12 @@ len = min_c(max_c((size_t)mb->m_len, 0), *numBytes); - // TODO we need something that cna join various chunks + mb = m_defrag(mb, 0); + if (mb == NULL) { + *numBytes = 0; + return B_NO_MEMORY; + } + memcpy(buf, mtod(mb, const void *), len); *numBytes = len; @@ -93,14 +99,65 @@ compat_write(void *cookie, off_t position, const void *buffer, size_t *numBytes) { - return B_ERROR; + device_t dev = cookie; + struct mbuf *mb; + + mb = m_getcl(0, MT_DATA, 0); + if (mb == NULL) + return ENOBUFS; + + /* if we are waiting, check after if the ifp is still valid */ + + mb->m_len = min_c(*numBytes, (size_t)MCLBYTES); + memcpy(mtod(mb, void *), buffer, mb->m_len); + + return dev->ifp->if_output(dev->ifp, mb, NULL, NULL); } static status_t compat_control(void *cookie, uint32 op, void *arg, size_t len) { - return B_ERROR; + device_t dev = cookie; + + switch (op) { + case ETHER_INIT: + return B_OK; + + case ETHER_GETADDR: + memcpy(arg, IF_LLADDR(dev->ifp), ETHER_ADDR_LEN); + return B_OK; + + case ETHER_NONBLOCK: + if (*(int32 *)arg) + dev->flags |= DEVICE_NON_BLOCK; + else + dev->flags &= ~DEVICE_NON_BLOCK; + return B_OK; + + case ETHER_SETPROMISC: + /* TODO */ + return B_ERROR; + + case ETHER_GETFRAMESIZE: + *(uint32 *)arg = dev->ifp->if_mtu; + return B_OK; + + case ETHER_ADDMULTI: + case ETHER_REMMULTI: + /* TODO */ + return B_ERROR; + + case ETHER_GET_LINK_STATE: + /* TODO */ + return B_ERROR; + + case ETHER_SET_LINK_STATE_SEM: + /* TODO */ + return B_OK; + } + + return B_BAD_VALUE; } @@ -119,7 +176,6 @@ { device_method_signature_t probe = NULL; struct device fakeDevice; - pci_info info; int i; dprintf("%s: init_hardware(%p)\n", gDriverName, driver); @@ -138,9 +194,8 @@ } memset(&fakeDevice, 0, sizeof(struct device)); - fakeDevice.pciInfo = &info; - for (i = 0; gPci->get_nth_pci_info(i, &info) == B_OK; i++) { + for (i = 0; gPci->get_nth_pci_info(i, &fakeDevice.pciInfo) == B_OK; i++) { if (probe(&fakeDevice) >= 0) { dprintf("%s, found %s at %i\n", gDriverName, fakeDevice.description, i); Modified: haiku/trunk/src/libs/compat/freebsd_network/device.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-05 00:47:39 UTC (rev 21027) +++ haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-05 02:19:44 UTC (rev 21028) @@ -25,7 +25,7 @@ struct device { int devId; - pci_info * pciInfo; + pci_info pciInfo; int32 flags; From hugosantos at mail.berlios.de Sat May 5 05:40:17 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Sat, 5 May 2007 05:40:17 +0200 Subject: [Haiku-commits] r21029 - haiku/trunk/src/libs/compat/freebsd_network Message-ID: <200705050340.l453eHjM028216@sheep.berlios.de> Author: hugosantos Date: 2007-05-05 05:40:07 +0200 (Sat, 05 May 2007) New Revision: 21029 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21029&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/busdma_machdep.c haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/device.h haiku/trunk/src/libs/compat/freebsd_network/mbuf.c haiku/trunk/src/libs/compat/freebsd_network/mutex.c Log: freebsd compat. layer: we now init the several sub-parts through init_hardware, as well as allocate the available device_ts. Modified: haiku/trunk/src/libs/compat/freebsd_network/busdma_machdep.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/busdma_machdep.c 2007-05-05 02:19:44 UTC (rev 21028) +++ haiku/trunk/src/libs/compat/freebsd_network/busdma_machdep.c 2007-05-05 03:40:07 UTC (rev 21029) @@ -53,6 +53,8 @@ #define contigfree(a, b, c) kernel_contigfree(a, b, c) #define __unused void busdma_swi(void); +void init_bounce_pages(void); +void uninit_bounce_pages(void); /* */ struct bounce_zone; @@ -130,7 +132,6 @@ static STAILQ_HEAD(, bus_dmamap) bounce_map_callbacklist; static struct bus_dmamap nobounce_dmamap; -static void init_bounce_pages(void *dummy); static int alloc_bounce_zone(bus_dma_tag_t dmat); static int alloc_bounce_pages(bus_dma_tag_t dmat, u_int numpages); static int reserve_bounce_pages(bus_dma_tag_t dmat, bus_dmamap_t map, @@ -936,8 +937,9 @@ } } -static void -init_bounce_pages(void *dummy __unused) + +void +init_bounce_pages() { total_bpages = 0; @@ -946,8 +948,18 @@ STAILQ_INIT(&bounce_map_callbacklist); mtx_init(&bounce_lock, "bounce pages lock", NULL, MTX_DEF); } -SYSINIT(bpages, SI_SUB_LOCK, SI_ORDER_ANY, init_bounce_pages, NULL); + +/* Haiku extension */ +void +uninit_bounce_pages() +{ + /* XXX deep free */ + + mtx_destroy(&bounce_lock); +} + + static struct sysctl_ctx_list * busdma_sysctl_tree(struct bounce_zone *bz) { Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-05 02:19:44 UTC (rev 21028) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-05 03:40:07 UTC (rev 21029) @@ -28,16 +28,16 @@ uint32_t pci_read_config(device_t dev, int offset, int size) { - return gPci->read_pci_config(dev->pciInfo.bus, dev->pciInfo.device, - dev->pciInfo.function, offset, size); + return gPci->read_pci_config(dev->pci_info.bus, dev->pci_info.device, + dev->pci_info.function, offset, size); } void pci_write_config(device_t dev, int offset, uint32_t value, int size) { - gPci->write_pci_config(dev->pciInfo.bus, dev->pciInfo.device, - dev->pciInfo.function, offset, size, value); + gPci->write_pci_config(dev->pci_info.bus, dev->pci_info.device, + dev->pci_info.function, offset, size, value); } Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-05 02:19:44 UTC (rev 21028) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-05 03:40:07 UTC (rev 21029) @@ -23,12 +23,45 @@ #define MAX_DEVICES 8 +device_t gDevices[MAX_DEVICES]; char *gDevNameList[MAX_DEVICES + 1]; +static device_t +allocate_device() +{ + char semName[64]; + + device_t dev = (device_t)malloc(sizeof(struct device)); + if (dev == NULL) + return NULL; + + memset(dev, 0, sizeof(struct device)); + + snprintf(semName, sizeof(semName), "%s rcv", gDriverName); + + dev->receive_sem = create_sem(0, semName); + if (dev->receive_sem < 0) { + free(dev); + return NULL; + } + + return dev; +} + + +static void +free_device(device_t dev) +{ + delete_sem(dev->receive_sem); + free(dev); +} + + static status_t compat_open(const char *name, uint32 flags, void **cookie) { + dprintf("%s, compat_open(%s, 0x%lx)\n", gDriverName, name, flags); return B_ERROR; } @@ -37,6 +70,9 @@ compat_close(void *cookie) { device_t dev = cookie; + + dprintf("%s, compat_close(%p)\n", gDriverName, dev); + return B_ERROR; } @@ -45,7 +81,10 @@ compat_free(void *cookie) { device_t dev = cookie; - free(dev); + + dprintf("%s, compat_free(%p)\n", gDriverName, dev); + + free_device(dev); return B_ERROR; } @@ -106,7 +145,7 @@ if (mb == NULL) return ENOBUFS; - /* if we are waiting, check after if the ifp is still valid */ + /* if we waited, check after if the ifp is still valid */ mb->m_len = min_c(*numBytes, (size_t)MCLBYTES); memcpy(mtod(mb, void *), buffer, mb->m_len); @@ -171,11 +210,26 @@ }; +static device_method_signature_t +_resolve_method(driver_t *driver, const char *name) +{ + device_method_signature_t method = NULL; + int i; + + for (i = 0; method == NULL && driver->methods[i].name != NULL; i++) { + if (strcmp(driver->methods[i].name, name) == 0) + method = driver->methods[i].method; + } + + return method; +} + + status_t _fbsd_init_hardware(driver_t *driver) { - device_method_signature_t probe = NULL; struct device fakeDevice; + device_probe_t *probe; int i; dprintf("%s: init_hardware(%p)\n", gDriverName, driver); @@ -183,11 +237,7 @@ if (get_module(B_PCI_MODULE_NAME, (module_info **)&gPci) < B_OK) return B_ERROR; - for (i = 0; probe == NULL && driver->methods[i].name != NULL; i++) { - if (strcmp(driver->methods[i].name, "device_probe") == 0) - probe = driver->methods[i].method; - } - + probe = (device_probe_t *)_resolve_method(driver, "device_probe"); if (probe == NULL) { dprintf("%s: driver has no device_probe method.\n", gDriverName); return B_ERROR; @@ -195,9 +245,9 @@ memset(&fakeDevice, 0, sizeof(struct device)); - for (i = 0; gPci->get_nth_pci_info(i, &fakeDevice.pciInfo) == B_OK; i++) { + for (i = 0; gPci->get_nth_pci_info(i, &fakeDevice.pci_info) == B_OK; i++) { if (probe(&fakeDevice) >= 0) { - dprintf("%s, found %s at %i\n", gDriverName, + dprintf("%s, found %s at %d\n", gDriverName, fakeDevice.description, i); put_module(B_PCI_MODULE_NAME); return B_OK; @@ -214,14 +264,76 @@ status_t _fbsd_init_driver(driver_t *driver) { + device_probe_t *probe; + int i, ncards = 0; + status_t status; + device_t dev; + dprintf("%s: init_driver(%p)\n", gDriverName, driver); - return B_ERROR; + probe = (device_probe_t *)_resolve_method(driver, "device_probe"); + + dev = allocate_device(); + if (dev == NULL) + return B_NO_MEMORY; + + status = init_mutexes(); + if (status < B_OK) { + free_device(dev); + return status; + } + + status = init_mbufs(); + if (status < B_OK) { + uninit_mutexes(); + free_device(dev); + return status; + } + + init_bounce_pages(); + + for (i = 0; dev != NULL + && gPci->get_nth_pci_info(i, &dev->pci_info) == B_OK; i++) { + if (probe(dev) >= 0) { + snprintf(dev->dev_name, sizeof(dev->dev_name), "/dev/net/%s/%i", + gDriverName, ncards); + dprintf("%s, adding %s @%d -> %s\n", gDriverName, dev->description, + i, dev->dev_name); + + gDevices[ncards] = dev; + gDevNameList[ncards] = dev->dev_name; + + ncards++; + if (ncards < MAX_DEVICES) + dev = allocate_device(); + else + dev = NULL; + } + } + + if (dev != NULL) + free_device(dev); + + dprintf("%s, ... %d cards.\n", gDriverName, ncards); + + gDevNameList[ncards + 1] = NULL; + + return B_OK; } void _fbsd_uninit_driver(driver_t *driver) { + int i; + dprintf("%s: uninit_driver(%p)\n", gDriverName, driver); + + for (i = 0; gDevNameList[i] != NULL; i++) { + free_device(gDevices[i]); + } + + uninit_bounce_pages(); + uninit_mbufs(); + uninit_mutexes(); } Modified: haiku/trunk/src/libs/compat/freebsd_network/device.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-05 02:19:44 UTC (rev 21028) +++ haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-05 03:40:07 UTC (rev 21029) @@ -24,8 +24,8 @@ struct ifnet; struct device { - int devId; - pci_info pciInfo; + pci_info pci_info; + char dev_name[128]; int32 flags; @@ -47,6 +47,16 @@ }; +status_t init_mbufs(void); +void uninit_mbufs(void); + +status_t init_mutexes(void); +void uninit_mutexes(void); + +/* busdma_machdep.c */ +void init_bounce_pages(void); +void uninit_bounce_pages(void); + extern struct net_stack_module_info *gStack; extern pci_module_info *gPci; Modified: haiku/trunk/src/libs/compat/freebsd_network/mbuf.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/mbuf.c 2007-05-05 02:19:44 UTC (rev 21028) +++ haiku/trunk/src/libs/compat/freebsd_network/mbuf.c 2007-05-05 03:40:07 UTC (rev 21029) @@ -10,6 +10,8 @@ * `m_defrag' and friends are straight from FreeBSD 6.2. */ +#include "device.h" + #include #include #include @@ -22,10 +24,6 @@ #define MBTOM(how) (how) -status_t init_mbufs(void); -void uninit_mbufs(void); - - #define CHUNK_SIZE 2048 static object_cache *sMBufCache; Modified: haiku/trunk/src/libs/compat/freebsd_network/mutex.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/mutex.c 2007-05-05 02:19:44 UTC (rev 21028) +++ haiku/trunk/src/libs/compat/freebsd_network/mutex.c 2007-05-05 03:40:07 UTC (rev 21029) @@ -6,15 +6,11 @@ * Hugo Santos, hugosantos at gmail.com */ -#include +#include "device.h" #include -status_t init_mutexes(void); -void uninit_mutexes(void); - - // these methods are bit unfriendly, a bit too much panic() around struct mtx Giant; @@ -51,12 +47,15 @@ status_t init_mutexes() { - return B_ERROR; + mtx_init(&Giant, "Banana Giant", NULL, MTX_DEF); + + return B_OK; } void uninit_mutexes() { + mtx_destroy(&Giant); } From hugosantos at mail.berlios.de Sat May 5 06:45:32 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Sat, 5 May 2007 06:45:32 +0200 Subject: [Haiku-commits] r21030 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/net compat/sys Message-ID: <200705050445.l454jWL3027363@sheep.berlios.de> Author: hugosantos Date: 2007-05-05 06:45:01 +0200 (Sat, 05 May 2007) New Revision: 21030 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21030&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/bus.c haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_var.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/device.h haiku/trunk/src/libs/compat/freebsd_network/if.c Log: freebsd compat. layer: added open(), which calls into the driver's attach. when testing with PCNET, a interface is already presented to the stack, it is even able to obtain the MAC address from the device, but still more work to do. Modified: haiku/trunk/src/libs/compat/freebsd_network/bus.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-05 03:40:07 UTC (rev 21029) +++ haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-05 04:45:01 UTC (rev 21030) @@ -183,7 +183,7 @@ intr->handler = handler; intr->arg = arg; - intr->irq = (int)res; + intr->irq = res->handle; status = install_io_interrupt_handler(intr->irq, intr_wrapper, intr, 0); if (status < B_OK) { @@ -193,7 +193,7 @@ *cookiep = intr; - return status; + return 0; } Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_var.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_var.h 2007-05-05 03:40:07 UTC (rev 21029) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_var.h 2007-05-05 04:45:01 UTC (rev 21030) @@ -105,6 +105,8 @@ struct mtx ifq_mtx; }; +struct device; + /* * Structure defining a network interface. * @@ -185,6 +187,7 @@ /* Haiku additions */ struct sockaddr_dl if_lladdr; + struct device *if_dev; }; typedef void if_init_f_t(void *); Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-05 03:40:07 UTC (rev 21029) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-05 04:45:01 UTC (rev 21030) @@ -33,7 +33,7 @@ typedef struct { const char *name; device_method_t *methods; - size_t size; + size_t softc_size; } driver_t; #define BUS_PROBE_LOW_PRIORITY 10 Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-05 03:40:07 UTC (rev 21029) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-05 04:45:01 UTC (rev 21030) @@ -96,7 +96,6 @@ pci_enable_io(device_t dev, int space) { /* adapted from FreeBSD's pci_enable_io_method */ - uint16_t command; int bit = 0; switch (space) { @@ -144,10 +143,8 @@ const char * device_get_name(device_t dev) { - /* - * if (dev != NULL && dev->devclass) - * return devclass_get_name(dev->devclass); - */ + if (dev) + return dev->dev_name; return NULL; } Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-05 03:40:07 UTC (rev 21029) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-05 04:45:01 UTC (rev 21030) @@ -27,8 +27,13 @@ char *gDevNameList[MAX_DEVICES + 1]; +static device_probe_t *sDeviceProbe; +static device_attach_t *sDeviceAttach; +static device_detach_t *sDeviceDetach; + + static device_t -allocate_device() +allocate_device(driver_t *driver) { char semName[64]; @@ -40,8 +45,15 @@ snprintf(semName, sizeof(semName), "%s rcv", gDriverName); + dev->softc = malloc(driver->softc_size); + if (dev->softc == NULL) { + free(dev); + return NULL; + } + dev->receive_sem = create_sem(0, semName); if (dev->receive_sem < 0) { + free(dev->softc); free(dev); return NULL; } @@ -54,15 +66,55 @@ free_device(device_t dev) { delete_sem(dev->receive_sem); + free(dev->softc); free(dev); } +static device_method_signature_t +_resolve_method(driver_t *driver, const char *name) +{ + device_method_signature_t method = NULL; + int i; + + for (i = 0; method == NULL && driver->methods[i].name != NULL; i++) { + if (strcmp(driver->methods[i].name, name) == 0) + method = driver->methods[i].method; + } + + return method; +} + + static status_t compat_open(const char *name, uint32 flags, void **cookie) { + status_t status; + device_t dev; + int i; + dprintf("%s, compat_open(%s, 0x%lx)\n", gDriverName, name, flags); - return B_ERROR; + + for (i = 0; gDevNameList[i] != NULL; i++) { + if (strcmp(gDevNameList[i], name) == 0) + break; + } + + if (gDevNameList[i] == NULL) + return B_ERROR; + + dev = gDevices[i]; + + if (atomic_or(&dev->flags, DEVICE_OPEN) & DEVICE_OPEN) + return B_BUSY; + + status = sDeviceAttach(dev); + if (status != 0) + dev->flags = 0; + + *cookie = dev; + + return status; } @@ -210,21 +262,6 @@ }; -static device_method_signature_t -_resolve_method(driver_t *driver, const char *name) -{ - device_method_signature_t method = NULL; - int i; - - for (i = 0; method == NULL && driver->methods[i].name != NULL; i++) { - if (strcmp(driver->methods[i].name, name) == 0) - method = driver->methods[i].method; - } - - return method; -} - - status_t _fbsd_init_hardware(driver_t *driver) { @@ -264,16 +301,17 @@ status_t _fbsd_init_driver(driver_t *driver) { - device_probe_t *probe; int i, ncards = 0; status_t status; device_t dev; dprintf("%s: init_driver(%p)\n", gDriverName, driver); - probe = (device_probe_t *)_resolve_method(driver, "device_probe"); + sDeviceProbe = (device_probe_t *)_resolve_method(driver, "device_probe"); + sDeviceAttach = (device_attach_t *)_resolve_method(driver, "device_attach"); + sDeviceDetach = (device_detach_t *)_resolve_method(driver, "device_detach"); - dev = allocate_device(); + dev = allocate_device(driver); if (dev == NULL) return B_NO_MEMORY; @@ -294,10 +332,10 @@ for (i = 0; dev != NULL && gPci->get_nth_pci_info(i, &dev->pci_info) == B_OK; i++) { - if (probe(dev) >= 0) { - snprintf(dev->dev_name, sizeof(dev->dev_name), "/dev/net/%s/%i", + if (sDeviceProbe(dev) >= 0) { + snprintf(dev->dev_name, sizeof(dev->dev_name), "net/%s/%i", gDriverName, ncards); - dprintf("%s, adding %s @%d -> %s\n", gDriverName, dev->description, + dprintf("%s, adding %s @%d -> /dev/%s\n", gDriverName, dev->description, i, dev->dev_name); gDevices[ncards] = dev; @@ -305,7 +343,7 @@ ncards++; if (ncards < MAX_DEVICES) - dev = allocate_device(); + dev = allocate_device(driver); else dev = NULL; } Modified: haiku/trunk/src/libs/compat/freebsd_network/device.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-05 03:40:07 UTC (rev 21029) +++ haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-05 04:45:01 UTC (rev 21030) @@ -42,8 +42,9 @@ enum { - DEVICE_CLOSED = 1 << 0, - DEVICE_NON_BLOCK = 1 << 1, + DEVICE_OPEN = 1 << 0, + DEVICE_CLOSED = 1 << 1, + DEVICE_NON_BLOCK = 1 << 2, }; @@ -60,4 +61,7 @@ extern struct net_stack_module_info *gStack; extern pci_module_info *gPci; +extern char *gDevNameList[]; +extern struct device *gDevices[]; + #endif Modified: haiku/trunk/src/libs/compat/freebsd_network/if.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-05 03:40:07 UTC (rev 21029) +++ haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-05 04:45:01 UTC (rev 21030) @@ -47,11 +47,28 @@ void if_initname(struct ifnet *ifp, const char *name, int unit) { + int i; + + dprintf("if_initname(%p, %s, %d)\n", ifp, name, unit); + + if (name == NULL) + panic("interface goes unamed"); + ifp->if_dname = name; ifp->if_dunit = unit; - /* XXX use a more Haiku friendly name here? */ - snprintf(ifp->if_xname, IFNAMSIZ, "%s%d", name, unit); + strlcpy(ifp->if_xname, name, sizeof(ifp->if_xname)); + + for (i = 0; gDevNameList[i] != NULL; i++) { + if (strcmp(gDevNameList[i], name) == 0) + break; + } + + if (gDevNameList[i] == NULL) + panic("unknown interface"); + + ifp->if_dev = gDevices[i]; + ifp->if_dev->ifp = ifp; } From axeld at mail.berlios.de Sat May 5 07:46:08 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sat, 5 May 2007 07:46:08 +0200 Subject: [Haiku-commits] r21031 - in haiku/trunk: headers/os/storage src/kits/storage Message-ID: <200705050546.l455k8Bs014422@sheep.berlios.de> Author: axeld Date: 2007-05-05 07:46:08 +0200 (Sat, 05 May 2007) New Revision: 21031 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21031&view=rev Modified: haiku/trunk/headers/os/storage/Statable.h haiku/trunk/src/kits/storage/Statable.cpp Log: Fixed binary compatibility problem I introduced yesterday. Modified: haiku/trunk/headers/os/storage/Statable.h =================================================================== --- haiku/trunk/headers/os/storage/Statable.h 2007-05-05 04:45:01 UTC (rev 21030) +++ haiku/trunk/headers/os/storage/Statable.h 2007-05-05 05:46:08 UTC (rev 21031) @@ -17,7 +17,9 @@ class BStatable { public: +#if __GNUC__ > 3 virtual ~BStatable(); +#endif virtual status_t GetStat(struct stat *st) const = 0; Modified: haiku/trunk/src/kits/storage/Statable.cpp =================================================================== --- haiku/trunk/src/kits/storage/Statable.cpp 2007-05-05 04:45:01 UTC (rev 21030) +++ haiku/trunk/src/kits/storage/Statable.cpp 2007-05-05 05:46:08 UTC (rev 21031) @@ -20,9 +20,11 @@ #include +#if __GNUC__ > 3 BStatable::~BStatable() { } +#endif /*! \fn status_t GetStat(struct stat *st) const From geist at foobox.com Sat May 5 11:32:28 2007 From: geist at foobox.com (Travis Geiselbrecht) Date: Sat, 5 May 2007 02:32:28 -0700 Subject: [Haiku-commits] r21019 - in haiku/trunk/src/add-ons/kernel/drivers/disk/virtual: fmap nbd In-Reply-To: <200705041435.l44EZ1xI031090@sheep.berlios.de> References: <200705041435.l44EZ1xI031090@sheep.berlios.de> Message-ID: On May 4, 2007, at 7:35 AM, mmu_man at BerliOS wrote: > Author: mmu_man > Date: 2007-05-04 16:35:01 +0200 (Fri, 04 May 2007) > New Revision: 21019 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21019&view=rev > > Modified: > haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/fmap/fmap.c > haiku/trunk/src/add-ons/kernel/drivers/disk/virtual/nbd/nbd.c > Log: > Add api_version. > Moved #define DEBUG after the lock.h include, as it wants to find > lots of header I'm too lazy to track. Yeah, #define DEBUG=1 and the kernel don't mix at the moment, which means all of those asserts aren't on. I think i had a tree that was mostly fixed, but didn't get a chance to check it in before my linux box crapped out. I should be able to get it set up again this weekend, and i'll resurrect DEBUG=1. travis From bonefish at cs.tu-berlin.de Sat May 5 13:05:04 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Sat, 05 May 2007 13:05:04 +0200 Subject: [Haiku-commits] r21021 - in haiku/trunk: headers/os/storage src/kits/storage In-Reply-To: <46863103586-BeMail@zon> References: <46863103586-BeMail@zon> Message-ID: <20070505130504.496.1@cs.tu-berlin.de> On 2007-05-04 at 21:27:45 [+0200], Axel D?rfler wrote: > Ingo Weinhold wrote: > > > Log: > > > Added virtual desctructor to calm down GCC 4. > > Er, binary compatibility? > > Oh, I thought the destructor would actually be generated automatically > when it was missing - I was worried, but accidently only checked > sizeof(BStatable) :-) A destructor is auto-generated. It's just not virtual. :-) > So we either need to do what Hugo suggests (ifdefs), or remove a > virtual slot. Too bad :/ ATM, I prefer the ifdef solution, too. CU, Ingo From bonefish at mail.berlios.de Sat May 5 15:16:00 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 5 May 2007 15:16:00 +0200 Subject: [Haiku-commits] r21032 - haiku/trunk/src/tools/fs_shell Message-ID: <200705051316.l45DG04Z027720@sheep.berlios.de> Author: bonefish Date: 2007-05-05 15:16:00 +0200 (Sat, 05 May 2007) New Revision: 21032 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21032&view=rev Modified: haiku/trunk/src/tools/fs_shell/unistd.cpp Log: Patch by Samuel Rodriguez Perez (slightly modified): Make the new bfs_shell build on FreeBSD. ioctl() is defined in a non-standard header. Modified: haiku/trunk/src/tools/fs_shell/unistd.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/unistd.cpp 2007-05-05 05:46:08 UTC (rev 21031) +++ haiku/trunk/src/tools/fs_shell/unistd.cpp 2007-05-05 13:16:00 UTC (rev 21032) @@ -19,7 +19,12 @@ #ifdef __BEOS__ # include #else -# include // the correct place of definition for ioctl() +# if defined(HAIKU_HOST_PLATFORM_FREEBSD) +# incluce +# else + // the (POSIX) correct place of definition for ioctl() +# include +# endif # if defined(HAIKU_HOST_PLATFORM_LINUX) # include From bonefish at mail.berlios.de Sat May 5 15:17:43 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 5 May 2007 15:17:43 +0200 Subject: [Haiku-commits] r21033 - haiku/trunk/src/apps/abouthaiku Message-ID: <200705051317.l45DHhrb027834@sheep.berlios.de> Author: bonefish Date: 2007-05-05 15:17:43 +0200 (Sat, 05 May 2007) New Revision: 21033 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21033&view=rev Modified: haiku/trunk/src/apps/abouthaiku/AboutHaiku.cpp Log: Added Samuel Rodriguez Perez to the list of contributors. Without him FreeBSD wouldn't be a supported build platform. Modified: haiku/trunk/src/apps/abouthaiku/AboutHaiku.cpp =================================================================== --- haiku/trunk/src/apps/abouthaiku/AboutHaiku.cpp 2007-05-05 13:16:00 UTC (rev 21032) +++ haiku/trunk/src/apps/abouthaiku/AboutHaiku.cpp 2007-05-05 13:17:43 UTC (rev 21033) @@ -413,6 +413,7 @@ "David Reid\n" "Daniel Reinhold\n" "Fran?ois Revol\n" + "Samuel Rodriguez Perez\n" "Thomas Roell\n" "Rafael Romo\n" "Reznikov Sergei\n" From bonefish at mail.berlios.de Sat May 5 15:27:33 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 5 May 2007 15:27:33 +0200 Subject: [Haiku-commits] r21034 - haiku/trunk/src/tests/servers/app Message-ID: <200705051327.l45DRX60028536@sheep.berlios.de> Author: bonefish Date: 2007-05-05 15:27:33 +0200 (Sat, 05 May 2007) New Revision: 21034 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21034&view=rev Modified: haiku/trunk/src/tests/servers/app/Jamfile Log: Fixed libbe_test app server build. ServerPicture.cpp uses the storage kit private OffsetFile.h. Modified: haiku/trunk/src/tests/servers/app/Jamfile =================================================================== --- haiku/trunk/src/tests/servers/app/Jamfile 2007-05-05 13:17:43 UTC (rev 21033) +++ haiku/trunk/src/tests/servers/app/Jamfile 2007-05-05 13:27:33 UTC (rev 21034) @@ -6,7 +6,7 @@ if $(TARGET_PLATFORM) = libbe_test { UseLibraryHeaders agg png zlib ; -UsePrivateHeaders app graphics input interface kernel shared ; +UsePrivateHeaders app graphics input interface kernel shared storage ; local appServerDir = [ FDirName $(HAIKU_TOP) src servers app ] ; From jackburton at mail.berlios.de Sat May 5 22:03:32 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Sat, 5 May 2007 22:03:32 +0200 Subject: [Haiku-commits] r21035 - haiku/trunk/src/kits/game Message-ID: <200705052003.l45K3WXA009171@sheep.berlios.de> Author: jackburton Date: 2007-05-05 22:03:31 +0200 (Sat, 05 May 2007) New Revision: 21035 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21035&view=rev Modified: haiku/trunk/src/kits/game/DirectWindow.cpp Log: Added optional debug output Modified: haiku/trunk/src/kits/game/DirectWindow.cpp =================================================================== --- haiku/trunk/src/kits/game/DirectWindow.cpp 2007-05-05 13:27:33 UTC (rev 21034) +++ haiku/trunk/src/kits/game/DirectWindow.cpp 2007-05-05 20:03:31 UTC (rev 21035) @@ -16,7 +16,13 @@ #include #include +//#define DEBUG 1 +#if DEBUG + #include + #include +#endif + // We don't need this kind of locking, since the directDaemonFunc // doesn't access critical shared data. #define DW_NEEDS_LOCKING 0 @@ -28,6 +34,60 @@ }; +#if DEBUG +static void +print_direct_buffer_state(const direct_buffer_state &state) +{ + if (state == 0) + return; + + char string[128]; + int modeState = state & B_DIRECT_MODE_MASK; + if (state == B_DIRECT_START) + strcpy(string, "B_DIRECT_START"); + else if (state == B_DIRECT_MODIFY) + strcpy(string, "B_DIRECT_MODIFY"); + else if (state == B_DIRECT_STOP) + strcpy(string, "B_DIRECT_STOP"); + + if (state & B_CLIPPING_MODIFIED) + strcat(string, " | B_CLIPPING_MODIFIED"); + if (state & B_BUFFER_RESIZED) + strcat(string, " | B_BUFFER_RESIZED"); + if (state & B_BUFFER_MOVED) + strcat(string, " | B_BUFFER_MOVED"); + if (state & B_BUFFER_RESET) + strcat(string, " | B_BUFFER_RESET"); + + printf("direct_buffer_state: %s", string); +} + + +static void +print_direct_driver_state(const direct_driver_state &state) +{ + if (state == 0) + return; + + char string[64]; + if (state == B_DRIVER_CHANGED) + strcpy(string, "B_DRIVER_CHANGED"); + else if (state == B_MODE_CHANGED) + strcpy(string, "B_MODE_CHANGED"); + + printf("direct_driver_state: %s\n", string); +} + + +static void +print_direct_buffer_info(const direct_buffer_info &info) +{ + print_direct_buffer_state(info.buffer_state); + print_direct_driver_state(info.driver_state); +} + +#endif + BDirectWindow::BDirectWindow(BRect frame, const char *title, window_type type, uint32 flags, uint32 workspace) : BWindow(frame, title, type, flags, workspace) @@ -335,11 +395,15 @@ if (status < B_OK) return -1; +#if DEBUG + print_direct_buffer_info(*fBufferDesc); +#endif + if (LockDirect()) { if ((fBufferDesc->buffer_state & B_DIRECT_MODE_MASK) == B_DIRECT_START) fConnectionEnable = true; - fInDirectConnect = true; + fInDirectConnect = true; DirectConnected(fBufferDesc); fInDirectConnect = false; From jackburton at mail.berlios.de Sat May 5 22:41:40 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Sat, 5 May 2007 22:41:40 +0200 Subject: [Haiku-commits] r21036 - haiku/trunk/src/kits/game Message-ID: <200705052041.l45Kfefi012646@sheep.berlios.de> Author: jackburton Date: 2007-05-05 22:41:39 +0200 (Sat, 05 May 2007) New Revision: 21036 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21036&view=rev Modified: haiku/trunk/src/kits/game/DirectWindow.cpp Log: forgot the \n Modified: haiku/trunk/src/kits/game/DirectWindow.cpp =================================================================== --- haiku/trunk/src/kits/game/DirectWindow.cpp 2007-05-05 20:03:31 UTC (rev 21035) +++ haiku/trunk/src/kits/game/DirectWindow.cpp 2007-05-05 20:41:39 UTC (rev 21036) @@ -59,7 +59,7 @@ if (state & B_BUFFER_RESET) strcat(string, " | B_BUFFER_RESET"); - printf("direct_buffer_state: %s", string); + printf("direct_buffer_state: %s\n", string); } From axeld at pinc-software.de Sun May 6 11:45:39 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Sun, 06 May 2007 11:45:39 +0200 CEST Subject: [Haiku-commits] r21020 - in haiku/trunk: headers/private/storage src/kits/storage In-Reply-To: <20070504205028.1478.6@cs.tu-berlin.de> Message-ID: <2749154566-BeMail@zon> Ingo Weinhold wrote: > Your proposal would fall into category 3. However, if it is a common > case > that more than one path is watched, style 1. or 2. might be better, > though, > since it seems quite unhandy to keep several objects around, just > because one > wants to watch more than one path. On the other hand, there'd be > little value > added by the object then. So one would probably go with 2. and make > the class > not instantiable, or just turn it into a namespace. So much for > favoring a > class over functions ... ;-) In that light, it might also be nice to have just a BNodeMonitor class that provides (static) methods like StartWatching(node_ref) and StartWatching(path) side-by-side. The only downside to this approach would be that StopWatching() would be slightly more expensive for the former case, as it would need to check the entries watched by path, too. BTW there would be one advantage I can think of to have a separate object: you could ask that object how many monitors are active - since the total number of monitors is limited, this might be a good idea; I dunno. Bye, Axel. From axeld at pinc-software.de Sun May 6 11:48:33 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Sun, 06 May 2007 11:48:33 +0200 CEST Subject: [Haiku-commits] (no subject) In-Reply-To: <1998602103-BeMail@primary> Message-ID: <2923083435-BeMail@zon> "Michael Lotz" wrote: > Yes, I tried that, but it didn't seem to be loaded. No output was > generated. I have looked at the SCSI bus_manager, but as far as I can > tell, it doesn't explicitly look for modules. In the USB bus manager > bus modules are looked up with open_module_list(), but I couldn't > find > anything like this in the SCSI bus manager. I guess the SIM module > needs to register itself in the SCSI bus manager, but how to do that > if > the module never get's loaded in the first place. AFAICT the SCSI bus module is a passive module, just like IDE. You need a driver that opens it, not the other way around. Bye, Axel. From bonefish at mail.berlios.de Sun May 6 14:32:45 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 6 May 2007 14:32:45 +0200 Subject: [Haiku-commits] r21037 - haiku/trunk/src/tools/fs_shell Message-ID: <200705061232.l46CWjjr019541@sheep.berlios.de> Author: bonefish Date: 2007-05-06 14:32:45 +0200 (Sun, 06 May 2007) New Revision: 21037 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21037&view=rev Modified: haiku/trunk/src/tools/fs_shell/unistd.cpp Log: Typo. Modified: haiku/trunk/src/tools/fs_shell/unistd.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/unistd.cpp 2007-05-05 20:41:39 UTC (rev 21036) +++ haiku/trunk/src/tools/fs_shell/unistd.cpp 2007-05-06 12:32:45 UTC (rev 21037) @@ -20,7 +20,7 @@ # include #else # if defined(HAIKU_HOST_PLATFORM_FREEBSD) -# incluce +# include # else // the (POSIX) correct place of definition for ioctl() # include From mmlr at mail.berlios.de Sun May 6 14:48:39 2007 From: mmlr at mail.berlios.de (mmlr at BerliOS) Date: Sun, 6 May 2007 14:48:39 +0200 Subject: [Haiku-commits] r21038 - haiku/trunk/src/add-ons/kernel/bus_managers/usb Message-ID: <200705061248.l46Cmddm020673@sheep.berlios.de> Author: mmlr Date: 2007-05-06 14:48:38 +0200 (Sun, 06 May 2007) New Revision: 21038 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21038&view=rev Modified: haiku/trunk/src/add-ons/kernel/bus_managers/usb/Device.cpp Log: Fixed wrong deallocation of device resources which caused KDL when unplugging devices with more than one interface. Modified: haiku/trunk/src/add-ons/kernel/bus_managers/usb/Device.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/usb/Device.cpp 2007-05-06 12:32:45 UTC (rev 21037) +++ haiku/trunk/src/add-ons/kernel/bus_managers/usb/Device.cpp 2007-05-06 12:48:38 UTC (rev 21038) @@ -222,7 +222,7 @@ for (int32 i = 0; i < fDeviceDescriptor.num_configurations; i++) { usb_configuration_info *configuration = &fConfigurations[i]; for (size_t j = 0; j < configuration->interface_count; j++) { - usb_interface_list *interfaceList = configuration->interface; + usb_interface_list *interfaceList = &configuration->interface[j]; for (size_t k = 0; k < interfaceList->alt_count; k++) { usb_interface_info *interface = &interfaceList->alt[k]; delete (Interface *)GetStack()->GetObject(interface->handle); From bonefish at mail.berlios.de Sun May 6 15:48:07 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 6 May 2007 15:48:07 +0200 Subject: [Haiku-commits] r21039 - haiku/trunk/src/tools/fs_shell Message-ID: <200705061348.l46Dm74p024533@sheep.berlios.de> Author: bonefish Date: 2007-05-06 15:48:07 +0200 (Sun, 06 May 2007) New Revision: 21039 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21039&view=rev Modified: haiku/trunk/src/tools/fs_shell/command_cp.cpp Log: Removed left over debug output. Modified: haiku/trunk/src/tools/fs_shell/command_cp.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/command_cp.cpp 2007-05-06 12:48:38 UTC (rev 21038) +++ haiku/trunk/src/tools/fs_shell/command_cp.cpp 2007-05-06 13:48:07 UTC (rev 21039) @@ -603,7 +603,6 @@ virtual fssh_status_t RemoveAttr(const char *name) { -printf("GuestNode::RemoveAttr(\"%s\")\n", name); return _kern_remove_attr(fFD, name); } From hugosantos at mail.berlios.de Sun May 6 17:08:08 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Sun, 6 May 2007 17:08:08 +0200 Subject: [Haiku-commits] r21040 - in haiku/trunk: headers/os/drivers src/system/kernel Message-ID: <200705061508.l46F88lR000846@sheep.berlios.de> Author: hugosantos Date: 2007-05-06 17:07:56 +0200 (Sun, 06 May 2007) New Revision: 21040 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21040&view=rev Modified: haiku/trunk/headers/os/drivers/KernelExport.h haiku/trunk/src/system/kernel/int.c Log: added io_interrupt_handler methods for dynamic handling of IO interrupts, including enabling/disabling without allocation and in interrupt context. Modified: haiku/trunk/headers/os/drivers/KernelExport.h =================================================================== --- haiku/trunk/headers/os/drivers/KernelExport.h 2007-05-06 13:48:07 UTC (rev 21039) +++ haiku/trunk/headers/os/drivers/KernelExport.h 2007-05-06 15:07:56 UTC (rev 21040) @@ -54,6 +54,18 @@ interrupt_handler handler, void *data); +/* Private, Haiku specific */ + +/* Flags that can be passwd to disable_io_interrupt_handle() */ +#define B_IN_INTERRUPT_CONTEXT 1 + +extern status_t create_io_interrupt_handler(long interrupt_number, + interrupt_handler handler, void *data, void **context); +void enable_io_interrupt_handler(void *context); +void disable_io_interrupt_handler(void *context, uint32 flags); +void delete_io_interrupt_handler(void *context); + + /*-------------------------------------------------------------*/ /* timer interrupts services */ Modified: haiku/trunk/src/system/kernel/int.c =================================================================== --- haiku/trunk/src/system/kernel/int.c 2007-05-06 13:48:07 UTC (rev 21039) +++ haiku/trunk/src/system/kernel/int.c 2007-05-06 15:07:56 UTC (rev 21040) @@ -31,6 +31,7 @@ struct io_handler { struct io_handler *next; struct io_handler *prev; + long vector; interrupt_handler func; void *data; bool use_enable_counter; @@ -144,41 +145,17 @@ status_t install_io_interrupt_handler(long vector, interrupt_handler handler, void *data, ulong flags) { - struct io_handler *io = NULL; - cpu_status state; + struct io_handler *io; + status_t status; - if (vector < 0 || vector >= NUM_IO_VECTORS) - return B_BAD_VALUE; + status = create_io_interrupt_handler(vector, handler, data, (void **)&io); + if (status < B_OK) + return status; - io = (struct io_handler *)malloc(sizeof(struct io_handler)); - if (io == NULL) - return B_NO_MEMORY; - - arch_debug_remove_interrupt_handler(vector); - // There might be a temporary debug interrupt installed on this - // vector that should be removed now. - - io->func = handler; - io->data = data; io->use_enable_counter = (flags & B_NO_ENABLE_COUNTER) == 0; - // Disable the interrupts, get the spinlock for this irq only - // and then insert the handler - state = disable_interrupts(); - acquire_spinlock(&io_vectors[vector].vector_lock); + enable_io_interrupt_handler(io); - insque(io, &io_vectors[vector].handler_list); - - // If B_NO_ENABLE_COUNTER is set, we're being asked to not alter - // whether the interrupt should be enabled or not - if (io->use_enable_counter) { - if (io_vectors[vector].enable_count++ == 0) - arch_int_enable_io_interrupt(vector); - } - - release_spinlock(&io_vectors[vector].vector_lock); - restore_interrupts(state); - return B_OK; } @@ -230,6 +207,90 @@ } +status_t +create_io_interrupt_handler(long vector, interrupt_handler handler, void *data, + void **context) +{ + struct io_handler *io = NULL; + + if (vector < 0 || vector >= NUM_IO_VECTORS) + return B_BAD_VALUE; + + io = (struct io_handler *)malloc(sizeof(struct io_handler)); + if (io == NULL) + return B_NO_MEMORY; + + io->vector = vector; + io->func = handler; + io->data = data; + io->use_enable_counter = true; + + *context = io; + return B_OK; +} + + +void +enable_io_interrupt_handler(void *context) +{ + struct io_handler *io = context; + long vector = io->vector; + cpu_status state; + + // Disable the interrupts, get the spinlock for this irq only + // and then insert the handler + state = disable_interrupts(); + acquire_spinlock(&io_vectors[vector].vector_lock); + + insque(io, &io_vectors[vector].handler_list); + + // If B_NO_ENABLE_COUNTER is set, we're being asked to not alter + // whether the interrupt should be enabled or not + if (io->use_enable_counter) { + if (io_vectors[vector].enable_count++ == 0) + arch_int_enable_io_interrupt(vector); + } + + release_spinlock(&io_vectors[vector].vector_lock); + restore_interrupts(state); +} + + +void +disable_io_interrupt_handler(void *context, uint32 flags) +{ + struct io_handler *io = context; + long vector = io->vector; + cpu_status state = 0; + + if ((flags & B_IN_INTERRUPT_CONTEXT) == 0) { + /* lock the structures down so it is not modified while we search */ + state = disable_interrupts(); + acquire_spinlock(&io_vectors[vector].vector_lock); + } + + remque(io); + + // Check if we need to disable the interrupt + if (io->use_enable_counter && --io_vectors[vector].enable_count == 0) + arch_int_disable_io_interrupt(vector); + + if ((flags & B_IN_INTERRUPT_CONTEXT) == 0) { + release_spinlock(&io_vectors[vector].vector_lock); + restore_interrupts(state); + } +} + + +void +delete_io_interrupt_handler(void *context) +{ + struct io_handler *io = context; + + free(io); +} + + /** actually process an interrupt via the handlers registered for that * vector (irq) */ @@ -259,9 +320,10 @@ * whatever the driver thought would be useful (ie. B_INVOKE_SCHEDULER) */ - for (io = io_vectors[vector].handler_list.next; - io != &io_vectors[vector].handler_list; // Are we already at the end of the list? - io = io->next) { + io = io_vectors[vector].handler_list.next; + while (io != &io_vectors[vector].handler_list) { + struct io_handler *next = io->next; + status = io->func(io->data); if (levelTriggered && status != B_UNHANDLED_INTERRUPT) @@ -271,6 +333,8 @@ handled = true; else if (status == B_INVOKE_SCHEDULER) invokeScheduler = true; + + io = next; } #ifdef DEBUG_INT From hugosantos at mail.berlios.de Sun May 6 17:08:28 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Sun, 6 May 2007 17:08:28 +0200 Subject: [Haiku-commits] r21041 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/net compat/sys Message-ID: <200705061508.l46F8SKk000873@sheep.berlios.de> Author: hugosantos Date: 2007-05-06 17:08:08 +0200 (Sun, 06 May 2007) New Revision: 21041 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21041&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/bus.c haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/compat/net/if.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/device.h haiku/trunk/src/libs/compat/freebsd_network/if.c Log: freebsd compat. layer: use a thread for deferred interrupt handling. fixed a issue with bus_space_write_N. init the receive queue on device creation. Modified: haiku/trunk/src/libs/compat/freebsd_network/bus.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-06 15:07:56 UTC (rev 21040) +++ haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-06 15:08:08 UTC (rev 21041) @@ -8,10 +8,10 @@ * Some of this code is based on previous work by Marcus Overhagen. */ +#include "device.h" + #include -#include - #include #include #include @@ -34,9 +34,17 @@ driver_intr_t handler; void *arg; int irq; + + void *context; + + thread_id thread; + sem_id sem; }; +static int32 intr_wrapper(void *data); + + static area_id map_mem(void **virtualAddr, void *_phy, size_t size, uint32 protection, const char *name) @@ -111,6 +119,9 @@ && type != SYS_RES_IOPORT) return NULL; + device_printf(dev, "bus_alloc_resource(%i, [%i], 0x%lx, 0x%lx, 0x%lx, 0x%lx)\n", + type, *rid, start, end, count, flags); + // maybe a local array of resources is enough res = malloc(sizeof(struct resource)); if (res == NULL) @@ -165,19 +176,66 @@ intr_wrapper(void *data) { struct internal_intr *intr = data; - intr->handler(intr->arg); + driver_printf("in interrupt handler.\n"); + + disable_io_interrupt_handler(intr->context, B_IN_INTERRUPT_CONTEXT); + release_sem_etc(intr->sem, 1, B_DO_NOT_RESCHEDULE); + + return B_INVOKE_SCHEDULER; +} + + +static int32 +intr_handler(void *data) +{ + struct internal_intr *intr = data; + status_t status; + + while (1) { + enable_io_interrupt_handler(intr->context); + + status = acquire_sem(intr->sem); + if (status < B_OK) + break; + + driver_printf("in soft interrupt handler.\n"); + + intr->handler(intr->arg); + } + + disable_io_interrupt_handler(intr->context, 0); + return 0; } +static void +free_internal_intr(struct internal_intr *intr) +{ + status_t status; + delete_sem(intr->sem); + wait_for_thread(intr->thread, &status); + + if (intr->context) + delete_io_interrupt_handler(intr->context); + + free(intr); +} + + int bus_setup_intr(device_t dev, struct resource *res, int flags, driver_intr_t handler, void *arg, void **cookiep) { + /* TODO check MPSAFE etc */ + struct internal_intr *intr = (struct internal_intr *)malloc( sizeof(struct internal_intr)); + char semName[64]; status_t status; + /* status_t status; */ + if (intr == NULL) return B_NO_MEMORY; @@ -185,12 +243,34 @@ intr->arg = arg; intr->irq = res->handle; - status = install_io_interrupt_handler(intr->irq, intr_wrapper, intr, 0); + snprintf(semName, sizeof(semName), "%s intr", dev->dev_name); + + intr->sem = create_sem(0, semName); + if (intr->sem < B_OK) { + free(intr); + return B_NO_MEMORY; + } + + snprintf(semName, sizeof(semName), "%s intr handler", dev->dev_name); + + intr->thread = spawn_kernel_thread(intr_handler, semName, + B_REAL_TIME_DISPLAY_PRIORITY, intr); + if (intr->thread < B_OK) { + delete_sem(intr->sem); + free(intr); + return B_NO_MEMORY; + } + + intr->context = NULL; + status = create_io_interrupt_handler(intr->irq, intr_wrapper, intr, + &intr->context); if (status < B_OK) { - free(intr); + free_internal_intr(intr); return status; } + resume_thread(intr->thread); + *cookiep = intr; return 0; @@ -201,8 +281,8 @@ bus_teardown_intr(device_t dev, struct resource *res, void *arg) { struct internal_intr *intr = arg; - remove_io_interrupt_handler(intr->irq, intr_wrapper, intr); - free(intr); + /* remove_io_interrupt_handler(intr->irq, intr_wrapper, intr); */ + free_internal_intr(intr); return 0; } @@ -215,3 +295,33 @@ return B_ERROR; } + +#define BUS_SPACE_READ(size, type, fun) \ + type bus_space_read_##size(bus_space_tag_t tag, \ + bus_space_handle_t handle, bus_size_t offset) \ + { \ + type value; \ + if (tag == I386_BUS_SPACE_IO) \ + value = fun(handle + offset); \ + else \ + value = *(volatile type *)(handle + offset); \ + return value; \ + } + +#define BUS_SPACE_WRITE(size, type, fun) \ + void bus_space_write_##size(bus_space_tag_t tag, \ + bus_space_handle_t handle, bus_size_t offset, type value) \ + { \ + if (tag == I386_BUS_SPACE_IO) \ + fun(value, handle + offset); \ + else \ + *(volatile type *)(handle + offset) = value; \ + } + +BUS_SPACE_READ(1, uint8_t, in8) +BUS_SPACE_READ(2, uint16_t, in16) +BUS_SPACE_READ(4, uint32_t, in32) + +BUS_SPACE_WRITE(1, uint8_t, out8) +BUS_SPACE_WRITE(2, uint16_t, out16) +BUS_SPACE_WRITE(4, uint32_t, out32) Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/net/if.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/net/if.h 2007-05-06 15:07:56 UTC (rev 21040) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/net/if.h 2007-05-06 15:08:08 UTC (rev 21041) @@ -26,6 +26,7 @@ #define IFF_DRV_RUNNING 0x10000 #define IFF_DRV_OACTIVE 0x20000 #define IFF_LINK0 0x40000 +#define IFF_DEBUG 0x80000 #define LINK_STATE_UNKNOWN 0 Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-06 15:07:56 UTC (rev 21040) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-06 15:08:08 UTC (rev 21041) @@ -24,69 +24,20 @@ #define BUS_SPACE_MAXSIZE_32BIT 0xffffffff #define BUS_SPACE_MAXSIZE 0xffffffff -static inline uint8_t -bus_space_read_1(bus_space_tag_t tag, bus_space_handle_t handle, - bus_size_t offset) -{ - if (tag == I386_BUS_SPACE_IO) - return in8(handle + offset); - return *(volatile uint8_t *)(handle + offset); -} +uint8_t bus_space_read_1(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset); +void bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset, uint8_t value); +uint16_t bus_space_read_2(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset); +void bus_space_write_2(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset, uint16_t value); +uint32_t bus_space_read_4(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset); +void bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset, uint32_t value); -static inline void -bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t handle, - bus_size_t offset, uint8_t value) -{ - if (tag == I386_BUS_SPACE_IO) - out8(handle + offset, value); - else - *(volatile uint8_t *)(handle + offset) = value; -} - - -static inline uint16_t -bus_space_read_2(bus_space_tag_t tag, bus_space_handle_t handle, - bus_size_t offset) -{ - if (tag == I386_BUS_SPACE_IO) - return in16(handle + offset); - return *(volatile uint16_t *)(handle + offset); -} - - -static inline void -bus_space_write_2(bus_space_tag_t tag, bus_space_handle_t handle, - bus_size_t offset, uint16_t value) -{ - if (tag == I386_BUS_SPACE_IO) - out16(handle + offset, value); - else - *(volatile uint16_t *)(handle + offset) = value; -} - - -static inline uint32_t -bus_space_read_4(bus_space_tag_t tag, bus_space_handle_t handle, - bus_size_t offset) -{ - if (tag == I386_BUS_SPACE_IO) - return in32(handle + offset); - return *(volatile uint32_t *)(handle + offset); -} - - -static inline void -bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t handle, - bus_size_t offset, uint32_t value) -{ - if (tag == I386_BUS_SPACE_IO) - out32(handle + offset, value); - else - *(volatile uint32_t *)(handle + offset) = value; -} - - #define BUS_SPACE_BARRIER_READ 1 #define BUS_SPACE_BARRIER_WRITE 2 Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-06 15:07:56 UTC (rev 21040) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-06 15:08:08 UTC (rev 21041) @@ -20,6 +20,14 @@ // TODO a lot. +#define DEBUG_PCI + +#ifdef DEBUG_PCI +#define TRACE_PCI(dev, format, args...) device_printf(dev, format , ##args) +#else +#define TRACE_PCI(dev, format, args...) do { } while (0) +#endif + status_t init_compat_layer(void); struct net_stack_module_info *gStack; @@ -28,14 +36,18 @@ uint32_t pci_read_config(device_t dev, int offset, int size) { - return gPci->read_pci_config(dev->pci_info.bus, dev->pci_info.device, - dev->pci_info.function, offset, size); + uint32_t value = gPci->read_pci_config(dev->pci_info.bus, + dev->pci_info.device, dev->pci_info.function, offset, size); + TRACE_PCI(dev, "pci_read_config(%i, %i) = 0x%lx\n", offset, size, value); + return value; } void pci_write_config(device_t dev, int offset, uint32_t value, int size) { + TRACE_PCI(dev, "pci_write_config(%i, 0x%lx, %i)\n", offset, value, size); + gPci->write_pci_config(dev->pci_info.bus, dev->pci_info.device, dev->pci_info.function, offset, size, value); } @@ -119,16 +131,48 @@ } +void +driver_printf(const char *format, ...) +{ + va_list vl; + va_start(vl, format); + driver_vprintf(format, vl); + va_end(vl); +} + + +static void +driver_vprintf_etc(const char *extra, const char *format, va_list vl) +{ + char buf[256]; + vsnprintf(buf, sizeof(buf), format, vl); + + if (extra) + dprintf("[%s] (%s) %s", gDriverName, extra, buf); + else + dprintf("[%s] %s", gDriverName, buf); +} + + +void +driver_vprintf(const char *format, va_list vl) +{ + driver_vprintf_etc(NULL, format, vl); +} + + int device_printf(device_t dev, const char *format, ...) { - char buf[256]; + char devDesc[32]; va_list vl; + + snprintf(devDesc, sizeof(devDesc), "%i:%i:%i", (int)dev->pci_info.bus, + (int)dev->pci_info.device, (int)dev->pci_info.function); + va_start(vl, format); - vsnprintf(buf, sizeof(buf), format, vl); + driver_vprintf_etc(devDesc, format, vl); va_end(vl); - - dprintf("[%s...] %s", gDriverName, buf); return 0; } @@ -180,13 +224,11 @@ int printf(const char *format, ...) { - char buf[256]; va_list vl; va_start(vl, format); - vsnprintf(buf, sizeof(buf), format, vl); + driver_vprintf(format, vl); va_end(vl); - dprintf(buf); return 0; } Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-06 15:07:56 UTC (rev 21040) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-06 15:08:08 UTC (rev 21041) @@ -58,6 +58,8 @@ return NULL; } + ifq_init(&dev->receive_queue, semName); + return dev; } @@ -66,6 +68,7 @@ free_device(device_t dev) { delete_sem(dev->receive_sem); + ifq_uninit(&dev->receive_queue); free(dev->softc); free(dev); } @@ -93,7 +96,7 @@ device_t dev; int i; - dprintf("%s, compat_open(%s, 0x%lx)\n", gDriverName, name, flags); + driver_printf("compat_open(%s, 0x%lx)\n", name, flags); for (i = 0; gDevNameList[i] != NULL; i++) { if (strcmp(gDevNameList[i], name) == 0) @@ -112,6 +115,8 @@ if (status != 0) dev->flags = 0; + driver_printf(" ... status = 0x%ld\n", status); + *cookie = dev; return status; @@ -123,7 +128,7 @@ { device_t dev = cookie; - dprintf("%s, compat_close(%p)\n", gDriverName, dev); + device_printf(dev, "compat_close()\n"); return B_ERROR; } @@ -134,7 +139,7 @@ { device_t dev = cookie; - dprintf("%s, compat_free(%p)\n", gDriverName, dev); + device_printf(dev, "compat_free()\n"); free_device(dev); return B_ERROR; @@ -150,6 +155,9 @@ struct mbuf *mb; size_t len; + driver_printf("compat_read(%p, %lld, %p, [%lu])\n", cookie, position, buf, + *numBytes); + if (dev->flags & DEVICE_CLOSED) return B_INTERRUPTED; @@ -193,6 +201,9 @@ device_t dev = cookie; struct mbuf *mb; + driver_printf("compat_write(%p, %lld, %p, [%lu])\n", cookie, position, + buffer, *numBytes); + mb = m_getcl(0, MT_DATA, 0); if (mb == NULL) return ENOBUFS; Modified: haiku/trunk/src/libs/compat/freebsd_network/device.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-06 15:07:56 UTC (rev 21040) +++ haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-06 15:08:08 UTC (rev 21041) @@ -58,6 +58,12 @@ void init_bounce_pages(void); void uninit_bounce_pages(void); +void driver_printf(const char *format, ...) __attribute__ ((format (__printf__, 1, 2))); +void driver_vprintf(const char *format, va_list vl); + +void ifq_init(struct ifqueue *ifq, const char *name); +void ifq_uninit(struct ifqueue *ifq); + extern struct net_stack_module_info *gStack; extern pci_module_info *gPci; Modified: haiku/trunk/src/libs/compat/freebsd_network/if.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-06 15:07:56 UTC (rev 21040) +++ haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-06 15:08:08 UTC (rev 21041) @@ -73,20 +73,40 @@ void +ifq_init(struct ifqueue *ifq, const char *name) +{ + ifq->ifq_head = NULL; + ifq->ifq_tail = NULL; + ifq->ifq_len = 0; + ifq->ifq_maxlen = IFQ_MAXLEN; + ifq->ifq_drops = 0; + + mtx_init(&ifq->ifq_mtx, name, NULL, MTX_DEF); +} + + +void +ifq_uninit(struct ifqueue *ifq) +{ + mtx_destroy(&ifq->ifq_mtx); +} + + +void if_attach(struct ifnet *ifp) { TAILQ_INIT(&ifp->if_addrhead); TAILQ_INIT(&ifp->if_prefixhead); TAILQ_INIT(&ifp->if_multiaddrs); - mtx_init(&ifp->if_snd.ifq_mtx, ifp->if_xname, NULL, MTX_DEF); + ifq_init((struct ifqueue *)&ifp->if_snd, ifp->if_xname); } void if_detach(struct ifnet *ifp) { - mtx_destroy(&ifp->if_snd.ifq_mtx); + ifq_uninit((struct ifqueue *)&ifp->if_snd); } @@ -97,7 +117,6 @@ if (ifp->if_flags & IFF_NEEDSGIANT) panic("freebsd compat.: unsupported giant requirement"); #endif - ifp->if_start(ifp); } @@ -133,7 +152,7 @@ ether_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct rtentry *rt0) { - int error; + int error = 0; IFQ_HANDOFF(ifp, m, error); return error; } @@ -270,3 +289,13 @@ return 0; } + +char * +ether_sprintf(const u_char *ap) +{ + static char etherbuf[18]; + snprintf(etherbuf, sizeof (etherbuf), + "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", + ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]); + return (etherbuf); +} From hugosantos at gmail.com Sun May 6 17:11:41 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Sun, 6 May 2007 16:11:41 +0100 Subject: [Haiku-commits] r21040 - in haiku/trunk: headers/os/drivers src/system/kernel In-Reply-To: <200705061508.l46F88lR000846@sheep.berlios.de> References: <200705061508.l46F88lR000846@sheep.berlios.de> Message-ID: <9c46321e0705060811h47ab3333y92cba5382f479ff@mail.gmail.com> Hey guys, Please let me know if you see anything wrong with these or if the definitions should go elsewhere than KernelExport.h. I've added these to be able to get the first interrupt and just defer the handling to a thread (check next commit). If i don't disable the interrupt it gets hammered so heavily the thread is not even scheduled. Using the current methods i couldn't free or remove the interrupt handler, so i added these ones. Let me know what you think. Thanks, Hugo On 5/6/07, hugosantos at mail.berlios.de wrote: > Author: hugosantos > Date: 2007-05-06 17:07:56 +0200 (Sun, 06 May 2007) > New Revision: 21040 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21040&view=rev > > Modified: > haiku/trunk/headers/os/drivers/KernelExport.h > haiku/trunk/src/system/kernel/int.c > Log: > added io_interrupt_handler methods for dynamic handling of IO interrupts, including enabling/disabling without allocation and in interrupt context. > > > Modified: haiku/trunk/headers/os/drivers/KernelExport.h > =================================================================== > --- haiku/trunk/headers/os/drivers/KernelExport.h 2007-05-06 13:48:07 UTC (rev 21039) > +++ haiku/trunk/headers/os/drivers/KernelExport.h 2007-05-06 15:07:56 UTC (rev 21040) > @@ -54,6 +54,18 @@ > interrupt_handler handler, void *data); > > > +/* Private, Haiku specific */ > + > +/* Flags that can be passwd to disable_io_interrupt_handle() */ > +#define B_IN_INTERRUPT_CONTEXT 1 > + > +extern status_t create_io_interrupt_handler(long interrupt_number, > + interrupt_handler handler, void *data, void **context); > +void enable_io_interrupt_handler(void *context); > +void disable_io_interrupt_handler(void *context, uint32 flags); > +void delete_io_interrupt_handler(void *context); > + > + > /*-------------------------------------------------------------*/ > /* timer interrupts services */ > > > Modified: haiku/trunk/src/system/kernel/int.c > =================================================================== > --- haiku/trunk/src/system/kernel/int.c 2007-05-06 13:48:07 UTC (rev 21039) > +++ haiku/trunk/src/system/kernel/int.c 2007-05-06 15:07:56 UTC (rev 21040) > @@ -31,6 +31,7 @@ > struct io_handler { > struct io_handler *next; > struct io_handler *prev; > + long vector; > interrupt_handler func; > void *data; > bool use_enable_counter; > @@ -144,41 +145,17 @@ > status_t > install_io_interrupt_handler(long vector, interrupt_handler handler, void *data, ulong flags) > { > - struct io_handler *io = NULL; > - cpu_status state; > + struct io_handler *io; > + status_t status; > > - if (vector < 0 || vector >= NUM_IO_VECTORS) > - return B_BAD_VALUE; > + status = create_io_interrupt_handler(vector, handler, data, (void **)&io); > + if (status < B_OK) > + return status; > > - io = (struct io_handler *)malloc(sizeof(struct io_handler)); > - if (io == NULL) > - return B_NO_MEMORY; > - > - arch_debug_remove_interrupt_handler(vector); > - // There might be a temporary debug interrupt installed on this > - // vector that should be removed now. > - > - io->func = handler; > - io->data = data; > io->use_enable_counter = (flags & B_NO_ENABLE_COUNTER) == 0; > > - // Disable the interrupts, get the spinlock for this irq only > - // and then insert the handler > - state = disable_interrupts(); > - acquire_spinlock(&io_vectors[vector].vector_lock); > + enable_io_interrupt_handler(io); > > - insque(io, &io_vectors[vector].handler_list); > - > - // If B_NO_ENABLE_COUNTER is set, we're being asked to not alter > - // whether the interrupt should be enabled or not > - if (io->use_enable_counter) { > - if (io_vectors[vector].enable_count++ == 0) > - arch_int_enable_io_interrupt(vector); > - } > - > - release_spinlock(&io_vectors[vector].vector_lock); > - restore_interrupts(state); > - > return B_OK; > } > > @@ -230,6 +207,90 @@ > } > > > +status_t > +create_io_interrupt_handler(long vector, interrupt_handler handler, void *data, > + void **context) > +{ > + struct io_handler *io = NULL; > + > + if (vector < 0 || vector >= NUM_IO_VECTORS) > + return B_BAD_VALUE; > + > + io = (struct io_handler *)malloc(sizeof(struct io_handler)); > + if (io == NULL) > + return B_NO_MEMORY; > + > + io->vector = vector; > + io->func = handler; > + io->data = data; > + io->use_enable_counter = true; > + > + *context = io; > + return B_OK; > +} > + > + > +void > +enable_io_interrupt_handler(void *context) > +{ > + struct io_handler *io = context; > + long vector = io->vector; > + cpu_status state; > + > + // Disable the interrupts, get the spinlock for this irq only > + // and then insert the handler > + state = disable_interrupts(); > + acquire_spinlock(&io_vectors[vector].vector_lock); > + > + insque(io, &io_vectors[vector].handler_list); > + > + // If B_NO_ENABLE_COUNTER is set, we're being asked to not alter > + // whether the interrupt should be enabled or not > + if (io->use_enable_counter) { > + if (io_vectors[vector].enable_count++ == 0) > + arch_int_enable_io_interrupt(vector); > + } > + > + release_spinlock(&io_vectors[vector].vector_lock); > + restore_interrupts(state); > +} > + > + > +void > +disable_io_interrupt_handler(void *context, uint32 flags) > +{ > + struct io_handler *io = context; > + long vector = io->vector; > + cpu_status state = 0; > + > + if ((flags & B_IN_INTERRUPT_CONTEXT) == 0) { > + /* lock the structures down so it is not modified while we search */ > + state = disable_interrupts(); > + acquire_spinlock(&io_vectors[vector].vector_lock); > + } > + > + remque(io); > + > + // Check if we need to disable the interrupt > + if (io->use_enable_counter && --io_vectors[vector].enable_count == 0) > + arch_int_disable_io_interrupt(vector); > + > + if ((flags & B_IN_INTERRUPT_CONTEXT) == 0) { > + release_spinlock(&io_vectors[vector].vector_lock); > + restore_interrupts(state); > + } > +} > + > + > +void > +delete_io_interrupt_handler(void *context) > +{ > + struct io_handler *io = context; > + > + free(io); > +} > + > + > /** actually process an interrupt via the handlers registered for that > * vector (irq) > */ > @@ -259,9 +320,10 @@ > * whatever the driver thought would be useful (ie. B_INVOKE_SCHEDULER) > */ > > - for (io = io_vectors[vector].handler_list.next; > - io != &io_vectors[vector].handler_list; // Are we already at the end of the list? > - io = io->next) { > + io = io_vectors[vector].handler_list.next; > + while (io != &io_vectors[vector].handler_list) { > + struct io_handler *next = io->next; > + > status = io->func(io->data); > > if (levelTriggered && status != B_UNHANDLED_INTERRUPT) > @@ -271,6 +333,8 @@ > handled = true; > else if (status == B_INVOKE_SCHEDULER) > invokeScheduler = true; > + > + io = next; > } > > #ifdef DEBUG_INT > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From mmlr at mail.berlios.de Sun May 6 17:17:00 2007 From: mmlr at mail.berlios.de (mmlr at BerliOS) Date: Sun, 6 May 2007 17:17:00 +0200 Subject: [Haiku-commits] r21042 - haiku/trunk/src/add-ons/kernel/bus_managers/usb Message-ID: <200705061517.l46FH0Mv001694@sheep.berlios.de> Author: mmlr Date: 2007-05-06 17:17:00 +0200 (Sun, 06 May 2007) New Revision: 21042 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21042&view=rev Modified: haiku/trunk/src/add-ons/kernel/bus_managers/usb/Hub.cpp haiku/trunk/src/add-ons/kernel/bus_managers/usb/Stack.cpp Log: * Moved around some initialization to avoid problems when deleting incompletely created objects * Also move waiting for the first explore to run through out of the constructor to reduce delays * Remove the old device when a new one is connected to the same port - this could happen when you very quickly un- and replug a device Modified: haiku/trunk/src/add-ons/kernel/bus_managers/usb/Hub.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/usb/Hub.cpp 2007-05-06 15:08:08 UTC (rev 21041) +++ haiku/trunk/src/add-ons/kernel/bus_managers/usb/Hub.cpp 2007-05-06 15:17:00 UTC (rev 21042) @@ -13,10 +13,15 @@ Hub::Hub(Object *parent, usb_device_descriptor &desc, int8 deviceAddress, usb_speed speed) - : Device(parent, desc, deviceAddress, speed) + : Device(parent, desc, deviceAddress, speed), + fInterruptPipe(NULL) { TRACE(("USB Hub %d: creating hub\n", DeviceAddress())); + memset(&fHubDescriptor, 0, sizeof(fHubDescriptor)); + for (int32 i = 0; i < 8; i++) + fChildren[i] = NULL; + if (!fInitOK) { TRACE_ERROR(("USB Hub %d: device failed to initialize\n", DeviceAddress())); return; @@ -30,9 +35,6 @@ return; } - for (int32 i = 0; i < 8; i++) - fChildren[i] = NULL; - if (fDeviceDescriptor.device_class != 9) { TRACE_ERROR(("USB Hub %d: wrong class! bailing out\n", DeviceAddress())); return; @@ -58,6 +60,11 @@ TRACE(("\tdevice_removeable:...0x%02x\n", fHubDescriptor.device_removeable)); TRACE(("\tpower_control_mask:..0x%02x\n", fHubDescriptor.power_control_mask)); + if (fHubDescriptor.num_ports > 8) { + TRACE(("USB Hub %d: hub supports more ports than we do (%d vs. 8)\n", DeviceAddress(), fHubDescriptor.num_ports)); + fHubDescriptor.num_ports = 8; + } + Object *object = GetStack()->GetObject(Configuration()->interface->active->endpoint[0].handle); if (!object || (object->Type() & USB_OBJECT_INTERRUPT_PIPE) == 0) { TRACE_ERROR(("USB Hub %d: no interrupt pipe found\n", DeviceAddress())); @@ -183,12 +190,6 @@ Hub::Explore() { for (int32 i = 0; i < fHubDescriptor.num_ports; i++) { - if (i >= 8) { - TRACE(("USB Hub %d: hub supports more ports than we do (%d)\n", DeviceAddress(), fHubDescriptor.num_ports)); - fHubDescriptor.num_ports = 8; - continue; - } - status_t result = UpdatePortStatus(i); if (result < B_OK) continue; @@ -228,6 +229,20 @@ continue; } + if (fChildren[i]) { + TRACE_ERROR(("USB Hub %d: new device on a port that is already in use\n", DeviceAddress())); + + // Remove previous device first + TRACE(("USB Hub %d: removing device 0x%08lx\n", DeviceAddress(), fChildren[i])); + GetStack()->NotifyDeviceChange(fChildren[i], false); + + if (Lock()) { + GetBusManager()->FreeDevice(fChildren[i]); + fChildren[i] = NULL; + Unlock(); + } + } + usb_speed speed = USB_SPEED_FULLSPEED; if (fPortStatus[i].status & PORT_STATUS_LOW_SPEED) speed = USB_SPEED_LOWSPEED; Modified: haiku/trunk/src/add-ons/kernel/bus_managers/usb/Stack.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/usb/Stack.cpp 2007-05-06 15:08:08 UTC (rev 21041) +++ haiku/trunk/src/add-ons/kernel/bus_managers/usb/Stack.cpp 2007-05-06 15:17:00 UTC (rev 21042) @@ -75,11 +75,6 @@ fExploreThread = spawn_kernel_thread(ExploreThread, "usb explore", B_LOW_PRIORITY, this); resume_thread(fExploreThread); - - // wait for the first explore to complete - // this ensures that we get all initial devices under InstallNotify - while (!fFirstExploreDone) - snooze(1000); } @@ -380,6 +375,11 @@ { TRACE(("USB Stack: installing notify hooks for driver \"%s\"\n", driverName)); + // wait for the first explore to complete + // this ensures that we get all initial devices + while (!fFirstExploreDone) + snooze(1000); + usb_driver_info *element = fDriverList; while (element) { if (strcmp(element->driver_name, driverName) == 0) { From mmlr at mail.berlios.de Sun May 6 17:22:12 2007 From: mmlr at mail.berlios.de (mmlr at BerliOS) Date: Sun, 6 May 2007 17:22:12 +0200 Subject: [Haiku-commits] r21043 - haiku/trunk/src/add-ons/kernel/bus_managers/usb Message-ID: <200705061522.l46FMC1W002174@sheep.berlios.de> Author: mmlr Date: 2007-05-06 17:22:12 +0200 (Sun, 06 May 2007) New Revision: 21043 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21043&view=rev Modified: haiku/trunk/src/add-ons/kernel/bus_managers/usb/BusManager.cpp haiku/trunk/src/add-ons/kernel/bus_managers/usb/Pipe.cpp haiku/trunk/src/add-ons/kernel/bus_managers/usb/usb_p.h Log: Prepare cancelling transfers from the stack side. The actual handling will happen in the HCD modules where transfer management has to be done anyway. Modified: haiku/trunk/src/add-ons/kernel/bus_managers/usb/BusManager.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/usb/BusManager.cpp 2007-05-06 15:17:00 UTC (rev 21042) +++ haiku/trunk/src/add-ons/kernel/bus_managers/usb/BusManager.cpp 2007-05-06 15:22:12 UTC (rev 21043) @@ -269,6 +269,14 @@ status_t +BusManager::CancelQueuedTransfers(Pipe *pipe) +{ + // virtual function to be overridden + return B_ERROR; +} + + +status_t BusManager::NotifyPipeChange(Pipe *pipe, usb_change change) { // virtual function to be overridden Modified: haiku/trunk/src/add-ons/kernel/bus_managers/usb/Pipe.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/usb/Pipe.cpp 2007-05-06 15:17:00 UTC (rev 21042) +++ haiku/trunk/src/add-ons/kernel/bus_managers/usb/Pipe.cpp 2007-05-06 15:22:12 UTC (rev 21043) @@ -41,8 +41,7 @@ status_t Pipe::CancelQueuedTransfers() { - TRACE_ERROR(("USB Pipe: cancelling transfers is not implemented!\n")); - return B_ERROR; + return GetBusManager()->CancelQueuedTransfers(this); } Modified: haiku/trunk/src/add-ons/kernel/bus_managers/usb/usb_p.h =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/usb/usb_p.h 2007-05-06 15:17:00 UTC (rev 21042) +++ haiku/trunk/src/add-ons/kernel/bus_managers/usb/usb_p.h 2007-05-06 15:22:12 UTC (rev 21043) @@ -171,6 +171,7 @@ virtual status_t Stop(); virtual status_t SubmitTransfer(Transfer *transfer); +virtual status_t CancelQueuedTransfers(Pipe *pipe); virtual status_t NotifyPipeChange(Pipe *pipe, usb_change change); From mmlr at mail.berlios.de Sun May 6 17:55:27 2007 From: mmlr at mail.berlios.de (mmlr at BerliOS) Date: Sun, 6 May 2007 17:55:27 +0200 Subject: [Haiku-commits] r21044 - haiku/trunk/src/add-ons/kernel/busses/usb Message-ID: <200705061555.l46FtR5J005331@sheep.berlios.de> Author: mmlr Date: 2007-05-06 17:55:26 +0200 (Sun, 06 May 2007) New Revision: 21044 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21044&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ehci.cpp haiku/trunk/src/add-ons/kernel/busses/usb/ehci.h Log: Implemented transfer cancelling for EHCI by reworking the previously unused CancelPendingTransfer() into CancelQueuedTransfers() with the pipe based semantic. Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ehci.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ehci.cpp 2007-05-06 15:22:12 UTC (rev 21043) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ehci.cpp 2007-05-06 15:55:26 UTC (rev 21044) @@ -903,7 +903,7 @@ status_t -EHCI::CancelPendingTransfer(Transfer *transfer) +EHCI::CancelQueuedTransfers(Pipe *pipe) { if (!Lock()) return B_ERROR; @@ -911,7 +911,8 @@ transfer_data *last = NULL; transfer_data *current = fFirstTransfer; while (current) { - if (current->transfer == transfer) { + if (current->transfer->TransferPipe() == pipe) { + UnlinkQueueHead(current->queue_head, &fFreeListHead); current->transfer->Finished(B_CANCELED, 0); delete current->transfer; @@ -924,8 +925,6 @@ fLastTransfer = last; delete current; - Unlock(); - return B_OK; } last = current; @@ -933,7 +932,7 @@ } Unlock(); - return B_BAD_VALUE; + return B_OK; } Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ehci.h =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ehci.h 2007-05-06 15:22:12 UTC (rev 21043) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ehci.h 2007-05-06 15:55:26 UTC (rev 21044) @@ -37,6 +37,7 @@ virtual status_t SubmitTransfer(Transfer *transfer); status_t SubmitPeriodicTransfer(Transfer *transfer); status_t SubmitAsyncTransfer(Transfer *transfer); +virtual status_t CancelQueuedTransfers(Pipe *pipe); virtual status_t NotifyPipeChange(Pipe *pipe, usb_change change); @@ -66,7 +67,6 @@ ehci_qh *queueHead, ehci_qtd *dataDescriptor, bool directionIn); - status_t CancelPendingTransfer(Transfer *transfer); status_t CancelAllPendingTransfers(); static int32 FinishThread(void *data); From marcusoverhagen at arcor.de Sun May 6 20:39:25 2007 From: marcusoverhagen at arcor.de (Marcus Overhagen) Date: Sun, 6 May 2007 20:39:25 +0200 (CEST) Subject: [Haiku-commits] r21040 - in haiku/trunk: headers/os/drivers In-Reply-To: <9c46321e0705060811h47ab3333y92cba5382f479ff@mail.gmail.com> References: <9c46321e0705060811h47ab3333y92cba5382f479ff@mail.gmail.com> <200705061508.l46F88lR000846@sheep.berlios.de> Message-ID: <27351094.1178476765082.JavaMail.ngmail@webmail12> Hugo Santos wrote: > Let me know what you think. > Seriously, I don't like that at all. I think this functionality should be removed from the kernel. Disabling an interrupt can degrade performance, especially with interrupt sharing. I don't think we should repeat BSDs failures just for an emulation layer. regards Marcus Viel oder wenig? Schnell oder langsam? Unbegrenzt surfen + telefonieren ohne Zeit- und Volumenbegrenzung? DAS TOP ANGEBOT JETZT bei Arcor: g?nstig und schnell mit DSL - das All-Inclusive-Paket f?r clevere Doppel-Sparer, nur 39,85 ? inkl. DSL- und ISDN-Grundgeb?hr! http://www.arcor.de/rd/emf-dsl-2 From hugosantos at gmail.com Sun May 6 21:36:24 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Sun, 6 May 2007 20:36:24 +0100 Subject: [Haiku-commits] r21040 - in haiku/trunk: headers/os/drivers In-Reply-To: <27351094.1178476765082.JavaMail.ngmail@webmail12> References: <200705061508.l46F88lR000846@sheep.berlios.de> <9c46321e0705060811h47ab3333y92cba5382f479ff@mail.gmail.com> <27351094.1178476765082.JavaMail.ngmail@webmail12> Message-ID: <9c46321e0705061236y1f036dferf0f92ca90d52e2b2@mail.gmail.com> Hi Marcus, I'm not sure i follow you. You mean remove the functionality i added? It is quite similiar to what {install,remove}_io_interrupt_handler already do. Here 'disable' is in fact remove the handler from the interrupt handler list. The interrupt itself is only disabled if that was the only handler registered. Are you referring to perform degradation due to disabling a single IO interrupt? I'm also not aware of what BSD failures you are pointing to, i'm just trying to defer interrupt handling from interrupt context to a thread, which also possibly helps with interactivity. Regarding the effort of adding such functionality just to service an 'emulation layer', i would expect some understanding from your side in that point, considering the effort involved in porting drivers individually. Hugo On 5/6/07, Marcus Overhagen wrote: > Hugo Santos wrote: > > > Let me know what you think. > > > Seriously, I don't like that at all. > > I think this functionality should be removed from the kernel. Disabling an interrupt > can degrade performance, especially with interrupt sharing. I don't think we should > repeat BSDs failures just for an emulation layer. > > regards > Marcus > > Viel oder wenig? Schnell oder langsam? Unbegrenzt surfen + telefonieren > ohne Zeit- und Volumenbegrenzung? DAS TOP ANGEBOT JETZT bei Arcor: g?nstig > und schnell mit DSL - das All-Inclusive-Paket f?r clevere Doppel-Sparer, > nur 39,85 ? inkl. DSL- und ISDN-Grundgeb?hr! > http://www.arcor.de/rd/emf-dsl-2 > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From geist at foobox.com Sun May 6 21:58:53 2007 From: geist at foobox.com (Travis Geiselbrecht) Date: Sun, 6 May 2007 12:58:53 -0700 Subject: [Haiku-commits] r21040 - in haiku/trunk: headers/os/drivers In-Reply-To: <9c46321e0705061236y1f036dferf0f92ca90d52e2b2@mail.gmail.com> References: <200705061508.l46F88lR000846@sheep.berlios.de> <9c46321e0705060811h47ab3333y92cba5382f479ff@mail.gmail.com> <27351094.1178476765082.JavaMail.ngmail@webmail12> <9c46321e0705061236y1f036dferf0f92ca90d52e2b2@mail.gmail.com> Message-ID: I think the problem with the mechanism of disabling the interrupt at the interrupt controller for thread processing is that in a shared environment it'll still keep firing all the other handlers registered on that vector. It's almost always better to disable the interrupt delivery at the device itself while processing in a thread, and most sane devices support such a thing. Of course, most sane platforms don't share interrupts either. On May 6, 2007, at 12:36 PM, Hugo Santos wrote: > Hi Marcus, > > I'm not sure i follow you. You mean remove the functionality i > added? It is quite similiar to what > {install,remove}_io_interrupt_handler already do. Here 'disable' is in > fact remove the handler from the interrupt handler list. The interrupt > itself is only disabled if that was the only handler registered. Are > you referring to perform degradation due to disabling a single IO > interrupt? I'm also not aware of what BSD failures you are pointing > to, i'm just trying to defer interrupt handling from interrupt context > to a thread, which also possibly helps with interactivity. > > Regarding the effort of adding such functionality just to service an > 'emulation layer', i would expect some understanding from your side in > that point, considering the effort involved in porting drivers > individually. > > Hugo > > On 5/6/07, Marcus Overhagen wrote: >> Hugo Santos wrote: >> >>> Let me know what you think. >>> >> Seriously, I don't like that at all. >> >> I think this functionality should be removed from the kernel. >> Disabling an interrupt >> can degrade performance, especially with interrupt sharing. I >> don't think we should >> repeat BSDs failures just for an emulation layer. >> >> regards >> Marcus >> >> Viel oder wenig? Schnell oder langsam? Unbegrenzt surfen + >> telefonieren >> ohne Zeit- und Volumenbegrenzung? DAS TOP ANGEBOT JETZT bei Arcor: >> g?nstig >> und schnell mit DSL - das All-Inclusive-Paket f?r clevere Doppel- >> Sparer, >> nur 39,85 ? inkl. DSL- und ISDN-Grundgeb?hr! >> http://www.arcor.de/rd/emf-dsl-2 >> _______________________________________________ >> Haiku-commits mailing list >> Haiku-commits at lists.berlios.de >> https://lists.berlios.de/mailman/listinfo/haiku-commits >> > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits From hugosantos at gmail.com Sun May 6 22:29:09 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Sun, 6 May 2007 21:29:09 +0100 Subject: [Haiku-commits] r21040 - in haiku/trunk: headers/os/drivers In-Reply-To: References: <200705061508.l46F88lR000846@sheep.berlios.de> <9c46321e0705060811h47ab3333y92cba5382f479ff@mail.gmail.com> <27351094.1178476765082.JavaMail.ngmail@webmail12> <9c46321e0705061236y1f036dferf0f92ca90d52e2b2@mail.gmail.com> Message-ID: <9c46321e0705061329j2beb164s7d533b0a7d3c4af0@mail.gmail.com> Hi Travis, On 5/6/07, Travis Geiselbrecht wrote: > I think the problem with the mechanism of disabling the interrupt at > the interrupt controller for thread processing is that in a shared > environment it'll still keep firing all the other handlers registered > on that vector. It's almost always better to disable the interrupt > delivery at the device itself while processing in a thread, and most > sane devices support such a thing. I understand your point wrt to IRQ sharing, and it is indeed a problem. However disabling the interrupts per device has the following problems: requires per driver additional code (wrt to original freebsd code, but doable); most devices require serialized access to registers, how will i be able to guarantee a clean disable of interrupts without claiming the lock (being in interrupt handling context) and without leaving the device in an inconsistent state? pcnet for instance does the following to write out a command (to disable interrupts i would even need two): [pcnet] bus_space_write_2(0x0, 0x1080, 0x12, 0x0) [pcnet] bus_space_write_2(0x0, 0x1080, 0x10, 0x1b0) where bus_space_write_2 is (tag, handle, offset, value) -> out16(value, handle + offset) It is signaling a future command and then outputing it. I can't really push and pop state here. A possible solution for the IRQ sharing case is not allowing the IRQ to be shared by drivers when the compat. layer is used. I'm open for better ideas, Hugo From axeld at pinc-software.de Sun May 6 22:34:07 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Sun, 06 May 2007 22:34:07 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r21040_-_in_haiku/trunk=3A_header?= =?iso-8859-15?q?s/os/drivers_src/system/kernel?= In-Reply-To: <9c46321e0705060811h47ab3333y92cba5382f479ff@mail.gmail.com> Message-ID: <41657615171-BeMail@zon> "Hugo Santos" wrote: > Please let me know if you see anything wrong with these or if the > definitions should go elsewhere than KernelExport.h. I've added these > to be able to get the first interrupt and just defer the handling to > a > thread (check next commit). If i don't disable the interrupt it gets > hammered so heavily the thread is not even scheduled. Using the > current methods i couldn't free or remove the interrupt handler, so i > added these ones. I can't add much to what Marcus and Travis already said, just that KernelExport.h would be the wrong place for private additions. And I think it's perfectly acceptable to not be able to incorporate open-source drivers unchanged. Bye, Axel. From hugosantos at gmail.com Sun May 6 22:40:53 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Sun, 6 May 2007 21:40:53 +0100 Subject: [Haiku-commits] r21040 - in haiku/trunk: headers/os/drivers src/system/kernel In-Reply-To: <41657615171-BeMail@zon> References: <9c46321e0705060811h47ab3333y92cba5382f479ff@mail.gmail.com> <41657615171-BeMail@zon> Message-ID: <9c46321e0705061340j4393edebvc3d3fe7a10d5f506@mail.gmail.com> Hi Axel, On 5/6/07, Axel D?rfler wrote: > I can't add much to what Marcus and Travis already said, just that > KernelExport.h would be the wrong place for private additions. > And I think it's perfectly acceptable to not be able to incorporate > open-source drivers unchanged. Yes, i assumed KernelExport.h wasn't the best place, i'll move them to private/kernel/ as soon as this discussion is over and we decide whether they stay in or not. :-) I think they are necessary, as i pointed out in my previous email regarding to IRQ sharing and disabling interrupts per device. But if there are better solutions, i'll be glad to adopt them. Hugo From hugosantos at gmail.com Sun May 6 22:42:23 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Sun, 6 May 2007 21:42:23 +0100 Subject: [Haiku-commits] r21040 - in haiku/trunk: headers/os/drivers In-Reply-To: <9c46321e0705061329j2beb164s7d533b0a7d3c4af0@mail.gmail.com> References: <200705061508.l46F88lR000846@sheep.berlios.de> <9c46321e0705060811h47ab3333y92cba5382f479ff@mail.gmail.com> <27351094.1178476765082.JavaMail.ngmail@webmail12> <9c46321e0705061236y1f036dferf0f92ca90d52e2b2@mail.gmail.com> <9c46321e0705061329j2beb164s7d533b0a7d3c4af0@mail.gmail.com> Message-ID: <9c46321e0705061342o3bf2dd60oe082725f09c00a54@mail.gmail.com> On 5/6/07, Hugo Santos wrote: > interrupts without claiming the lock (being in interrupt handling This would be the driver's lock, that wasn't clear. Hugo From axeld at pinc-software.de Sun May 6 22:49:45 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Sun, 06 May 2007 22:49:45 +0200 CEST Subject: [Haiku-commits] r21040 - in haiku/trunk: headers/os/drivers In-Reply-To: <9c46321e0705061329j2beb164s7d533b0a7d3c4af0@mail.gmail.com> Message-ID: <42595691332-BeMail@zon> "Hugo Santos" wrote: > However disabling the interrupts per device has the following > problems: requires per driver additional code (wrt to original > freebsd > code, but doable); most devices require serialized access to > registers, how will i be able to guarantee a clean disable of > interrupts without claiming the lock (being in interrupt handling > context) and without leaving the device in an inconsistent state? You obviously can't use a semaphore, but you can (and must, in this case) use a spinlock. With interrupts turned off, the spinlock is only used in an SMP environment, anyway. > A possible solution for the IRQ sharing case is not allowing the > IRQ > to be shared by drivers when the compat. layer is used. The problem of your solution is that it just doesn't work for shared IRQs - and we currently cannot control how IRQs are chosen; we rely on the BIOS for this. Another problem is that you can easily lose IRQs when you disable them that way, though the drivers might already contain code to cope with that. Bye, Axel. From hugosantos at gmail.com Sun May 6 23:02:21 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Sun, 6 May 2007 22:02:21 +0100 Subject: [Haiku-commits] r21040 - in haiku/trunk: headers/os/drivers In-Reply-To: <42595691332-BeMail@zon> References: <9c46321e0705061329j2beb164s7d533b0a7d3c4af0@mail.gmail.com> <42595691332-BeMail@zon> Message-ID: <9c46321e0705061402ja9e20e0t30bc725de4364e1c@mail.gmail.com> On 5/6/07, Axel D?rfler wrote: > You obviously can't use a semaphore, but you can (and must, in this > case) use a spinlock. With interrupts turned off, the spinlock is only > used in an SMP environment, anyway. I considered this solution, but would rather not change the driver's lock a spinlock before asserting fully that the usage of mutexes is not possible. Besides having a lot of repercussions in the original driver's source, Haiku should scale well in multi processor environments. Handling the driver's interrupt handler with interrupts disabled also leads to other problems, including with the allocation and freeing of memory. What FreeBSD does is handling what it considers "non fast" interrupts in a dedicated thread. Not saying Haiku should copy of FreeBSD, I believe it is a good solution as it reduces possible latency and allows the kernel to schedule the pending work better, specially if we consider RT. And in this context i tried to mimic what the driver expects. > The problem of your solution is that it just doesn't work for shared > IRQs - and we currently cannot control how IRQs are chosen; we rely on > the BIOS for this. > Another problem is that you can easily lose IRQs when you disable them > that way, though the drivers might already contain code to cope with > that. I understand the problem, but does this mean the current solution isn't acceptable? Hugo From hugosantos at gmail.com Sun May 6 23:45:21 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Sun, 6 May 2007 22:45:21 +0100 Subject: [Haiku-commits] r21040 - in haiku/trunk: headers/os/drivers In-Reply-To: <9c46321e0705061402ja9e20e0t30bc725de4364e1c@mail.gmail.com> References: <9c46321e0705061329j2beb164s7d533b0a7d3c4af0@mail.gmail.com> <42595691332-BeMail@zon> <9c46321e0705061402ja9e20e0t30bc725de4364e1c@mail.gmail.com> Message-ID: <9c46321e0705061445v1ca08a9cka7fe097cd5d1dfdf@mail.gmail.com> After discussing a bit with Travis, and mostly through his input, the following was identified as a solution: Protect access to the device's registers which have the interrupt enabling/disabling capabilities with a spinlock, and disable the device interrupts in real interrupt context. This fixes the shared IRQ issues and allows the driver interrupt handler to be run in a separate thread outside real interrupt context. As most FreeBSD drivers have the register accessing functions clearly separated this can be done (generally) without much effort. Comments? Hugo On 5/6/07, Hugo Santos wrote: > On 5/6/07, Axel D?rfler wrote: > > You obviously can't use a semaphore, but you can (and must, in this > > case) use a spinlock. With interrupts turned off, the spinlock is only > > used in an SMP environment, anyway. > > I considered this solution, but would rather not change the driver's > lock a spinlock before asserting fully that the usage of mutexes is > not possible. Besides having a lot of repercussions in the original > driver's source, Haiku should scale well in multi processor > environments. Handling the driver's interrupt handler with interrupts > disabled also leads to other problems, including with the allocation > and freeing of memory. > > What FreeBSD does is handling what it considers "non fast" > interrupts in a dedicated thread. Not saying Haiku should copy of > FreeBSD, I believe it is a good solution as it reduces possible > latency and allows the kernel to schedule the pending work better, > specially if we consider RT. And in this context i tried to mimic what > the driver expects. > > > The problem of your solution is that it just doesn't work for shared > > IRQs - and we currently cannot control how IRQs are chosen; we rely on > > the BIOS for this. > > Another problem is that you can easily lose IRQs when you disable them > > that way, though the drivers might already contain code to cope with > > that. > > I understand the problem, but does this mean the current solution > isn't acceptable? > > Hugo > From hugosantos at mail.berlios.de Mon May 7 00:40:52 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Mon, 7 May 2007 00:40:52 +0200 Subject: [Haiku-commits] r21045 - in haiku/trunk/src: add-ons/kernel/drivers/network/pcnet/dev/le libs/compat/freebsd_network libs/compat/freebsd_network/compat/sys Message-ID: <200705062240.l46MeqJm004252@sheep.berlios.de> Author: hugosantos Date: 2007-05-07 00:40:19 +0200 (Mon, 07 May 2007) New Revision: 21045 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21045&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/if_le_pci.c haiku/trunk/src/libs/compat/freebsd_network/bus.c haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/device.h haiku/trunk/src/libs/compat/freebsd_network/if.c Log: freebsd compat. layer: instead of disabling the IRQ, disable the device's interrupts on real interrupt request as suggested by Travis. This solves potential issues with shared IRQs. The check & disable interrupts function is part of the required glue code. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c 2007-05-06 15:55:26 UTC (rev 21044) +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c 2007-05-06 22:40:19 UTC (rev 21045) @@ -1,3 +1,58 @@ #include +#include + +#include +#include +#include + +/* from if_le_pci.c */ +#define PCNET_PCI_RDP 0x10 +#define PCNET_PCI_RAP 0x12 + +struct le_pci_softc { + struct am79900_softc sc_am79900; /* glue to MI code */ + + int sc_rrid; + struct resource *sc_rres; + bus_space_tag_t sc_regt; + bus_space_handle_t sc_regh; + + int sc_irid; + struct resource *sc_ires; + void *sc_ih; + + bus_dma_tag_t sc_pdmat; + bus_dma_tag_t sc_dmat; + bus_dmamap_t sc_dmam; +}; + HAIKU_FBSD_DRIVER_GLUE(pcnet, le, pci) + +int HAIKU_CHECK_DISABLE_INTERRUPTS(device_t dev) { + struct le_pci_softc *lesc = (struct le_pci_softc *)device_get_softc(dev); + cpu_status status; + uint16_t value; + + HAIKU_INTR_REGISTER_ENTER(status); + + /* get current flags */ + bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, LE_CSR0); + bus_space_barrier(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, 2, + BUS_SPACE_BARRIER_WRITE); + value = bus_space_read_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RDP); + + /* is there a pending interrupt? */ + if (value & LE_C0_INTR) { + /* set the new flags, disable interrupts */ + bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, LE_CSR0); + bus_space_barrier(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, 2, + BUS_SPACE_BARRIER_WRITE); + bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RDP, + value & ~LE_C0_INEA); + } + + HAIKU_INTR_REGISTER_LEAVE(status); + + return value & LE_C0_INTR; +} Modified: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/if_le_pci.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/if_le_pci.c 2007-05-06 15:55:26 UTC (rev 21044) +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/if_le_pci.c 2007-05-06 22:40:19 UTC (rev 21045) @@ -195,22 +195,35 @@ le_pci_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) { struct le_pci_softc *lesc = (struct le_pci_softc *)sc; + cpu_status status = 0; + if (port == LE_CSR0) + HAIKU_INTR_REGISTER_ENTER(status); bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, port); bus_space_barrier(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, 2, BUS_SPACE_BARRIER_WRITE); bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RDP, val); + if (port == LE_CSR0) + HAIKU_INTR_REGISTER_LEAVE(status); } static uint16_t le_pci_rdcsr(struct lance_softc *sc, uint16_t port) { struct le_pci_softc *lesc = (struct le_pci_softc *)sc; + cpu_status status = 0; + uint16_t value; + if (port == LE_CSR0) + HAIKU_INTR_REGISTER_ENTER(status); bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, port); bus_space_barrier(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, 2, BUS_SPACE_BARRIER_WRITE); - return (bus_space_read_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RDP)); + value = bus_space_read_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RDP); + if (port == LE_CSR0) + HAIKU_INTR_REGISTER_LEAVE(status); + + return value; } static int Modified: haiku/trunk/src/libs/compat/freebsd_network/bus.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-06 15:55:26 UTC (rev 21044) +++ haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-06 22:40:19 UTC (rev 21045) @@ -31,12 +31,11 @@ struct internal_intr { + device_t dev; driver_intr_t handler; void *arg; int irq; - void *context; - thread_id thread; sem_id sem; }; @@ -176,11 +175,13 @@ intr_wrapper(void *data) { struct internal_intr *intr = data; - driver_printf("in interrupt handler.\n"); - disable_io_interrupt_handler(intr->context, B_IN_INTERRUPT_CONTEXT); + device_printf(intr->dev, "in interrupt handler.\n"); + + if (!HAIKU_CHECK_DISABLE_INTERRUPTS(intr->dev)) + return B_UNHANDLED_INTERRUPT; + release_sem_etc(intr->sem, 1, B_DO_NOT_RESCHEDULE); - return B_INVOKE_SCHEDULER; } @@ -192,19 +193,15 @@ status_t status; while (1) { - enable_io_interrupt_handler(intr->context); - status = acquire_sem(intr->sem); if (status < B_OK) break; - driver_printf("in soft interrupt handler.\n"); + device_printf(intr->dev, "in soft interrupt handler.\n"); intr->handler(intr->arg); } - disable_io_interrupt_handler(intr->context, 0); - return 0; } @@ -215,10 +212,6 @@ status_t status; delete_sem(intr->sem); wait_for_thread(intr->thread, &status); - - if (intr->context) - delete_io_interrupt_handler(intr->context); - free(intr); } @@ -234,11 +227,10 @@ char semName[64]; status_t status; - /* status_t status; */ - if (intr == NULL) return B_NO_MEMORY; + intr->dev = dev; intr->handler = handler; intr->arg = arg; intr->irq = res->handle; @@ -261,9 +253,7 @@ return B_NO_MEMORY; } - intr->context = NULL; - status = create_io_interrupt_handler(intr->irq, intr_wrapper, intr, - &intr->context); + status = install_io_interrupt_handler(intr->irq, intr_wrapper, intr, 0); if (status < B_OK) { free_internal_intr(intr); return status; @@ -281,7 +271,7 @@ bus_teardown_intr(device_t dev, struct resource *res, void *arg) { struct internal_intr *intr = arg; - /* remove_io_interrupt_handler(intr->irq, intr_wrapper, intr); */ + remove_io_interrupt_handler(intr->irq, intr_wrapper, intr); free_internal_intr(intr); return 0; } @@ -296,6 +286,15 @@ } +#define DEBUG_BUS_SPACE_RW + +#ifdef DEBUG_BUS_SPACE_RW +#define TRACE_BUS_SPACE_RW(x) driver_printf x +#else +#define TRACE_BUS_SPACE_RW(x) +#endif + + #define BUS_SPACE_READ(size, type, fun) \ type bus_space_read_##size(bus_space_tag_t tag, \ bus_space_handle_t handle, bus_size_t offset) \ @@ -305,6 +304,8 @@ value = fun(handle + offset); \ else \ value = *(volatile type *)(handle + offset); \ + TRACE_BUS_SPACE_RW(("bus_space_read_%s(0x%lx, 0x%lx, 0x%lx) = 0x%lx\n", \ + #size, (uint32)tag, (uint32)handle, (uint32)offset, (uint32)value)); \ return value; \ } @@ -312,6 +313,8 @@ void bus_space_write_##size(bus_space_tag_t tag, \ bus_space_handle_t handle, bus_size_t offset, type value) \ { \ + TRACE_BUS_SPACE_RW(("bus_space_write_%s(0x%lx, 0x%lx, 0x%lx, 0x%lx)\n", \ + #size, (uint32)tag, (uint32)handle, (uint32)offset, (uint32)value)); \ if (tag == I386_BUS_SPACE_IO) \ fun(value, handle + offset); \ else \ Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-06 15:55:26 UTC (rev 21044) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-06 22:40:19 UTC (rev 21045) @@ -74,6 +74,21 @@ const char **publish_devices() { return (const char **)gDevNameList; } \ device_hooks *find_device(const char *name) { return &gDeviceHooks; } +extern spinlock __haiku_intr_spinlock; +extern int __haiku_disable_interrupts(device_t dev); + +#define HAIKU_CHECK_DISABLE_INTERRUPTS __haiku_disable_interrupts + +#define HAIKU_INTR_REGISTER_ENTER(status) do { \ + status = disable_interrupts(); \ + acquire_spinlock(&__haiku_intr_spinlock); \ +} while (0) + +#define HAIKU_INTR_REGISTER_LEAVE(status) do { \ + release_spinlock(&__haiku_intr_spinlock); \ + restore_interrupts(status); \ +} while (0) + #define DEFINE_CLASS_0(name, driver, methods, size) \ driver_t driver = { #name, methods, size } Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-06 15:55:26 UTC (rev 21044) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-06 22:40:19 UTC (rev 21045) @@ -28,7 +28,7 @@ #define TRACE_PCI(dev, format, args...) do { } while (0) #endif -status_t init_compat_layer(void); +spinlock __haiku_intr_spinlock; struct net_stack_module_info *gStack; pci_module_info *gPci; @@ -224,10 +224,12 @@ int printf(const char *format, ...) { + char buf[256]; va_list vl; va_start(vl, format); - driver_vprintf(format, vl); + vsnprintf(buf, sizeof(buf), format, vl); va_end(vl); + dprintf(buf); return 0; } @@ -309,6 +311,7 @@ status_t init_compat_layer() { + __haiku_intr_spinlock = 0; return B_OK; } Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-06 15:55:26 UTC (rev 21044) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-06 22:40:19 UTC (rev 21045) @@ -16,6 +16,7 @@ #include +#include #include #include @@ -326,6 +327,8 @@ if (dev == NULL) return B_NO_MEMORY; + init_compat_layer(); + status = init_mutexes(); if (status < B_OK) { free_device(dev); Modified: haiku/trunk/src/libs/compat/freebsd_network/device.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-06 15:55:26 UTC (rev 21044) +++ haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-06 22:40:19 UTC (rev 21045) @@ -54,6 +54,8 @@ status_t init_mutexes(void); void uninit_mutexes(void); +status_t init_compat_layer(void); + /* busdma_machdep.c */ void init_bounce_pages(void); void uninit_bounce_pages(void); Modified: haiku/trunk/src/libs/compat/freebsd_network/if.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-06 15:55:26 UTC (rev 21044) +++ haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-06 22:40:19 UTC (rev 21045) @@ -295,7 +295,8 @@ { static char etherbuf[18]; snprintf(etherbuf, sizeof (etherbuf), - "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", - ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]); + "%02x:%02x:%02x:%02x:%02x:%02x", + (uint32)ap[0], (uint32)ap[1], (uint32)ap[2], (uint32)ap[3], + (uint32)ap[4], (uint32)ap[5]); return (etherbuf); } From hugosantos at mail.berlios.de Mon May 7 00:41:09 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Mon, 7 May 2007 00:41:09 +0200 Subject: [Haiku-commits] r21046 - in haiku/trunk: headers/os/drivers src/system/kernel Message-ID: <200705062241.l46Mf9Oa004793@sheep.berlios.de> Author: hugosantos Date: 2007-05-07 00:40:52 +0200 (Mon, 07 May 2007) New Revision: 21046 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21046&view=rev Modified: haiku/trunk/headers/os/drivers/KernelExport.h haiku/trunk/src/system/kernel/int.c Log: the previously added IO interrupt handling routines are no longer necessary, at least for now. Modified: haiku/trunk/headers/os/drivers/KernelExport.h =================================================================== --- haiku/trunk/headers/os/drivers/KernelExport.h 2007-05-06 22:40:19 UTC (rev 21045) +++ haiku/trunk/headers/os/drivers/KernelExport.h 2007-05-06 22:40:52 UTC (rev 21046) @@ -54,18 +54,6 @@ interrupt_handler handler, void *data); -/* Private, Haiku specific */ - -/* Flags that can be passwd to disable_io_interrupt_handle() */ -#define B_IN_INTERRUPT_CONTEXT 1 - -extern status_t create_io_interrupt_handler(long interrupt_number, - interrupt_handler handler, void *data, void **context); -void enable_io_interrupt_handler(void *context); -void disable_io_interrupt_handler(void *context, uint32 flags); -void delete_io_interrupt_handler(void *context); - - /*-------------------------------------------------------------*/ /* timer interrupts services */ Modified: haiku/trunk/src/system/kernel/int.c =================================================================== --- haiku/trunk/src/system/kernel/int.c 2007-05-06 22:40:19 UTC (rev 21045) +++ haiku/trunk/src/system/kernel/int.c 2007-05-06 22:40:52 UTC (rev 21046) @@ -31,7 +31,6 @@ struct io_handler { struct io_handler *next; struct io_handler *prev; - long vector; interrupt_handler func; void *data; bool use_enable_counter; @@ -145,17 +144,41 @@ status_t install_io_interrupt_handler(long vector, interrupt_handler handler, void *data, ulong flags) { - struct io_handler *io; - status_t status; + struct io_handler *io = NULL; + cpu_status state; - status = create_io_interrupt_handler(vector, handler, data, (void **)&io); - if (status < B_OK) - return status; + if (vector < 0 || vector >= NUM_IO_VECTORS) + return B_BAD_VALUE; + io = (struct io_handler *)malloc(sizeof(struct io_handler)); + if (io == NULL) + return B_NO_MEMORY; + + arch_debug_remove_interrupt_handler(vector); + // There might be a temporary debug interrupt installed on this + // vector that should be removed now. + + io->func = handler; + io->data = data; io->use_enable_counter = (flags & B_NO_ENABLE_COUNTER) == 0; - enable_io_interrupt_handler(io); + // Disable the interrupts, get the spinlock for this irq only + // and then insert the handler + state = disable_interrupts(); + acquire_spinlock(&io_vectors[vector].vector_lock); + insque(io, &io_vectors[vector].handler_list); + + // If B_NO_ENABLE_COUNTER is set, we're being asked to not alter + // whether the interrupt should be enabled or not + if (io->use_enable_counter) { + if (io_vectors[vector].enable_count++ == 0) + arch_int_enable_io_interrupt(vector); + } + + release_spinlock(&io_vectors[vector].vector_lock); + restore_interrupts(state); + return B_OK; } @@ -207,90 +230,6 @@ } -status_t -create_io_interrupt_handler(long vector, interrupt_handler handler, void *data, - void **context) -{ - struct io_handler *io = NULL; - - if (vector < 0 || vector >= NUM_IO_VECTORS) - return B_BAD_VALUE; - - io = (struct io_handler *)malloc(sizeof(struct io_handler)); - if (io == NULL) - return B_NO_MEMORY; - - io->vector = vector; - io->func = handler; - io->data = data; - io->use_enable_counter = true; - - *context = io; - return B_OK; -} - - -void -enable_io_interrupt_handler(void *context) -{ - struct io_handler *io = context; - long vector = io->vector; - cpu_status state; - - // Disable the interrupts, get the spinlock for this irq only - // and then insert the handler - state = disable_interrupts(); - acquire_spinlock(&io_vectors[vector].vector_lock); - - insque(io, &io_vectors[vector].handler_list); - - // If B_NO_ENABLE_COUNTER is set, we're being asked to not alter - // whether the interrupt should be enabled or not - if (io->use_enable_counter) { - if (io_vectors[vector].enable_count++ == 0) - arch_int_enable_io_interrupt(vector); - } - - release_spinlock(&io_vectors[vector].vector_lock); - restore_interrupts(state); -} - - -void -disable_io_interrupt_handler(void *context, uint32 flags) -{ - struct io_handler *io = context; - long vector = io->vector; - cpu_status state = 0; - - if ((flags & B_IN_INTERRUPT_CONTEXT) == 0) { - /* lock the structures down so it is not modified while we search */ - state = disable_interrupts(); - acquire_spinlock(&io_vectors[vector].vector_lock); - } - - remque(io); - - // Check if we need to disable the interrupt - if (io->use_enable_counter && --io_vectors[vector].enable_count == 0) - arch_int_disable_io_interrupt(vector); - - if ((flags & B_IN_INTERRUPT_CONTEXT) == 0) { - release_spinlock(&io_vectors[vector].vector_lock); - restore_interrupts(state); - } -} - - -void -delete_io_interrupt_handler(void *context) -{ - struct io_handler *io = context; - - free(io); -} - - /** actually process an interrupt via the handlers registered for that * vector (irq) */ @@ -320,10 +259,9 @@ * whatever the driver thought would be useful (ie. B_INVOKE_SCHEDULER) */ - io = io_vectors[vector].handler_list.next; - while (io != &io_vectors[vector].handler_list) { - struct io_handler *next = io->next; - + for (io = io_vectors[vector].handler_list.next; + io != &io_vectors[vector].handler_list; // Are we already at the end of the list? + io = io->next) { status = io->func(io->data); if (levelTriggered && status != B_UNHANDLED_INTERRUPT) @@ -333,8 +271,6 @@ handled = true; else if (status == B_INVOKE_SCHEDULER) invokeScheduler = true; - - io = next; } #ifdef DEBUG_INT From hugosantos at mail.berlios.de Mon May 7 05:21:29 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Mon, 7 May 2007 05:21:29 +0200 Subject: [Haiku-commits] r21047 - in haiku/trunk/src: add-ons/kernel/drivers/network/pcnet/dev/le libs/compat/freebsd_network libs/compat/freebsd_network/compat/sys libs/compat/freebsd_network/compat/vm Message-ID: <200705070321.l473LTZ6017923@sheep.berlios.de> Author: hugosantos Date: 2007-05-07 05:20:58 +0200 (Mon, 07 May 2007) New Revision: 21047 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21047&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am79900.c haiku/trunk/src/libs/compat/freebsd_network/Jamfile haiku/trunk/src/libs/compat/freebsd_network/busdma_machdep.c haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/compat/sys/endian.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/ktr.h haiku/trunk/src/libs/compat/freebsd_network/compat/vm/vm.h haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/if.c haiku/trunk/src/libs/compat/freebsd_network/if_media.c Log: freebsd compat. layer: couple fixes, sending now works with PCNET. enabled ifmedia_ioctl, and when opening a device, set it down, change media to ETHER/AUTO and set it back up so it sees a IFF_UP. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/Jamfile 2007-05-06 22:40:52 UTC (rev 21046) +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/Jamfile 2007-05-07 03:20:58 UTC (rev 21047) @@ -7,7 +7,7 @@ UseHeaders [ FDirName $(SUBDIR) .. .. ] : true ; UseHeaders [ FDirName $(HAIKU_TOP) src libs compat freebsd_network compat ] : true ; -SubDirCcFlags [ FDefines _KERNEL=1 ] ; +SubDirCcFlags [ FDefines _KERNEL=1 LEDEBUG=128 ] ; KernelAddon pcnet : am7990.c Modified: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am79900.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am79900.c 2007-05-06 22:40:52 UTC (rev 21046) +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am79900.c 2007-05-07 03:20:58 UTC (rev 21047) @@ -172,6 +172,8 @@ if (mem > sc->lsc.sc_memsize) panic("%s: memsize", __func__); + sc->lsc.sc_flags |= LE_DEBUG; + lance_attach(&sc->lsc); return (0); @@ -450,10 +452,12 @@ if (sc->sc_flags & LE_DEBUG) if_printf(ifp, "%s: entering with isr=%04x\n", __func__, isr); #endif +#if 0 if ((isr & LE_C0_INTR) == 0) { LE_UNLOCK(sc); return; } +#endif /* * Clear interrupt source flags and turn off interrupts. If we Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-06 22:40:52 UTC (rev 21046) +++ haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-07 03:20:58 UTC (rev 21047) @@ -5,7 +5,7 @@ UseHeaders [ FDirName $(SUBDIR) ] : true ; UseHeaders [ FDirName $(SUBDIR) compat ] : true ; -SubDirCcFlags [ FDefines _KERNEL=1 ] ; +SubDirCcFlags [ FDefines _KERNEL=1 KTR=1 ] ; Library libfreebsd_network.a : bus.c Modified: haiku/trunk/src/libs/compat/freebsd_network/busdma_machdep.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/busdma_machdep.c 2007-05-06 22:40:52 UTC (rev 21046) +++ haiku/trunk/src/libs/compat/freebsd_network/busdma_machdep.c 2007-05-07 03:20:58 UTC (rev 21047) @@ -528,7 +528,7 @@ printf("bus_dmamem_alloc failed to align memory properly.\n"); } CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", - __func__, dmat, dmat->flags, ENOMEM); + __func__, dmat, dmat->flags, 0); return (0); } Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/endian.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/endian.h 2007-05-06 22:40:52 UTC (rev 21046) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/endian.h 2007-05-07 03:20:58 UTC (rev 21047) @@ -58,7 +58,7 @@ * Host to big endian, host to little endian, big endian to host, and little * endian to host byte order functions as detailed in byteorder(9). */ -#if _YTE_ORDER == _LITTLE_ENDIAN +#if _BYTE_ORDER == _LITTLE_ENDIAN #define htobe16(x) bswap16((x)) #define htobe32(x) bswap32((x)) #define htobe64(x) bswap64((x)) Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/ktr.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/ktr.h 2007-05-06 22:40:52 UTC (rev 21046) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/ktr.h 2007-05-07 03:20:58 UTC (rev 21047) @@ -128,9 +128,15 @@ #ifdef KTR +#if 0 void ktr_tracepoint(u_int mask, const char *file, int line, const char *format, u_long arg1, u_long arg2, u_long arg3, u_long arg4, u_long arg5, u_long arg6); +#else +extern void driver_printf(const char *format, ...); +#define ktr_tracepoint(mask, file, line, format, arg1, arg2, arg3, arg4, arg5, arg6) \ + driver_printf("(%s:%i) " format "\n", file, line, arg1, arg2, arg3, arg4, arg5, arg6) +#endif #define CTR6(m, format, p1, p2, p3, p4, p5, p6) do { \ if (KTR_COMPILE & (m)) \ Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/vm/vm.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/vm/vm.h 2007-05-06 22:40:52 UTC (rev 21046) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/vm/vm.h 2007-05-07 03:20:58 UTC (rev 21047) @@ -17,19 +17,6 @@ #define pmap_kextract(vaddr) vtophys(vaddr) -/* Marcus' vtophys */ -static inline unsigned long -vtophys(vm_offset_t vaddr) -{ - physical_entry pe; - status_t status; +unsigned long vtophys(vm_offset_t vaddr); - status = get_memory_map((void *)vaddr, 1, &pe, 1); - if (status < 0) - panic("fbsd compat: get_memory_map failed for %p, error %08lx\n", - (void *)vaddr, status); - - return (unsigned long)pe.address; -} - #endif Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-06 22:40:52 UTC (rev 21046) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-07 03:20:58 UTC (rev 21047) @@ -293,10 +293,13 @@ snprintf(name, sizeof(name), "contig:%s:%d", file, line); area = create_area(name, &addr, B_ANY_KERNEL_ADDRESS, size, - B_FULL_LOCK | B_CONTIGUOUS, 0); + B_FULL_LOCK | B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA); if (area < 0) return NULL; + driver_printf("(%s) addr = %p, area = %d, size = %lu\n", + name, addr, area, size); + return addr; } @@ -308,6 +311,21 @@ } +/* Marcus' vtophys */ +unsigned long +vtophys(vm_offset_t vaddr) +{ + physical_entry pe; + status_t status; + + status = get_memory_map((void *)vaddr, 1, &pe, 1); + if (status < 0) + panic("fbsd compat: get_memory_map failed for %p, error %08lx\n", + (void *)vaddr, status); + + return (unsigned long)pe.address; +} + status_t init_compat_layer() { Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-06 22:40:52 UTC (rev 21046) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-07 03:20:58 UTC (rev 21047) @@ -14,6 +14,8 @@ #include #include +#include + #include #include @@ -118,6 +120,21 @@ driver_printf(" ... status = 0x%ld\n", status); + if (status == 0) { + struct ifnet *ifp = dev->ifp; + struct ifreq ifr; + + ifp->if_flags = 0; + ifp->if_ioctl(ifp, SIOCSIFFLAGS, NULL); + + memset(&ifr, 0, sizeof(ifr)); + ifr.ifr_media = IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, 0); + ifp->if_ioctl(ifp, SIOCSIFMEDIA, &ifr); + + ifp->if_flags = IFF_UP; + ifp->if_ioctl(ifp, SIOCSIFFLAGS, NULL); + } + *cookie = dev; return status; Modified: haiku/trunk/src/libs/compat/freebsd_network/if.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-06 22:40:52 UTC (rev 21046) +++ haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-07 03:20:58 UTC (rev 21047) @@ -295,7 +295,7 @@ { static char etherbuf[18]; snprintf(etherbuf, sizeof (etherbuf), - "%02x:%02x:%02x:%02x:%02x:%02x", + "%02lx:%02lx:%02lx:%02lx:%02lx:%02lx", (uint32)ap[0], (uint32)ap[1], (uint32)ap[2], (uint32)ap[3], (uint32)ap[4], (uint32)ap[5]); return (etherbuf); Modified: haiku/trunk/src/libs/compat/freebsd_network/if_media.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/if_media.c 2007-05-06 22:40:52 UTC (rev 21046) +++ haiku/trunk/src/libs/compat/freebsd_network/if_media.c 2007-05-07 03:20:58 UTC (rev 21047) @@ -62,11 +62,13 @@ * Useful for debugging newly-ported drivers. */ +#define IFMEDIA_DEBUG + static struct ifmedia_entry *ifmedia_match(struct ifmedia *ifm, int flags, int mask); #ifdef IFMEDIA_DEBUG -int ifmedia_debug = 0; +int ifmedia_debug = 1; static void ifmedia_printword(int); #endif @@ -198,7 +200,6 @@ struct ifmedia *ifm; u_long cmd; { -#if 0 struct ifmedia_entry *match; struct ifmediareq *ifmr = (struct ifmediareq *) ifr; int error = 0, sticky; @@ -330,9 +331,13 @@ */ sticky = error; if ((error == 0 || error == E2BIG) && ifmr->ifm_count != 0) { +#if 0 error = copyout((caddr_t)kptr, (caddr_t)ifmr->ifm_ulist, ifmr->ifm_count * sizeof(int)); +#endif + /* this ioctl() is only called from within the kernel -hugo */ + memcpy(kptr, ifmr->ifm_ulist, ifmr->ifm_count * sizeof(int)); } if (error == 0) @@ -350,8 +355,6 @@ } return (error); -#endif - return ENOTSUP; } /* From hugosantos at mail.berlios.de Mon May 7 07:28:55 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Mon, 7 May 2007 07:28:55 +0200 Subject: [Haiku-commits] r21048 - in haiku/trunk/src: add-ons/kernel/drivers/network/pcnet/dev/le libs/compat/freebsd_network Message-ID: <200705070528.l475Stbw006980@sheep.berlios.de> Author: hugosantos Date: 2007-05-07 07:28:38 +0200 (Mon, 07 May 2007) New Revision: 21048 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21048&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am79900.c haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/lancevar.h haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/if.c Log: freebsd compat. layer: now both receiving and sending work with PCNET. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am79900.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am79900.c 2007-05-07 03:20:58 UTC (rev 21047) +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am79900.c 2007-05-07 05:28:38 UTC (rev 21048) @@ -447,17 +447,25 @@ return; } +#if 0 isr = (*sc->sc_rdcsr)(sc, LE_CSR0); +#endif + { + cpu_status status; + HAIKU_INTR_REGISTER_ENTER(status); + isr = sc->sc_lastisr; + sc->sc_lastisr = 0; + HAIKU_INTR_REGISTER_LEAVE(status); + } + #if defined(LEDEBUG) && LEDEBUG > 1 if (sc->sc_flags & LE_DEBUG) if_printf(ifp, "%s: entering with isr=%04x\n", __func__, isr); #endif -#if 0 if ((isr & LE_C0_INTR) == 0) { LE_UNLOCK(sc); return; } -#endif /* * Clear interrupt source flags and turn off interrupts. If we Modified: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c 2007-05-07 03:20:58 UTC (rev 21047) +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c 2007-05-07 05:28:38 UTC (rev 21048) @@ -50,6 +50,7 @@ BUS_SPACE_BARRIER_WRITE); bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RDP, value & ~LE_C0_INEA); + lesc->sc_am79900.lsc.sc_lastisr |= value; } HAIKU_INTR_REGISTER_LEAVE(status); Modified: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/lancevar.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/lancevar.h 2007-05-07 03:20:58 UTC (rev 21047) +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/lancevar.h 2007-05-07 05:28:38 UTC (rev 21048) @@ -119,6 +119,8 @@ #define LE_CARRIER (1 << 2) #define LE_DEBUG (1 << 3) #define LE_PROMISC (1 << 4) + + uint16_t sc_lastisr; }; #define LE_LOCK_INIT(_sc, _name) \ Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-07 03:20:58 UTC (rev 21047) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-07 05:28:38 UTC (rev 21048) @@ -198,11 +198,13 @@ len = min_c(max_c((size_t)mb->m_len, 0), *numBytes); +#if 0 mb = m_defrag(mb, 0); if (mb == NULL) { *numBytes = 0; return B_NO_MEMORY; } +#endif memcpy(buf, mtod(mb, const void *), len); *numBytes = len; Modified: haiku/trunk/src/libs/compat/freebsd_network/if.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-07 03:20:58 UTC (rev 21047) +++ haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-07 05:28:38 UTC (rev 21048) @@ -161,7 +161,7 @@ static void ether_input(struct ifnet *ifp, struct mbuf *m) { - device_t dev = NULL; /* XXX */ + device_t dev = ifp->if_dev; IF_ENQUEUE(&dev->receive_queue, m); release_sem_etc(dev->receive_sem, 1, B_DO_NOT_RESCHEDULE); From hugosantos at mail.berlios.de Mon May 7 07:29:06 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Mon, 7 May 2007 07:29:06 +0200 Subject: [Haiku-commits] r21049 - in haiku/trunk: headers/posix/net src/bin/network/ifconfig Message-ID: <200705070529.l475T6NL007005@sheep.berlios.de> Author: hugosantos Date: 2007-05-07 07:28:55 +0200 (Mon, 07 May 2007) New Revision: 21049 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21049&view=rev Modified: haiku/trunk/headers/posix/net/if_media.h haiku/trunk/src/bin/network/ifconfig/ifconfig.cpp Log: added IFM_AUTO to if_media and ifconfig. Modified: haiku/trunk/headers/posix/net/if_media.h =================================================================== --- haiku/trunk/headers/posix/net/if_media.h 2007-05-07 05:28:38 UTC (rev 21048) +++ haiku/trunk/headers/posix/net/if_media.h 2007-05-07 05:28:55 UTC (rev 21049) @@ -26,6 +26,7 @@ /* Media subtypes */ /* Ethernet */ +#define IFM_AUTO 0 #define IFM_10_T 3 /* 10Base-T - RJ45 */ #define IFM_100_TX 6 /* 100Base-TX - RJ45 */ #define IFM_1000_T 16 /* 1000Base-T - RJ45 */ Modified: haiku/trunk/src/bin/network/ifconfig/ifconfig.cpp =================================================================== --- haiku/trunk/src/bin/network/ifconfig/ifconfig.cpp 2007-05-07 05:28:38 UTC (rev 21048) +++ haiku/trunk/src/bin/network/ifconfig/ifconfig.cpp 2007-05-07 05:28:55 UTC (rev 21049) @@ -223,6 +223,9 @@ switch (IFM_TYPE(request.ifr_media)) { case IFM_ETHER: switch (IFM_SUBTYPE(request.ifr_media)) { + case IFM_AUTO: + type = "Auto-select"; + break; case IFM_10_T: type = "10 MBit, 10BASE-T"; break; From hugosantos at mail.berlios.de Mon May 7 07:29:17 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Mon, 7 May 2007 07:29:17 +0200 Subject: [Haiku-commits] r21050 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/net Message-ID: <200705070529.l475THcf007043@sheep.berlios.de> Author: hugosantos Date: 2007-05-07 07:29:06 +0200 (Mon, 07 May 2007) New Revision: 21050 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21050&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_media.h haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/device.h haiku/trunk/src/libs/compat/freebsd_network/if.c Log: freebsd compat. layer: added ETHER_SETPROMISC, ETHER_GET_LINK_STATE and ETHER_SET_LINK_STATE_SEM support. Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_media.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_media.h 2007-05-07 05:28:55 UTC (rev 21049) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_media.h 2007-05-07 05:29:06 UTC (rev 21050) @@ -267,8 +267,8 @@ /* * Status bits */ -#define IFM_AVALID 0x00000001 /* Active bit valid */ -#define IFM_ACTIVE 0x00000002 /* Interface attached to working net */ +#define IFM_AVALID 0x10000000 /* Active bit valid */ +#define IFM_ACTIVE 0x00800000 /* same as Haiku's */ /* Mask of "status valid" bits, for ifconfig(8). */ #define IFM_STATUS_VALID IFM_AVALID Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-07 05:28:55 UTC (rev 21049) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-07 05:29:06 UTC (rev 21050) @@ -61,6 +61,8 @@ return NULL; } + dev->link_state_sem = -1; + ifq_init(&dev->receive_queue, semName); return dev; @@ -241,29 +243,47 @@ compat_control(void *cookie, uint32 op, void *arg, size_t len) { device_t dev = cookie; + struct ifnet *ifp = dev->ifp; switch (op) { case ETHER_INIT: return B_OK; case ETHER_GETADDR: - memcpy(arg, IF_LLADDR(dev->ifp), ETHER_ADDR_LEN); - return B_OK; + return user_memcpy(arg, IF_LLADDR(dev->ifp), ETHER_ADDR_LEN); case ETHER_NONBLOCK: - if (*(int32 *)arg) + { + int32 value; + if (len < 4) + return B_BAD_VALUE; + if (user_memcpy(&value, arg, sizeof(int32)) < B_OK) + return B_BAD_ADDRESS; + if (value) dev->flags |= DEVICE_NON_BLOCK; else dev->flags &= ~DEVICE_NON_BLOCK; return B_OK; + } case ETHER_SETPROMISC: - /* TODO */ - return B_ERROR; + { + int32 value; + if (len < 4) + return B_BAD_VALUE; + if (user_memcpy(&value, arg, sizeof(int32)) < B_OK) + return B_BAD_ADDRESS; + if (value) + ifp->if_flags |= IFF_PROMISC; + else + ifp->if_flags &= ~IFF_PROMISC; + return ifp->if_ioctl(ifp, SIOCSIFFLAGS, NULL); + } case ETHER_GETFRAMESIZE: - *(uint32 *)arg = dev->ifp->if_mtu; - return B_OK; + if (len < 4) + return B_BAD_VALUE; + return user_memcpy(arg, &dev->ifp->if_mtu, 4); case ETHER_ADDMULTI: case ETHER_REMMULTI: @@ -271,11 +291,38 @@ return B_ERROR; case ETHER_GET_LINK_STATE: - /* TODO */ - return B_ERROR; + { + struct ifmediareq mediareq; + ether_link_state_t state; + status_t status; + if (len < sizeof(ether_link_state_t)) + return EINVAL; + + memset(&mediareq, 0, sizeof(mediareq)); + status = ifp->if_ioctl(ifp, SIOCGIFMEDIA, &mediareq); + if (status < B_OK) + return status; + + state.media = mediareq.ifm_active; + if (mediareq.ifm_status & IFM_ACTIVE) + state.media |= IFM_ACTIVE; + if (mediareq.ifm_active & IFM_10_T) + state.speed = 10000; + else if (mediareq.ifm_active & IFM_100_TX) + state.speed = 100000; + else + state.speed = 1000000; + state.quality = 1000; + + return user_memcpy(arg, &state, sizeof(ether_link_state_t)); + } + case ETHER_SET_LINK_STATE_SEM: - /* TODO */ + if (user_memcpy(&dev->link_state_sem, arg, sizeof(sem_id)) < B_OK) { + dev->link_state_sem = -1; + return B_BAD_ADDRESS; + } return B_OK; } Modified: haiku/trunk/src/libs/compat/freebsd_network/device.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-07 05:28:55 UTC (rev 21049) +++ haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-07 05:29:06 UTC (rev 21050) @@ -32,6 +32,8 @@ struct ifqueue receive_queue; sem_id receive_sem; + sem_id link_state_sem; + struct ifnet * ifp; int unit; Modified: haiku/trunk/src/libs/compat/freebsd_network/if.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-07 05:28:55 UTC (rev 21049) +++ haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-07 05:29:06 UTC (rev 21050) @@ -143,8 +143,7 @@ ifp->if_link_state = link_state; - /* XXX */ - /* wake network stack's link state sem */ + release_sem_etc(ifp->if_dev->link_state_sem, 1, B_DO_NOT_RESCHEDULE); } From hugosantos at gmail.com Mon May 7 07:44:50 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Mon, 7 May 2007 06:44:50 +0100 Subject: [Haiku-commits] r21045 - in haiku/trunk/src: add-ons/kernel/drivers/network/pcnet/dev/le libs/compat/freebsd_network libs/compat/freebsd_network/compat/sys In-Reply-To: <200705062240.l46MeqJm004252@sheep.berlios.de> References: <200705062240.l46MeqJm004252@sheep.berlios.de> Message-ID: <9c46321e0705062244u6289320by6ba3129c0a98b562@mail.gmail.com> Unfortunately this probably won't work for the general case either. I was looking at more drivers and disabling the device interrupts while keeping the rest of the bits set will be hard. 3com cards for instance (if_xl) require that the interrupts be acknowledged, and the status bits are consumed in the process. PCNET also consumes the interrupt bits when i disable interrupts. I worked around this by keeping a mask of the last bits seen in interrupt context, which works for this particular driver. The generic disable IRQ would work but has the problems which already discussed wtr to shared interrupts. Anyone has a better idea? Would be nice to have a generic solution for this. I'm afraid that in some cases, where per-interrupt values are relevant, some sort of interrupt ring buffer of values will need to be used (ugh). How do people feel about the possibility of the compat. layer checking if the IRQ the device uses is shared, and in that case fail to init. At least for the cases where 'disable interrupts per device' isn't possible. A bit of status update, in terms of the code itself, PCNET now works completely, for both send and receive. The only modifications to the base driver code were adding the spinlock around accesses to the status register related with interrupt disabling as mentioned before. My next go will be at a driver that uses DMA. Hugo On 5/6/07, hugosantos at mail.berlios.de wrote: > Author: hugosantos > Date: 2007-05-07 00:40:19 +0200 (Mon, 07 May 2007) > New Revision: 21045 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21045&view=rev > > Modified: > haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c > haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/if_le_pci.c > haiku/trunk/src/libs/compat/freebsd_network/bus.c > haiku/trunk/src/libs/compat/freebsd_network/compat.c > haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h > haiku/trunk/src/libs/compat/freebsd_network/device.c > haiku/trunk/src/libs/compat/freebsd_network/device.h > haiku/trunk/src/libs/compat/freebsd_network/if.c > Log: > freebsd compat. layer: instead of disabling the IRQ, disable the device's interrupts on real interrupt request as suggested by Travis. This solves potential issues with shared IRQs. The check & disable interrupts function is part of the required glue code. > > > Modified: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c > =================================================================== > --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c 2007-05-06 15:55:26 UTC (rev 21044) > +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c 2007-05-06 22:40:19 UTC (rev 21045) > @@ -1,3 +1,58 @@ > #include > > +#include > + > +#include > +#include > +#include > + > +/* from if_le_pci.c */ > +#define PCNET_PCI_RDP 0x10 > +#define PCNET_PCI_RAP 0x12 > + > +struct le_pci_softc { > + struct am79900_softc sc_am79900; /* glue to MI code */ > + > + int sc_rrid; > + struct resource *sc_rres; > + bus_space_tag_t sc_regt; > + bus_space_handle_t sc_regh; > + > + int sc_irid; > + struct resource *sc_ires; > + void *sc_ih; > + > + bus_dma_tag_t sc_pdmat; > + bus_dma_tag_t sc_dmat; > + bus_dmamap_t sc_dmam; > +}; > + > HAIKU_FBSD_DRIVER_GLUE(pcnet, le, pci) > + > +int HAIKU_CHECK_DISABLE_INTERRUPTS(device_t dev) { > + struct le_pci_softc *lesc = (struct le_pci_softc *)device_get_softc(dev); > + cpu_status status; > + uint16_t value; > + > + HAIKU_INTR_REGISTER_ENTER(status); > + > + /* get current flags */ > + bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, LE_CSR0); > + bus_space_barrier(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, 2, > + BUS_SPACE_BARRIER_WRITE); > + value = bus_space_read_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RDP); > + > + /* is there a pending interrupt? */ > + if (value & LE_C0_INTR) { > + /* set the new flags, disable interrupts */ > + bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, LE_CSR0); > + bus_space_barrier(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, 2, > + BUS_SPACE_BARRIER_WRITE); > + bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RDP, > + value & ~LE_C0_INEA); > + } > + > + HAIKU_INTR_REGISTER_LEAVE(status); > + > + return value & LE_C0_INTR; > +} > > Modified: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/if_le_pci.c > =================================================================== > --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/if_le_pci.c 2007-05-06 15:55:26 UTC (rev 21044) > +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/if_le_pci.c 2007-05-06 22:40:19 UTC (rev 21045) > @@ -195,22 +195,35 @@ > le_pci_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) > { > struct le_pci_softc *lesc = (struct le_pci_softc *)sc; > + cpu_status status = 0; > > + if (port == LE_CSR0) > + HAIKU_INTR_REGISTER_ENTER(status); > bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, port); > bus_space_barrier(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, 2, > BUS_SPACE_BARRIER_WRITE); > bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RDP, val); > + if (port == LE_CSR0) > + HAIKU_INTR_REGISTER_LEAVE(status); > } > > static uint16_t > le_pci_rdcsr(struct lance_softc *sc, uint16_t port) > { > struct le_pci_softc *lesc = (struct le_pci_softc *)sc; > + cpu_status status = 0; > + uint16_t value; > > + if (port == LE_CSR0) > + HAIKU_INTR_REGISTER_ENTER(status); > bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, port); > bus_space_barrier(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, 2, > BUS_SPACE_BARRIER_WRITE); > - return (bus_space_read_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RDP)); > + value = bus_space_read_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RDP); > + if (port == LE_CSR0) > + HAIKU_INTR_REGISTER_LEAVE(status); > + > + return value; > } > > static int > > Modified: haiku/trunk/src/libs/compat/freebsd_network/bus.c > =================================================================== > --- haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-06 15:55:26 UTC (rev 21044) > +++ haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-06 22:40:19 UTC (rev 21045) > @@ -31,12 +31,11 @@ > > > struct internal_intr { > + device_t dev; > driver_intr_t handler; > void *arg; > int irq; > > - void *context; > - > thread_id thread; > sem_id sem; > }; > @@ -176,11 +175,13 @@ > intr_wrapper(void *data) > { > struct internal_intr *intr = data; > - driver_printf("in interrupt handler.\n"); > > - disable_io_interrupt_handler(intr->context, B_IN_INTERRUPT_CONTEXT); > + device_printf(intr->dev, "in interrupt handler.\n"); > + > + if (!HAIKU_CHECK_DISABLE_INTERRUPTS(intr->dev)) > + return B_UNHANDLED_INTERRUPT; > + > release_sem_etc(intr->sem, 1, B_DO_NOT_RESCHEDULE); > - > return B_INVOKE_SCHEDULER; > } > > @@ -192,19 +193,15 @@ > status_t status; > > while (1) { > - enable_io_interrupt_handler(intr->context); > - > status = acquire_sem(intr->sem); > if (status < B_OK) > break; > > - driver_printf("in soft interrupt handler.\n"); > + device_printf(intr->dev, "in soft interrupt handler.\n"); > > intr->handler(intr->arg); > } > > - disable_io_interrupt_handler(intr->context, 0); > - > return 0; > } > > @@ -215,10 +212,6 @@ > status_t status; > delete_sem(intr->sem); > wait_for_thread(intr->thread, &status); > - > - if (intr->context) > - delete_io_interrupt_handler(intr->context); > - > free(intr); > } > > @@ -234,11 +227,10 @@ > char semName[64]; > status_t status; > > - /* status_t status; */ > - > if (intr == NULL) > return B_NO_MEMORY; > > + intr->dev = dev; > intr->handler = handler; > intr->arg = arg; > intr->irq = res->handle; > @@ -261,9 +253,7 @@ > return B_NO_MEMORY; > } > > - intr->context = NULL; > - status = create_io_interrupt_handler(intr->irq, intr_wrapper, intr, > - &intr->context); > + status = install_io_interrupt_handler(intr->irq, intr_wrapper, intr, 0); > if (status < B_OK) { > free_internal_intr(intr); > return status; > @@ -281,7 +271,7 @@ > bus_teardown_intr(device_t dev, struct resource *res, void *arg) > { > struct internal_intr *intr = arg; > - /* remove_io_interrupt_handler(intr->irq, intr_wrapper, intr); */ > + remove_io_interrupt_handler(intr->irq, intr_wrapper, intr); > free_internal_intr(intr); > return 0; > } > @@ -296,6 +286,15 @@ > } > > > +#define DEBUG_BUS_SPACE_RW > + > +#ifdef DEBUG_BUS_SPACE_RW > +#define TRACE_BUS_SPACE_RW(x) driver_printf x > +#else > +#define TRACE_BUS_SPACE_RW(x) > +#endif > + > + > #define BUS_SPACE_READ(size, type, fun) \ > type bus_space_read_##size(bus_space_tag_t tag, \ > bus_space_handle_t handle, bus_size_t offset) \ > @@ -305,6 +304,8 @@ > value = fun(handle + offset); \ > else \ > value = *(volatile type *)(handle + offset); \ > + TRACE_BUS_SPACE_RW(("bus_space_read_%s(0x%lx, 0x%lx, 0x%lx) = 0x%lx\n", \ > + #size, (uint32)tag, (uint32)handle, (uint32)offset, (uint32)value)); \ > return value; \ > } > > @@ -312,6 +313,8 @@ > void bus_space_write_##size(bus_space_tag_t tag, \ > bus_space_handle_t handle, bus_size_t offset, type value) \ > { \ > + TRACE_BUS_SPACE_RW(("bus_space_write_%s(0x%lx, 0x%lx, 0x%lx, 0x%lx)\n", \ > + #size, (uint32)tag, (uint32)handle, (uint32)offset, (uint32)value)); \ > if (tag == I386_BUS_SPACE_IO) \ > fun(value, handle + offset); \ > else \ > > Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h > =================================================================== > --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-06 15:55:26 UTC (rev 21044) > +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-06 22:40:19 UTC (rev 21045) > @@ -74,6 +74,21 @@ > const char **publish_devices() { return (const char **)gDevNameList; } \ > device_hooks *find_device(const char *name) { return &gDeviceHooks; } > > +extern spinlock __haiku_intr_spinlock; > +extern int __haiku_disable_interrupts(device_t dev); > + > +#define HAIKU_CHECK_DISABLE_INTERRUPTS __haiku_disable_interrupts > + > +#define HAIKU_INTR_REGISTER_ENTER(status) do { \ > + status = disable_interrupts(); \ > + acquire_spinlock(&__haiku_intr_spinlock); \ > +} while (0) > + > +#define HAIKU_INTR_REGISTER_LEAVE(status) do { \ > + release_spinlock(&__haiku_intr_spinlock); \ > + restore_interrupts(status); \ > +} while (0) > + > #define DEFINE_CLASS_0(name, driver, methods, size) \ > driver_t driver = { #name, methods, size } > > > Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c > =================================================================== > --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-06 15:55:26 UTC (rev 21044) > +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-06 22:40:19 UTC (rev 21045) > @@ -28,7 +28,7 @@ > #define TRACE_PCI(dev, format, args...) do { } while (0) > #endif > > -status_t init_compat_layer(void); > +spinlock __haiku_intr_spinlock; > > struct net_stack_module_info *gStack; > pci_module_info *gPci; > @@ -224,10 +224,12 @@ > int > printf(const char *format, ...) > { > + char buf[256]; > va_list vl; > va_start(vl, format); > - driver_vprintf(format, vl); > + vsnprintf(buf, sizeof(buf), format, vl); > va_end(vl); > + dprintf(buf); > > return 0; > } > @@ -309,6 +311,7 @@ > status_t > init_compat_layer() > { > + __haiku_intr_spinlock = 0; > return B_OK; > } > > > Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c > =================================================================== > --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-06 15:55:26 UTC (rev 21044) > +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-06 22:40:19 UTC (rev 21045) > @@ -16,6 +16,7 @@ > > #include > > +#include > #include > #include > > @@ -326,6 +327,8 @@ > if (dev == NULL) > return B_NO_MEMORY; > > + init_compat_layer(); > + > status = init_mutexes(); > if (status < B_OK) { > free_device(dev); > > Modified: haiku/trunk/src/libs/compat/freebsd_network/device.h > =================================================================== > --- haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-06 15:55:26 UTC (rev 21044) > +++ haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-06 22:40:19 UTC (rev 21045) > @@ -54,6 +54,8 @@ > status_t init_mutexes(void); > void uninit_mutexes(void); > > +status_t init_compat_layer(void); > + > /* busdma_machdep.c */ > void init_bounce_pages(void); > void uninit_bounce_pages(void); > > Modified: haiku/trunk/src/libs/compat/freebsd_network/if.c > =================================================================== > --- haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-06 15:55:26 UTC (rev 21044) > +++ haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-06 22:40:19 UTC (rev 21045) > @@ -295,7 +295,8 @@ > { > static char etherbuf[18]; > snprintf(etherbuf, sizeof (etherbuf), > - "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", > - ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]); > + "%02x:%02x:%02x:%02x:%02x:%02x", > + (uint32)ap[0], (uint32)ap[1], (uint32)ap[2], (uint32)ap[3], > + (uint32)ap[4], (uint32)ap[5]); > return (etherbuf); > } > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From leavengood at mail.berlios.de Mon May 7 07:48:31 2007 From: leavengood at mail.berlios.de (leavengood at BerliOS) Date: Mon, 7 May 2007 07:48:31 +0200 Subject: [Haiku-commits] r21051 - in haiku/trunk/src/preferences: . joysticks Message-ID: <200705070548.l475mVgM008436@sheep.berlios.de> Author: leavengood Date: 2007-05-07 07:48:30 +0200 (Mon, 07 May 2007) New Revision: 21051 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21051&view=rev Added: haiku/trunk/src/preferences/joysticks/ haiku/trunk/src/preferences/joysticks/CalibWin.cpp haiku/trunk/src/preferences/joysticks/CalibWin.h haiku/trunk/src/preferences/joysticks/Global.h haiku/trunk/src/preferences/joysticks/Jamfile haiku/trunk/src/preferences/joysticks/JoyWin.cpp haiku/trunk/src/preferences/joysticks/JoyWin.h haiku/trunk/src/preferences/joysticks/Joysticks.cpp haiku/trunk/src/preferences/joysticks/Joysticks.h haiku/trunk/src/preferences/joysticks/Joysticks.rdef haiku/trunk/src/preferences/joysticks/MessageWin.cpp haiku/trunk/src/preferences/joysticks/MessageWin.h haiku/trunk/src/preferences/joysticks/MessagedItem.h Modified: haiku/trunk/src/preferences/Jamfile Log: Initial check-in of Joysticks preferences, courtesy of Oliver Ruiz Dorantes. There is still work to be done. I did some code formatting as well as created the Jamfile and rdef. I copied the R5 Joysticks bitmap icons, but am working on a Haiku vector icon. For now I just copied the Fonts icon for purposes of having something in the rdef. Modified: haiku/trunk/src/preferences/Jamfile =================================================================== --- haiku/trunk/src/preferences/Jamfile 2007-05-07 05:29:06 UTC (rev 21050) +++ haiku/trunk/src/preferences/Jamfile 2007-05-07 05:48:30 UTC (rev 21051) @@ -8,6 +8,7 @@ SubInclude HAIKU_TOP src preferences dun ; SubInclude HAIKU_TOP src preferences filetypes ; SubInclude HAIKU_TOP src preferences fonts ; +SubInclude HAIKU_TOP src preferences joysticks ; SubInclude HAIKU_TOP src preferences keyboard ; SubInclude HAIKU_TOP src preferences keymap ; SubInclude HAIKU_TOP src preferences mail ; Added: haiku/trunk/src/preferences/joysticks/CalibWin.cpp =================================================================== --- haiku/trunk/src/preferences/joysticks/CalibWin.cpp 2007-05-07 05:29:06 UTC (rev 21050) +++ haiku/trunk/src/preferences/joysticks/CalibWin.cpp 2007-05-07 05:48:30 UTC (rev 21051) @@ -0,0 +1,101 @@ +/* + * Copyright 2007 Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * Ryan Leavengood, leavengood at gmail.com + */ + + +#include "CalibWin.h" + +#include +#include +#include +#include +#include +#include + +/* + All this code is here is just to not have an empty view at + Clicking the Calibrate function. + + All controls in this view needs to be created and placed dynamically according + with the Joystick descriptors +*/ + +CalibWin::CalibWin(BRect frame,const char *title, window_look look, + window_feel feel, uint32 flags, uint32 workspace) + : BWindow(frame,title,look,feel,flags,workspace) +{ + // Allocate object + fButton12 = new BButton(BRect(213.00,86.00,268.00,105.00),"Button12","Button",NULL); + fButton11 = new BButton(BRect(148.00,88.00,206.00,110.00),"Button11","Button",NULL); + fButton10 = new BButton(BRect(205.00,168.00,260.00,190.00),"Button10","Button",NULL); + fButton9 = new BButton(BRect(213.00,137.00,263.00,163.00),"Button9","Button", NULL); + fButton8 = new BButton(BRect(144.00,173.00,189.00,194.00),"Button8","Button",NULL); + fButton7 = new BButton(BRect(145.00,145.00,193.00,168.00),"Button7","Button",NULL); + fButton6 = new BButton(BRect(217.00,109.00,261.00,131.00),"Button6","Button",NULL); + fButton5 = new BButton(BRect(147.00,116.00,194.00,139.00),"Button5","Button",NULL); + fButton4 = new BButton(BRect(189.00,263.00,271.00,288.00),"Button4","Button",NULL); + fButton3 = new BButton(BRect(17.00,254.00,100.00,284.00),"Button3","Button",NULL); + + fStringView9 = new BStringView(BRect(8.00,175.00,116.00,190.00),"StringView9","Text"); + fStringView8 = new BStringView(BRect(10.00,154.00,112.00,172.00),"StringView8","Text"); + fStringView7 = new BStringView(BRect(9.00,132.00,116.00,148.00),"StringView7","Text"); + fStringView6 = new BStringView(BRect(11.00,114.00,120.00,128.00),"StringView6","Text"); + fStringView5 = new BStringView(BRect(11.00,93.00,121.00,108.00),"StringView5","Text"); + fStringView4 = new BStringView(BRect(12.00,73.00,121.00,88.00),"StringView4","Text"); + fStringView3 = new BStringView(BRect(26.00,17.00,258.00,45.00),"StringView3","Text3"); + + fBox = new BBox(BRect(12.00,7.00,280.00,67.00),"Box1", + B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_NAVIGABLE, B_FANCY_BORDER); + + fView = new BView(Bounds(),"View3", B_FOLLOW_NONE,B_WILL_DRAW); + + fView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + // Adding object + fBox->AddChild(fStringView3); + + fView->AddChild(fButton3); + fView->AddChild(fButton4); + fView->AddChild(fBox); + + fView->AddChild(fStringView4); + fView->AddChild(fStringView5); + fView->AddChild(fStringView6); + fView->AddChild(fStringView7); + fView->AddChild(fStringView8); + fView->AddChild(fStringView9); + + fView->AddChild(fButton5); + fView->AddChild(fButton6); + fView->AddChild(fButton7); + fView->AddChild(fButton8); + fView->AddChild(fButton9); + fView->AddChild(fButton10); + fView->AddChild(fButton11); + fView->AddChild(fButton12); + + AddChild(fView); +} + + +void CalibWin::MessageReceived(BMessage *message) +{ + switch(message->what) + { + default: + BWindow::MessageReceived(message); + break; + } +} + + +bool CalibWin::QuitRequested() +{ + return BWindow::QuitRequested(); +} + Added: haiku/trunk/src/preferences/joysticks/CalibWin.h =================================================================== --- haiku/trunk/src/preferences/joysticks/CalibWin.h 2007-05-07 05:29:06 UTC (rev 21050) +++ haiku/trunk/src/preferences/joysticks/CalibWin.h 2007-05-07 05:48:30 UTC (rev 21051) @@ -0,0 +1,70 @@ +/* + * Copyright 2007 Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * Ryan Leavengood, leavengood at gmail.com + */ +#ifndef _CALIB_WIN_H +#define _CALIB_WIN_H + + +#include + +class BView; +class BCheckBox; +class BStringView; +class BButton; +class BBox; + + +/* + All this code is here is just to not have an empty view at + Clicking the Calibrate function. + + All controls in this view needs to be created and placed dynamically according + with the Joystick descriptors +*/ + + +class CalibWin : public BWindow +{ + public: + CalibWin(BRect frame, const char *title, + window_look look, + window_feel feel, + uint32 flags, + uint32 workspace = B_CURRENT_WORKSPACE); + + virtual void MessageReceived(BMessage *message); + virtual bool QuitRequested(); + + protected: + BStringView* fStringView3; + BStringView* fStringView4; + BStringView* fStringView5; + BStringView* fStringView6; + BStringView* fStringView7; + BStringView* fStringView8; + BStringView* fStringView9; + + BButton* fButton3; + BButton* fButton4; + + BButton* fButton5; + BButton* fButton6; + BButton* fButton7; + BButton* fButton8; + BButton* fButton9; + BButton* fButton10; + BButton* fButton11; + BButton* fButton12; + + BBox* fBox; + BView* fView; +}; + + +#endif /* _CALIB_WIN_H */ + Added: haiku/trunk/src/preferences/joysticks/Global.h =================================================================== --- haiku/trunk/src/preferences/joysticks/Global.h 2007-05-07 05:29:06 UTC (rev 21050) +++ haiku/trunk/src/preferences/joysticks/Global.h 2007-05-07 05:48:30 UTC (rev 21051) @@ -0,0 +1,22 @@ +/* + * Copyright 2007 Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * Ryan Leavengood, leavengood at gmail.com + */ +#ifndef _GLOBAL_H +#define _GLOBAL_H + + +/* Application Messages */ +#define PORT_SELECTED 'pSeL' +#define JOY_SELECTED 'jYSl' + +#define PORT_INVOKE 'PInV' +#define JOY_INVOKE 'jInV' + + +#endif /* _GLOBAL_H */ + Added: haiku/trunk/src/preferences/joysticks/Jamfile =================================================================== --- haiku/trunk/src/preferences/joysticks/Jamfile 2007-05-07 05:29:06 UTC (rev 21050) +++ haiku/trunk/src/preferences/joysticks/Jamfile 2007-05-07 05:48:30 UTC (rev 21051) @@ -0,0 +1,18 @@ +SubDir HAIKU_TOP src preferences joysticks ; + +SetSubDirSupportedPlatformsBeOSCompatible ; +AddSubDirSupportedPlatforms libbe_test ; + +Preference Joysticks : + CalibWin.cpp + JoyWin.cpp + Joysticks.cpp + MessageWin.cpp + : be device + : Joysticks.rdef + ; + +if $(TARGET_PLATFORM) = libbe_test { + HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : Joysticks + : tests!apps ; +} Added: haiku/trunk/src/preferences/joysticks/JoyWin.cpp =================================================================== --- haiku/trunk/src/preferences/joysticks/JoyWin.cpp 2007-05-07 05:29:06 UTC (rev 21050) +++ haiku/trunk/src/preferences/joysticks/JoyWin.cpp 2007-05-07 05:48:30 UTC (rev 21051) @@ -0,0 +1,221 @@ +/* + * Copyright 2007 Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * Ryan Leavengood, leavengood at gmail.com + */ + + +#include "JoyWin.h" +#include "MessagedItem.h" +#include "MessageWin.h" +#include "CalibWin.h" +#include "Global.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +JoyWin::JoyWin(BRect frame, const char *title, window_look look, + window_feel feel, uint32 flags, uint32 workspace = B_CURRENT_WORKSPACE) + : BWindow(frame, title, look, feel, flags, workspace) +{ + fProbeButton = new BButton(BRect(15.00, 260.00, 115.00, 285.00), "ProbeButton", "Probe", NULL); + fCalibrateButton = new BButton(BRect(270.00, 260.00, 370.00, 285.00), "CalibrateButton", "Calibrate", NULL); + + fGamePortL = new BListView(BRect(15.00, 30.00, 145.00, 250.00), "gamePort"); + fGamePortL->SetSelectionMessage(new BMessage(PORT_SELECTED)); + fGamePortL->SetInvocationMessage(new BMessage(PORT_INVOKE)); + + fConControllerL = new BListView(BRect(175.00,30.00,370.00,250.00),"conController"); + fConControllerL->SetSelectionMessage(new BMessage(JOY_SELECTED)); + fConControllerL->SetInvocationMessage(new BMessage(JOY_INVOKE)); + + fGamePortS = new BStringView(BRect(15, 5, 160, 25), "gpString", "Game Port"); + fGamePortS->SetFont(be_bold_font); + fConControllerS = new BStringView(BRect(170, 5, 330, 25), "ccString", "Connected Controller"); + fConControllerS->SetFont(be_bold_font); + + fCheckbox = new BCheckBox(BRect(131.00, 260.00, 227.00, 280.00), "Disabled", "Disabled", NULL); + fBox = new BBox( Bounds(),"box", B_FOLLOW_ALL, + B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE, + B_PLAIN_BORDER); + fBox->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + // Adding object + fBox->AddChild(fCheckbox); + + fBox->AddChild(fGamePortS); + fBox->AddChild(fConControllerS); + + // Add listViews with their scrolls + fBox->AddChild(new BScrollView("PortScroll", fGamePortL, + B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW, false, true)); + fBox->AddChild(new BScrollView("ConScroll", fConControllerL, + B_FOLLOW_ALL, B_WILL_DRAW, false, true)); + + fBox->AddChild(fProbeButton); + fBox->AddChild(fCalibrateButton); + + AddChild(fBox); + + // This resizable feature is not in R5 but. + // making horizontal resizing allows + // long joysticks names to be seen completelly + SetSizeLimits(400, 600, Bounds().Height(), Bounds().Height()); + + /* Add all the devices */ + AddDevices(); + + /* Add the joysticks specifications */ + AddJoysticks(); +} + + +void JoyWin::MessageReceived(BMessage *message) +{ + switch(message->what) + { + case PORT_SELECTED: + break; + + case PORT_INVOKE: + // Do we have any port? + + // And some joysticks ? + + // Probe! + PerformProbe(); + + break; + + case JOY_SELECTED: + break; + + case JOY_INVOKE: + + // Do we have a selected definition? + + // And a suitale selected port? + + // Calibrate it! + Calibrate(); + + break; + + default: + BWindow::MessageReceived(message); + break; + } +} + + +bool JoyWin::QuitRequested() +{ + // Apply changes and save configurations etc etc + + be_app->PostMessage(B_QUIT_REQUESTED); + + return BWindow::QuitRequested(); +} + + +/* Initialization */ +status_t JoyWin::AddDevices() +{ + char buf[256]; + int devId = 0; + MessagedItem* device; + BMessage* message; + BString str; + + while (!fJoystick.GetDeviceName(devId, buf, 256)) { + message = new BMessage(PORT_SELECTED); + message->AddString("devname", buf); + // NOTE: Adding the index in the list might be useful. + + // TODO: Change it with leaf path + str.SetTo(buf); + //str = str.Remove(0, str.FindLast('/') ); + + device = new MessagedItem(str.String(), message); + fGamePortL->AddItem(device); + + devId++; + } + + /* TODO: Add the Disabled devices */ + + /* We do not have any Joystick dev */ + if (devId == 0) { + // keep track of it + // Alert it + + return B_ERROR; + } + + return B_OK; +} + + +status_t JoyWin::AddJoysticks() +{ + return B_OK; +} + + +/* Management */ +status_t JoyWin::Calibrate() +{ + CalibWin* calibw; + + calibw = new CalibWin(BRect(100, 100, 500, 400), "Calibrate", + B_DOCUMENT_WINDOW_LOOK, + B_NORMAL_WINDOW_FEEL, + B_NOT_RESIZABLE | B_NOT_ZOOMABLE); + + calibw->Show(); + + return B_OK; +} + + +status_t JoyWin::PerformProbe() +{ + MessageWin* mesgw; + + // [...] + + mesgw = new MessageWin(Frame(),"Probing", + B_MODAL_WINDOW_LOOK, + B_MODAL_APP_WINDOW_FEEL, + B_NOT_RESIZABLE | B_NOT_ZOOMABLE ); + + mesgw->Show(); + mesgw->SetText("Looking for: X in port Y ..."); + return B_OK; +} + + +/* Configuration */ +status_t JoyWin::ApplyChanges() +{ + return B_OK; +} + + +/* Configuration */ +status_t JoyWin::GetSettings() +{ + return B_OK; +} + Added: haiku/trunk/src/preferences/joysticks/JoyWin.h =================================================================== --- haiku/trunk/src/preferences/joysticks/JoyWin.h 2007-05-07 05:29:06 UTC (rev 21050) +++ haiku/trunk/src/preferences/joysticks/JoyWin.h 2007-05-07 05:48:30 UTC (rev 21051) @@ -0,0 +1,61 @@ +/* + * Copyright 2007 Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * Ryan Leavengood, leavengood at gmail.com + */ +#ifndef _JOY_WIN_H +#define _JOY_WIN_H + + +#include +#include + +class BView; +class BCheckBox; +class BStringView; +class BListView; +class BButton; +class BBox; + + +class JoyWin : public BWindow +{ + public: + JoyWin(BRect frame,const char *title, + window_look look, + window_feel feel, + uint32 flags, + uint32 workspace = B_CURRENT_WORKSPACE); + + virtual void MessageReceived(BMessage *message); + virtual bool QuitRequested(); + + protected: + BJoystick fJoystick; + + BBox* fBox; + BCheckBox* fCheckbox; + + BStringView* fGamePortS; + BStringView* fConControllerS; + + BListView* fGamePortL; + BListView* fConControllerL; + + BButton* fCalibrateButton; + BButton* fProbeButton; + + status_t AddDevices(); + status_t AddJoysticks(); + status_t Calibrate(); + status_t PerformProbe(); + status_t ApplyChanges(); + status_t GetSettings(); + +}; + +#endif /* _JOY_WIN_H */ + Added: haiku/trunk/src/preferences/joysticks/Joysticks.cpp =================================================================== --- haiku/trunk/src/preferences/joysticks/Joysticks.cpp 2007-05-07 05:29:06 UTC (rev 21050) +++ haiku/trunk/src/preferences/joysticks/Joysticks.cpp 2007-05-07 05:48:30 UTC (rev 21051) @@ -0,0 +1,56 @@ +/* + * Copyright 2007 Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * Ryan Leavengood, leavengood at gmail.com + */ + + +#include "Joysticks.h" +#include "JoyWin.h" + +#include +#include +#include +#include +#include + + +int main(void) +{ + Joysticks application("application/x-vnd.Haiku-Joysticks"); + + // Start Application + application.Run(); + + return 0; +} + + +Joysticks::Joysticks(const char *signature) : BApplication(signature) +{ + +} + + +Joysticks::~Joysticks() +{ + +} + + +void Joysticks::ReadyToRun() +{ + fJoywin = new JoyWin(BRect(100, 100, 500, 400), "Joysticks", + B_DOCUMENT_WINDOW_LOOK, + B_NORMAL_WINDOW_FEEL, + B_NOT_ZOOMABLE); + + if (fJoywin != NULL) + fJoywin->Show(); + else + be_app->PostMessage(B_QUIT_REQUESTED); +} + Added: haiku/trunk/src/preferences/joysticks/Joysticks.h =================================================================== --- haiku/trunk/src/preferences/joysticks/Joysticks.h 2007-05-07 05:29:06 UTC (rev 21050) +++ haiku/trunk/src/preferences/joysticks/Joysticks.h 2007-05-07 05:48:30 UTC (rev 21051) @@ -0,0 +1,33 @@ +/* + * Copyright 2007 Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * Ryan Leavengood, leavengood at gmail.com + */ +#ifndef _JOYSTICKS_H +#define _JOYSTICKS_H + + +#include + +class JoyWin; +class BWindow; + + +class Joysticks : public BApplication +{ + public: + Joysticks(const char *signature); + ~Joysticks(); + + virtual void ReadyToRun(); + + protected: + JoyWin* fJoywin; + +}; + + +#endif /* _JOYSTICKS_H */ Added: haiku/trunk/src/preferences/joysticks/Joysticks.rdef =================================================================== --- haiku/trunk/src/preferences/joysticks/Joysticks.rdef 2007-05-07 05:29:06 UTC (rev 21050) +++ haiku/trunk/src/preferences/joysticks/Joysticks.rdef 2007-05-07 05:48:30 UTC (rev 21051) @@ -0,0 +1,95 @@ + +resource app_signature "application/x-vnd.Haiku-Joysticks"; + +resource app_version { + major = 1, + middle = 0, + minor = 0, + + /* 0 = development 1 = alpha 2 = beta + 3 = gamma 4 = golden master 5 = final */ + variety = 2, + + internal = 0, + + short_info = "Joysticks", + long_info = "Joysticks ?2007 Haiku" +}; + +resource app_flags B_SINGLE_LAUNCH; + +#ifdef HAIKU_TARGET_PLATFORM_HAIKU + +resource vector_icon { + $"6E63696608050004005F020006023D5F39368F62B905F93FFB6B4ACB36BEDE32" + $"00032288FF1944E7020006023AAFCC3BFAA8BF50A93E3D044B460F48AEEC0002" + $"0258FF1919E7020006023BA7EB3CD6E4BF5D013E2A4C4B0DDA478DDF0097C3FF" + $"FF376AFF02000602380D3A384399BEF6CA3EAF9C4B2833C6F2DC00E3ECFFFFAC" + $"C7FF02000602371F7FB98A813FA8F13D3A58C4B8AC48909300CEDEFFFF3778FF" + $"02000602371F7FB98A813FA8F13D3A58C60C5648909300BADAFFFF032E850B0A" + $"0432482C503E543C4B0A0550485452485E565A60500A0A47273D24322A244A2C" + $"4E34C2B0BE5BC408BFBFC94F485C52520A0447273C2D485C52520A08BE5AC40E" + $"4058485CBE3D2D322A244A2C4EB935C20F0A03BC12BB843BC1D3B9EBC0700A03" + $"BC12BB84BCC2BE1AB9EBC0700A03BD75C0B13BC1D3B9EBC0700A03BCC2BE1ABD" + $"75C0B1B9EBC0700A032C4E34C2B0B939C20A0A043D24322A3C2D4727090A0102" + $"0001000A0001021001178400040A020103000A030109000A030106000A060107" + $"000A070108000A04020405000A05010A00" +}; + +#else // HAIKU_TARGET_PLATFORM_HAIKU + +resource large_icon { + $"FFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFF001012FFFFFF000D0D0D0D00FFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFF00000D0DFFFFFFFF00090D0D0000FFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFF000D0D001012FFFFFF000D09060600FFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFF000D0000FFFFFFFFFFFF000D0A090600FFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FF000D00FFFFFFFFFFFFFFFF000D0A090600FFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FF000D00FFFFFFFFFFFFFFFF000D0A090600FFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"001000FFFFFFFFFFFFFFFF00000D0A090600FFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"001000FFFFFFFFFFFFFF000D000D0A09060000FFFFFFFFFFFFFFFFFFFFFFFFFF" + $"00100000FFFFFFFFFF000D0D000D0A0906000D0000FFFFFFFFFFFFFFFFFFFFFF" + $"FF0010100000FFFF000D0D0D000D0A0906000D0D0D0000FFFFFFFFFFFFFFFFFF" + $"FFFF00000D0D00000DA50D0D000D0A0906000D7DA50D0D0000FFFFFFFFFFFFFF" + $"FFFFFFFF000D000DA57DA50000000A09060000090D0D0D0D0D0000FFFFFFFFFF" + $"FFFFFFFF00000D0D0D0D00007B7B000906000000090D0D0D0D0D0D0000FFFFFF" + $"FFFFFFFF000D0D0D0D000A00DA7B7B000600000000090D0D0D0D0D0D0D00FFFF" + $"FFFFFF000D0D0D0D0D00002B2BDA7B000000000600097DA50D0D0D0D0D00FFFF" + $"FFFF00A57DA50D7DA500002B2F2F00000009000600090D0D0D0D0D0D0600FFFF" + $"FF000D7D7D7DAA0D0D002B2CEB2F00090900000900090D0D0D0D0D060600FFFF" + $"00100D5B7DA50D0D0D002B2F2F00000000090900090D0D0D0D0D060606001111" + $"000A10100D0D0D0D002B2CEB2F000A0A090000090D7D0D0D0D06060600111111" + $"000A000000100D0D002B2F2F0000000000090D0D0D0D0D0D0606060600111111" + $"00007B7B7B0010002B2CEB2F000D0D0D7DA50D0D0D0D0D060606060600111111" + $"007B7B7BDA000A002B2F2F000D0D0D0D0D0D0D0D0D0D060606060600111111FF" + $"002B2CDA7B7B002B2CEB2F000D0D0D0D0D0D0D0D0D060606060600111111FFFF" + $"FF002B2CDA7B2B2CEB2F000A10100D0D0D0D0D0D060606060600111111FFFFFF" + $"FF002B2CDA7B2B2CEB2F000A0A0A10100D0D0D060606060600111111FFFFFFFF" + $"FFFF002B2C2B2B2F2F000A0A0A0A0A0A1010060606060600111111FFFFFFFFFF" + $"FFFF002B2C2B2B2F2F000A0A0A0A0A0A0A060606060600111111FFFFFFFFFFFF" + $"FFFFFF002B2CEB2F0000000A0A0A0A0A0A0606060600111111FFFFFFFFFFFFFF" + $"FFFFFF002B2CEB2F00FFFF00000A0A0A0A06060600111111FFFFFFFFFFFFFFFF" + $"FFFFFFFF002B2F00111111111100000A0A060000111111FFFFFFFFFFFFFFFFFF" + $"FFFFFFFF000000111111111111111100000011111111FFFFFFFFFFFFFFFFFFFF" +}; + +resource mini_icon { + $"FFFFFFFFFFFFFF00FFFFFFFFFFFFFFFF" + $"FFFF010BFFFF000C00FFFFFFFFFFFFFF" + $"FF0505FFFFFF000903FFFFFFFFFFFFFF" + $"FF05FFFFFFFF000903FFFFFFFFFFFFFF" + $"FF05FFFFFF0400090407FFFFFFFFFFFF" + $"FF060606040D000904890707FFFFFFFF" + $"FFFF0704AAD7000904000D0D0707FFFF" + $"FFFF040D0D007B000001027D0D0D05FF" + $"FF047DAA0E002F000702010D0D0605FF" + $"0410100C002F00090702AA0D06050F0F" + $"04000710002F000D7D0D0D0606050F0F" + $"002B00002F00100D0D0D0606050F10FF" + $"002B7B2CEB000910100606050F0FFFFF" + $"FF002B2F00000A0A0806050F0FFFFFFF" + $"FF002B2F00FF000005050F0FFFFFFFFF" + $"FFFF00000E0F0F0F0FFFFFFFFFFFFFFF" +}; + +#endif // HAIKU_TARGET_PLATFORM_HAIKU Added: haiku/trunk/src/preferences/joysticks/MessageWin.cpp =================================================================== --- haiku/trunk/src/preferences/joysticks/MessageWin.cpp 2007-05-07 05:29:06 UTC (rev 21050) +++ haiku/trunk/src/preferences/joysticks/MessageWin.cpp 2007-05-07 05:48:30 UTC (rev 21051) @@ -0,0 +1,72 @@ +/* + * Copyright 2007 Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * Ryan Leavengood, leavengood at gmail.com + */ + + +#include "MessageWin.h" + +#include +#include +#include +#include + +/* frame will be the frame of the parent window as*/ +MessageWin::MessageWin(BRect parentFrame, const char *title, + window_look look, window_feel feel, uint32 flags, uint32 workspace) + : BWindow(parentFrame ,title ,look ,feel, flags, workspace) +{ + fBox = new BBox(Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER); + fBox->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + fBox->SetLowColor(fBox->ViewColor()); + + // Rects for the text view + BRect outside(fBox->Bounds()); + outside.InsetBy(10, 10); + BRect insider(outside); + insider.OffsetTo(B_ORIGIN); + + fText = new BTextView(outside, "message", insider, B_FOLLOW_NONE, B_WILL_DRAW); + fText->MakeEditable(false); + fText->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + fText->SetLowColor(fText->ViewColor()); + + fBox->AddChild(fText); + AddChild(fBox); + + /* Relocate the window to the center of what its being given */ + ResizeTo(parentFrame.Width(), floor(parentFrame.Height() / 3)); + MoveBy(0, floor(parentFrame.Height() / 2 - (parentFrame.Height()/3) / 2 )); + +} + + +void MessageWin::SetText(const char* str) +{ + Lock(); + fText->SetText(str); + fText->Flush(); + Unlock(); +} + + +void MessageWin::MessageReceived(BMessage *message) +{ + switch(message->what) + { + default: + BWindow::MessageReceived(message); + break; + } +} + + +bool MessageWin::QuitRequested() +{ + return BWindow::QuitRequested(); +} + Added: haiku/trunk/src/preferences/joysticks/MessageWin.h =================================================================== --- haiku/trunk/src/preferences/joysticks/MessageWin.h 2007-05-07 05:29:06 UTC (rev 21050) +++ haiku/trunk/src/preferences/joysticks/MessageWin.h 2007-05-07 05:48:30 UTC (rev 21051) @@ -0,0 +1,42 @@ +/* + * Copyright 2007 Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * Ryan Leavengood, leavengood at gmail.com + */ +#ifndef _MESSAGE_WIN_H +#define _MESSAGE_WIN_H + + +#include + +class BBox; +class BButton; +class BCheckBox; +class BStringView; +class BView; +class BTextView; + + +class MessageWin : public BWindow +{ + public: + MessageWin(BRect parent_frame, const char *title, + window_look look, + window_feel feel, + uint32 flags, + uint32 workspace = B_CURRENT_WORKSPACE); + + void SetText(const char* str); + virtual void MessageReceived(BMessage *message); + virtual bool QuitRequested(); + + protected: + BBox* fBox; + BTextView* fText; +}; + +#endif /* _MESSAGE_WIN_H */ + Added: haiku/trunk/src/preferences/joysticks/MessagedItem.h =================================================================== --- haiku/trunk/src/preferences/joysticks/MessagedItem.h 2007-05-07 05:29:06 UTC (rev 21050) +++ haiku/trunk/src/preferences/joysticks/MessagedItem.h 2007-05-07 05:48:30 UTC (rev 21051) @@ -0,0 +1,43 @@ +/* + * Copyright 2007 Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * Ryan Leavengood, leavengood at gmail.com + */ +#ifndef MESSAGED_ITEM_H +#define MESSAGED_ITEM_H + + +#include +#include +#include +#include + + +class MessagedItem : public BStringItem { + public: + MessagedItem(const char* label, BMessage* information) : BStringItem(label) + { + fMessage = information; + } + + ~MessagedItem() + { + delete fMessage; + } + + BMessage* getMessage() + { + return fMessage; + } + + protected: + BMessage* fMessage; + +}; + + +#endif /* MESSAGED_ITEM_H */ + From axeld at pinc-software.de Mon May 7 08:52:54 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Mon, 07 May 2007 08:52:54 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r21049_-_in_haiku/trunk=3A_header?= =?iso-8859-15?q?s/posix/net_src/bin/network/ifconfig?= In-Reply-To: <200705070529.l475T6NL007005@sheep.berlios.de> Message-ID: <1113505650-BeMail@zon> hugosantos at mail.berlios.de wrote: > Log: > added IFM_AUTO to if_media and ifconfig. [...] > /* Ethernet */ > +#define IFM_AUTO 0 I'm not sure I am misunderstanding the purpose of IFM_AUTO or you; but I think IFM_AUTO is neither restricted to ethernet, nor is it supposed to be returned as if_media - it's supposed to be set this way in case you let the driver auto-detect the media type; the correct one should still be returned in if_media, then, of course. IFM_AUTO is the default setting. Bye, Axel. From hugosantos at gmail.com Mon May 7 08:59:08 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Mon, 7 May 2007 07:59:08 +0100 Subject: [Haiku-commits] r21049 - in haiku/trunk: headers/posix/net src/bin/network/ifconfig In-Reply-To: <1113505650-BeMail@zon> References: <200705070529.l475T6NL007005@sheep.berlios.de> <1113505650-BeMail@zon> Message-ID: <9c46321e0705062359v27800f68q4999fe7efba6ce54@mail.gmail.com> You are right, IFM_AUTO isn't restricted to Ethernet. A driver might return it if it is set to auto-negotiate but isn't able to know which media was negotiated (some 10Mbit cards). It should also be available when setting media, like you point out. Hugo On 5/7/07, Axel D?rfler wrote: > hugosantos at mail.berlios.de wrote: > > Log: > > added IFM_AUTO to if_media and ifconfig. > [...] > > /* Ethernet */ > > +#define IFM_AUTO 0 > > I'm not sure I am misunderstanding the purpose of IFM_AUTO or you; but > I think IFM_AUTO is neither restricted to ethernet, nor is it supposed > to be returned as if_media - it's supposed to be set this way in case > you let the driver auto-detect the media type; the correct one should > still be returned in if_media, then, of course. IFM_AUTO is the default > setting. > > Bye, > Axel. > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From philippe.houdoin at free.fr Mon May 7 12:06:34 2007 From: philippe.houdoin at free.fr (Philippe Houdoin) Date: Mon, 07 May 2007 12:06:34 +0200 Subject: [Haiku-commits] r21040 - in haiku/trunk: headers/os/drivers src/system/kernel Message-ID: <1178532394.463efa2a59985@imp.free.fr> Axel replied: > "Hugo Santos" wrote: >> Please let me know if you see anything wrong with these or if the >> definitions should go elsewhere than KernelExport.h. I've added these >> to be able to get the first interrupt and just defer the handling to >> a >> thread (check next commit). If i don't disable the interrupt it gets >> hammered so heavily the thread is not even scheduled. Using the >> current methods i couldn't free or remove the interrupt handler, so i >> added these ones. > > I can't add much to what Marcus and Travis already said, just that > KernelExport.h would be the wrong place for private additions. > And I think it's perfectly acceptable to not be able to incorporate > open-source drivers unchanged. I agree too, but as I'm not that a kernel guy... Anyway, if the issue is deferring interrupt handling, why not trying to (re-)use our Deferred Procedure Call (DPC) kernel module to do it? If it works enough for ACPI interrupts, why not for the others too??? It's living under src/add-ons/kernel/generic/dpc, and its (small) module interface is defined in headers/os/drivers/dpc.h. - Philippe From axeld at mail.berlios.de Mon May 7 12:45:53 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 7 May 2007 12:45:53 +0200 Subject: [Haiku-commits] r21052 - haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs/mkbfs Message-ID: <200705071045.l47Ajrvt000917@sheep.berlios.de> Author: axeld Date: 2007-05-07 12:45:42 +0200 (Mon, 07 May 2007) New Revision: 21052 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21052&view=rev Modified: haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs/mkbfs/allocationGroups.cpp Log: A bit more useful output. Modified: haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs/mkbfs/allocationGroups.cpp =================================================================== --- haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs/mkbfs/allocationGroups.cpp 2007-05-07 05:48:30 UTC (rev 21051) +++ haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs/mkbfs/allocationGroups.cpp 2007-05-07 10:45:42 UTC (rev 21052) @@ -1,7 +1,7 @@ -/* -** Copyright 2004, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ +/* + * Copyright 2004-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include @@ -34,6 +34,11 @@ return -1; } + int32 blockShift = 9; + while ((1UL << blockShift) < blockSize) { + blockShift++; + } + uint32 blocks_per_ag = 1; uint32 ag_shift = 13; uint32 num_ags = 0; @@ -61,12 +66,18 @@ } printf("blocks = %Ld\n", numBlocks); + printf("block shift = %ld\n", blockShift); printf("bits per block = %lu\n", bitsPerBlock); printf("bitmap blocks = %Ld\n", bitmapBlocks); printf("allocation groups = %lu\n", num_ags); printf("shift = %lu (%lu)\n", ag_shift, 1UL << ag_shift); printf("blocks per group = %lu\n", blocks_per_ag); + uint32 bitsPerGroup = 8 * (blocks_per_ag << blockShift); + + printf("\nBits per group: %ld\n", bitsPerGroup); + printf("Bits in last group: %ld\n", numBlocks - (num_ags - 1) * bitsPerGroup); + return 0; } From axeld at mail.berlios.de Mon May 7 12:56:42 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 7 May 2007 12:56:42 +0200 Subject: [Haiku-commits] r21053 - in haiku/trunk/src: add-ons/kernel/file_systems/bfs tests/add-ons/kernel/file_systems/bfs/r5 Message-ID: <200705071056.l47AugkR011929@sheep.berlios.de> Author: axeld Date: 2007-05-07 12:56:40 +0200 (Mon, 07 May 2007) New Revision: 21053 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21053&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.cpp haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs/r5/Volume.cpp Log: * Fixed a bug introduced with big-endian fixes in r17557; the super block's blocks_per_ag field was always 1, and therefore, the last allocation group could grow too large. Thanks to Samuel Rodriguez Perez for reporting the error (bfs_shell was crashing on larger images). * Minor cleanup in BlockAllocator::_Initialize(). Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp 2007-05-07 10:45:42 UTC (rev 21052) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp 2007-05-07 10:56:40 UTC (rev 21053) @@ -1,10 +1,11 @@ -/* BlockAllocator - block bitmap handling and allocation policies - * +/* * Copyright 2001-2007, Axel D?rfler, axeld at pinc-software.de. * This file may be used under the terms of the MIT License. */ +//! block bitmap handling and allocation policies + #include "Debug.h" #include "BlockAllocator.h" #include "Volume.h" @@ -451,11 +452,10 @@ Volume *volume = allocator->fVolume; uint32 blocks = allocator->fBlocksPerGroup; - uint32 numBits = 8 * blocks * volume->BlockSize(); uint32 blockShift = volume->BlockShift(); off_t freeBlocks = 0; - uint32 *buffer = (uint32 *)malloc(numBits >> 3); + uint32 *buffer = (uint32 *)malloc(blocks << blockShift); if (buffer == NULL) { allocator->fLock.Unlock(); RETURN_ERROR(B_NO_MEMORY); @@ -463,36 +463,41 @@ AllocationGroup *groups = allocator->fGroups; off_t offset = 1; - int32 num = allocator->fNumGroups; + uint32 bitsPerGroup = 8 * (blocks << blockShift); + int32 numGroups = allocator->fNumGroups; - for (int32 i = 0; i < num; i++) { + for (int32 i = 0; i < numGroups; i++) { if (read_pos(volume->Device(), offset << blockShift, buffer, blocks << blockShift) < B_OK) break; // the last allocation group may contain less blocks than the others - if (i == num - 1) { - groups[i].fNumBits = volume->NumBlocks() - i * numBits; + if (i == numGroups - 1) { + groups[i].fNumBits = volume->NumBlocks() - i * bitsPerGroup; groups[i].fNumBlocks = 1 + ((groups[i].NumBits() - 1) >> (blockShift + 3)); } else { - groups[i].fNumBits = numBits; + groups[i].fNumBits = bitsPerGroup; groups[i].fNumBlocks = blocks; } groups[i].fStart = offset; // finds all free ranges in this allocation group int32 start = -1, range = 0; - int32 size = groups[i].fNumBits, num = 0; + int32 numBits = groups[i].fNumBits, bit = 0; + int32 count = (numBits + 31) / 32; - for (int32 k = 0;k < (size >> 2);k++) { - for (int32 j = 0; j < 32 && num < size; j++, num++) { + for (int32 k = 0; k < count; k++) { + for (int32 j = 0; j < 32 && bit < numBits; j++, bit++) { if (buffer[k] & (1UL << j)) { + // block is in use if (range > 0) { groups[i].AddFreeRange(start, range); range = 0; } - } else if (range++ == 0) - start = num; + } else if (range++ == 0) { + // block is free, start new free range + start = bit; + } } } if (range) Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.cpp 2007-05-07 10:45:42 UTC (rev 21052) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.cpp 2007-05-07 10:56:40 UTC (rev 21053) @@ -1,10 +1,11 @@ -/* Volume - BFS super block, mounting, etc. - * - * Copyright 2001-2006, Axel D?rfler, axeld at pinc-software.de. +/* + * Copyright 2001-2007, Axel D?rfler, axeld at pinc-software.de. * This file may be used under the terms of the MIT License. */ +//! super block, mounting, etc. + #include "Debug.h" #include "Volume.h" #include "Journal.h" @@ -233,7 +234,7 @@ } num_ags = HOST_ENDIAN_TO_BFS_INT32(numGroups); - blocks_per_ag = HOST_ENDIAN_TO_BFS_INT32(1); + blocks_per_ag = HOST_ENDIAN_TO_BFS_INT32(blocksPerGroup); ag_shift = HOST_ENDIAN_TO_BFS_INT32(groupShift); } Modified: haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs/r5/Volume.cpp =================================================================== --- haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs/r5/Volume.cpp 2007-05-07 10:45:42 UTC (rev 21052) +++ haiku/trunk/src/tests/add-ons/kernel/file_systems/bfs/r5/Volume.cpp 2007-05-07 10:56:40 UTC (rev 21053) @@ -1,10 +1,11 @@ -/* Volume - BFS super block, mounting, etc. - * - * Copyright 2001-2006, Axel D?rfler, axeld at pinc-software.de. All Rights Reserved. +/* + * Copyright 2001-2007, Axel D?rfler, axeld at pinc-software.de. All Rights Reserved. * This file may be used under the terms of the MIT License. */ +//! super block, mounting, etc. + #include "Debug.h" #include "Volume.h" #include "Journal.h" @@ -223,7 +224,7 @@ } num_ags = HOST_ENDIAN_TO_BFS_INT32(numGroups); - blocks_per_ag = HOST_ENDIAN_TO_BFS_INT32(1); + blocks_per_ag = HOST_ENDIAN_TO_BFS_INT32(blocksPerGroup); ag_shift = HOST_ENDIAN_TO_BFS_INT32(groupShift); } From korli at users.berlios.de Mon May 7 14:12:04 2007 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Mon, 7 May 2007 14:12:04 +0200 Subject: [Haiku-commits] r21044 - haiku/trunk/src/add-ons/kernel/busses/usb In-Reply-To: <200705061555.l46FtR5J005331@sheep.berlios.de> References: <200705061555.l46FtR5J005331@sheep.berlios.de> Message-ID: 2007/5/6, mmlr at BerliOS : > --- haiku/trunk/src/add-ons/kernel/busses/usb/ehci.cpp 2007-05-06 15:22:12 UTC (rev 21043) > +++ haiku/trunk/src/add-ons/kernel/busses/usb/ehci.cpp 2007-05-06 15:55:26 UTC (rev 21044) > > delete current; > - Unlock(); > - return B_OK; > } > > last = current; This change doesn't look good enough: the transfer_date hold in current is deleted, but accessed some lines later with "current = current->link;" Bye, J?r?me From axeld at mail.berlios.de Mon May 7 14:26:22 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 7 May 2007 14:26:22 +0200 Subject: [Haiku-commits] r21054 - haiku/trunk/src/add-ons/kernel/file_systems/bfs Message-ID: <200705071226.l47CQMdc029437@sheep.berlios.de> Author: axeld Date: 2007-05-07 14:26:21 +0200 (Mon, 07 May 2007) New Revision: 21054 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21054&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.h haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/Debug.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/Lock.h haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.cpp Log: * Removed unused code when USER is defined - the fs_shell no longer does this, but provides a kernel emulation layer. * Renamed all private BPlusTree methods to have the '_' prefix. * Removed useless set_sem_owner() from Lock.h - all semaphores created in the kernel always belong to the system team automatically. * Some cleanup. Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp 2007-05-07 10:56:40 UTC (rev 21053) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp 2007-05-07 12:26:21 UTC (rev 21054) @@ -1,13 +1,14 @@ -/* BPlusTree - BFS B+Tree implementation +/* + * Copyright 2001-2007, Axel D?rfler, axeld at pinc-software.de. + * This file may be used under the terms of the MIT License. * * Roughly based on 'btlib' written by Marcus J. Ranum - it shares * no code but achieves binary compatibility with the on disk format. - * - * Copyright 2001-2006, Axel D?rfler, axeld at pinc-software.de. - * This file may be used under the terms of the MIT License. */ +//! B+Tree implementation + #include "Debug.h" #include "BPlusTree.h" #include "Inode.h" @@ -215,7 +216,8 @@ uint8 *block; if (transaction != NULL) { - block = (uint8 *)block_cache_get_writable(volume->BlockCache(), fBlockNumber, transaction->ID()); + block = (uint8 *)block_cache_get_writable(volume->BlockCache(), + fBlockNumber, transaction->ID()); fWritable = true; } else { block = (uint8 *)block_cache_get(volume->BlockCache(), fBlockNumber); @@ -270,7 +272,8 @@ status_t -CachedNode::Allocate(Transaction &transaction, bplustree_node **_node, off_t *_offset) +CachedNode::Allocate(Transaction &transaction, bplustree_node **_node, + off_t *_offset) { if (fTree == NULL || fTree->fHeader == NULL || fTree->fStream == NULL) RETURN_ERROR(B_BAD_VALUE); @@ -307,7 +310,8 @@ // the maximum_size has to be changed before the call to SetTo() - or // else it will fail because the requested node is out of bounds off_t offset = header->MaximumSize(); - header->maximum_size = HOST_ENDIAN_TO_BFS_INT64(header->MaximumSize() + fTree->fNodeSize); + header->maximum_size = HOST_ENDIAN_TO_BFS_INT64(header->MaximumSize() + + fTree->fNodeSize); if (SetToWritable(transaction, offset, false) != NULL) { fNode->Initialize(); @@ -318,7 +322,8 @@ } // revert header size to old value - header->maximum_size = HOST_ENDIAN_TO_BFS_INT64(header->MaximumSize() - fTree->fNodeSize); + header->maximum_size = HOST_ENDIAN_TO_BFS_INT64(header->MaximumSize() + - fTree->fNodeSize); RETURN_ERROR(B_ERROR); } @@ -374,8 +379,7 @@ } -/** Create a new B+Tree on the specified stream */ - +/*! Create a new B+Tree on the specified stream */ status_t BPlusTree::SetTo(Transaction &transaction, Inode *stream, int32 nodeSize) { @@ -397,8 +401,8 @@ fHeader = header; fAllowDuplicates = ((stream->Mode() & S_INDEX_DIR) == S_INDEX_DIR - && stream->BlockRun() != stream->Parent()) - || (stream->Mode() & S_ALLOW_DUPS) != 0; + && stream->BlockRun() != stream->Parent()) + || (stream->Mode() & S_ALLOW_DUPS) != 0; fNodeSize = nodeSize; @@ -460,13 +464,16 @@ fNodeSize = fHeader->NodeSize(); { - uint32 toMode[] = {S_STR_INDEX, S_INT_INDEX, S_UINT_INDEX, S_LONG_LONG_INDEX, - S_ULONG_LONG_INDEX, S_FLOAT_INDEX, S_DOUBLE_INDEX}; - uint32 mode = stream->Mode() & (S_STR_INDEX | S_INT_INDEX | S_UINT_INDEX | S_LONG_LONG_INDEX - | S_ULONG_LONG_INDEX | S_FLOAT_INDEX | S_DOUBLE_INDEX); + uint32 toMode[] = {S_STR_INDEX, S_INT_INDEX, S_UINT_INDEX, + S_LONG_LONG_INDEX, S_ULONG_LONG_INDEX, S_FLOAT_INDEX, + S_DOUBLE_INDEX}; + uint32 mode = stream->Mode() & (S_STR_INDEX | S_INT_INDEX + | S_UINT_INDEX | S_LONG_LONG_INDEX | S_ULONG_LONG_INDEX + | S_FLOAT_INDEX | S_DOUBLE_INDEX); if (fHeader->DataType() > BPLUSTREE_DOUBLE_TYPE - || (stream->Mode() & S_INDEX_DIR) && toMode[fHeader->DataType()] != mode + || (stream->Mode() & S_INDEX_DIR) + && toMode[fHeader->DataType()] != mode || !stream->IsContainer()) { D( dump_bplustree_header(fHeader); dump_inode(&stream->Node()); @@ -477,8 +484,8 @@ // although it's in stat.h, the S_ALLOW_DUPS flag is obviously unused // in the original BFS code - we will honour it nevertheless fAllowDuplicates = ((stream->Mode() & S_INDEX_DIR) == S_INDEX_DIR - && stream->BlockRun() != stream->Parent()) - || (stream->Mode() & S_ALLOW_DUPS) != 0; + && stream->BlockRun() != stream->Parent()) + || (stream->Mode() & S_ALLOW_DUPS) != 0; } CachedNode cached(this, fHeader->RootNode()); @@ -548,8 +555,8 @@ void -BPlusTree::UpdateIterators(off_t offset, off_t nextOffset, uint16 keyIndex, uint16 splitAt, - int8 change) +BPlusTree::_UpdateIterators(off_t offset, off_t nextOffset, uint16 keyIndex, + uint16 splitAt, int8 change) { // Although every iterator which is affected by this update currently // waits on a semaphore, other iterators could be added/removed at @@ -566,7 +573,7 @@ void -BPlusTree::AddIterator(TreeIterator *iterator) +BPlusTree::_AddIterator(TreeIterator *iterator) { if (fIteratorLock.Lock() < B_OK) return; @@ -578,7 +585,7 @@ void -BPlusTree::RemoveIterator(TreeIterator *iterator) +BPlusTree::_RemoveIterator(TreeIterator *iterator) { if (fIteratorLock.Lock() < B_OK) return; @@ -590,7 +597,8 @@ int32 -BPlusTree::CompareKeys(const void *key1, int keyLength1, const void *key2, int keyLength2) +BPlusTree::_CompareKeys(const void *key1, int keyLength1, const void *key2, + int keyLength2) { type_code type = 0; switch (fHeader->data_type) { @@ -621,8 +629,8 @@ status_t -BPlusTree::FindKey(const bplustree_node *node, const uint8 *key, uint16 keyLength, - uint16 *_index, off_t *_next) +BPlusTree::_FindKey(const bplustree_node *node, const uint8 *key, + uint16 keyLength, uint16 *_index, off_t *_next) { #ifdef DEBUG NodeChecker checker(node, fNodeSize, "find"); @@ -645,13 +653,14 @@ uint16 searchLength; uint8 *searchKey = node->KeyAt(i, &searchLength); - if (searchKey + searchLength + sizeof(off_t) + sizeof(uint16) > (uint8 *)node + fNodeSize + if (searchKey + searchLength + sizeof(off_t) + sizeof(uint16) + > (uint8 *)node + fNodeSize || searchLength > BPLUSTREE_MAX_KEY_LENGTH) { fStream->GetVolume()->Panic(); RETURN_ERROR(B_BAD_DATA); } - int32 cmp = CompareKeys(key, keyLength, searchKey, searchLength); + int32 cmp = _CompareKeys(key, keyLength, searchKey, searchLength); if (cmp < 0) { last = i - 1; saveIndex = i; @@ -678,13 +687,14 @@ } -/** Prepares the stack to contain all nodes that were passed while - * following the key, from the root node to the leaf node that could - * or should contain that key. - */ - +/*! + Prepares the stack to contain all nodes that were passed while + following the key, from the root node to the leaf node that could + or should contain that key. +*/ status_t -BPlusTree::SeekDown(Stack &stack, const uint8 *key, uint16 keyLength) +BPlusTree::_SeekDown(Stack &stack, const uint8 *key, + uint16 keyLength) { // set the root node to begin with node_and_key nodeAndKey; @@ -703,7 +713,8 @@ } off_t nextOffset; - status_t status = FindKey(node, key, keyLength, &nodeAndKey.keyIndex, &nextOffset); + status_t status = _FindKey(node, key, keyLength, &nodeAndKey.keyIndex, + &nextOffset); if (status == B_ENTRY_NOT_FOUND && nextOffset == nodeAndKey.nodeOffset) RETURN_ERROR(B_ERROR); @@ -714,17 +725,18 @@ nodeAndKey.nodeOffset = nextOffset; } - FATAL(("BPlusTree::SeekDown() could not open node %Ld\n", nodeAndKey.nodeOffset)); + FATAL(("BPlusTree::SeekDown() could not open node %Ld\n", + nodeAndKey.nodeOffset)); return B_ERROR; } -/** This will find a free duplicate fragment in the given bplustree_node. - * The CachedNode will be set to the writable fragment on success. - */ - +/*! + This will find a free duplicate fragment in the given bplustree_node. + The CachedNode will be set to the writable fragment on success. +*/ status_t -BPlusTree::FindFreeDuplicateFragment(Transaction &transaction, +BPlusTree::_FindFreeDuplicateFragment(Transaction &transaction, const bplustree_node *node, CachedNode &cached, off_t *_offset, bplustree_node **_fragment, uint32 *_index) { @@ -765,7 +777,7 @@ status_t -BPlusTree::InsertDuplicate(Transaction &transaction, CachedNode &cached, +BPlusTree::_InsertDuplicate(Transaction &transaction, CachedNode &cached, const bplustree_node *node, uint16 index, off_t value) { CachedNode cachedDuplicate(this); @@ -784,7 +796,8 @@ if (duplicate == NULL) return B_IO_ERROR; - duplicate_array *array = duplicate->FragmentAt(bplustree_node::FragmentIndex(oldValue)); + duplicate_array *array = duplicate->FragmentAt( + bplustree_node::FragmentIndex(oldValue)); if (array->count > NUM_FRAGMENT_VALUES || array->count < 1) { FATAL(("insertDuplicate: Invalid array[%d] size in fragment %Ld == %Ld!\n", @@ -803,9 +816,10 @@ // reuse it as a duplicate node offset = bplustree_node::FragmentOffset(oldValue); - memmove(duplicate->DuplicateArray(), array, (NUM_FRAGMENT_VALUES + 1) * sizeof(off_t)); - duplicate->left_link = duplicate->right_link = HOST_ENDIAN_TO_BFS_INT64( - (uint64)BPLUSTREE_NULL); + memmove(duplicate->DuplicateArray(), array, + (NUM_FRAGMENT_VALUES + 1) * sizeof(off_t)); + duplicate->left_link = duplicate->right_link + = HOST_ENDIAN_TO_BFS_INT64((uint64)BPLUSTREE_NULL); array = duplicate->DuplicateArray(); array->Insert(value); @@ -816,13 +830,15 @@ // the old duplicate has not been touched, so we can reuse it bplustree_node *newDuplicate; - status = cachedDuplicate.Allocate(transaction, &newDuplicate, &offset); + status = cachedDuplicate.Allocate(transaction, + &newDuplicate, &offset); if (status < B_OK) RETURN_ERROR(status); // copy the array from the fragment node to the duplicate node // and free the old entry (by zero'ing all values) - newDuplicate->overflow_link = HOST_ENDIAN_TO_BFS_INT64(array->count); + newDuplicate->overflow_link = HOST_ENDIAN_TO_BFS_INT64( + array->count); memcpy(&newDuplicate->all_key_count, &array->values[0], array->count * sizeof(off_t)); memset(array, 0, (NUM_FRAGMENT_VALUES + 1) * sizeof(off_t)); @@ -894,10 +910,11 @@ uint32 fragmentIndex = 0; bplustree_node *fragment; - if (FindFreeDuplicateFragment(transaction, node, cachedDuplicate, + if (_FindFreeDuplicateFragment(transaction, node, cachedDuplicate, &offset, &fragment, &fragmentIndex) != B_OK) { // allocate a new duplicate fragment node - if ((status = cachedDuplicate.Allocate(transaction, &fragment, &offset)) < B_OK) + if ((status = cachedDuplicate.Allocate(transaction, &fragment, + &offset)) < B_OK) RETURN_ERROR(status); memset(fragment, 0, fNodeSize); @@ -918,8 +935,8 @@ void -BPlusTree::InsertKey(bplustree_node *node, uint16 index, uint8 *key, uint16 keyLength, - off_t value) +BPlusTree::_InsertKey(bplustree_node *node, uint16 index, uint8 *key, + uint16 keyLength, off_t value) { // should never happen, but who knows? if (index > node->NumKeys()) @@ -930,13 +947,15 @@ uint8 *keys = node->Keys(); node->all_key_count = HOST_ENDIAN_TO_BFS_INT16(node->NumKeys() + 1); - node->all_key_length = HOST_ENDIAN_TO_BFS_INT16(node->AllKeyLength() + keyLength); + node->all_key_length = HOST_ENDIAN_TO_BFS_INT16(node->AllKeyLength() + + keyLength); off_t *newValues = node->Values(); uint16 *newKeyLengths = node->KeyLengths(); // move values and copy new value into them - memmove(newValues + index + 1, values + index, sizeof(off_t) * (node->NumKeys() - 1 - index)); + memmove(newValues + index + 1, values + index, + sizeof(off_t) * (node->NumKeys() - 1 - index)); memmove(newValues, values, sizeof(off_t) * index); newValues[index] = HOST_ENDIAN_TO_BFS_INT64(value); @@ -950,7 +969,8 @@ int32 keyStart; newKeyLengths[index] = HOST_ENDIAN_TO_BFS_INT16(keyLength - + (keyStart = index > 0 ? BFS_ENDIAN_TO_HOST_INT16(newKeyLengths[index - 1]) : 0)); + + (keyStart = index > 0 + ? BFS_ENDIAN_TO_HOST_INT16(newKeyLengths[index - 1]) : 0)); // move keys and copy new key into them uint16 length = BFS_ENDIAN_TO_HOST_INT16(newKeyLengths[index]); @@ -962,14 +982,15 @@ } -/** Splits the \a node into two halves - the other half will be put into \a other. - * It also takes care to create a new overflow link if the node to split is an - * index node. - */ - +/*! + Splits the \a node into two halves - the other half will be put into \a other. + It also takes care to create a new overflow link if the node to split is an + index node. +*/ status_t -BPlusTree::SplitNode(bplustree_node *node, off_t nodeOffset, bplustree_node *other, - off_t otherOffset, uint16 *_keyIndex, uint8 *key, uint16 *_keyLength, off_t *_value) +BPlusTree::_SplitNode(bplustree_node *node, off_t nodeOffset, + bplustree_node *other, off_t otherOffset, uint16 *_keyIndex, uint8 *key, + uint16 *_keyLength, off_t *_value) { if (*_keyIndex > node->NumKeys() + 1) return B_BAD_VALUE; @@ -992,14 +1013,18 @@ size_t size = fNodeSize >> 1; int32 out, in; for (in = out = 0; in < node->NumKeys() + 1;) { - if (!bytes) - bytesBefore = in > 0 ? BFS_ENDIAN_TO_HOST_INT16(inKeyLengths[in - 1]) : 0; + if (!bytes) { + bytesBefore = in > 0 + ? BFS_ENDIAN_TO_HOST_INT16(inKeyLengths[in - 1]) : 0; + } if (in == keyIndex && !bytes) { bytes = *_keyLength; } else { - if (keyIndex < out) - bytesAfter = BFS_ENDIAN_TO_HOST_INT16(inKeyLengths[in]) - bytesBefore; + if (keyIndex < out) { + bytesAfter = BFS_ENDIAN_TO_HOST_INT16(inKeyLengths[in]) + - bytesBefore; + } in++; } @@ -1022,7 +1047,8 @@ other->left_link = node->left_link; other->right_link = HOST_ENDIAN_TO_BFS_INT64(nodeOffset); - other->all_key_length = HOST_ENDIAN_TO_BFS_INT16(bytes + bytesBefore + bytesAfter); + other->all_key_length = HOST_ENDIAN_TO_BFS_INT16(bytes + bytesBefore + + bytesAfter); other->all_key_count = HOST_ENDIAN_TO_BFS_INT16(out); uint16 *outKeyLengths = other->KeyLengths(); @@ -1043,13 +1069,15 @@ if (bytesAfter) { // copy the keys after the new key - memcpy(outKeys + bytesBefore + bytes, inKeys + bytesBefore, bytesAfter); + memcpy(outKeys + bytesBefore + bytes, inKeys + bytesBefore, + bytesAfter); keys = out - keyIndex - 1; for (int32 i = 0;i < keys;i++) { outKeyLengths[keyIndex + i + 1] = HOST_ENDIAN_TO_BFS_INT16( BFS_ENDIAN_TO_HOST_INT16(inKeyLengths[keyIndex + i]) + bytes); } - memcpy(outKeyValues + keyIndex + 1, inKeyValues + keyIndex, keys * sizeof(off_t)); + memcpy(outKeyValues + keyIndex + 1, inKeyValues + keyIndex, + keys * sizeof(off_t)); } } @@ -1080,7 +1108,8 @@ // If a key is dropped (is not the new key), we have to copy // it, because it would be lost if not. uint8 *droppedKey = node->KeyAt(in, &newLength); - if (droppedKey + newLength + sizeof(off_t) + sizeof(uint16) > (uint8 *)node + fNodeSize + if (droppedKey + newLength + sizeof(off_t) + sizeof(uint16) + > (uint8 *)node + fNodeSize || newLength > BPLUSTREE_MAX_KEY_LENGTH) { fStream->GetVolume()->Panic(); RETURN_ERROR(B_BAD_DATA); @@ -1106,7 +1135,8 @@ // it's enough to set bytesBefore once here, because we do // not need to know the exact length of all keys in this // loop - bytesBefore = in > skip ? BFS_ENDIAN_TO_HOST_INT16(inKeyLengths[in - 1]) : 0; + bytesBefore = in > skip + ? BFS_ENDIAN_TO_HOST_INT16(inKeyLengths[in - 1]) : 0; bytes = *_keyLength; } else { if (in < node->NumKeys()) { @@ -1132,9 +1162,10 @@ } // adjust the byte counts (since we were a bit lazy in the loop) - if (keyIndex >= in && keyIndex - skip < out) - bytesAfter = BFS_ENDIAN_TO_HOST_INT16(inKeyLengths[in]) - bytesBefore - total; - else if (keyIndex < skip) + if (keyIndex >= in && keyIndex - skip < out) { + bytesAfter = BFS_ENDIAN_TO_HOST_INT16(inKeyLengths[in]) + - bytesBefore - total; + } else if (keyIndex < skip) bytesBefore = node->AllKeyLength() - total; if (bytesBefore < 0 || bytesAfter < 0) @@ -1142,7 +1173,8 @@ node->left_link = HOST_ENDIAN_TO_BFS_INT64(otherOffset); // right link, and overflow link can stay the same - node->all_key_length = HOST_ENDIAN_TO_BFS_INT16(bytes + bytesBefore + bytesAfter); + node->all_key_length = HOST_ENDIAN_TO_BFS_INT16(bytes + bytesBefore + + bytesAfter); node->all_key_count = HOST_ENDIAN_TO_BFS_INT16(out - 1); // array positions have changed @@ -1157,19 +1189,25 @@ if (bytesBefore) memmove(inKeys, inKeys + total, bytesBefore); - if (bytesAfter) - memmove(inKeys + bytesBefore + bytes, inKeys + total + bytesBefore, bytesAfter); + if (bytesAfter) { + memmove(inKeys + bytesBefore + bytes, inKeys + total + bytesBefore, + bytesAfter); + } if (bytesBefore) memmove(outKeyLengths, inKeyLengths + skip, keys * sizeof(uint16)); in = out - keyIndex - 1; - if (bytesAfter) - memmove(outKeyLengths + keyIndex + 1, inKeyLengths + skip + keyIndex, in * sizeof(uint16)); + if (bytesAfter) { + memmove(outKeyLengths + keyIndex + 1, inKeyLengths + skip + keyIndex, + in * sizeof(uint16)); + } if (bytesBefore) memmove(outKeyValues, inKeyValues + skip, keys * sizeof(off_t)); - if (bytesAfter) - memmove(outKeyValues + keyIndex + 1, inKeyValues + skip + keyIndex, in * sizeof(off_t)); + if (bytesAfter) { + memmove(outKeyValues + keyIndex + 1, inKeyValues + skip + keyIndex, + in * sizeof(off_t)); + } if (bytes) { // finally, copy the newly inserted key (don't overwrite anything) @@ -1196,14 +1234,16 @@ } -/** This inserts a key into the tree. The changes made to the tree will - * all be part of the \a transaction. - */ - +/*! + This inserts a key into the tree. The changes made to the tree will + all be part of the \a transaction. +*/ status_t -BPlusTree::Insert(Transaction &transaction, const uint8 *key, uint16 keyLength, off_t value) +BPlusTree::Insert(Transaction &transaction, const uint8 *key, uint16 keyLength, + off_t value) { - if (keyLength < BPLUSTREE_MIN_KEY_LENGTH || keyLength > BPLUSTREE_MAX_KEY_LENGTH) + if (keyLength < BPLUSTREE_MIN_KEY_LENGTH + || keyLength > BPLUSTREE_MAX_KEY_LENGTH) RETURN_ERROR(B_BAD_VALUE); #ifdef DEBUG if (value < 0) @@ -1214,7 +1254,7 @@ WriteLocked locked(fStream->Lock()); Stack stack; - if (SeekDown(stack, key, keyLength) != B_OK) + if (_SeekDown(stack, key, keyLength) != B_OK) RETURN_ERROR(B_ERROR); uint8 keyBuffer[BPLUSTREE_MAX_KEY_LENGTH + 1]; @@ -1226,23 +1266,26 @@ const bplustree_node *node; CachedNode cached(this); - while (stack.Pop(&nodeAndKey) && (node = cached.SetTo(nodeAndKey.nodeOffset)) != NULL) { + while (stack.Pop(&nodeAndKey) + && (node = cached.SetTo(nodeAndKey.nodeOffset)) != NULL) { #ifdef DEBUG NodeChecker checker(node, fNodeSize, "insert"); #endif if (node->IsLeaf()) { // first round, check for duplicate entries - status_t status = FindKey(node, key, keyLength, &nodeAndKey.keyIndex); + status_t status = _FindKey(node, key, keyLength, + &nodeAndKey.keyIndex); // is this a duplicate entry? if (status == B_OK) { if (fAllowDuplicates) { - status = InsertDuplicate(transaction, cached, node, nodeAndKey.keyIndex, value); + status = _InsertDuplicate(transaction, cached, node, + nodeAndKey.keyIndex, value); if (status != B_OK) RETURN_ERROR(status); return B_OK; } - + RETURN_ERROR(B_NAME_IN_USE); } } @@ -1252,11 +1295,14 @@ return B_IO_ERROR; // is the node big enough to hold the pair? - if (int32(round_up(sizeof(bplustree_node) + writableNode->AllKeyLength() + keyLength) - + (writableNode->NumKeys() + 1) * (sizeof(uint16) + sizeof(off_t))) < fNodeSize) - { - InsertKey(writableNode, nodeAndKey.keyIndex, keyBuffer, keyLength, value); - UpdateIterators(nodeAndKey.nodeOffset, BPLUSTREE_NULL, nodeAndKey.keyIndex, 0, 1); + if (int32(round_up(sizeof(bplustree_node) + + writableNode->AllKeyLength() + keyLength) + + (writableNode->NumKeys() + 1) * (sizeof(uint16) + + sizeof(off_t))) < fNodeSize) { + _InsertKey(writableNode, nodeAndKey.keyIndex, + keyBuffer, keyLength, value); + _UpdateIterators(nodeAndKey.nodeOffset, BPLUSTREE_NULL, + nodeAndKey.keyIndex, 0, 1); return B_OK; } else { @@ -1268,7 +1314,8 @@ off_t newRoot = BPLUSTREE_NULL; if (nodeAndKey.nodeOffset == fHeader->RootNode()) { bplustree_node *root; - status_t status = cachedNewRoot.Allocate(transaction, &root, &newRoot); + status_t status = cachedNewRoot.Allocate(transaction, &root, + &newRoot); if (status < B_OK) { // The tree is most likely corrupted! // But it's still sane at leaf level - we could set @@ -1283,14 +1330,16 @@ // reserve space for the other node bplustree_node *other; off_t otherOffset; - status_t status = cachedOther.Allocate(transaction, &other, &otherOffset); + status_t status = cachedOther.Allocate(transaction, &other, + &otherOffset); if (status < B_OK) { cachedNewRoot.Free(transaction, newRoot); RETURN_ERROR(status); } - if (SplitNode(writableNode, nodeAndKey.nodeOffset, other, otherOffset, - &nodeAndKey.keyIndex, keyBuffer, &keyLength, &value) < B_OK) { + if (_SplitNode(writableNode, nodeAndKey.nodeOffset, other, + otherOffset, &nodeAndKey.keyIndex, keyBuffer, &keyLength, + &value) < B_OK) { // free root node & other node here cachedOther.Free(transaction, otherOffset); cachedNewRoot.Free(transaction, newRoot); @@ -1302,11 +1351,12 @@ NodeChecker otherChecker(other, fNodeSize, "insert split other"); #endif - UpdateIterators(nodeAndKey.nodeOffset, otherOffset, nodeAndKey.keyIndex, - writableNode->NumKeys(), 1); + _UpdateIterators(nodeAndKey.nodeOffset, otherOffset, + nodeAndKey.keyIndex, writableNode->NumKeys(), 1); // update the right link of the node in the left of the new node - if ((other = cachedOther.SetToWritable(transaction, other->LeftLink())) != NULL) { + if ((other = cachedOther.SetToWritable(transaction, + other->LeftLink())) != NULL) { other->right_link = HOST_ENDIAN_TO_BFS_INT64(otherOffset); } @@ -1314,16 +1364,20 @@ if (newRoot != BPLUSTREE_NULL) { bplustree_node *root = cachedNewRoot.Node(); - InsertKey(root, 0, keyBuffer, keyLength, writableNode->LeftLink()); - root->overflow_link = HOST_ENDIAN_TO_BFS_INT64(nodeAndKey.nodeOffset); + _InsertKey(root, 0, keyBuffer, keyLength, + writableNode->LeftLink()); + root->overflow_link = HOST_ENDIAN_TO_BFS_INT64( + nodeAndKey.nodeOffset); - bplustree_header *header = fCachedHeader.MakeWritableHeader(transaction); + bplustree_header *header + = fCachedHeader.MakeWritableHeader(transaction); if (header == NULL) return B_IO_ERROR; // finally, update header to point to the new root header->root_node_pointer = HOST_ENDIAN_TO_BFS_INT64(newRoot); - header->max_number_of_levels = HOST_ENDIAN_TO_BFS_INT32(header->MaxNumberOfLevels() + 1); + header->max_number_of_levels = HOST_ENDIAN_TO_BFS_INT32( + header->MaxNumberOfLevels() + 1); return B_OK; } @@ -1333,13 +1387,14 @@ } -/** Removes the duplicate index/value pair from the tree. - * It's part of the private tree interface. - */ - +/*! + Removes the duplicate index/value pair from the tree. + It's part of the private tree interface. +*/ status_t -BPlusTree::RemoveDuplicate(Transaction &transaction, const bplustree_node *node, - CachedNode &cached, uint16 index, off_t value) +BPlusTree::_RemoveDuplicate(Transaction &transaction, + const bplustree_node *node, CachedNode &cached, uint16 index, + off_t value) { off_t *values = node->Values(); off_t oldValue = BFS_ENDIAN_TO_HOST_INT64(values[index]); @@ -1353,7 +1408,8 @@ // if it's a duplicate fragment, remove the entry from there if (bplustree_node::LinkType(oldValue) == BPLUSTREE_DUPLICATE_FRAGMENT) { - duplicate_array *array = duplicate->FragmentAt(bplustree_node::FragmentIndex(oldValue)); + duplicate_array *array = duplicate->FragmentAt( + bplustree_node::FragmentIndex(oldValue)); if (array->count > NUM_FRAGMENT_VALUES || array->count < 1) { @@ -1488,7 +1544,7 @@ bplustree_node *fragment = NULL; uint32 fragmentIndex = 0; off_t offset; - if (FindFreeDuplicateFragment(transaction, node, cachedOther, + if (_FindFreeDuplicateFragment(transaction, node, cachedOther, &offset, &fragment, &fragmentIndex) == B_OK) { // move to other node duplicate_array *target = fragment->FragmentAt(fragmentIndex); @@ -1514,14 +1570,14 @@ } -/** Removes the key with the given index from the specified node. - * Since it has to get the key from the node anyway (to obtain it's - * pointer), it's not needed to pass the key & its length, although - * the calling method (BPlusTree::Remove()) have this data. - */ - +/*! + Removes the key with the given index from the specified node. + Since it has to get the key from the node anyway (to obtain it's + pointer), it's not needed to pass the key & its length, although + the calling method (BPlusTree::Remove()) have this data. +*/ void -BPlusTree::RemoveKey(bplustree_node *node, uint16 index) +BPlusTree::_RemoveKey(bplustree_node *node, uint16 index) { // should never happen, but who knows? if (index > node->NumKeys() && node->NumKeys() > 0) { @@ -1575,35 +1631,38 @@ } -/** Removes the specified key from the tree. The "value" parameter is only used - * for trees which allow duplicates, so you may safely ignore it. - * It's not an optional parameter, so at least you have to think about it. - */ - +/*! + Removes the specified key from the tree. The "value" parameter is only used + for trees which allow duplicates, so you may safely ignore it. + It's not an optional parameter, so at least you have to think about it. +*/ status_t -BPlusTree::Remove(Transaction &transaction, const uint8 *key, uint16 keyLength, off_t value) +BPlusTree::Remove(Transaction &transaction, const uint8 *key, uint16 keyLength, + off_t value) { - if (keyLength < BPLUSTREE_MIN_KEY_LENGTH || keyLength > BPLUSTREE_MAX_KEY_LENGTH) + if (keyLength < BPLUSTREE_MIN_KEY_LENGTH + || keyLength > BPLUSTREE_MAX_KEY_LENGTH) RETURN_ERROR(B_BAD_VALUE); // lock access to stream WriteLocked locked(fStream->Lock()); Stack stack; - if (SeekDown(stack, key, keyLength) != B_OK) + if (_SeekDown(stack, key, keyLength) != B_OK) RETURN_ERROR(B_ERROR); node_and_key nodeAndKey; const bplustree_node *node; CachedNode cached(this); - while (stack.Pop(&nodeAndKey) && (node = cached.SetTo(nodeAndKey.nodeOffset)) != NULL) { + while (stack.Pop(&nodeAndKey) + && (node = cached.SetTo(nodeAndKey.nodeOffset)) != NULL) { #ifdef DEBUG NodeChecker checker(node, fNodeSize, "remove"); #endif if (node->IsLeaf()) { // first round, check for duplicate entries - status_t status = FindKey(node, key, keyLength, &nodeAndKey.keyIndex); + status_t status = _FindKey(node, key, keyLength, &nodeAndKey.keyIndex); if (status < B_OK) RETURN_ERROR(status); @@ -1611,15 +1670,16 @@ // to the next node after the current - if there aren't any // more nodes, we need a way to prevent the TreeIterators to // touch the old node again, we use BPLUSTREE_FREE for this - off_t next = node->RightLink() == BPLUSTREE_NULL ? BPLUSTREE_FREE : node->RightLink(); - UpdateIterators(nodeAndKey.nodeOffset, node->NumKeys() == 1 ? - next : BPLUSTREE_NULL, nodeAndKey.keyIndex, 0 , -1); + off_t next = node->RightLink() == BPLUSTREE_NULL + ? BPLUSTREE_FREE : node->RightLink(); + _UpdateIterators(nodeAndKey.nodeOffset, node->NumKeys() == 1 + ? next : BPLUSTREE_NULL, nodeAndKey.keyIndex, 0 , -1); // is this a duplicate entry? if (bplustree_node::IsDuplicate(BFS_ENDIAN_TO_HOST_INT64( node->Values()[nodeAndKey.keyIndex]))) { if (fAllowDuplicates) { - return RemoveDuplicate(transaction, node, cached, + return _RemoveDuplicate(transaction, node, cached, nodeAndKey.keyIndex, value); } else { FATAL(("dupliate node found where no duplicates are allowed!\n")); @@ -1658,7 +1718,7 @@ // the overflow link, so we have to drop the last key) if (writableNode->NumKeys() > 1 || !writableNode->IsLeaf() && writableNode->NumKeys() == 1) { - RemoveKey(writableNode, nodeAndKey.keyIndex); + _RemoveKey(writableNode, nodeAndKey.keyIndex); return B_OK; } @@ -1680,19 +1740,21 @@ } -/** Replaces the value for the key in the tree. - * Returns B_OK if the key could be found and its value replaced, - * B_ENTRY_NOT_FOUND if the key couldn't be found, and other errors - * to indicate that something went terribly wrong. - * Note that this doesn't work with duplicates - it will just - * return B_BAD_TYPE if you call this function on a tree where - * duplicates are allowed. - */ - +/*! + Replaces the value for the key in the tree. + Returns B_OK if the key could be found and its value replaced, + B_ENTRY_NOT_FOUND if the key couldn't be found, and other errors + to indicate that something went terribly wrong. + Note that this doesn't work with duplicates - it will just + return B_BAD_TYPE if you call this function on a tree where + duplicates are allowed. +*/ status_t -BPlusTree::Replace(Transaction &transaction, const uint8 *key, uint16 keyLength, off_t value) +BPlusTree::Replace(Transaction &transaction, const uint8 *key, + uint16 keyLength, off_t value) { - if (keyLength < BPLUSTREE_MIN_KEY_LENGTH || keyLength > BPLUSTREE_MAX_KEY_LENGTH + if (keyLength < BPLUSTREE_MIN_KEY_LENGTH + || keyLength > BPLUSTREE_MAX_KEY_LENGTH || key == NULL) RETURN_ERROR(B_BAD_VALUE); @@ -1709,7 +1771,7 @@ while ((node = cached.SetTo(nodeOffset)) != NULL) { uint16 keyIndex = 0; off_t nextOffset; - status_t status = FindKey(node, key, keyLength, &keyIndex, &nextOffset); + status_t status = _FindKey(node, key, keyLength, &keyIndex, &nextOffset); if (node->OverflowLink() == BPLUSTREE_NULL) { if (status == B_OK) { @@ -1730,22 +1792,23 @@ } -/** Searches the key in the tree, and stores the offset found in - * _value, if successful. - * It's very similar to BPlusTree::SeekDown(), but doesn't fill - * a stack while it descends the tree. - * Returns B_OK when the key could be found, B_ENTRY_NOT_FOUND - * if not. It can also return other errors to indicate that - * something went wrong. - * Note that this doesn't work with duplicates - it will just - * return B_BAD_TYPE if you call this function on a tree where - * duplicates are allowed. - */ - +/*! + Searches the key in the tree, and stores the offset found in + _value, if successful. + It's very similar to BPlusTree::SeekDown(), but doesn't fill + a stack while it descends the tree. + Returns B_OK when the key could be found, B_ENTRY_NOT_FOUND + if not. It can also return other errors to indicate that + something went wrong. + Note that this doesn't work with duplicates - it will just + return B_BAD_TYPE if you call this function on a tree where + duplicates are allowed. +*/ status_t BPlusTree::Find(const uint8 *key, uint16 keyLength, off_t *_value) { - if (keyLength < BPLUSTREE_MIN_KEY_LENGTH || keyLength > BPLUSTREE_MAX_KEY_LENGTH + if (keyLength < BPLUSTREE_MIN_KEY_LENGTH + || keyLength > BPLUSTREE_MAX_KEY_LENGTH || key == NULL) RETURN_ERROR(B_BAD_VALUE); @@ -1766,7 +1829,7 @@ while ((node = cached.SetTo(nodeOffset)) != NULL) { uint16 keyIndex = 0; off_t nextOffset; - status_t status = FindKey(node, key, keyLength, &keyIndex, &nextOffset); + status_t status = _FindKey(node, key, keyLength, &keyIndex, &nextOffset); #ifdef DEBUG levels++; @@ -1799,14 +1862,14 @@ fCurrentNodeOffset(BPLUSTREE_NULL), fNext(NULL) { - tree->AddIterator(this); + tree->_AddIterator(this); } TreeIterator::~TreeIterator() { if (fTree) - fTree->RemoveIterator(this); + fTree->_RemoveIterator(this); } @@ -1840,7 +1903,8 @@ nextOffset = node->OverflowLink(); else { if (node->AllKeyLength() > fTree->fNodeSize - || (uint32)node->Values() > (uint32)node + fTree->fNodeSize - 8 * node->NumKeys()) + || (uint32)node->Values() > (uint32)node + fTree->fNodeSize + - 8 * node->NumKeys()) RETURN_ERROR(B_ERROR); nextOffset = BFS_ENDIAN_TO_HOST_INT64(node->Values()[0]); @@ -1856,21 +1920,21 @@ } -/** Iterates through the tree in the specified direction. - * When it iterates through duplicates, the "key" is only updated for the - * first entry - if you need to know when this happens, use the "duplicate" - * parameter which is 0 for no duplicate, 1 for the first, and 2 for all - * the other duplicates. - * That's not too nice, but saves the 256 bytes that would be needed to - * store the last key - if this will ever become an issue, it will be - * easy to change. - * The other advantage of this is, that the queries can skip all duplicates - * at once when they are not relevant to them. - */ - +/*! + Iterates through the tree in the specified direction. + When it iterates through duplicates, the "key" is only updated for the + first entry - if you need to know when this happens, use the "duplicate" + parameter which is 0 for no duplicate, 1 for the first, and 2 for all + the other duplicates. + That's not too nice, but saves the 256 bytes that would be needed to + store the last key - if this will ever become an issue, it will be + easy to change. + The other advantage of this is, that the queries can skip all duplicates + at once when they are not relevant to them. +*/ status_t -TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, uint16 maxLength, - off_t *value, uint16 *duplicate) +TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, + uint16 maxLength, off_t *value, uint16 *duplicate) { if (fTree == NULL) return B_INTERRUPTED; @@ -2007,11 +2071,11 @@ } -/** This is more or less a copy of BPlusTree::Find() - but it just - * sets the current position in the iterator, regardless of if the - * key could be found or not. - */ - +/*! + This is more or less a copy of BPlusTree::Find() - but it just + sets the current position in the iterator, regardless of if the + key could be found or not. +*/ status_t TreeIterator::Find(const uint8 *key, uint16 keyLength) { @@ -2031,7 +2095,8 @@ while ((node = cached.SetTo(nodeOffset)) != NULL) { uint16 keyIndex = 0; off_t nextOffset; - status_t status = fTree->FindKey(node, key, keyLength, &keyIndex, &nextOffset); + status_t status = fTree->_FindKey(node, key, keyLength, &keyIndex, + &nextOffset); if (node->OverflowLink() == BPLUSTREE_NULL) { fCurrentNodeOffset = nodeOffset; @@ -2160,12 +2225,11 @@ } -/** Although the name suggests it, this function doesn't return the real - * used fragment count; at least, it can only count to two: it returns - * 0, if there is no fragment used, 1 if there is only one fragment - * used, and 2 if there are at least 2 fragments used. - */ - +/*! Although the name suggests it, this function doesn't return the real + used fragment count; at least, it can only count to two: it returns + 0, if there is no fragment used, 1 if there is only one fragment + used, and 2 if there are at least 2 fragments used. +*/ uint32 bplustree_node::FragmentsUsed(uint32 nodeSize) const { @@ -2210,14 +2274,11 @@ int32 -compareKeys(type_code type, const void *key1, int keyLength1, const void *key2, int keyLength2) +compareKeys(type_code type, const void *key1, int keyLength1, + const void *key2, int keyLength2) { // if one of the keys is NULL, bail out gracefully if (key1 == NULL || key2 == NULL) { -//#if USER -// // that's here to see if it's reasonable to handle this case nicely at all -// DEBUGGER(("compareKeys() got NULL key!")); -//#endif // even if it's most probably a bug in the calling code, we try to [... truncated: 469 lines follow ...] From bonefish at mail.berlios.de Mon May 7 15:41:13 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 7 May 2007 15:41:13 +0200 Subject: [Haiku-commits] r21055 - in haiku/trunk: headers/private/fs_shell src/tools/fs_shell Message-ID: <200705071341.l47DfDYo002042@sheep.berlios.de> Author: bonefish Date: 2007-05-07 15:41:12 +0200 (Mon, 07 May 2007) New Revision: 21055 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21055&view=rev Modified: haiku/trunk/headers/private/fs_shell/fssh_stat.h haiku/trunk/src/tools/fs_shell/vfs.cpp Log: Surprising how much gcc 4 compilers on Linux differ. Another attempt to make both gcc 2.95.3 and the plethora of gcc 4s happy: Typedefed struct fssh_stat to fssh_struct_stat, thus hopefully avoiding spurious errors concerning clashes with the function or regarding namespacing. Modified: haiku/trunk/headers/private/fs_shell/fssh_stat.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_stat.h 2007-05-07 12:26:21 UTC (rev 21054) +++ haiku/trunk/headers/private/fs_shell/fssh_stat.h 2007-05-07 13:41:12 UTC (rev 21055) @@ -31,6 +31,7 @@ // can only retrieve the R5 stat structure unsigned int fssh_st_type; /* attribute/index type */ }; +typedef struct fssh_stat fssh_struct_stat; /* extended file types */ #define FSSH_S_ATTR_DIR 01000000000 /* attribute directory */ Modified: haiku/trunk/src/tools/fs_shell/vfs.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/vfs.cpp 2007-05-07 12:26:21 UTC (rev 21054) +++ haiku/trunk/src/tools/fs_shell/vfs.cpp 2007-05-07 13:41:12 UTC (rev 21055) @@ -4959,17 +4959,17 @@ fssh_status_t _kern_read_stat(int fd, const char *path, bool traverseLeafLink, - struct ::fssh_stat *stat, fssh_size_t statSize) + fssh_struct_stat *stat, fssh_size_t statSize) { - struct ::fssh_stat completeStat; - struct ::fssh_stat *originalStat = NULL; + fssh_struct_stat completeStat; + fssh_struct_stat *originalStat = NULL; fssh_status_t status; - if (statSize > sizeof(struct ::fssh_stat)) + if (statSize > sizeof(fssh_struct_stat)) return FSSH_B_BAD_VALUE; // this supports different stat extensions - if (statSize < sizeof(struct ::fssh_stat)) { + if (statSize < sizeof(fssh_struct_stat)) { originalStat = stat; stat = &completeStat; } @@ -5028,16 +5028,16 @@ fssh_status_t _kern_write_stat(int fd, const char *path, bool traverseLeafLink, - const struct ::fssh_stat *stat, fssh_size_t statSize, int statMask) + const fssh_struct_stat *stat, fssh_size_t statSize, int statMask) { - struct ::fssh_stat completeStat; + fssh_struct_stat completeStat; - if (statSize > sizeof(struct ::fssh_stat)) + if (statSize > sizeof(fssh_struct_stat)) return FSSH_B_BAD_VALUE; // this supports different stat extensions - if (statSize < sizeof(struct ::fssh_stat)) { - fssh_memset((uint8_t *)&completeStat + statSize, 0, sizeof(struct ::fssh_stat) - statSize); + if (statSize < sizeof(fssh_struct_stat)) { + fssh_memset((uint8_t *)&completeStat + statSize, 0, sizeof(fssh_struct_stat) - statSize); fssh_memcpy(&completeStat, stat, statSize); stat = &completeStat; } @@ -5128,7 +5128,7 @@ fssh_status_t -_kern_read_index_stat(fssh_dev_t device, const char *name, struct ::fssh_stat *stat) +_kern_read_index_stat(fssh_dev_t device, const char *name, fssh_struct_stat *stat) { return index_name_read_stat(device, name, stat, true); } From bonefish at mail.berlios.de Mon May 7 15:43:55 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 7 May 2007 15:43:55 +0200 Subject: [Haiku-commits] r21056 - haiku/trunk/src/tools/fs_shell Message-ID: <200705071343.l47Dht3C002172@sheep.berlios.de> Author: bonefish Date: 2007-05-07 15:43:55 +0200 (Mon, 07 May 2007) New Revision: 21056 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21056&view=rev Modified: haiku/trunk/src/tools/fs_shell/posix_compatibility.h Log: Since I haven't got enough information to solve the missing LLONG_MAX issue on some Linux distros by now, here's a work-around. Modified: haiku/trunk/src/tools/fs_shell/posix_compatibility.h =================================================================== --- haiku/trunk/src/tools/fs_shell/posix_compatibility.h 2007-05-07 13:41:12 UTC (rev 21055) +++ haiku/trunk/src/tools/fs_shell/posix_compatibility.h 2007-05-07 13:43:55 UTC (rev 21056) @@ -5,13 +5,19 @@ #ifndef _FSSH_POSIX_COMPATIBILITY_H #define _FSSH_POSIX_COMPATIBILITY_H -// BeOS doesn't define [U]LLONG_{MIN,MAX}, but [U]LONGLONG_{MIN,MAX} #include -#ifndef LLONG_MIN -# define LLONG_MIN LONGLONG_MIN -# define LLONG_MAX LONGLONG_MAX -# define ULLONG_MAX ULONGLONG_MAX + +// BeOS doesn't define [U]LLONG_{MIN,MAX}, but [U]LONGLONG_{MIN,MAX}. +// And under some stupid Linux platforms we don't get the macros when +// compiling in C++ mode. +#ifndef LLONG_MAX +# ifdef LONGLONG_MAX + // define to the BeOS macro +# define LLONG_MAX LONGLONG_MAX +# else + // minimum acceptable value as per standard +# define LLONG_MAX (9223372036854775807LL) +# endif #endif #endif // _FSSH_POSIX_COMPATIBILITY_H - From korli at mail.berlios.de Mon May 7 16:08:30 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Mon, 7 May 2007 16:08:30 +0200 Subject: [Haiku-commits] r21057 - haiku/trunk/src/add-ons/kernel/busses/usb Message-ID: <200705071408.l47E8U4d004281@sheep.berlios.de> Author: korli Date: 2007-05-07 16:08:30 +0200 (Mon, 07 May 2007) New Revision: 21057 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21057&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/usb/uhci.cpp haiku/trunk/src/add-ons/kernel/busses/usb/uhci.h Log: implemented CancelQueuedTransfers for uhci Modified: haiku/trunk/src/add-ons/kernel/busses/usb/uhci.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/uhci.cpp 2007-05-07 13:43:55 UTC (rev 21056) +++ haiku/trunk/src/add-ons/kernel/busses/usb/uhci.cpp 2007-05-07 14:08:30 UTC (rev 21057) @@ -539,6 +539,45 @@ status_t +UHCI::CancelQueuedTransfers(Pipe *pipe) +{ + if (!Lock()) + return B_ERROR; + + transfer_data *last = NULL; + transfer_data *current = fFirstTransfer; + while (current) { + if (current->transfer->TransferPipe() == pipe) { + current->queue->RemoveTransfer(current->transfer_queue); + FreeDescriptorChain(current->first_descriptor); + FreeTransferQueue(current->transfer_queue); + current->transfer->Finished(B_CANCELED, 0); + delete current->transfer; + + transfer_data *next = current->link; + if (last) + last->link = next; + else + fFirstTransfer = next; + + if (fLastTransfer == current) + fLastTransfer = last; + + delete current; + current = next; + } else { + last = current; + current = current->link; + } + } + + Unlock(); + + return B_OK; +} + + +status_t UHCI::SubmitRequest(Transfer *transfer) { Pipe *pipe = transfer->TransferPipe(); Modified: haiku/trunk/src/add-ons/kernel/busses/usb/uhci.h =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/uhci.h 2007-05-07 13:43:55 UTC (rev 21056) +++ haiku/trunk/src/add-ons/kernel/busses/usb/uhci.h 2007-05-07 14:08:30 UTC (rev 21057) @@ -68,6 +68,7 @@ status_t Start(); virtual status_t SubmitTransfer(Transfer *transfer); +virtual status_t CancelQueuedTransfers(Pipe *pipe); status_t SubmitRequest(Transfer *transfer); static status_t AddTo(Stack *stack); From mmlr at mail.berlios.de Mon May 7 18:58:10 2007 From: mmlr at mail.berlios.de (mmlr at BerliOS) Date: Mon, 7 May 2007 18:58:10 +0200 Subject: [Haiku-commits] r21058 - haiku/trunk/src/add-ons/kernel/busses/usb Message-ID: <200705071658.l47GwAWj028598@sheep.berlios.de> Author: mmlr Date: 2007-05-07 18:58:00 +0200 (Mon, 07 May 2007) New Revision: 21058 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21058&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ehci.cpp Log: Fixed wrong cancelling algorithm. This is what you get when you "rework" an existing function without thinking it through again... Thanks J Jerome for noticing\! Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ehci.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ehci.cpp 2007-05-07 14:08:30 UTC (rev 21057) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ehci.cpp 2007-05-07 16:58:00 UTC (rev 21058) @@ -916,19 +916,21 @@ current->transfer->Finished(B_CANCELED, 0); delete current->transfer; + transfer_data *next = current->link; if (last) - last->link = current->link; + last->link = next; else - fFirstTransfer = current->link; + fFirstTransfer = next; if (fLastTransfer == current) fLastTransfer = last; delete current; + current = next; + } else { + last = current; + current = current->link; } - - last = current; - current = current->link; } Unlock(); From mmlr at mail.berlios.de Mon May 7 19:57:30 2007 From: mmlr at mail.berlios.de (mmlr at BerliOS) Date: Mon, 7 May 2007 19:57:30 +0200 Subject: [Haiku-commits] r21059 - in haiku/trunk/src/add-ons/kernel: bus_managers/usb busses/usb Message-ID: <200705071757.l47HvUWL011222@sheep.berlios.de> Author: mmlr Date: 2007-05-07 19:57:30 +0200 (Mon, 07 May 2007) New Revision: 21059 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21059&view=rev Modified: haiku/trunk/src/add-ons/kernel/bus_managers/usb/Transfer.cpp haiku/trunk/src/add-ons/kernel/bus_managers/usb/usb_p.h haiku/trunk/src/add-ons/kernel/busses/usb/ehci.cpp haiku/trunk/src/add-ons/kernel/busses/usb/uhci.cpp Log: * Reworked userland buffer access functionality into two functions in the Transfer class to not duplicate code in each HCD * Use these functions in UHCI and EHCI which greatly reduces overhead on fragmented transfers as the vector conversion and area cloning is only done once * Use the PrepareKernelAccess() function before submitting fragments which fixes the crash when trying to access the next fragments buffer in user memory from the kernel thread This should fix bug #1167 which could be encountered when sending data to a mass storage device with an application that uses a large enough transfer buffer size. Modified: haiku/trunk/src/add-ons/kernel/bus_managers/usb/Transfer.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/usb/Transfer.cpp 2007-05-07 16:58:00 UTC (rev 21058) +++ haiku/trunk/src/add-ons/kernel/bus_managers/usb/Transfer.cpp 2007-05-07 17:57:30 UTC (rev 21059) @@ -17,6 +17,8 @@ fBaseAddress(NULL), fFragmented(false), fActualLength(0), + fUserArea(-1), + fClonedArea(-1), fCallback(NULL), fCallbackCookie(NULL), fRequestData(NULL) @@ -32,6 +34,9 @@ if (fVector && fVector != &fData) delete[] fVector; + + if (fClonedArea >= B_OK) + delete_area(fClonedArea); } @@ -101,6 +106,72 @@ } +status_t +Transfer::InitKernelAccess() +{ +#ifndef HAIKU_TARGET_PLATFORM_HAIKU + // we might need to access a buffer in userspace. this will not + // be possible in the kernel space finisher thread unless we + // get the proper area id for the space we need and then clone it + // before reading from or writing to it. + iovec *vector = fVector; + for (size_t i = 0; i < fVectorCount; i++) { + if (IS_USER_ADDRESS(vector[i].iov_base)) { + fUserArea = area_for(vector[i].iov_base); + if (fUserArea < B_OK) + return B_BAD_ADDRESS; + break; + } + } + + // no user area required for access + if (fUserArea < B_OK) + return B_OK; + + area_info areaInfo; + if (fUserArea < B_OK || get_area_info(fUserArea, &areaInfo) < B_OK) + return B_BAD_ADDRESS; + + for (size_t i = 0; i < fVectorCount; i++) { + (uint8 *)vector[i].iov_base -= (uint8 *)areaInfo.address; + + if ((size_t)vector[i].iov_base > areaInfo.size + || (size_t)vector[i].iov_base + vector[i].iov_len > areaInfo.size) { + TRACE_ERROR(("USB Transfer: data buffer spans across multiple areas!\n")); + return B_BAD_ADDRESS; + } + } +#endif // !HAIKU_TARGET_PLATFORM_HAIKU + + return B_OK; +} + + +status_t +Transfer::PrepareKernelAccess() +{ +#ifndef HAIKU_TARGET_PLATFORM_HAIKU + // done if there is no userspace buffer or if we already cloned its area + if (fUserArea < B_OK || fClonedArea >= B_OK) + return B_OK; + + void *clonedMemory = NULL; + // we got a userspace buffer, need to clone the area for that + // space first and map the iovecs to this cloned area. + fClonedArea = clone_area("userspace accessor", &clonedMemory, + B_ANY_ADDRESS, B_WRITE_AREA | B_KERNEL_WRITE_AREA, fUserArea); + + if (fClonedArea < B_OK) + return fClonedArea; + + for (size_t i = 0; i < fVectorCount; i++) + (uint8 *)fVector[i].iov_base += (addr_t)clonedMemory; +#endif // !HAIKU_TARGET_PLATFORM_HAIKU + + return B_OK; +} + + void Transfer::SetCallback(usb_callback_func callback, void *cookie) { Modified: haiku/trunk/src/add-ons/kernel/bus_managers/usb/usb_p.h =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/usb/usb_p.h 2007-05-07 16:58:00 UTC (rev 21058) +++ haiku/trunk/src/add-ons/kernel/bus_managers/usb/usb_p.h 2007-05-07 17:57:30 UTC (rev 21059) @@ -533,6 +533,9 @@ bool IsFragmented() { return fFragmented; }; void AdvanceByFragment(size_t actualLength); + status_t InitKernelAccess(); + status_t PrepareKernelAccess(); + void SetCallback(usb_callback_func callback, void *cookie); @@ -547,6 +550,8 @@ void *fBaseAddress; bool fFragmented; size_t fActualLength; + area_id fUserArea; + area_id fClonedArea; usb_callback_func fCallback; void *fCallbackCookie; Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ehci.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ehci.cpp 2007-05-07 16:58:00 UTC (rev 21058) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ehci.cpp 2007-05-07 17:57:30 UTC (rev 21059) @@ -835,6 +835,10 @@ if (!data) return B_NO_MEMORY; + status_t result = transfer->InitKernelAccess(); + if (result < B_OK) + return result; + data->transfer = transfer; data->queue_head = queueHead; data->data_descriptor = dataDescriptor; @@ -842,49 +846,6 @@ data->incoming = directionIn; data->link = NULL; -#ifndef HAIKU_TARGET_PLATFORM_HAIKU - if (directionIn) { - // we might need to access a buffer in userspace. this will not - // be possible in the kernel space finisher thread unless we - // get the proper area id for the space we need and then clone it - // before writing to it. this is of course terribly inefficient... - iovec *vector = transfer->Vector(); - size_t vectorCount = transfer->VectorCount(); - for (size_t i = 0; i < vectorCount; i++) { - if (IS_USER_ADDRESS(vector[i].iov_base)) { - data->user_area = area_for(vector[i].iov_base); - if (data->user_area < B_OK) { - TRACE_ERROR(("usb_ehci: failed to get area of userspace buffer\n")); - delete data; - return B_BAD_ADDRESS; - } - - break; - } - } - - if (data->user_area >= B_OK) { - area_info areaInfo; - if (get_area_info(data->user_area, &areaInfo) < B_OK) { - TRACE_ERROR(("usb_ehci: failed to get info about user area\n")); - delete data; - return B_BAD_ADDRESS; - } - - for (size_t i = 0; i < vectorCount; i++) { - (uint8 *)vector[i].iov_base -= (uint8 *)areaInfo.address; - - if ((size_t)vector[i].iov_base > areaInfo.size - || (size_t)vector[i].iov_base + vector[i].iov_len > areaInfo.size) { - TRACE_ERROR(("usb_ehci: output data buffer spans across multiple areas!\n")); - delete data; - return B_BAD_ADDRESS; - } - } - } - } -#endif // !HAIKU_TARGET_PLATFORM_HAIKU - if (!Lock()) { delete data; return B_ERROR; @@ -1053,36 +1014,11 @@ // data to read out iovec *vector = transfer->transfer->Vector(); size_t vectorCount = transfer->transfer->VectorCount(); - -#ifndef HAIKU_TARGET_PLATFORM_HAIKU - area_id clonedArea = -1; - void *clonedMemory = NULL; - if (transfer->user_area >= B_OK) { - // we got a userspace output buffer, need to clone - // the area for that space first and map the iovecs - // to this cloned area. - clonedArea = clone_area("userspace accessor", - &clonedMemory, B_ANY_ADDRESS, - B_WRITE_AREA | B_KERNEL_WRITE_AREA, - transfer->user_area); - - for (size_t i = 0; i < vectorCount; i++) - (uint8 *)vector[i].iov_base += (addr_t)clonedMemory; - } -#endif // !HAIKU_TARGET_PLATFORM_HAIKU - + transfer->transfer->PrepareKernelAccess(); actualLength = ReadDescriptorChain( transfer->data_descriptor, vector, vectorCount, &nextDataToggle); - -#ifndef HAIKU_TARGET_PLATFORM_HAIKU - if (clonedArea >= B_OK) { - for (size_t i = 0; i < vectorCount; i++) - (uint8 *)vector[i].iov_base -= (addr_t)clonedMemory; - delete_area(clonedArea); - } -#endif // !HAIKU_TARGET_PLATFORM_HAIKU } else { // calculate transfered length actualLength = ReadActualLength( @@ -1096,6 +1032,7 @@ transfer->transfer->AdvanceByFragment(actualLength); if (transfer->transfer->VectorLength() > 0) { FreeDescriptorChain(transfer->data_descriptor); + transfer->transfer->PrepareKernelAccess(); FillQueueWithData(transfer->transfer, transfer->queue_head, &transfer->data_descriptor, NULL); Modified: haiku/trunk/src/add-ons/kernel/busses/usb/uhci.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/uhci.cpp 2007-05-07 16:58:00 UTC (rev 21058) +++ haiku/trunk/src/add-ons/kernel/busses/usb/uhci.cpp 2007-05-07 17:57:30 UTC (rev 21059) @@ -668,6 +668,10 @@ if (!data) return B_NO_MEMORY; + status_t result = transfer->InitKernelAccess(); + if (result < B_OK) + return result; + data->transfer = transfer; data->queue = queue; data->transfer_queue = transferQueue; @@ -677,49 +681,6 @@ data->incoming = directionIn; data->link = NULL; -#ifndef HAIKU_TARGET_PLATFORM_HAIKU - if (directionIn) { - // we might need to access a buffer in userspace. this will not - // be possible in the kernel space finisher thread unless we - // get the proper area id for the space we need and then clone it - // before writing to it. this is of course terribly inefficient... - iovec *vector = transfer->Vector(); - size_t vectorCount = transfer->VectorCount(); - for (size_t i = 0; i < vectorCount; i++) { - if (IS_USER_ADDRESS(vector[i].iov_base)) { - data->user_area = area_for(vector[i].iov_base); - if (data->user_area < B_OK) { - TRACE_ERROR(("usb_uhci: failed to get area of userspace buffer\n")); - delete data; - return B_BAD_ADDRESS; - } - - break; - } - } - - if (data->user_area >= B_OK) { - area_info areaInfo; - if (get_area_info(data->user_area, &areaInfo) < B_OK) { - TRACE_ERROR(("usb_uhci: failed to get info about user area\n")); - delete data; - return B_BAD_ADDRESS; - } - - for (size_t i = 0; i < vectorCount; i++) { - (uint8 *)vector[i].iov_base -= (uint8 *)areaInfo.address; - - if ((size_t)vector[i].iov_base > areaInfo.size - || (size_t)vector[i].iov_base + vector[i].iov_len > areaInfo.size) { - TRACE_ERROR(("usb_uhci: output data buffer spans across multiple areas!\n")); - delete data; - return B_BAD_ADDRESS; - } - } - } - } -#endif // !HAIKU_TARGET_PLATFORM_HAIKU - if (!Lock()) { delete data; return B_ERROR; @@ -840,35 +801,11 @@ iovec *vector = transfer->transfer->Vector(); size_t vectorCount = transfer->transfer->VectorCount(); -#ifndef HAIKU_TARGET_PLATFORM_HAIKU - area_id clonedArea = -1; - void *clonedMemory = NULL; - if (transfer->user_area >= B_OK) { - // we got a userspace output buffer, need to clone - // the area for that space first and map the iovecs - // to this cloned area. - clonedArea = clone_area("userspace accessor", - &clonedMemory, B_ANY_ADDRESS, - B_WRITE_AREA | B_KERNEL_WRITE_AREA, - transfer->user_area); - - for (size_t i = 0; i < vectorCount; i++) - (uint8 *)vector[i].iov_base += (addr_t)clonedMemory; - } -#endif // !HAIKU_TARGET_PLATFORM_HAIKU - + transfer->transfer->PrepareKernelAccess(); actualLength = ReadDescriptorChain( transfer->data_descriptor, vector, vectorCount, &lastDataToggle); - -#ifndef HAIKU_TARGET_PLATFORM_HAIKU - if (clonedArea >= B_OK) { - for (size_t i = 0; i < vectorCount; i++) - (uint8 *)vector[i].iov_base -= (addr_t)clonedMemory; - delete_area(clonedArea); - } -#endif // !HAIKU_TARGET_PLATFORM_HAIKU } else { // read the actual length that was sent actualLength = ReadActualLength( @@ -886,6 +823,7 @@ TRACE(("usb_uhci: still %ld bytes left on transfer\n", transfer->transfer->VectorLength())); // resubmit the advanced transfer so the rest // of the buffers are transmitted over the bus + transfer->transfer->PrepareKernelAccess(); status_t result = CreateFilledTransfer(transfer->transfer, &transfer->first_descriptor, &transfer->transfer_queue); From korli at mail.berlios.de Mon May 7 20:08:55 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Mon, 7 May 2007 20:08:55 +0200 Subject: [Haiku-commits] r21060 - in haiku/trunk/src/add-ons/kernel/drivers/network: bcm440x bcm570x Message-ID: <200705071808.l47I8tqC011970@sheep.berlios.de> Author: korli Date: 2007-05-07 20:08:55 +0200 (Mon, 07 May 2007) New Revision: 21060 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21060&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/network/bcm440x/b44mm.h haiku/trunk/src/add-ons/kernel/drivers/network/bcm440x/b44um.c haiku/trunk/src/add-ons/kernel/drivers/network/bcm570x/b57um.c haiku/trunk/src/add-ons/kernel/drivers/network/bcm570x/mm.h Log: added missing ioctl for handling link state change. I noted it's not supported on my bcm440x chipset Modified: haiku/trunk/src/add-ons/kernel/drivers/network/bcm440x/b44mm.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/bcm440x/b44mm.h 2007-05-07 17:57:30 UTC (rev 21059) +++ haiku/trunk/src/add-ons/kernel/drivers/network/bcm440x/b44mm.h 2007-05-07 18:08:55 UTC (rev 21060) @@ -82,6 +82,10 @@ int block; spinlock lock; + +#ifdef HAIKU_TARGET_PLATFORM_HAIKU + sem_id linkChangeSem; +#endif }; struct B_UM_PACKET { Modified: haiku/trunk/src/add-ons/kernel/drivers/network/bcm440x/b44um.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/bcm440x/b44um.c 2007-05-07 17:57:30 UTC (rev 21059) +++ haiku/trunk/src/add-ons/kernel/drivers/network/bcm440x/b44um.c 2007-05-07 18:08:55 UTC (rev 21060) @@ -109,6 +109,9 @@ be_b44_dev_cards[sCardsFound].opened = 0; be_b44_dev_cards[sCardsFound].block = 1; be_b44_dev_cards[sCardsFound].lock = 0; +#ifdef HAIKU_TARGET_PLATFORM_HAIKU + be_b44_dev_cards[sCardsFound].linkChangeSem = -1; +#endif if (b44_LM_GetAdapterInfo(&be_b44_dev_cards[sCardsFound].lm_dev) != LM_STATUS_SUCCESS) return ENODEV; @@ -216,7 +219,7 @@ status_t -b44_ioctl(void *cookie,uint32 op,void *data,size_t len) +b44_ioctl(void *cookie,uint32 op, void *data, size_t len) { struct be_b44_dev *pUmDevice = (struct be_b44_dev *)cookie; @@ -278,6 +281,16 @@ return user_memcpy(data, &state, sizeof(ether_link_state_t)); } + + case ETHER_SET_LINK_STATE_SEM: + { + if (user_memcpy(&pUmDevice->linkChangeSem, data, sizeof(sem_id)) < B_OK) { + pUmDevice->linkChangeSem = -1; + return B_BAD_ADDRESS; + } + return B_OK; + } + #endif } return B_ERROR; @@ -600,6 +613,14 @@ LM_STATUS b44_MM_IndicateStatus(PLM_DEVICE_BLOCK pDevice, LM_STATUS Status) { +#ifdef HAIKU_TARGET_PLATFORM_HAIKU + struct be_b44_dev *pUmDevice = (struct be_b44_dev *)pDevice; + + if (pUmDevice->linkChangeSem != -1) + release_sem_etc(pUmDevice->linkChangeSem, 1, + B_DO_NOT_RESCHEDULE); +#endif + return LM_STATUS_SUCCESS; } Modified: haiku/trunk/src/add-ons/kernel/drivers/network/bcm570x/b57um.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/bcm570x/b57um.c 2007-05-07 17:57:30 UTC (rev 21059) +++ haiku/trunk/src/add-ons/kernel/drivers/network/bcm570x/b57um.c 2007-05-07 18:08:55 UTC (rev 21060) @@ -327,6 +327,9 @@ be_b57_dev_cards[cards_found].opened = 0; be_b57_dev_cards[cards_found].block = 1; be_b57_dev_cards[cards_found].lock = 0; +#ifdef HAIKU_TARGET_PLATFORM_HAIKU + be_b57_dev_cards[cards_found].linkChangeSem = -1; +#endif if (LM_GetAdapterInfo(&be_b57_dev_cards[cards_found].lm_dev) != LM_STATUS_SUCCESS) { put_module(B_PCI_MODULE_NAME); @@ -519,6 +522,15 @@ return user_memcpy(data, &state, sizeof(ether_link_state_t)); } + case ETHER_SET_LINK_STATE_SEM: + { + if (user_memcpy(&pUmDevice->linkChangeSem, data, sizeof(sem_id)) < B_OK) { + pUmDevice->linkChangeSem = -1; + return B_BAD_ADDRESS; + } + return B_OK; + } + #endif } return B_ERROR; @@ -909,7 +921,16 @@ LM_STATUS -MM_IndicateStatus(PLM_DEVICE_BLOCK pDevice, LM_STATUS Status) { +MM_IndicateStatus(PLM_DEVICE_BLOCK pDevice, LM_STATUS Status) +{ +#ifdef HAIKU_TARGET_PLATFORM_HAIKU + struct be_b57_dev *pUmDevice = (struct be_b57_dev *)pDevice; + + if (pUmDevice->linkChangeSem != -1) + release_sem_etc(pUmDevice->linkChangeSem, 1, + B_DO_NOT_RESCHEDULE); +#endif + return LM_STATUS_SUCCESS; } Modified: haiku/trunk/src/add-ons/kernel/drivers/network/bcm570x/mm.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/bcm570x/mm.h 2007-05-07 17:57:30 UTC (rev 21059) +++ haiku/trunk/src/add-ons/kernel/drivers/network/bcm570x/mm.h 2007-05-07 18:08:55 UTC (rev 21060) @@ -84,6 +84,10 @@ int block; spinlock lock; cpu_status cpu; + +#ifdef HAIKU_TARGET_PLATFORM_HAIKU + sem_id linkChangeSem; +#endif }; struct B_UM_PACKET { From jackburton at mail.berlios.de Mon May 7 22:49:59 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Mon, 7 May 2007 22:49:59 +0200 Subject: [Haiku-commits] r21061 - haiku/trunk/src/kits/game Message-ID: <200705072049.l47KnxZp032496@sheep.berlios.de> Author: jackburton Date: 2007-05-07 22:49:58 +0200 (Mon, 07 May 2007) New Revision: 21061 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21061&view=rev Modified: haiku/trunk/src/kits/game/DirectWindow.cpp Log: finally fixed debug output Modified: haiku/trunk/src/kits/game/DirectWindow.cpp =================================================================== --- haiku/trunk/src/kits/game/DirectWindow.cpp 2007-05-07 18:08:55 UTC (rev 21060) +++ haiku/trunk/src/kits/game/DirectWindow.cpp 2007-05-07 20:49:58 UTC (rev 21061) @@ -38,16 +38,13 @@ static void print_direct_buffer_state(const direct_buffer_state &state) { - if (state == 0) - return; - char string[128]; int modeState = state & B_DIRECT_MODE_MASK; - if (state == B_DIRECT_START) + if (modeState == B_DIRECT_START) strcpy(string, "B_DIRECT_START"); - else if (state == B_DIRECT_MODIFY) + else if (modeState == B_DIRECT_MODIFY) strcpy(string, "B_DIRECT_MODIFY"); - else if (state == B_DIRECT_STOP) + else if (modeState == B_DIRECT_STOP) strcpy(string, "B_DIRECT_STOP"); if (state & B_CLIPPING_MODIFIED) From jackburton at mail.berlios.de Mon May 7 23:21:30 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Mon, 7 May 2007 23:21:30 +0200 Subject: [Haiku-commits] r21062 - haiku/trunk/src/kits/opengl Message-ID: <200705072121.l47LLUeM005746@sheep.berlios.de> Author: jackburton Date: 2007-05-07 23:21:28 +0200 (Mon, 07 May 2007) New Revision: 21062 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21062&view=rev Modified: haiku/trunk/src/kits/opengl/GLView.cpp Log: call lock/unlock_draw() in SwapBuffers too. Don't set the view color to B_TRANSPARENT_32_BIT because it doesn't look good in direct mode. Korli, please review. Modified: haiku/trunk/src/kits/opengl/GLView.cpp =================================================================== --- haiku/trunk/src/kits/opengl/GLView.cpp 2007-05-07 20:49:58 UTC (rev 21061) +++ haiku/trunk/src/kits/opengl/GLView.cpp 2007-05-07 21:21:28 UTC (rev 21062) @@ -98,8 +98,11 @@ void BGLView::SwapBuffers(bool vSync) { - if (fRenderer) + if (fRenderer) { + lock_draw(); fRenderer->SwapBuffers(vSync); + unlock_draw(); + } } @@ -177,9 +180,16 @@ fRenderer = fRoster->GetRenderer(); if (fRenderer) { + // Jackburton: The following code was commented because it doesn't look good in "direct" mode: + // when the window is moved, the app_server doesn't paint the view's background, and + // the stuff behind the window itself shows up. + // Setting the view color to black, instead, looks a bit more elegant. +#if 0 // Don't paint white window background when resized SetViewColor(B_TRANSPARENT_32_BIT); - +#else + SetViewColor(0, 0, 0); +#endif // Set default OpenGL viewport: glViewport(0, 0, Bounds().IntegerWidth(), Bounds().IntegerHeight()); @@ -205,7 +215,7 @@ BView::AllAttached(); } - + void BGLView::DetachedFromWindow() { From jackburton at mail.berlios.de Mon May 7 23:26:33 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Mon, 7 May 2007 23:26:33 +0200 Subject: [Haiku-commits] r21063 - haiku/trunk/src/servers/app Message-ID: <200705072126.l47LQXKL006418@sheep.berlios.de> Author: jackburton Date: 2007-05-07 23:26:33 +0200 (Mon, 07 May 2007) New Revision: 21063 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21063&view=rev Modified: haiku/trunk/src/servers/app/ServerWindow.cpp Log: Avoid sending an extra (useless) B_DIRECT_MODIFY notification to the client, when the connection is stopped. But cache the "reason" of the notification, and join it with the next one, when B_DIRECT_START is notified. Experimental, could be reverted. Modified: haiku/trunk/src/servers/app/ServerWindow.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerWindow.cpp 2007-05-07 21:21:28 UTC (rev 21062) +++ haiku/trunk/src/servers/app/ServerWindow.cpp 2007-05-07 21:26:33 UTC (rev 21063) @@ -85,11 +85,12 @@ ~direct_window_data(); status_t InitCheck() const; - + sem_id sem; sem_id sem_ack; area_id area; bool started; + int next_buffer_state; direct_buffer_info *buffer_info; }; @@ -100,6 +101,7 @@ sem_ack(-1), area(-1), started(false), + next_buffer_state(0), buffer_info(NULL) { area = create_area("direct area", (void **)&buffer_info, @@ -2740,12 +2742,21 @@ || (!fDirectWindowData->started && (bufferState & B_DIRECT_MODE_MASK) != B_DIRECT_START)) return; + + // If the direct connection is stopped, only continue if a start notification is received. + // But save the "reason" of the call (B_BUFFER_RESIZED, B_CLIPPING_MODIFIED, etc) + if ((fDirectWindowData->buffer_info->buffer_state & B_DIRECT_MODE_MASK) == B_DIRECT_STOP + && (bufferState & B_DIRECT_MODE_MASK) != B_DIRECT_START) { + fDirectWindowData->next_buffer_state |= bufferState & ~B_DIRECT_MODE_MASK; + return; + } fDirectWindowData->started = true; - if (bufferState != -1) - fDirectWindowData->buffer_info->buffer_state = (direct_buffer_state)bufferState; - + fDirectWindowData->buffer_info->buffer_state = + (direct_buffer_state)(bufferState | fDirectWindowData->next_buffer_state); + fDirectWindowData->next_buffer_state = 0; + if (driverState != -1) fDirectWindowData->buffer_info->driver_state = (direct_driver_state)driverState; From mmu_man at mail.berlios.de Tue May 8 01:05:53 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Tue, 8 May 2007 01:05:53 +0200 Subject: [Haiku-commits] r21064 - haiku/trunk/src/apps/terminal Message-ID: <200705072305.l47N5rVQ009442@sheep.berlios.de> Author: mmu_man Date: 2007-05-08 01:05:52 +0200 (Tue, 08 May 2007) New Revision: 21064 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21064&view=rev Modified: haiku/trunk/src/apps/terminal/FindWindow.h haiku/trunk/src/apps/terminal/TermApp.cpp Log: Fix building on R5 (dano at least). Modified: haiku/trunk/src/apps/terminal/FindWindow.h =================================================================== --- haiku/trunk/src/apps/terminal/FindWindow.h 2007-05-07 21:26:33 UTC (rev 21063) +++ haiku/trunk/src/apps/terminal/FindWindow.h 2007-05-07 23:05:52 UTC (rev 21064) @@ -16,6 +16,10 @@ const ulong MSG_FIND_START = 'msac'; const ulong MSG_FIND_CLOSED = 'mfcl'; +class BTextControl; +class BRadioButton; +class BBox; +class BCheckBox; class FindWindow : public BWindow { public: Modified: haiku/trunk/src/apps/terminal/TermApp.cpp =================================================================== --- haiku/trunk/src/apps/terminal/TermApp.cpp 2007-05-07 21:26:33 UTC (rev 21063) +++ haiku/trunk/src/apps/terminal/TermApp.cpp 2007-05-07 23:05:52 UTC (rev 21064) @@ -29,6 +29,7 @@ #include #include #include +#include // Preference temporary From axeld at mail.berlios.de Tue May 8 02:01:51 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 8 May 2007 02:01:51 +0200 Subject: [Haiku-commits] r21065 - haiku/trunk/src/add-ons/kernel/drivers/common Message-ID: <200705080001.l4801p0L007384@sheep.berlios.de> Author: axeld Date: 2007-05-08 02:01:51 +0200 (Tue, 08 May 2007) New Revision: 21065 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21065&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/common/dprintf.cpp Log: We now respond to TCGETA to let isatty() think we're a terminal which caused our libroot to use unbuffered I/O. Modified: haiku/trunk/src/add-ons/kernel/drivers/common/dprintf.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/common/dprintf.cpp 2007-05-07 23:05:52 UTC (rev 21064) +++ haiku/trunk/src/add-ons/kernel/drivers/common/dprintf.cpp 2007-05-08 00:01:51 UTC (rev 21065) @@ -1,5 +1,5 @@ /* - * Copyright 2005, Haiku Inc. All rights reserved. + * Copyright 2005-2007, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Author(s): @@ -10,13 +10,13 @@ */ -#include - #include #include #include +#include +#include #define DEVICE_NAME "dprintf" @@ -49,6 +49,12 @@ static status_t dprintf_ioctl(void *cookie, uint32 op, void *buffer, size_t length) { + if (op == TCGETA) { + // let isatty() think we are a terminal + // (this lets libroot use unbuffered I/O) + return B_OK; + } + return EPERM; } From axeld at mail.berlios.de Tue May 8 02:31:01 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 8 May 2007 02:31:01 +0200 Subject: [Haiku-commits] r21066 - in haiku/trunk: headers/private/storage src/kits/storage src/tests/kits/storage/testapps Message-ID: <200705080031.l480V1m5011212@sheep.berlios.de> Author: axeld Date: 2007-05-08 02:30:59 +0200 (Tue, 08 May 2007) New Revision: 21066 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21066&view=rev Added: haiku/trunk/src/tests/kits/storage/testapps/PathMonitorTest.cpp Modified: haiku/trunk/headers/private/storage/PathMonitor.h haiku/trunk/src/kits/storage/PathMonitor.cpp haiku/trunk/src/tests/kits/storage/testapps/Jamfile Log: * Revamped BPathMonitor API as suggested by Ingo - we could rename it to BNodeMonitor and add wrappers for watch_node() as well, though. * Implemented more or less all what is needed for the path monitoring to work. * Added a test application: works fine under Haiku, but somewhat flaky under BeOS, dunno why yet. Modified: haiku/trunk/headers/private/storage/PathMonitor.h =================================================================== --- haiku/trunk/headers/private/storage/PathMonitor.h 2007-05-08 00:01:51 UTC (rev 21065) +++ haiku/trunk/headers/private/storage/PathMonitor.h 2007-05-08 00:30:59 UTC (rev 21066) @@ -17,22 +17,18 @@ namespace BPrivate { -class PathHandler; - class BPathMonitor { public: - BPathMonitor(); - BPathMonitor(const char* path, uint32 flags, BMessenger target); - ~BPathMonitor(); + static status_t StartWatching(const char* path, uint32 flags, BMessenger target); - status_t InitCheck() const; - status_t SetTo(const char* path, uint32 flags, BMessenger target); - status_t SetTarget(BMessenger target); - void Unset(); + static status_t StopWatching(const char* path, BMessenger target); + static status_t StopWatching(BMessenger target); private: - PathHandler* fHandler; - status_t fStatus; + BPathMonitor(); + ~BPathMonitor(); + + static status_t _InitIfNeeded(); }; } // namespace BPrivate Modified: haiku/trunk/src/kits/storage/PathMonitor.cpp =================================================================== --- haiku/trunk/src/kits/storage/PathMonitor.cpp 2007-05-08 00:01:51 UTC (rev 21065) +++ haiku/trunk/src/kits/storage/PathMonitor.cpp 2007-05-08 00:30:59 UTC (rev 21066) @@ -9,13 +9,19 @@ #include +#include + #include +#include #include #include #include +#include #include #include +#include +#include #include using namespace BPrivate; @@ -24,10 +30,23 @@ #define WATCH_NODE_FLAG_MASK 0x00ff -typedef set DirectorySet; - namespace BPrivate { +struct watched_directory { + node_ref node; + bool contained; +}; +typedef set DirectorySet; +typedef set FileSet; + +class PathHandler; +typedef map HandlerMap; + +struct watcher { + HandlerMap handlers; +}; +typedef map WatcherMap; + class PathHandler : public BHandler { public: PathHandler(const char* path, uint32 flags, BMessenger target); @@ -38,16 +57,31 @@ void Quit(); virtual void MessageReceived(BMessage* message); + void Dump(); private: + status_t _GetClosest(const char* path, bool updatePath, + node_ref& nodeRef); + bool _WatchRecursively(); + bool _WatchFilesOnly(); + void _EntryCreated(BMessage* message); + void _EntryRemoved(BMessage* message); + void _EntryMoved(BMessage* message); bool _IsContained(const node_ref& nodeRef) const; bool _IsContained(BEntry& entry) const; - bool _HasDirectory(const node_ref& nodeRef) const; + bool _HasDirectory(const node_ref& nodeRef, bool* _contained = NULL) const; + bool _CloserToPath(BEntry& entry) const; void _NotifyTarget(BMessage* message) const; status_t _AddDirectory(BEntry& entry); - status_t _RemoveDirectory(const node_ref& nodeRef); - status_t _RemoveDirectory(BEntry& entry); + status_t _AddDirectory(node_ref& nodeRef); + status_t _RemoveDirectory(const node_ref& nodeRef, ino_t directoryNode); + status_t _RemoveDirectory(BEntry& entry, ino_t directoryNode); + bool _HasFile(const node_ref& nodeRef) const; + status_t _AddFile(BEntry& entry); + status_t _RemoveFile(const node_ref& nodeRef); + status_t _RemoveFile(BEntry& entry); + BPath fPath; int32 fPathLength; BMessenger fTarget; @@ -55,11 +89,14 @@ status_t fStatus; bool fOwnsLooper; DirectorySet fDirectories; + FileSet fFiles; }; -} +static WatcherMap sWatchers; +static BLocker* sLocker; + static status_t set_entry(node_ref& nodeRef, const char* name, BEntry& entry) { @@ -87,51 +124,48 @@ } +bool +operator<(const watched_directory& a, const watched_directory& b) +{ + return a.node < b.node; +} + + // #pragma mark - PathHandler::PathHandler(const char* path, uint32 flags, BMessenger target) : BHandler(path), - fPath(path, NULL, true), fTarget(target), fFlags(flags), fOwnsLooper(false) { - fPathLength = strlen(fPath.Path()); + if (path == NULL || !path[0]) { + fStatus = B_BAD_VALUE; + return; + } - BPath first(path); + // TODO: support watching not-yet-mounted volumes as well! node_ref nodeRef; - - while (true) { - // try to find the first part of the path that exists - BDirectory directory; - fStatus = directory.SetTo(first.Path()); - if (fStatus == B_OK) { - fStatus = directory.GetNodeRef(&nodeRef); - if (fStatus == B_OK) - break; - } - - if (first.GetParent(&first) != B_OK) { - fStatus = B_ERROR; - break; - } - } - + fStatus = _GetClosest(path, true, nodeRef); if (fStatus < B_OK) return; + BLooper* looper; if (be_app != NULL) { - be_app->AddHandler(this); + looper = be_app; } else { // TODO: only have a single global looper! - BLooper* looper = new BLooper("PathMonitor looper"); + looper = new BLooper("PathMonitor looper"); looper->Run(); - looper->AddHandler(this); fOwnsLooper = true; } - fStatus = watch_node(&nodeRef, flags & WATCH_NODE_FLAG_MASK, this); + looper->Lock(); + looper->AddHandler(this); + looper->Unlock(); + + fStatus = _AddDirectory(nodeRef); } @@ -148,13 +182,6 @@ void -PathHandler::SetTarget(BMessenger target) -{ - fTarget = target; -} - - -void PathHandler::Quit() { BMessenger me(this); @@ -163,135 +190,259 @@ void -PathHandler::MessageReceived(BMessage* message) +PathHandler::Dump() { - switch (message->what) { - case B_NODE_MONITOR: - { - int32 opcode; - if (message->FindInt32("opcode", &opcode) != B_OK) - return; + printf("WATCHING DIRECTORIES:\n"); + DirectorySet::iterator i = fDirectories.begin(); + for (; i != fDirectories.end(); i++) { + printf(" %ld:%Ld (%s)\n", i->node.device, i->node.node, i->contained ? "contained" : "-"); + } - switch (opcode) { - case B_ENTRY_CREATED: - { - const char* name; - node_ref nodeRef; - if (message->FindInt32("device", &nodeRef.device) != B_OK - || message->FindInt64("directory", &nodeRef.node) != B_OK - || message->FindString("name", &name) != B_OK) - break; + printf("WATCHING FILES:\n"); - BEntry entry; - if (set_entry(nodeRef, name, entry) != B_OK) - break; + FileSet::iterator j = fFiles.begin(); + for (; j != fFiles.end(); j++) { + printf(" %ld:%Ld\n", j->device, j->node); + } +} - bool notify = true; - if (entry.IsDirectory()) { - // a new directory to watch for us - if (_AddDirectory(entry) != B_OK - || (fFlags & B_WATCH_FILES_ONLY) != 0) - notify = false; - } +status_t +PathHandler::_GetClosest(const char* path, bool updatePath, node_ref& nodeRef) +{ + BPath first(path); + BString missing; - if (notify && _IsContained(entry)) { - message->AddBool("added", true); - _NotifyTarget(message); + while (true) { + // try to find the first part of the path that exists + BDirectory directory; + status_t status = directory.SetTo(first.Path()); + if (status == B_OK) { + status = directory.GetNodeRef(&nodeRef); + if (status == B_OK) { + if (updatePath) { + // normalize path + status = fPath.SetTo(&directory, NULL, true); + if (status == B_OK) { + fPath.Append(missing.String()); + fPathLength = strlen(fPath.Path()); } - break; } + return status; + } + } - case B_ENTRY_MOVED: - { - // has the entry been moved into a monitored directory or has - // it been removed from one? - const char* name; - node_ref nodeRef; - uint64 fromNode; - uint64 node; - if (message->FindInt32("device", &nodeRef.device) != B_OK - || message->FindInt64("to directory", &nodeRef.node) != B_OK - || message->FindInt64("from directory", (int64 *)&fromNode) != B_OK - || message->FindInt64("node", (int64 *)&node) != B_OK - || message->FindString("name", &name) != B_OK) - break; + if (updatePath) { + if (missing.Length() > 0) + missing.Prepend("/"); + missing.Prepend(first.Leaf()); + } - BEntry entry; - if (set_entry(nodeRef, name, entry) != B_OK) - break; + if (first.GetParent(&first) != B_OK) + return B_ERROR; + } +} - bool wasAdded = false; - bool wasRemoved = false; - bool notify = true; - if (_HasDirectory(nodeRef)) { - // something has been added to our watched directories +bool +PathHandler::_WatchRecursively() +{ + return (fFlags & B_WATCH_RECURSIVELY) != 0; +} - // test, if the source directory is one of ours as well - nodeRef.node = fromNode; - bool hasFromDirectory = _HasDirectory(nodeRef); - if (entry.IsDirectory()) { - if (!hasFromDirectory) { - // there is a new directory to watch for us - _AddDirectory(entry); - wasAdded = true; - } - if ((fFlags & B_WATCH_FILES_ONLY) != 0) - notify = false; - } else if (!hasFromDirectory) { - // file has been added - wasAdded = true; - } - } else { - // and entry has been removed from our directories - wasRemoved = true; +bool +PathHandler::_WatchFilesOnly() +{ + return (fFlags & B_WATCH_FILES_ONLY) != 0; +} - if (entry.IsDirectory()) { - _RemoveDirectory(entry); - if ((fFlags & B_WATCH_FILES_ONLY) != 0) - notify = false; - } - } - if (notify && _IsContained(entry)) { - if (wasAdded) - message->AddBool("added", true); - if (wasRemoved) - message->AddBool("removed", true); +void +PathHandler::_EntryCreated(BMessage* message) +{ + const char* name; + node_ref nodeRef; + if (message->FindInt32("device", &nodeRef.device) != B_OK + || message->FindInt64("directory", &nodeRef.node) != B_OK + || message->FindString("name", &name) != B_OK) + return; - _NotifyTarget(message); - } - break; + BEntry entry; + if (set_entry(nodeRef, name, entry) != B_OK) + return; + + bool parentContained = false; + bool entryContained = _IsContained(entry); + if (entryContained) + parentContained = _IsContained(nodeRef); + bool notify = entryContained; + + if (entry.IsDirectory()) { + // ignore the directory if it's already known + if (entry.GetNodeRef(&nodeRef) == B_OK + && _HasDirectory(nodeRef)) { + printf(" WE ALREADY HAVE DIR %s, %ld:%Ld\n", + name, nodeRef.device, nodeRef.node); + return; + } + + // a new directory to watch for us + if (!entryContained && !_CloserToPath(entry) + || parentContained && !_WatchRecursively() + || _AddDirectory(entry) != B_OK + || _WatchFilesOnly()) + notify = parentContained; + } else if (entryContained) { + printf(" NEW ENTRY PARENT CONTAINED: %d\n", parentContained); + _AddFile(entry); + } + + if (notify && entryContained) { + message->AddBool("added", true); + _NotifyTarget(message); + } +} + + +void +PathHandler::_EntryRemoved(BMessage* message) +{ + node_ref nodeRef; + uint64 directoryNode; + if (message->FindInt32("device", &nodeRef.device) != B_OK + || message->FindInt64("directory", (int64 *)&directoryNode) != B_OK + || message->FindInt64("node", &nodeRef.node) != B_OK) + return; + + bool notify = false; + + if (_HasDirectory(nodeRef, ¬ify)) { + // the directory has been removed, so we remove it as well + _RemoveDirectory(nodeRef, directoryNode); + if (_WatchFilesOnly()) + notify = false; + } else if (_HasFile(nodeRef)) { + _RemoveFile(nodeRef); + notify = true; + } + + if (notify) { + message->AddBool("removed", true); + _NotifyTarget(message); + } +} + + +void +PathHandler::_EntryMoved(BMessage* message) +{ + // has the entry been moved into a monitored directory or has + // it been removed from one? + const char* name; + node_ref nodeRef; + uint64 fromNode; + uint64 node; + if (message->FindInt32("device", &nodeRef.device) != B_OK + || message->FindInt64("to directory", &nodeRef.node) != B_OK + || message->FindInt64("from directory", (int64 *)&fromNode) != B_OK + || message->FindInt64("node", (int64 *)&node) != B_OK + || message->FindString("name", &name) != B_OK) + return; + + BEntry entry; + if (set_entry(nodeRef, name, entry) != B_OK) + return; + + bool entryContained = _IsContained(entry); + bool wasAdded = false; + bool wasRemoved = false; + bool notify = false; + + bool parentContained; + if (_HasDirectory(nodeRef, &parentContained)) { + // something has been added to our watched directories + + nodeRef.node = node; +printf(" ADDED TO PARENT (%d), has entry %d/%d, entry %d %d\n", +parentContained, _HasDirectory(nodeRef), _HasFile(nodeRef), +entryContained, _CloserToPath(entry)); + + if (entry.IsDirectory()) { + if (!_HasDirectory(nodeRef) + && (entryContained || _CloserToPath(entry))) { + // there is a new directory to watch for us + if (entryContained + || parentContained && !_WatchRecursively()) + _AddDirectory(entry); + else if (_GetClosest(fPath.Path(), false, + nodeRef) == B_OK) { + // the new directory might put us even + // closer to the path we are after + _AddDirectory(nodeRef); } - case B_ENTRY_REMOVED: - { - node_ref nodeRef; - uint64 directoryNode; - if (message->FindInt32("device", &nodeRef.device) != B_OK - || message->FindInt64("directory", (int64 *)&directoryNode) != B_OK - || message->FindInt64("node", &nodeRef.node) != B_OK) - break; + wasAdded = true; + notify = entryContained; + } + if (_WatchFilesOnly()) + notify = false; + } else if (!_HasFile(nodeRef) && entryContained) { + // file has been added + wasAdded = true; + notify = true; + _AddFile(entry); + } + } else { + // and entry has been removed from our directories + wasRemoved = true; - bool notify = true; + nodeRef.node = node; + if (entry.IsDirectory()) { + if (_HasDirectory(nodeRef, ¬ify)) + _RemoveDirectory(entry, fromNode); + if (_WatchFilesOnly()) + notify = false; + } else { + _RemoveFile(entry); + notify = true; + } + } - if (_HasDirectory(nodeRef)) { - // the directory has been removed, so we remove it as well - _RemoveDirectory(nodeRef); - if ((fFlags & B_WATCH_FILES_ONLY) != 0) - notify = false; - } + if (notify) { + if (wasAdded) + message->AddBool("added", true); + if (wasRemoved) + message->AddBool("removed", true); - nodeRef.node = directoryNode; - if (notify && _IsContained(nodeRef)) { - message->AddBool("removed", true); - _NotifyTarget(message); - } + _NotifyTarget(message); + } +} + + +void +PathHandler::MessageReceived(BMessage* message) +{ + switch (message->what) { + case B_NODE_MONITOR: + { + int32 opcode; + if (message->FindInt32("opcode", &opcode) != B_OK) + return; + + switch (opcode) { + case B_ENTRY_CREATED: + _EntryCreated(message); break; - } + case B_ENTRY_REMOVED: + _EntryRemoved(message); + break; + + case B_ENTRY_MOVED: + _EntryMoved(message); + break; + default: _NotifyTarget(message); break; @@ -316,6 +467,8 @@ BHandler::MessageReceived(message); break; } + + Dump(); } @@ -341,18 +494,45 @@ if (entry.GetPath(&path) != B_OK) return false; - return strncmp(path.Path(), fPath.Path(), fPathLength) == 0; + bool contained = strncmp(path.Path(), fPath.Path(), fPathLength) == 0; + if (!contained) + return false; + + const char* last = &path.Path()[fPathLength]; + if (last[0] && last[0] != '/') + return false; + + return true; } bool -PathHandler::_HasDirectory(const node_ref& nodeRef) const +PathHandler::_HasDirectory(const node_ref& nodeRef, bool* _contained = NULL) const { - DirectorySet::const_iterator iterator = fDirectories.find(nodeRef); - return iterator != fDirectories.end(); + watched_directory directory; + directory.node = nodeRef; + + DirectorySet::const_iterator iterator = fDirectories.find(directory); + if (iterator == fDirectories.end()) + return false; + + if (_contained != NULL) + *_contained = iterator->contained; + return true; } +bool +PathHandler::_CloserToPath(BEntry& entry) const +{ + BPath path; + if (entry.GetPath(&path) != B_OK) + return false; + + return strncmp(path.Path(), fPath.Path(), strlen(path.Path())) == 0; +} + + void PathHandler::_NotifyTarget(BMessage* message) const { @@ -365,27 +545,37 @@ status_t PathHandler::_AddDirectory(BEntry& entry) { - node_ref nodeRef; - status_t status = entry.GetNodeRef(&nodeRef); + watched_directory directory; + status_t status = entry.GetNodeRef(&directory.node); if (status != B_OK) return status; +//#ifdef TRACE_MONITOR +{ + BPath path(&entry); + printf(" ADD DIRECTORY %s, %ld:%Ld\n", + path.Path(), directory.node.device, directory.node.node); +} +//#endif + // check if we are already know this directory - if (_HasDirectory(nodeRef)) + if (_HasDirectory(directory.node)) return B_OK; + directory.contained = _IsContained(entry); + uint32 flags; - if (_IsContained(entry)) - flags = fFlags & WATCH_NODE_FLAG_MASK; + if (directory.contained) + flags = (fFlags & WATCH_NODE_FLAG_MASK) | B_WATCH_DIRECTORY; else flags = B_WATCH_DIRECTORY; - status = watch_node(&nodeRef, flags, this); + status = watch_node(&directory.node, flags, this); if (status != B_OK) return status; - fDirectories.insert(nodeRef); + fDirectories.insert(directory); #if 0 BEntry parent; @@ -399,95 +589,243 @@ status_t -PathHandler::_RemoveDirectory(const node_ref& nodeRef) +PathHandler::_AddDirectory(node_ref& nodeRef) { - DirectorySet::iterator iterator = fDirectories.find(nodeRef); + BDirectory directory(&nodeRef); + status_t status = directory.InitCheck(); + if (status == B_OK) { + BEntry entry; + status = directory.GetEntry(&entry); + if (status == B_OK) + status = _AddDirectory(entry); + } + + return status; +} + + +status_t +PathHandler::_RemoveDirectory(const node_ref& nodeRef, ino_t directoryNode) +{ + printf(" REMOVE DIRECTORY %ld:%Ld\n", nodeRef.device, nodeRef.node); + + watched_directory directory; + directory.node = nodeRef; + + DirectorySet::iterator iterator = fDirectories.find(directory); if (iterator == fDirectories.end()) return B_ENTRY_NOT_FOUND; + watch_node(&directory.node, B_STOP_WATCHING, this); + + node_ref directoryRef; + directoryRef.device = nodeRef.device; + directoryRef.node = directoryNode; + + if (!_HasDirectory(directoryRef)) { + // we don't have the parent directory now, but we'll need it in order + // to find this directory again in case it's added again + if (_AddDirectory(directoryRef) != B_OK + && _GetClosest(fPath.Path(), false, directoryRef) == B_OK) + _AddDirectory(directoryRef); + } + fDirectories.erase(iterator); return B_OK; } status_t -PathHandler::_RemoveDirectory(BEntry& entry) +PathHandler::_RemoveDirectory(BEntry& entry, ino_t directoryNode) { node_ref nodeRef; status_t status = entry.GetNodeRef(&nodeRef); if (status != B_OK) return status; - return _RemoveDirectory(nodeRef); + return _RemoveDirectory(nodeRef, directoryNode); } -// #pragma mark - +bool +PathHandler::_HasFile(const node_ref& nodeRef) const +{ + FileSet::const_iterator iterator = fFiles.find(nodeRef); + return iterator != fFiles.end(); +} -BPathMonitor::BPathMonitor() - : - fHandler(NULL), - fStatus(B_NO_INIT) +status_t +PathHandler::_AddFile(BEntry& entry) { + if ((fFlags & (WATCH_NODE_FLAG_MASK & ~B_WATCH_DIRECTORY)) == 0) + return B_OK; + +{ + BPath path(&entry); + printf(" ADD FILE %s\n", path.Path()); } + node_ref nodeRef; + status_t status = entry.GetNodeRef(&nodeRef); + if (status != B_OK) + return status; -BPathMonitor::BPathMonitor(const char* path, uint32 flags, BMessenger target) - : - fHandler(NULL), - fStatus(B_NO_INIT) + // check if we are already know this file + + if (_HasFile(nodeRef)) + return B_OK; + + status = watch_node(&nodeRef, (fFlags & WATCH_NODE_FLAG_MASK), this); + if (status != B_OK) + return status; + + fFiles.insert(nodeRef); + return B_OK; +} + + +status_t +PathHandler::_RemoveFile(const node_ref& nodeRef) { - SetTo(path, flags, target); + printf(" REMOVE FILE %ld:%Ld\n", nodeRef.device, nodeRef.node); + + FileSet::iterator iterator = fFiles.find(nodeRef); + if (iterator == fFiles.end()) + return B_ENTRY_NOT_FOUND; + + watch_node(&nodeRef, B_STOP_WATCHING, this); + fFiles.erase(iterator); + return B_OK; } +status_t +PathHandler::_RemoveFile(BEntry& entry) +{ + node_ref nodeRef; + status_t status = entry.GetNodeRef(&nodeRef); + if (status != B_OK) + return status; + + return _RemoveFile(nodeRef); +} + + +// #pragma mark - + + +BPathMonitor::BPathMonitor() +{ +} + + BPathMonitor::~BPathMonitor() { - Unset(); } -status_t -BPathMonitor::InitCheck() const +/*static*/ status_t +BPathMonitor::_InitIfNeeded() { - return fStatus; + static vint32 lock = 0; + + if (sLocker != NULL) + return B_OK; + + while (sLocker == NULL) { + if (atomic_add(&lock, 1) == 0) { + sLocker = new BLocker("path monitor"); + } + snooze(5000); + } + + return B_OK; } -status_t -BPathMonitor::SetTo(const char* path, uint32 flags, BMessenger target) +/*static*/ status_t +BPathMonitor::StartWatching(const char* path, uint32 flags, BMessenger target) { - Unset(); + status_t status = _InitIfNeeded(); + if (status != B_OK) + return status; - fHandler = new PathHandler(path, flags, target); - status_t status = fHandler->InitCheck(); + BAutolock _(sLocker); + + WatcherMap::iterator iterator = sWatchers.find(target); + struct watcher* watcher = NULL; + if (iterator != sWatchers.end()) + watcher = iterator->second; + + PathHandler* handler = new PathHandler(path, flags, target); + status = handler->InitCheck(); if (status < B_OK) - Unset(); + return status; - return fStatus = status; + if (watcher == NULL) { + watcher = new BPrivate::watcher; + sWatchers[target] = watcher; + } + + watcher->handlers[path] = handler; + return B_OK; } -status_t -BPathMonitor::SetTarget(BMessenger target) +/*static*/ status_t +BPathMonitor::StopWatching(const char* path, BMessenger target) { - if (fStatus < B_OK) - return B_NO_INIT; + BAutolock _(sLocker); - fHandler->SetTarget(target); + WatcherMap::iterator iterator = sWatchers.find(target); + if (iterator == sWatchers.end()) + return B_BAD_VALUE; + + struct watcher* watcher = iterator->second; + HandlerMap::iterator i = watcher->handlers.find(path); + + if (i == watcher->handlers.end()) + return B_BAD_VALUE; + + PathHandler* handler = i->second; + watcher->handlers.erase(i); + + if (handler->LockLooper()) + handler->Quit(); + + if (watcher->handlers.empty()) { + sWatchers.erase(iterator); + delete watcher; + } + return B_OK; } -void -BPathMonitor::Unset() +/*static*/ status_t +BPathMonitor::StopWatching(BMessenger target) { - if (fHandler != NULL) { - fHandler->Quit(); - fHandler = NULL; + BAutolock _(sLocker); + + WatcherMap::iterator iterator = sWatchers.find(target); + if (iterator == sWatchers.end()) + return B_BAD_VALUE; + + struct watcher* watcher = iterator->second; + HandlerMap::iterator i = watcher->handlers.begin(); + for (; i != watcher->handlers.end(); i++) { + PathHandler* handler = i->second; + watcher->handlers.erase(i); + + if (handler->LockLooper()) + handler->Quit(); } - fStatus = B_NO_INIT; + + sWatchers.erase(iterator); + delete watcher; + + return B_OK; } -//} // namespace BPrivate +} // namespace BPrivate Modified: haiku/trunk/src/tests/kits/storage/testapps/Jamfile =================================================================== --- haiku/trunk/src/tests/kits/storage/testapps/Jamfile 2007-05-08 00:01:51 UTC (rev 21065) +++ haiku/trunk/src/tests/kits/storage/testapps/Jamfile 2007-05-08 00:30:59 UTC (rev 21066) @@ -1,8 +1,12 @@ SubDir HAIKU_TOP src tests kits storage testapps ; +UsePrivateHeaders shared storage ; + SetSubDirSupportedPlatformsBeOSCompatible ; AddSubDirSupportedPlatforms libbe_test ; +SEARCH_SOURCE += [ FDirName $(TOP) src kits storage ] ; + SimpleTest clipboard : clipboard.cpp : be ; @@ -11,3 +15,8 @@ SimpleTest NodeMonitorTest : NodeMonitorTest.cpp : be ; + +SimpleTest PathMonitorTest + : PathMonitorTest.cpp PathMonitor.cpp + : be $(TARGET_LIBSTDC++) +; [... truncated: 195 lines follow ...] From hugosantos at mail.berlios.de Tue May 8 15:10:45 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Tue, 8 May 2007 15:10:45 +0200 Subject: [Haiku-commits] r21067 - in haiku/trunk/src/libs/compat/freebsd_network: . compat compat/dev/pci compat/machine compat/net compat/netinet compat/sys compat/vm Message-ID: <200705081310.l48DAjqd013253@sheep.berlios.de> Author: hugosantos Date: 2007-05-08 15:10:02 +0200 (Tue, 08 May 2007) New Revision: 21067 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21067&view=rev Added: haiku/trunk/src/libs/compat/freebsd_network/compat/machine/in_cksum.h haiku/trunk/src/libs/compat/freebsd_network/compat/netinet/ haiku/trunk/src/libs/compat/freebsd_network/compat/netinet/if_ether.h haiku/trunk/src/libs/compat/freebsd_network/compat/netinet/in_systm.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kthread.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/protosw.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/taskqueue.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/types.h haiku/trunk/src/libs/compat/freebsd_network/compat/vm/pmap.h haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile haiku/trunk/src/libs/compat/freebsd_network/bus.c haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcireg.h haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_vlan_var.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kernel.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/malloc.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mutex.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/param.h haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/device.h haiku/trunk/src/libs/compat/freebsd_network/mbuf.c Log: freebsd compat. layer: a few more definitions, preparing for a DMA-using driver. Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-08 13:10:02 UTC (rev 21067) @@ -18,4 +18,5 @@ mbuf.c mii.c mutex.c + taskqueue.c ; Modified: haiku/trunk/src/libs/compat/freebsd_network/bus.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-08 13:10:02 UTC (rev 21067) @@ -187,6 +187,18 @@ static int32 +intr_fast_wrapper(void *data) +{ + struct internal_intr *intr = data; + + intr->handler(intr->arg); + + /* no way to know, so let other devices get it as well */ + return B_UNHANDLED_INTERRUPT; +} + + +static int32 intr_handler(void *data) { struct internal_intr *intr = data; @@ -209,9 +221,12 @@ static void free_internal_intr(struct internal_intr *intr) { - status_t status; - delete_sem(intr->sem); - wait_for_thread(intr->thread, &status); + if (intr->sem >= B_OK) { + status_t status; + delete_sem(intr->sem); + wait_for_thread(intr->thread, &status); + } + free(intr); } @@ -235,25 +250,35 @@ intr->arg = arg; intr->irq = res->handle; - snprintf(semName, sizeof(semName), "%s intr", dev->dev_name); + if (flags & INTR_FAST) { + intr->sem = -1; + intr->thread = -1; - intr->sem = create_sem(0, semName); - if (intr->sem < B_OK) { - free(intr); - return B_NO_MEMORY; - } + status = install_io_interrupt_handler(intr->irq, + intr_fast_wrapper, intr, 0); + } else { + snprintf(semName, sizeof(semName), "%s intr", dev->dev_name); - snprintf(semName, sizeof(semName), "%s intr handler", dev->dev_name); + intr->sem = create_sem(0, semName); + if (intr->sem < B_OK) { + free(intr); + return B_NO_MEMORY; + } - intr->thread = spawn_kernel_thread(intr_handler, semName, - B_REAL_TIME_DISPLAY_PRIORITY, intr); - if (intr->thread < B_OK) { - delete_sem(intr->sem); - free(intr); - return B_NO_MEMORY; + snprintf(semName, sizeof(semName), "%s intr handler", dev->dev_name); + + intr->thread = spawn_kernel_thread(intr_handler, semName, + B_REAL_TIME_DISPLAY_PRIORITY, intr); + if (intr->thread < B_OK) { + delete_sem(intr->sem); + free(intr); + return B_NO_MEMORY; + } + + status = install_io_interrupt_handler(intr->irq, + intr_wrapper, intr, 0); } - status = install_io_interrupt_handler(intr->irq, intr_wrapper, intr, 0); if (status < B_OK) { free_internal_intr(intr); return status; @@ -280,12 +305,27 @@ int bus_generic_detach(device_t dev) { - /* TODO */ + UNIMPLEMENTED(); + return B_ERROR; +} + +int +bus_generic_suspend(device_t dev) +{ + UNIMPLEMENTED(); return B_ERROR; } +int +bus_generic_resume(device_t dev) +{ + UNIMPLEMENTED(); + return B_ERROR; +} + + #define DEBUG_BUS_SPACE_RW #ifdef DEBUG_BUS_SPACE_RW Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcireg.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcireg.h 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/dev/pci/pcireg.h 2007-05-08 13:10:02 UTC (rev 21067) @@ -7,11 +7,13 @@ #define PCIR_SUBVEND_0 0x2c #define PCIR_SUBDEV_0 0x2e -#define PCIM_CMD_PORTEN 0x0001 -#define PCIM_CMD_MEMEN 0x0002 -#define PCIM_CMD_MWRICEN 0x0010 +#define PCIM_CMD_PORTEN 0x0001 +#define PCIM_CMD_MEMEN 0x0002 +#define PCIM_CMD_BUSMASTEREN 0x0004 +#define PCIM_CMD_MWRICEN 0x0010 #define PCIR_BARS 0x10 #define PCIR_BAR(x) (PCIR_BARS + (x) * 4) +#define PCIR_CIS 0x28 #endif Added: haiku/trunk/src/libs/compat/freebsd_network/compat/machine/in_cksum.h =================================================================== Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_vlan_var.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_vlan_var.h 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_vlan_var.h 2007-05-08 13:10:02 UTC (rev 21067) @@ -59,6 +59,11 @@ #define SIOCGETVLAN SIOCGIFGENERIC #ifdef _KERNEL +#if 1 +#define VLAN_INPUT_TAG_NEW(_ifp, _m, _t) do { } while (0) +#define VLAN_OUTPUT_TAG(_ifp, _m) NULL +#define VLAN_TAG_VALUE(_mt) 0 +#else /* * Drivers that are capable of adding and removing the VLAN header * in hardware indicate they support this by marking IFCAP_VLAN_HWTAGGING @@ -141,6 +146,7 @@ #define VLAN_OUTPUT_TAG(_ifp, _m) \ ((_m)->m_flags & M_VLANTAG ? \ m_tag_locate((_m), MTAG_VLAN, MTAG_VLAN_TAG, NULL) : NULL) +#endif #endif /* _KERNEL */ #endif /* _NET_IF_VLAN_VAR_H_ */ Added: haiku/trunk/src/libs/compat/freebsd_network/compat/netinet/if_ether.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/netinet/if_ether.h 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/netinet/if_ether.h 2007-05-08 13:10:02 UTC (rev 21067) @@ -0,0 +1,8 @@ +#ifndef _FBSD_COMPAT_NETINET_IF_ETHER_H_ +#define _FBSD_COMPAT_NETINET_IF_ETHER_H_ + +/* Haiku does it's own ARP management */ + +#define arp_ifinit(ifp, ifa) + +#endif Added: haiku/trunk/src/libs/compat/freebsd_network/compat/netinet/in_systm.h =================================================================== Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-08 13:10:02 UTC (rev 21067) @@ -54,10 +54,13 @@ enum intr_type { INTR_TYPE_NET = 4, + INTR_FAST = 128, INTR_MPSAFE = 512, }; int bus_generic_detach(device_t dev); +int bus_generic_suspend(device_t dev); +int bus_generic_resume(device_t dev); typedef void (*driver_intr_t)(void *); @@ -86,6 +89,7 @@ void *device_get_softc(device_t dev); int device_printf(device_t dev, const char *, ...) __printflike(2, 3); void device_set_desc(device_t dev, const char *desc); +void device_set_desc_copy(device_t dev, const char *desc); device_t device_add_child(device_t dev, const char *name, int unit); int device_delete_child(device_t dev, device_t child); Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-08 13:10:02 UTC (rev 21067) @@ -79,6 +79,12 @@ #define HAIKU_CHECK_DISABLE_INTERRUPTS __haiku_disable_interrupts +#define NO_HAIKU_CHECK_DISABLE_INTERRUPTS() \ + int HAIKU_CHECK_DISABLE_INTERRUPTS(device_t dev) { \ + panic("should never be called."); \ + return -1; \ + } + #define HAIKU_INTR_REGISTER_ENTER(status) do { \ status = disable_interrupts(); \ acquire_spinlock(&__haiku_intr_spinlock); \ Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kernel.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kernel.h 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kernel.h 2007-05-08 13:10:02 UTC (rev 21067) @@ -28,6 +28,8 @@ #define SYSINIT(uniquifier, subsystem, order, func, ident) \ struct __system_init __init_##uniquifier = { func } +#define TUNABLE_INT(path, var) + #define __packed __attribute__ ((packed)) #define __printflike(a, b) __attribute__ ((format (__printf__, a, b))) Added: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kthread.h =================================================================== Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/malloc.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/malloc.h 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/malloc.h 2007-05-08 13:10:02 UTC (rev 21067) @@ -31,4 +31,9 @@ #define kernel_contigfree(addr, size, base) \ _kernel_contigfree(addr, size) +#ifdef FBSD_DRIVER +#define malloc(size, tag, flags) kernel_malloc(size, tag, flags) +#define free(pointer, tag) kernel_free(pointer, tag) #endif + +#endif Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h 2007-05-08 13:10:02 UTC (rev 21067) @@ -28,7 +28,7 @@ }; struct m_ext { - void * ext_buf; + caddr_t ext_buf; unsigned int ext_size; int ext_type; }; @@ -84,6 +84,7 @@ #define CSUM_PSEUDO_HDR 0x0800 #define CSUM_DELAY_DATA (CSUM_TCP | CSUM_UDP) +#define M_MOVE_PKTHDR(to, from) m_move_pkthdr((to), (from)) #define MGET(m, how, type) ((m) = m_get((how), (type))) #define MGETHDR(m, how, type) ((m) = m_gethdr((how), (type))) #define MCLGET(m, how) m_clget((m), (how)) @@ -92,6 +93,10 @@ void m_freem(struct mbuf *mbuf); struct mbuf *m_free(struct mbuf *m); struct mbuf *m_defrag(struct mbuf *m, int); +void m_adj(struct mbuf *m, int); +struct mbuf *m_pullup(struct mbuf *m, int len); +struct mbuf *m_prepend(struct mbuf *m, int, int); +void m_move_pkthdr(struct mbuf *, struct mbuf *); u_int m_length(struct mbuf *m, struct mbuf **last); u_int m_fixhdr(struct mbuf *m); @@ -104,11 +109,88 @@ #define mtod(m, type) (type)((m)->m_data) +#define m_tag_delete(mb, tag) \ + panic("m_tag_delete unsupported."); + /* Check if the supplied mbuf has a packet header, or else panic. */ #define M_ASSERTPKTHDR(m) \ KASSERT(m != NULL && m->m_flags & M_PKTHDR, \ ("%s: no mbuf packet header!", __func__)) +#define MBUF_CHECKSLEEP(how) do { } while (0) + + +/* + * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place + * an object of the specified size at the end of the mbuf, longword aligned. + */ +#define M_ALIGN(m, len) do { \ + (m)->m_data += (MLEN - (len)) & ~(sizeof(long) - 1); \ +} while (0) + +/* + * As above, for mbufs allocated with m_gethdr/MGETHDR + * or initialized by M_COPY_PKTHDR. + */ +#define MH_ALIGN(m, len) do { \ + (m)->m_data += (MHLEN - (len)) & ~(sizeof(long) - 1); \ +} while (0) + + +/* +#define MEXT_IS_REF(m) (((m)->m_ext.ref_cnt != NULL) \ + && (*((m)->m_ext.ref_cnt) > 1)) + */ +#define MEXT_IS_REF(m) 0 + +/* + * Evaluate TRUE if it's safe to write to the mbuf m's data region (this + * can be both the local data payload, or an external buffer area, + * depending on whether M_EXT is set). + */ + +/* +#define M_WRITABLE(m) (!((m)->m_flags & M_RDONLY) && (!((m)->m_flags \ + & M_EXT) || !MEXT_IS_REF(m))) + */ +#define M_WRITABLE(m) (!((m)->m_flags & M_EXT) || !MEXT_IS_REF(m)) + +/* + * Compute the amount of space available + * before the current start of data in an mbuf. + * + * The M_WRITABLE() is a temporary, conservative safety measure: the burden + * of checking writability of the mbuf data area rests solely with the caller. + */ +#define M_LEADINGSPACE(m) \ + ((m)->m_flags & M_EXT ? \ + (M_WRITABLE(m) ? (m)->m_data - (m)->m_ext.ext_buf : 0): \ + (m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat : \ + (m)->m_data - (m)->m_dat) + +/* + * Arrange to prepend space of size plen to mbuf m. + * If a new mbuf must be allocated, how specifies whether to wait. + * If the allocation fails, the original mbuf chain is freed and m is + * set to NULL. + */ +#define M_PREPEND(m, plen, how) do { \ + struct mbuf **_mmp = &(m); \ + struct mbuf *_mm = *_mmp; \ + int _mplen = (plen); \ + int __mhow = (how); \ + \ + MBUF_CHECKSLEEP(how); \ + if (M_LEADINGSPACE(_mm) >= _mplen) { \ + _mm->m_data -= _mplen; \ + _mm->m_len += _mplen; \ + } else \ + _mm = m_prepend(_mm, _mplen, __mhow); \ + if (_mm != NULL && _mm->m_flags & M_PKTHDR) \ + _mm->m_pkthdr.len += _mplen; \ + *_mmp = _mm; \ +} while (0) + #endif #endif Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mutex.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mutex.h 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mutex.h 2007-05-08 13:10:02 UTC (rev 21067) @@ -53,6 +53,9 @@ void mtx_init(struct mtx *m, const char *name, const char *type, int opts); void mtx_destroy(struct mtx *m); +#define NET_LOCK_GIANT() +#define NET_UNLOCK_GIANT() + extern struct mtx Giant; #endif Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/param.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/param.h 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/param.h 2007-05-08 13:10:02 UTC (rev 21067) @@ -33,4 +33,6 @@ #define ALIGN_BYTES (sizeof(int) - 1) #define ALIGN(x) ((((unsigned)x) + ALIGN_BYTES) & ~ALIGN_BYTES) +#define roundup2(x, y) (((x) + ((y) - 1)) & (~((y) - 1))) + #endif Added: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/protosw.h =================================================================== Added: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/taskqueue.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/taskqueue.h 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/taskqueue.h 2007-05-08 13:10:02 UTC (rev 21067) @@ -0,0 +1,35 @@ +#ifndef _FBSD_COMPAT_SYS_TASKQUEUE_H_ +#define _FBSD_COMPAT_SYS_TASKQUEUE_H_ + +#include + +#define PI_NET 0 + +struct task; +struct taskqueue; + +typedef void (*task_handler_t)(void *context, int pending); + +#define TASK_INIT(taskp, prio, hand, arg) task_init(taskp, prio, hand, arg) + +typedef void (*taskqueue_enqueue_fn)(void *context); + +struct taskqueue *taskqueue_create(const char *name, int mflags, + taskqueue_enqueue_fn enqueue, void *context, void **); +int taskqueue_start_threads(struct taskqueue **tq, int count, int pri, + const char *name, ...) __printflike(4, 5); +void taskqueue_free(struct taskqueue *tq); +void taskqueue_drain(struct taskqueue *tq, struct task *task); + +int taskqueue_enqueue(struct taskqueue *tq, struct task *task); + +void taskqueue_thread_enqueue(void *context); + +extern struct taskqueue *taskqueue_fast; +int taskqueue_enqueue_fast(struct taskqueue *queue, struct task *task); +struct taskqueue *taskqueue_create_fast(const char *name, int mflags, + taskqueue_enqueue_fn enqueue, void *context); + +void task_init(struct task *, int prio, task_handler_t handler, void *arg); + +#endif Added: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/types.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/types.h 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/types.h 2007-05-08 13:10:02 UTC (rev 21067) @@ -0,0 +1,8 @@ +#ifndef _FBSD_COMPAT_SYS_TYPES_H_ +#define _FBSD_COMPAT_SYS_TYPES_H_ + +#include + +typedef int boolean_t; + +#endif Added: haiku/trunk/src/libs/compat/freebsd_network/compat/vm/pmap.h =================================================================== Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-08 13:10:02 UTC (rev 21067) @@ -184,6 +184,14 @@ } +void +device_set_desc_copy(device_t dev, const char *desc) +{ + dev->description = strdup(desc); + dev->flags |= DEVICE_DESC_ALLOCED; +} + + const char * device_get_name(device_t dev) { @@ -297,7 +305,7 @@ if (area < 0) return NULL; - driver_printf("(%s) addr = %p, area = %d, size = %lu\n", + driver_printf("(%s) addr = %p, area = %ld, size = %lu\n", name, addr, area, size); return addr; Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-08 13:10:02 UTC (rev 21067) @@ -75,6 +75,8 @@ delete_sem(dev->receive_sem); ifq_uninit(&dev->receive_queue); free(dev->softc); + if (dev->flags & DEVICE_DESC_ALLOCED) + free((char *)dev->description); free(dev); } @@ -131,7 +133,7 @@ memset(&ifr, 0, sizeof(ifr)); ifr.ifr_media = IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, 0); - ifp->if_ioctl(ifp, SIOCSIFMEDIA, &ifr); + ifp->if_ioctl(ifp, SIOCSIFMEDIA, (caddr_t)&ifr); ifp->if_flags = IFF_UP; ifp->if_ioctl(ifp, SIOCSIFFLAGS, NULL); @@ -300,7 +302,7 @@ return EINVAL; memset(&mediareq, 0, sizeof(mediareq)); - status = ifp->if_ioctl(ifp, SIOCGIFMEDIA, &mediareq); + status = ifp->if_ioctl(ifp, SIOCGIFMEDIA, (caddr_t)&mediareq); if (status < B_OK) return status; @@ -358,10 +360,14 @@ return B_ERROR; } - memset(&fakeDevice, 0, sizeof(struct device)); for (i = 0; gPci->get_nth_pci_info(i, &fakeDevice.pci_info) == B_OK; i++) { - if (probe(&fakeDevice) >= 0) { + int result; + memset(&fakeDevice, 0, sizeof(struct device)); + result = probe(&fakeDevice); + if (fakeDevice.flags & DEVICE_DESC_ALLOCED) + free((char *)fakeDevice.description); + if (result >= 0) { dprintf("%s, found %s at %d\n", gDriverName, fakeDevice.description, i); put_module(B_PCI_MODULE_NAME); Modified: haiku/trunk/src/libs/compat/freebsd_network/device.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-08 13:10:02 UTC (rev 21067) @@ -47,9 +47,13 @@ DEVICE_OPEN = 1 << 0, DEVICE_CLOSED = 1 << 1, DEVICE_NON_BLOCK = 1 << 2, + DEVICE_DESC_ALLOCED = 1 << 3, }; +#define UNIMPLEMENTED() \ + panic("fbsd compat, unimplemented: " __FUNCTION__) + status_t init_mbufs(void); void uninit_mbufs(void); Modified: haiku/trunk/src/libs/compat/freebsd_network/mbuf.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/mbuf.c 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/mbuf.c 2007-05-08 13:10:02 UTC (rev 21067) @@ -20,16 +20,14 @@ #include -#define MBUF_CHECKSLEEP(how) do { } while (0) #define MBTOM(how) (how) - -#define CHUNK_SIZE 2048 - static object_cache *sMBufCache; static object_cache *sChunkCache; +static const int max_protohdr = 40 + 20; /* ip6 + tcp */ + static int m_to_oc_flags(int how) { @@ -374,6 +372,201 @@ } +void +m_adj(struct mbuf *mp, int req_len) +{ + int len = req_len; + struct mbuf *m; + int count; + + if ((m = mp) == NULL) + return; + if (len >= 0) { + /* + * Trim from head. + */ + while (m != NULL && len > 0) { + if (m->m_len <= len) { + len -= m->m_len; + m->m_len = 0; + m = m->m_next; + } else { + m->m_len -= len; + m->m_data += len; + len = 0; + } + } + m = mp; + if (mp->m_flags & M_PKTHDR) + m->m_pkthdr.len -= (req_len - len); + } else { + /* + * Trim from tail. Scan the mbuf chain, + * calculating its length and finding the last mbuf. + * If the adjustment only affects this mbuf, then just + * adjust and return. Otherwise, rescan and truncate + * after the remaining size. + */ + len = -len; + count = 0; + for (;;) { + count += m->m_len; + if (m->m_next == (struct mbuf *)0) + break; + m = m->m_next; + } + if (m->m_len >= len) { + m->m_len -= len; + if (mp->m_flags & M_PKTHDR) + mp->m_pkthdr.len -= len; + return; + } + count -= len; + if (count < 0) + count = 0; + /* + * Correct length for chain is "count". + * Find the mbuf with last data, adjust its length, + * and toss data from remaining mbufs on chain. + */ + m = mp; + if (m->m_flags & M_PKTHDR) + m->m_pkthdr.len = count; + for (; m; m = m->m_next) { + if (m->m_len >= count) { + m->m_len = count; + if (m->m_next != NULL) { + m_freem(m->m_next); + m->m_next = NULL; + } + break; + } + count -= m->m_len; + } + } +} + + +/* + * Rearange an mbuf chain so that len bytes are contiguous + * and in the data area of an mbuf (so that mtod and dtom + * will work for a structure of size len). Returns the resulting + * mbuf chain on success, frees it and returns null on failure. + * If there is room, it will add up to max_protohdr-len extra bytes to the + * contiguous region in an attempt to avoid being called next time. + */ +struct mbuf * +m_pullup(struct mbuf *n, int len) +{ + struct mbuf *m; + int count; + int space; + + /* + * If first mbuf has no cluster, and has room for len bytes + * without shifting current data, pullup into it, + * otherwise allocate a new mbuf to prepend to the chain. + */ + if ((n->m_flags & M_EXT) == 0 && + n->m_data + len < &n->m_dat[MLEN] && n->m_next) { + if (n->m_len >= len) + return (n); + m = n; + n = n->m_next; + len -= m->m_len; + } else { + if (len > MHLEN) + goto bad; + MGET(m, M_DONTWAIT, n->m_type); + if (m == NULL) + goto bad; + m->m_len = 0; + if (n->m_flags & M_PKTHDR) + M_MOVE_PKTHDR(m, n); + } + space = &m->m_dat[MLEN] - (m->m_data + m->m_len); + do { + count = min(min(max(len, max_protohdr), space), n->m_len); + bcopy(mtod(n, caddr_t), mtod(m, caddr_t) + m->m_len, + (u_int)count); + len -= count; + m->m_len += count; + n->m_len -= count; + space -= count; + if (n->m_len) + n->m_data += count; + else + n = m_free(n); + } while (len > 0 && n); + if (len > 0) { + (void) m_free(m); + goto bad; + } + m->m_next = n; + return (m); +bad: + m_freem(n); + return (NULL); +} + + +/* + * Lesser-used path for M_PREPEND: + * allocate new mbuf to prepend to chain, + * copy junk along. + */ +struct mbuf * +m_prepend(struct mbuf *m, int len, int how) +{ + struct mbuf *mn; + + if (m->m_flags & M_PKTHDR) + MGETHDR(mn, how, m->m_type); + else + MGET(mn, how, m->m_type); + if (mn == NULL) { + m_freem(m); + return (NULL); + } + if (m->m_flags & M_PKTHDR) + M_MOVE_PKTHDR(mn, m); + mn->m_next = m; + m = mn; + if (len < MHLEN) + MH_ALIGN(m, len); + m->m_len = len; + return (m); +} + + +/* + * "Move" mbuf pkthdr from "from" to "to". + * "from" must have M_PKTHDR set, and "to" must be empty. + */ +void +m_move_pkthdr(struct mbuf *to, struct mbuf *from) +{ +#ifdef MAC + /* + * XXXMAC: It could be this should also occur for non-MAC? + */ + if (to->m_flags & M_PKTHDR) + m_tag_delete_chain(to, NULL); +#endif + /* to->m_flags = (from->m_flags & M_COPYFLAGS) | (to->m_flags & M_EXT); */ + /* we don't have M_COPYFLAGS -hugo */ + to->m_flags = to->m_flags & M_EXT; + if ((to->m_flags & M_EXT) == 0) + to->m_data = to->m_pktdat; + to->m_pkthdr = from->m_pkthdr; /* especially tags */ + /* we don't have tags -hugo */ +#if 0 + SLIST_INIT(&from->m_pkthdr.tags); /* purge tags from src */ +#endif + from->m_flags &= ~M_PKTHDR; +} + + status_t init_mbufs() { Added: haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c 2007-05-08 00:30:59 UTC (rev 21066) +++ haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c 2007-05-08 13:10:02 UTC (rev 21067) @@ -0,0 +1,95 @@ +/* + * Copyright 2007, Hugo Santos. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Hugo Santos, hugosantos at gmail.com + */ + +#include "device.h" + +#include + +struct task { + int priority; + task_handler_t handler; + void *argument; +}; + +struct taskqueue { +}; + +struct taskqueue *taskqueue_fast; + +struct taskqueue * +taskqueue_create(const char *name, int mflags, taskqueue_enqueue_fn enqueue, + void *context, void **unused) +{ + UNIMPLEMENTED(); + return NULL; +} + + +int +taskqueue_start_threads(struct taskqueue **tq, int count, int pri, + const char *name, ...) +{ + UNIMPLEMENTED(); + return -1; +} + + +void +taskqueue_free(struct taskqueue *tq) +{ + UNIMPLEMENTED(); +} + + +void +taskqueue_drain(struct taskqueue *tq, struct task *task) +{ + UNIMPLEMENTED(); +} + + +int +taskqueue_enqueue(struct taskqueue *tq, struct task *task) +{ + UNIMPLEMENTED(); + return -1; +} + + +void +taskqueue_thread_enqueue(void *context) +{ + UNIMPLEMENTED(); +} + + +int +taskqueue_enqueue_fast(struct taskqueue *queue, struct task *task) +{ + UNIMPLEMENTED(); + return -1; +} + + +struct taskqueue * +taskqueue_create_fast(const char *name, int mflags, + taskqueue_enqueue_fn enqueue, void *context) +{ + UNIMPLEMENTED(); + return NULL; +} + + +void +task_init(struct task *t, int prio, task_handler_t handler, void *context) +{ + t->priority = prio; + t->handler = handler; + t->argument = context; +} + From hugosantos at mail.berlios.de Tue May 8 15:10:51 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Tue, 8 May 2007 15:10:51 +0200 Subject: [Haiku-commits] r21068 - haiku/trunk/headers/posix/netinet Message-ID: <200705081310.l48DApRs013274@sheep.berlios.de> Author: hugosantos Date: 2007-05-08 15:10:45 +0200 (Tue, 08 May 2007) New Revision: 21068 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21068&view=rev Modified: haiku/trunk/headers/posix/netinet/tcp.h Log: make tcphdr public, it is used by several applications. Modified: haiku/trunk/headers/posix/netinet/tcp.h =================================================================== --- haiku/trunk/headers/posix/netinet/tcp.h 2007-05-08 13:10:02 UTC (rev 21067) +++ haiku/trunk/headers/posix/netinet/tcp.h 2007-05-08 13:10:45 UTC (rev 21068) @@ -10,8 +10,6 @@ #include -// TODO: if tcpdump is the only potential user of the part commented out, remove it -#if 0 struct tcphdr { uint16_t th_sport; /* source port */ uint16_t th_dport; /* destination port */ @@ -31,6 +29,7 @@ uint16_t th_urp; /* end of urgent data offset */ } _PACKED; +#if 0 #define TH_FIN 0x01 #define TH_SYN 0x02 #define TH_RST 0x04 From hugosantos at mail.berlios.de Tue May 8 17:38:50 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Tue, 8 May 2007 17:38:50 +0200 Subject: [Haiku-commits] r21069 - haiku/trunk/src/add-ons/kernel/network/protocols/tcp Message-ID: <200705081538.l48Fco6D029385@sheep.berlios.de> Author: hugosantos Date: 2007-05-08 17:38:33 +0200 (Tue, 08 May 2007) New Revision: 21069 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21069&view=rev Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.cpp Log: tcp: allow TCP_NODELAY to be set Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp 2007-05-08 13:10:45 UTC (rev 21068) +++ haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp 2007-05-08 15:38:33 UTC (rev 21069) @@ -724,6 +724,27 @@ } +status_t +TCPEndpoint::SetOption(int option, const void *_value, int length) +{ + if (option != TCP_NODELAY) + return B_BAD_VALUE; + + if (length != sizeof(int)) + return B_BAD_VALUE; + + const int *value = (const int *)_value; + + RecursiveLocker _(fLock); + if (*value) + fOptions |= TCP_NODELAY; + else + fOptions &= ~TCP_NODELAY; + + return B_OK; +} + + // #pragma mark - misc Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h 2007-05-08 13:10:45 UTC (rev 21068) +++ haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h 2007-05-08 15:38:33 UTC (rev 21069) @@ -67,6 +67,8 @@ status_t SetSendBufferSize(size_t length); status_t SetReceiveBufferSize(size_t length); + status_t SetOption(int option, const void *value, int length); + tcp_state State() const { return fState; } bool IsBound() const; Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.cpp 2007-05-08 13:10:45 UTC (rev 21068) +++ haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.cpp 2007-05-08 15:38:33 UTC (rev 21069) @@ -489,7 +489,8 @@ if (status < B_OK) return status; } - } + } else if (level == IPPROTO_TCP) + return protocol->SetOption(option, _value, length); return protocol->next->module->setsockopt(protocol->next, level, option, _value, length); From korli at mail.berlios.de Tue May 8 18:27:57 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Tue, 8 May 2007 18:27:57 +0200 Subject: [Haiku-commits] r21070 - in haiku/trunk/src/add-ons/kernel/drivers/network: bcm440x bcm570x Message-ID: <200705081627.l48GRvYs002089@sheep.berlios.de> Author: korli Date: 2007-05-08 18:27:56 +0200 (Tue, 08 May 2007) New Revision: 21070 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21070&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/network/bcm440x/b44um.c haiku/trunk/src/add-ons/kernel/drivers/network/bcm570x/b57um.c Log: now polls the link status for older revisions of bcm440x inversed active status Modified: haiku/trunk/src/add-ons/kernel/drivers/network/bcm440x/b44um.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/bcm440x/b44um.c 2007-05-08 15:38:33 UTC (rev 21069) +++ haiku/trunk/src/add-ons/kernel/drivers/network/bcm440x/b44um.c 2007-05-08 16:27:56 UTC (rev 21070) @@ -261,8 +261,12 @@ case ETHER_GET_LINK_STATE: { ether_link_state_t state; + + if (pUmDevice->lm_dev.corerev < 7) { + b44_LM_PollLink(&pUmDevice->lm_dev); + } state.media = (pUmDevice->lm_dev.LinkStatus - == LM_STATUS_LINK_DOWN ? IFM_ACTIVE : 0) | IFM_ETHER; + == LM_STATUS_LINK_DOWN ? 0 : IFM_ACTIVE) | IFM_ETHER; switch (pUmDevice->lm_dev.LineSpeed) { case LM_LINE_SPEED_10MBPS: state.media |= IFM_10_T; Modified: haiku/trunk/src/add-ons/kernel/drivers/network/bcm570x/b57um.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/bcm570x/b57um.c 2007-05-08 15:38:33 UTC (rev 21069) +++ haiku/trunk/src/add-ons/kernel/drivers/network/bcm570x/b57um.c 2007-05-08 16:27:56 UTC (rev 21070) @@ -499,7 +499,7 @@ { ether_link_state_t state; state.media = (pUmDevice->lm_dev.LinkStatus - == LM_STATUS_LINK_DOWN ? IFM_ACTIVE : 0) | IFM_ETHER; + == LM_STATUS_LINK_DOWN ? 0 : IFM_ACTIVE) | IFM_ETHER; switch (pUmDevice->lm_dev.LineSpeed) { case LM_LINE_SPEED_10MBPS: state.media |= IFM_10_T; From hugosantos at mail.berlios.de Tue May 8 18:52:48 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Tue, 8 May 2007 18:52:48 +0200 Subject: [Haiku-commits] r21071 - haiku/trunk/src/libs/compat/freebsd_network Message-ID: <200705081652.l48GqmuD004931@sheep.berlios.de> Author: hugosantos Date: 2007-05-08 18:52:26 +0200 (Tue, 08 May 2007) New Revision: 21071 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21071&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/device.h haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c Log: freebsd compat. layer: taskqueue implementation. Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-08 16:27:56 UTC (rev 21070) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-08 16:52:26 UTC (rev 21071) @@ -399,20 +399,21 @@ if (dev == NULL) return B_NO_MEMORY; - init_compat_layer(); + status = init_compat_layer(); + if (status < B_OK) + goto err_1; status = init_mutexes(); - if (status < B_OK) { - free_device(dev); - return status; - } + if (status < B_OK) + goto err_2; + status = init_taskqueues(); + if (status < B_OK) + goto err_3; + status = init_mbufs(); - if (status < B_OK) { - uninit_mutexes(); - free_device(dev); - return status; - } + if (status < B_OK) + goto err_4; init_bounce_pages(); @@ -443,6 +444,15 @@ gDevNameList[ncards + 1] = NULL; return B_OK; + +err_4: + uninit_taskqueues(); +err_3: + uninit_mutexes(); +err_2: +err_1: + free(dev); + return status; } @@ -459,5 +469,6 @@ uninit_bounce_pages(); uninit_mbufs(); + uninit_taskqueues(); uninit_mutexes(); } Modified: haiku/trunk/src/libs/compat/freebsd_network/device.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-08 16:27:56 UTC (rev 21070) +++ haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-08 16:52:26 UTC (rev 21071) @@ -62,6 +62,9 @@ status_t init_compat_layer(void); +status_t init_taskqueues(void); +void uninit_taskqueues(void); + /* busdma_machdep.c */ void init_bounce_pages(void); void uninit_bounce_pages(void); Modified: haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c 2007-05-08 16:27:56 UTC (rev 21070) +++ haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c 2007-05-08 16:52:26 UTC (rev 21071) @@ -8,71 +8,241 @@ #include "device.h" +#include +#include + #include struct task { - int priority; - task_handler_t handler; - void *argument; + int ta_priority; + task_handler_t ta_handler; + void *ta_argument; + int ta_pending; + + struct list_link ta_link; }; struct taskqueue { + char tq_name[64]; + mutex tq_mutex; + struct list tq_list; + taskqueue_enqueue_fn tq_enqueue; + void *tq_arg; + int tq_fast; + int32 tq_spinlock; + sem_id tq_sem; + thread_id *tq_threads; + int tq_threadcount; }; -struct taskqueue *taskqueue_fast; +struct taskqueue *taskqueue_fast = NULL; + + +static struct taskqueue * +_taskqueue_create(const char *name, int mflags, int fast, + taskqueue_enqueue_fn enqueue, void *context) +{ + struct taskqueue *tq = malloc(sizeof(struct taskqueue)); + if (tq == NULL) + return NULL; + + tq->tq_fast = fast; + + if (fast) { + tq->tq_spinlock = 0; + } else { + if (mutex_init(&tq->tq_mutex, name) < B_OK) { + free(tq); + return NULL; + } + } + + strlcpy(tq->tq_name, name, sizeof(tq->tq_name)); + list_init_etc(&tq->tq_list, offsetof(struct task, ta_link)); + tq->tq_enqueue = enqueue; + tq->tq_arg = context; + + tq->tq_sem = -1; + tq->tq_threads = NULL; + tq->tq_threadcount = 0; + + return tq; +} + + +static void +tq_lock(struct taskqueue *tq, cpu_status *status) +{ + if (tq->tq_fast) { + *status = disable_interrupts(); + acquire_spinlock(&tq->tq_spinlock); + } else { + mutex_lock(&tq->tq_mutex); + } +} + + +static void +tq_unlock(struct taskqueue *tq, cpu_status status) +{ + if (tq->tq_fast) { + release_spinlock(&tq->tq_spinlock); + restore_interrupts(status); + } else { + mutex_unlock(&tq->tq_mutex); + } +} + + struct taskqueue * taskqueue_create(const char *name, int mflags, taskqueue_enqueue_fn enqueue, void *context, void **unused) { - UNIMPLEMENTED(); - return NULL; + return _taskqueue_create(name, mflags, 0, enqueue, context); } +static int32 +tq_handle_thread(void *data) +{ + struct taskqueue *tq = data; + cpu_status cpu_state; + struct task *t; + int pending; + + while (1) { + status_t status = acquire_sem(tq->tq_sem); + if (status < B_OK) + break; + + tq_lock(tq, &cpu_state); + t = list_remove_head_item(&tq->tq_list); + pending = t->ta_pending; + t->ta_pending = 0; + tq_unlock(tq, cpu_state); + + t->ta_handler(t->ta_argument, pending); + } + + return 0; +} + + int -taskqueue_start_threads(struct taskqueue **tq, int count, int pri, - const char *name, ...) +taskqueue_start_threads(struct taskqueue **tqp, int count, int pri, + const char *format, ...) { - UNIMPLEMENTED(); - return -1; + struct taskqueue *tq = (*tqp); + char name[64]; + va_list vl; + int i, j; + + if (count == 0) + return -1; + + if (tq->tq_threads != NULL) + return -1; + + va_start(vl, format); + vsnprintf(name, sizeof(name), format, vl); + va_end(vl); + + tq->tq_threads = malloc(sizeof(thread_id) * count); + if (tq->tq_threads == NULL) + return B_NO_MEMORY; + + tq->tq_sem = create_sem(0, tq->tq_name); + if (tq->tq_sem < B_OK) { + free(tq->tq_threads); + tq->tq_threads = NULL; + return tq->tq_sem; + } + + for (i = 0; i < count; i++) { + tq->tq_threads[i] = spawn_kernel_thread(tq_handle_thread, tq->tq_name, + B_REAL_TIME_DISPLAY_PRIORITY - 20, tq); + if (tq->tq_threads[i] < B_OK) { + status_t status = tq->tq_threads[i]; + for (j = 0; j < i; j++) + kill_thread(tq->tq_threads[j]); + free(tq->tq_threads); + tq->tq_threads = NULL; + delete_sem(tq->tq_sem); + return status; + } + } + + for (i = 0; i < count; i++) + resume_thread(tq->tq_threads[i]); + + return 0; } void taskqueue_free(struct taskqueue *tq) { - UNIMPLEMENTED(); + /* lock and drain list? */ + if (!tq->tq_fast) + mutex_destroy(&tq->tq_mutex); + if (tq->tq_sem != -1) { + int i; + + delete_sem(tq->tq_sem); + + for (i = 0; i < tq->tq_threadcount; i++) { + status_t status; + wait_for_thread(tq->tq_threads[i], &status); + } + } + + free(tq); } void taskqueue_drain(struct taskqueue *tq, struct task *task) { - UNIMPLEMENTED(); + cpu_status status; + + tq_lock(tq, &status); + if (task->ta_pending != 0) + panic("unimplemented, taskqueue drain"); + tq_unlock(tq, status); } int taskqueue_enqueue(struct taskqueue *tq, struct task *task) { - UNIMPLEMENTED(); - return -1; + cpu_status status; + tq_lock(tq, &status); + /* we don't really support priorities */ + if (task->ta_pending) { + task->ta_pending++; + } else { + list_add_item(&tq->tq_list, task); + task->ta_pending = 1; + tq->tq_enqueue(tq->tq_arg); + } + tq_unlock(tq, status); + return 0; } void taskqueue_thread_enqueue(void *context) { - UNIMPLEMENTED(); + struct taskqueue **tqp = context; + release_sem_etc((*tqp)->tq_sem, 1, B_DO_NOT_RESCHEDULE); } int -taskqueue_enqueue_fast(struct taskqueue *queue, struct task *task) +taskqueue_enqueue_fast(struct taskqueue *tq, struct task *task) { - UNIMPLEMENTED(); - return -1; + return taskqueue_enqueue(tq, task); } @@ -80,16 +250,39 @@ taskqueue_create_fast(const char *name, int mflags, taskqueue_enqueue_fn enqueue, void *context) { - UNIMPLEMENTED(); - return NULL; + return _taskqueue_create(name, mflags, 1, enqueue, context); } void task_init(struct task *t, int prio, task_handler_t handler, void *context) { - t->priority = prio; - t->handler = handler; - t->argument = context; + t->ta_priority = prio; + t->ta_handler = handler; + t->ta_argument = context; + t->ta_pending = 0; } + +status_t +init_taskqueues() +{ + taskqueue_fast = taskqueue_create_fast("fast taskq", 0, + taskqueue_thread_enqueue, NULL); + if (taskqueue_fast == NULL) + return B_NO_MEMORY; + + if (taskqueue_start_threads(&taskqueue_fast, 1, 0, "fast taskq") < 0) { + taskqueue_free(taskqueue_fast); + return B_ERROR; + } + + return B_OK; +} + + +void +uninit_taskqueues() +{ + taskqueue_free(taskqueue_fast); +} From hugosantos at mail.berlios.de Tue May 8 18:53:13 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Tue, 8 May 2007 18:53:13 +0200 Subject: [Haiku-commits] r21072 - in haiku/trunk/src: add-ons/kernel/drivers/network/pcnet/dev/le libs/compat/freebsd_network libs/compat/freebsd_network/compat/sys Message-ID: <200705081653.l48GrDUt005320@sheep.berlios.de> Author: hugosantos Date: 2007-05-08 18:52:48 +0200 (Tue, 08 May 2007) New Revision: 21072 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21072&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h haiku/trunk/src/libs/compat/freebsd_network/device.c Log: freebsd compat. layer: added a requirements field so not all drivers init all subsystems. pcnet for instance doesn't need taskqueues. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c 2007-05-08 16:52:26 UTC (rev 21071) +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c 2007-05-08 16:52:48 UTC (rev 21072) @@ -6,6 +6,9 @@ #include #include +HAIKU_FBSD_DRIVER_GLUE(pcnet, le, pci); +HAIKU_DRIVER_REQUIREMENTS(0); + /* from if_le_pci.c */ #define PCNET_PCI_RDP 0x10 #define PCNET_PCI_RAP 0x12 @@ -27,8 +30,6 @@ bus_dmamap_t sc_dmam; }; -HAIKU_FBSD_DRIVER_GLUE(pcnet, le, pci) - int HAIKU_CHECK_DISABLE_INTERRUPTS(device_t dev) { struct le_pci_softc *lesc = (struct le_pci_softc *)device_get_softc(dev); cpu_status status; Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-08 16:52:26 UTC (rev 21071) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-08 16:52:48 UTC (rev 21072) @@ -85,6 +85,17 @@ return -1; \ } +extern int __haiku_driver_requirements; + +enum { + FBSD_TASKQUEUES = 1 << 0, +}; + +#define HAIKU_DRIVER_REQUIREMENTS(flags) \ + int __haiku_driver_requirements = (flags) + +#define HAIKU_DRIVER_REQUIRES(flag) (__haiku_driver_requirements & (flag)) + #define HAIKU_INTR_REGISTER_ENTER(status) do { \ status = disable_interrupts(); \ acquire_spinlock(&__haiku_intr_spinlock); \ Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-08 16:52:26 UTC (rev 21071) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-08 16:52:48 UTC (rev 21072) @@ -407,9 +407,11 @@ if (status < B_OK) goto err_2; - status = init_taskqueues(); - if (status < B_OK) - goto err_3; + if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES)) { + status = init_taskqueues(); + if (status < B_OK) + goto err_3; + } status = init_mbufs(); if (status < B_OK) @@ -446,7 +448,8 @@ return B_OK; err_4: - uninit_taskqueues(); + if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES)) + uninit_taskqueues(); err_3: uninit_mutexes(); err_2: @@ -469,6 +472,7 @@ uninit_bounce_pages(); uninit_mbufs(); - uninit_taskqueues(); + if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES)) + uninit_taskqueues(); uninit_mutexes(); } From hugosantos at mail.berlios.de Tue May 8 18:53:38 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Tue, 8 May 2007 18:53:38 +0200 Subject: [Haiku-commits] r21073 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/sys Message-ID: <200705081653.l48GrcYI005800@sheep.berlios.de> Author: hugosantos Date: 2007-05-08 18:53:13 +0200 (Tue, 08 May 2007) New Revision: 21073 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21073&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c Log: freebsd compat. layer: only init taskqueue_fast if FBSD_FAST_TASKQUEUE requirement is set (since it starts a thread and consumes a couple semaphores). Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-08 16:52:48 UTC (rev 21072) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-08 16:53:13 UTC (rev 21073) @@ -89,6 +89,7 @@ enum { FBSD_TASKQUEUES = 1 << 0, + FBSD_FAST_TASKQUEUE = 1 << 1, }; #define HAIKU_DRIVER_REQUIREMENTS(flags) \ Modified: haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c 2007-05-08 16:52:48 UTC (rev 21072) +++ haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c 2007-05-08 16:53:13 UTC (rev 21073) @@ -12,6 +12,7 @@ #include #include +#include struct task { int ta_priority; @@ -267,14 +268,16 @@ status_t init_taskqueues() { - taskqueue_fast = taskqueue_create_fast("fast taskq", 0, - taskqueue_thread_enqueue, NULL); - if (taskqueue_fast == NULL) - return B_NO_MEMORY; + if (HAIKU_DRIVER_REQUIRES(FBSD_FAST_TASKQUEUE)) { + taskqueue_fast = taskqueue_create_fast("fast taskq", 0, + taskqueue_thread_enqueue, NULL); + if (taskqueue_fast == NULL) + return B_NO_MEMORY; - if (taskqueue_start_threads(&taskqueue_fast, 1, 0, "fast taskq") < 0) { - taskqueue_free(taskqueue_fast); - return B_ERROR; + if (taskqueue_start_threads(&taskqueue_fast, 1, 0, "fast taskq") < 0) { + taskqueue_free(taskqueue_fast); + return B_ERROR; + } } return B_OK; @@ -284,5 +287,6 @@ void uninit_taskqueues() { - taskqueue_free(taskqueue_fast); + if (HAIKU_DRIVER_REQUIRES(FBSD_FAST_TASKQUEUE)) + taskqueue_free(taskqueue_fast); } From hugosantos at mail.berlios.de Tue May 8 19:01:26 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Tue, 8 May 2007 19:01:26 +0200 Subject: [Haiku-commits] r21074 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/sys Message-ID: <200705081701.l48H1QpO014327@sheep.berlios.de> Author: hugosantos Date: 2007-05-08 19:01:10 +0200 (Tue, 08 May 2007) New Revision: 21074 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21074&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/_task.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/taskqueue.h haiku/trunk/src/libs/compat/freebsd_network/device.h haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c Log: freebsd compat. layer: gcc 4 fixes, it seems __FUNCTION__ is variant. Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/_task.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/_task.h 2007-05-08 16:53:13 UTC (rev 21073) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/_task.h 2007-05-08 17:01:10 UTC (rev 21074) @@ -1,7 +1,18 @@ #ifndef _FBSD_COMPAT_SYS__TASK_H_ #define _FBSD_COMPAT_SYS__TASK_H_ +/* Haiku's list management */ +#include + +typedef void (*task_handler_t)(void *context, int pending); + struct task { + int ta_priority; + task_handler_t ta_handler; + void *ta_argument; + int ta_pending; + + struct list_link ta_link; }; #endif Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/taskqueue.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/taskqueue.h 2007-05-08 16:53:13 UTC (rev 21073) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/taskqueue.h 2007-05-08 17:01:10 UTC (rev 21074) @@ -2,14 +2,12 @@ #define _FBSD_COMPAT_SYS_TASKQUEUE_H_ #include +#include #define PI_NET 0 -struct task; struct taskqueue; -typedef void (*task_handler_t)(void *context, int pending); - #define TASK_INIT(taskp, prio, hand, arg) task_init(taskp, prio, hand, arg) typedef void (*taskqueue_enqueue_fn)(void *context); Modified: haiku/trunk/src/libs/compat/freebsd_network/device.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-08 16:53:13 UTC (rev 21073) +++ haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-08 17:01:10 UTC (rev 21074) @@ -11,6 +11,7 @@ #define _DEVICE_H_ #include +#include #include #include @@ -51,9 +52,17 @@ }; -#define UNIMPLEMENTED() \ - panic("fbsd compat, unimplemented: " __FUNCTION__) +static inline void +__unimplemented(const char *method) +{ + char msg[128]; + snprintf(msg, sizeof(msg), "fbsd compat, unimplemented: %s", method); + panic(msg); +} + +#define UNIMPLEMENTED() __unimplemented(__FUNCTION__) + status_t init_mbufs(void); void uninit_mbufs(void); Modified: haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c 2007-05-08 16:53:13 UTC (rev 21073) +++ haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c 2007-05-08 17:01:10 UTC (rev 21074) @@ -9,20 +9,10 @@ #include "device.h" #include -#include #include #include -struct task { - int ta_priority; - task_handler_t ta_handler; - void *ta_argument; - int ta_pending; - - struct list_link ta_link; -}; - struct taskqueue { char tq_name[64]; mutex tq_mutex; From hugosantos at mail.berlios.de Tue May 8 19:15:37 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Tue, 8 May 2007 19:15:37 +0200 Subject: [Haiku-commits] r21075 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/sys Message-ID: <200705081715.l48HFblC000763@sheep.berlios.de> Author: hugosantos Date: 2007-05-08 19:15:16 +0200 (Tue, 08 May 2007) New Revision: 21075 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21075&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/taskqueue.h haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c Log: freebsd compat. layer: respect requested priority in taskqueue_start_threads. Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/taskqueue.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/taskqueue.h 2007-05-08 17:01:10 UTC (rev 21074) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/taskqueue.h 2007-05-08 17:15:16 UTC (rev 21075) @@ -4,7 +4,7 @@ #include #include -#define PI_NET 0 +#define PI_NET (B_REAL_TIME_DISPLAY_PRIORITY - 1) struct taskqueue; Modified: haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c 2007-05-08 17:01:10 UTC (rev 21074) +++ haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c 2007-05-08 17:15:16 UTC (rev 21075) @@ -101,9 +101,15 @@ cpu_status cpu_state; struct task *t; int pending; + sem_id sem; + /* just a synchronization point */ + tq_lock(tq, &cpu_state); + sem = tq->tq_sem; + tq_unlock(tq, cpu_state); + while (1) { - status_t status = acquire_sem(tq->tq_sem); + status_t status = acquire_sem(sem); if (status < B_OK) break; @@ -121,10 +127,11 @@ int -taskqueue_start_threads(struct taskqueue **tqp, int count, int pri, +taskqueue_start_threads(struct taskqueue **tqp, int count, int prio, const char *format, ...) { struct taskqueue *tq = (*tqp); + cpu_status state; char name[64]; va_list vl; int i, j; @@ -132,27 +139,34 @@ if (count == 0) return -1; - if (tq->tq_threads != NULL) + tq_lock(tq, &state); + + if (tq->tq_threads != NULL) { + tq_unlock(tq, state); return -1; + } va_start(vl, format); vsnprintf(name, sizeof(name), format, vl); va_end(vl); tq->tq_threads = malloc(sizeof(thread_id) * count); - if (tq->tq_threads == NULL) + if (tq->tq_threads == NULL) { + tq_unlock(tq, state); return B_NO_MEMORY; + } tq->tq_sem = create_sem(0, tq->tq_name); if (tq->tq_sem < B_OK) { free(tq->tq_threads); tq->tq_threads = NULL; + tq_unlock(tq, state); return tq->tq_sem; } for (i = 0; i < count; i++) { tq->tq_threads[i] = spawn_kernel_thread(tq_handle_thread, tq->tq_name, - B_REAL_TIME_DISPLAY_PRIORITY - 20, tq); + prio, tq); if (tq->tq_threads[i] < B_OK) { status_t status = tq->tq_threads[i]; for (j = 0; j < i; j++) @@ -160,13 +174,17 @@ free(tq->tq_threads); tq->tq_threads = NULL; delete_sem(tq->tq_sem); + tq_unlock(tq, state); return status; } } + tq->tq_threadcount = count; + for (i = 0; i < count; i++) resume_thread(tq->tq_threads[i]); + tq_unlock(tq, state); return 0; } @@ -264,7 +282,8 @@ if (taskqueue_fast == NULL) return B_NO_MEMORY; - if (taskqueue_start_threads(&taskqueue_fast, 1, 0, "fast taskq") < 0) { + if (taskqueue_start_threads(&taskqueue_fast, 1, B_REAL_TIME_PRIORITY, + "fast taskq") < 0) { taskqueue_free(taskqueue_fast); return B_ERROR; } From hugosantos at gmail.com Tue May 8 19:18:11 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Tue, 8 May 2007 18:18:11 +0100 Subject: [Haiku-commits] r21040 - in haiku/trunk: headers/os/drivers src/system/kernel In-Reply-To: <1178532394.463efa2a59985@imp.free.fr> References: <1178532394.463efa2a59985@imp.free.fr> Message-ID: <9c46321e0705081018n1a582978gf79d814ebef353fd@mail.gmail.com> Hi Philippe, Thanks for the suggestion. However we diverted from the thread path right now (although i think that in the future it should be supported). FreeBSD's taskqueue also demands a closer interaction with the underlying interface so i couldn't use it for that as well. Hugo On 5/7/07, Philippe Houdoin wrote: > Axel replied: > > "Hugo Santos" wrote: > >> Please let me know if you see anything wrong with these or if the > >> definitions should go elsewhere than KernelExport.h. I've added these > >> to be able to get the first interrupt and just defer the handling to > >> a > >> thread (check next commit). If i don't disable the interrupt it gets > >> hammered so heavily the thread is not even scheduled. Using the > >> current methods i couldn't free or remove the interrupt handler, so i > >> added these ones. > > > > I can't add much to what Marcus and Travis already said, just that > > KernelExport.h would be the wrong place for private additions. > > And I think it's perfectly acceptable to not be able to incorporate > > open-source drivers unchanged. > > I agree too, but as I'm not that a kernel guy... > > Anyway, if the issue is deferring interrupt handling, why not trying to (re-)use > our Deferred Procedure Call (DPC) kernel module to do it? > If it works enough for ACPI interrupts, why not for the others too??? > > It's living under src/add-ons/kernel/generic/dpc, and its (small) module > interface is defined in headers/os/drivers/dpc.h. > > - Philippe > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From hugosantos at mail.berlios.de Wed May 9 02:29:37 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 9 May 2007 02:29:37 +0200 Subject: [Haiku-commits] r21076 - haiku/trunk/src/libs/compat/freebsd_network Message-ID: <200705090029.l490TbpR003975@sheep.berlios.de> Author: hugosantos Date: 2007-05-09 02:29:29 +0200 (Wed, 09 May 2007) New Revision: 21076 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21076&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/bus.c haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c Log: freebsd compat. layer: a couple more changes. a DMA-using driver (FreeBSD's em, Intel Pro 1000) now works without any modifications (it has a fast interrupt mode). Modified: haiku/trunk/src/libs/compat/freebsd_network/bus.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-08 17:15:16 UTC (rev 21075) +++ haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-09 00:29:29 UTC (rev 21076) @@ -344,8 +344,9 @@ value = fun(handle + offset); \ else \ value = *(volatile type *)(handle + offset); \ - TRACE_BUS_SPACE_RW(("bus_space_read_%s(0x%lx, 0x%lx, 0x%lx) = 0x%lx\n", \ - #size, (uint32)tag, (uint32)handle, (uint32)offset, (uint32)value)); \ + if (tag == I386_BUS_SPACE_IO) \ + TRACE_BUS_SPACE_RW(("bus_space_read_%s(0x%lx, 0x%lx, 0x%lx) = 0x%lx\n", \ + #size, (uint32)tag, (uint32)handle, (uint32)offset, (uint32)value)); \ return value; \ } @@ -353,9 +354,10 @@ void bus_space_write_##size(bus_space_tag_t tag, \ bus_space_handle_t handle, bus_size_t offset, type value) \ { \ - TRACE_BUS_SPACE_RW(("bus_space_write_%s(0x%lx, 0x%lx, 0x%lx, 0x%lx)\n", \ - #size, (uint32)tag, (uint32)handle, (uint32)offset, (uint32)value)); \ if (tag == I386_BUS_SPACE_IO) \ + TRACE_BUS_SPACE_RW(("bus_space_write_%s(0x%lx, 0x%lx, 0x%lx, 0x%lx)\n", \ + #size, (uint32)tag, (uint32)handle, (uint32)offset, (uint32)value)); \ + if (tag == I386_BUS_SPACE_IO) \ fun(value, handle + offset); \ else \ *(volatile type *)(handle + offset) = value; \ Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-08 17:15:16 UTC (rev 21075) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-09 00:29:29 UTC (rev 21076) @@ -340,9 +340,3 @@ __haiku_intr_spinlock = 0; return B_OK; } - -module_dependency module_dependencies[] = { - {NET_STACK_MODULE_NAME, (module_info **)&gStack}, - {B_PCI_MODULE_NAME, (module_info **)&gPci}, - {} -}; Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-08 17:15:16 UTC (rev 21075) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-09 00:29:29 UTC (rev 21076) @@ -48,7 +48,7 @@ snprintf(semName, sizeof(semName), "%s rcv", gDriverName); - dev->softc = malloc(driver->softc_size); + dev->softc = _kernel_malloc(driver->softc_size, M_ZERO); if (dev->softc == NULL) { free(dev); return NULL; @@ -105,6 +105,10 @@ driver_printf("compat_open(%s, 0x%lx)\n", name, flags); + status = get_module(NET_STACK_MODULE_NAME, (module_info **)&gStack); + if (status < B_OK) + return status; + for (i = 0; gDevNameList[i] != NULL; i++) { if (strcmp(gDevNameList[i], name) == 0) break; @@ -151,7 +155,7 @@ device_t dev = cookie; device_printf(dev, "compat_close()\n"); - + UNIMPLEMENTED(); return B_ERROR; } @@ -163,7 +167,9 @@ device_printf(dev, "compat_free()\n"); + put_module(NET_STACK_MODULE_NAME); free_device(dev); + UNIMPLEMENTED(); return B_ERROR; } @@ -290,6 +296,7 @@ case ETHER_ADDMULTI: case ETHER_REMMULTI: /* TODO */ + UNIMPLEMENTED(); return B_ERROR; case ETHER_GET_LINK_STATE: @@ -360,16 +367,16 @@ return B_ERROR; } + memset(&fakeDevice, 0, sizeof(struct device)); for (i = 0; gPci->get_nth_pci_info(i, &fakeDevice.pci_info) == B_OK; i++) { int result; - memset(&fakeDevice, 0, sizeof(struct device)); result = probe(&fakeDevice); - if (fakeDevice.flags & DEVICE_DESC_ALLOCED) - free((char *)fakeDevice.description); if (result >= 0) { dprintf("%s, found %s at %d\n", gDriverName, fakeDevice.description, i); + if (fakeDevice.flags & DEVICE_DESC_ALLOCED) + free((char *)fakeDevice.description); put_module(B_PCI_MODULE_NAME); return B_OK; } @@ -391,31 +398,37 @@ dprintf("%s: init_driver(%p)\n", gDriverName, driver); + status = get_module(B_PCI_MODULE_NAME, (module_info **)&gPci); + if (status < B_OK) { + driver_printf("Failed to load PCI module.\n"); + return status; + } + sDeviceProbe = (device_probe_t *)_resolve_method(driver, "device_probe"); sDeviceAttach = (device_attach_t *)_resolve_method(driver, "device_attach"); sDeviceDetach = (device_detach_t *)_resolve_method(driver, "device_detach"); dev = allocate_device(driver); if (dev == NULL) - return B_NO_MEMORY; + goto err_1; status = init_compat_layer(); if (status < B_OK) - goto err_1; + goto err_2; status = init_mutexes(); if (status < B_OK) - goto err_2; + goto err_3; if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES)) { status = init_taskqueues(); if (status < B_OK) - goto err_3; + goto err_4; } status = init_mbufs(); if (status < B_OK) - goto err_4; + goto err_5; init_bounce_pages(); @@ -447,14 +460,17 @@ return B_OK; -err_4: +err_5: if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES)) uninit_taskqueues(); +err_4: + uninit_mutexes(); err_3: - uninit_mutexes(); err_2: + free(dev); err_1: - free(dev); +err_0: + put_module(B_PCI_MODULE_NAME); return status; } @@ -475,4 +491,6 @@ if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES)) uninit_taskqueues(); uninit_mutexes(); + + put_module(B_PCI_MODULE_NAME); } Modified: haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c 2007-05-08 17:15:16 UTC (rev 21075) +++ haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c 2007-05-09 00:29:29 UTC (rev 21076) @@ -13,6 +13,8 @@ #include #include +#define MAX_TASKQUEUE_THREADS 2 + struct taskqueue { char tq_name[64]; mutex tq_mutex; @@ -22,7 +24,7 @@ int tq_fast; int32 tq_spinlock; sem_id tq_sem; - thread_id *tq_threads; + thread_id tq_threads[MAX_TASKQUEUE_THREADS]; int tq_threadcount; }; @@ -40,10 +42,17 @@ tq->tq_fast = fast; + tq->tq_sem = create_sem(0, tq->tq_name); + if (tq->tq_sem < B_OK) { + free(tq); + return tq->tq_sem; + } + if (fast) { tq->tq_spinlock = 0; } else { if (mutex_init(&tq->tq_mutex, name) < B_OK) { + delete_sem(tq->tq_sem); free(tq); return NULL; } @@ -54,8 +63,6 @@ tq->tq_enqueue = enqueue; tq->tq_arg = context; - tq->tq_sem = -1; - tq->tq_threads = NULL; tq->tq_threadcount = 0; return tq; @@ -101,15 +108,9 @@ cpu_status cpu_state; struct task *t; int pending; - sem_id sem; - /* just a synchronization point */ - tq_lock(tq, &cpu_state); - sem = tq->tq_sem; - tq_unlock(tq, cpu_state); - while (1) { - status_t status = acquire_sem(sem); + status_t status = acquire_sem(tq->tq_sem); if (status < B_OK) break; @@ -126,44 +127,19 @@ } -int -taskqueue_start_threads(struct taskqueue **tqp, int count, int prio, - const char *format, ...) +static int +_taskqueue_start_threads(struct taskqueue **tqp, int count, int prio, + const char *name) { struct taskqueue *tq = (*tqp); - cpu_status state; - char name[64]; - va_list vl; int i, j; if (count == 0) return -1; - tq_lock(tq, &state); + if (count > MAX_TASKQUEUE_THREADS) + panic("_taskqueue_start_threads, too many threads requested"); - if (tq->tq_threads != NULL) { - tq_unlock(tq, state); - return -1; - } - - va_start(vl, format); - vsnprintf(name, sizeof(name), format, vl); - va_end(vl); - - tq->tq_threads = malloc(sizeof(thread_id) * count); - if (tq->tq_threads == NULL) { - tq_unlock(tq, state); - return B_NO_MEMORY; - } - - tq->tq_sem = create_sem(0, tq->tq_name); - if (tq->tq_sem < B_OK) { - free(tq->tq_threads); - tq->tq_threads = NULL; - tq_unlock(tq, state); - return tq->tq_sem; - } - for (i = 0; i < count; i++) { tq->tq_threads[i] = spawn_kernel_thread(tq_handle_thread, tq->tq_name, prio, tq); @@ -171,10 +147,6 @@ status_t status = tq->tq_threads[i]; for (j = 0; j < i; j++) kill_thread(tq->tq_threads[j]); - free(tq->tq_threads); - tq->tq_threads = NULL; - delete_sem(tq->tq_sem); - tq_unlock(tq, state); return status; } } @@ -184,11 +156,36 @@ for (i = 0; i < count; i++) resume_thread(tq->tq_threads[i]); - tq_unlock(tq, state); return 0; } +int +taskqueue_start_threads(struct taskqueue **tqp, int count, int prio, + const char *format, ...) +{ + /* we assume that start_threads is called in a sane place, and + * thus don't lock. This is mostly due to the fact that if the + * TQ is 'fast', locking it disables interrupts... and then we + * can't create semaphores, threads and bananas. */ + + /* cpu_status state; */ + char name[64]; + int result; + va_list vl; + + va_start(vl, format); + vsnprintf(name, sizeof(name), format, vl); + va_end(vl); + + /*tq_lock(*tqp, &state);*/ + result = _taskqueue_start_threads(tqp, count, prio, name); + /*tq_unlock(*tqp, state);*/ + + return result; +} + + void taskqueue_free(struct taskqueue *tq) { From hugosantos at mail.berlios.de Wed May 9 02:55:17 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 9 May 2007 02:55:17 +0200 Subject: [Haiku-commits] r21077 - haiku/trunk/src/libs/compat/freebsd_network Message-ID: <200705090055.l490tHdo006069@sheep.berlios.de> Author: hugosantos Date: 2007-05-09 02:55:10 +0200 (Wed, 09 May 2007) New Revision: 21077 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21077&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c Log: freebsd compat. layer: remove arbitrary limit on number of created threads available in taskqueue_start_threads. Modified: haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c 2007-05-09 00:29:29 UTC (rev 21076) +++ haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c 2007-05-09 00:55:10 UTC (rev 21077) @@ -13,8 +13,6 @@ #include #include -#define MAX_TASKQUEUE_THREADS 2 - struct taskqueue { char tq_name[64]; mutex tq_mutex; @@ -24,7 +22,8 @@ int tq_fast; int32 tq_spinlock; sem_id tq_sem; - thread_id tq_threads[MAX_TASKQUEUE_THREADS]; + thread_id *tq_threads; + thread_id tq_thread_storage; int tq_threadcount; }; @@ -42,17 +41,10 @@ tq->tq_fast = fast; - tq->tq_sem = create_sem(0, tq->tq_name); - if (tq->tq_sem < B_OK) { - free(tq); - return tq->tq_sem; - } - if (fast) { tq->tq_spinlock = 0; } else { if (mutex_init(&tq->tq_mutex, name) < B_OK) { - delete_sem(tq->tq_sem); free(tq); return NULL; } @@ -63,6 +55,8 @@ tq->tq_enqueue = enqueue; tq->tq_arg = context; + tq->tq_sem = -1; + tq->tq_threads = NULL; tq->tq_threadcount = 0; return tq; @@ -108,9 +102,15 @@ cpu_status cpu_state; struct task *t; int pending; + sem_id sem; + /* just a synchronization point */ + tq_lock(tq, &cpu_state); + sem = tq->tq_sem; + tq_unlock(tq, cpu_state); + while (1) { - status_t status = acquire_sem(tq->tq_sem); + status_t status = acquire_sem(sem); if (status < B_OK) break; @@ -137,9 +137,25 @@ if (count == 0) return -1; - if (count > MAX_TASKQUEUE_THREADS) - panic("_taskqueue_start_threads, too many threads requested"); + if (tq->tq_threads != NULL) + return -1; + if (count == 1) { + tq->tq_threads = &tq->tq_thread_storage; + } else { + tq->tq_threads = malloc(sizeof(thread_id) * count); + if (tq->tq_threads == NULL) + return B_NO_MEMORY; + } + + tq->tq_sem = create_sem(0, tq->tq_name); + if (tq->tq_sem < B_OK) { + if (count > 1) + free(tq->tq_threads); + tq->tq_threads = NULL; + return tq->tq_sem; + } + for (i = 0; i < count; i++) { tq->tq_threads[i] = spawn_kernel_thread(tq_handle_thread, tq->tq_name, prio, tq); @@ -147,6 +163,10 @@ status_t status = tq->tq_threads[i]; for (j = 0; j < i; j++) kill_thread(tq->tq_threads[j]); + if (count > 1) + free(tq->tq_threads); + tq->tq_threads = NULL; + delete_sem(tq->tq_sem); return status; } } @@ -164,10 +184,10 @@ taskqueue_start_threads(struct taskqueue **tqp, int count, int prio, const char *format, ...) { - /* we assume that start_threads is called in a sane place, and - * thus don't lock. This is mostly due to the fact that if the - * TQ is 'fast', locking it disables interrupts... and then we - * can't create semaphores, threads and bananas. */ + /* we assume that start_threads is called in a sane place, and thus + * don't need to be locked. This is mostly due to the fact that if + * the TQ is 'fast', locking the TQ disables interrupts... and then + * we can't create semaphores, threads and bananas. */ /* cpu_status state; */ char name[64]; @@ -201,6 +221,9 @@ status_t status; wait_for_thread(tq->tq_threads[i], &status); } + + if (tq->tq_threadcount > 1) + free(tq->tq_threads); } free(tq); @@ -214,7 +237,7 @@ tq_lock(tq, &status); if (task->ta_pending != 0) - panic("unimplemented, taskqueue drain"); + UNIMPLEMENTED(); tq_unlock(tq, status); } From hugosantos at mail.berlios.de Wed May 9 03:28:14 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 9 May 2007 03:28:14 +0200 Subject: [Haiku-commits] r21078 - haiku/trunk/src/libs/compat/freebsd_network Message-ID: <200705090128.l491SEcU007820@sheep.berlios.de> Author: hugosantos Date: 2007-05-09 03:28:02 +0200 (Wed, 09 May 2007) New Revision: 21078 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21078&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/device.h Log: freebsd compat. layer: close() and free(). Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-09 00:55:10 UTC (rev 21077) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-09 01:28:02 UTC (rev 21078) @@ -48,7 +48,8 @@ snprintf(semName, sizeof(semName), "%s rcv", gDriverName); - dev->softc = _kernel_malloc(driver->softc_size, M_ZERO); + dev->softc_size = driver->softc_size; + dev->softc = malloc(driver->softc_size); if (dev->softc == NULL) { free(dev); return NULL; @@ -119,9 +120,12 @@ dev = gDevices[i]; - if (atomic_or(&dev->flags, DEVICE_OPEN) & DEVICE_OPEN) + if (!atomic_test_and_set(&dev->open, 1, 0)) return B_BUSY; + /* some drivers expect the softc to be zero'ed out */ + memset(dev->softc, 0, dev->softc_size); + status = sDeviceAttach(dev); if (status != 0) dev->flags = 0; @@ -144,7 +148,6 @@ } *cookie = dev; - return status; } @@ -155,8 +158,15 @@ device_t dev = cookie; device_printf(dev, "compat_close()\n"); - UNIMPLEMENTED(); - return B_ERROR; + + atomic_or(&dev->flags, DEVICE_CLOSED); + + /* do we need a memory barrier in read() or is the atomic_or + * (and the implicit 'lock') enough? */ + + release_sem_etc(dev->receive_sem, 1, B_RELEASE_ALL); + + return B_OK; } @@ -167,10 +177,14 @@ device_printf(dev, "compat_free()\n"); + sDeviceDetach(dev); + + /* XXX empty out the send queue */ + + atomic_and(&dev->open, 0); put_module(NET_STACK_MODULE_NAME); - free_device(dev); - UNIMPLEMENTED(); - return B_ERROR; + + return B_OK; } @@ -469,7 +483,6 @@ err_2: free(dev); err_1: -err_0: put_module(B_PCI_MODULE_NAME); return status; } Modified: haiku/trunk/src/libs/compat/freebsd_network/device.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-09 00:55:10 UTC (rev 21077) +++ haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-09 01:28:02 UTC (rev 21078) @@ -28,6 +28,7 @@ pci_info pci_info; char dev_name[128]; + int32 open; int32 flags; struct ifqueue receive_queue; @@ -41,6 +42,7 @@ char nameunit[64]; const char * description; void * softc; + size_t softc_size; }; From hugosantos at mail.berlios.de Wed May 9 05:01:16 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 9 May 2007 05:01:16 +0200 Subject: [Haiku-commits] r21079 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/sys Message-ID: <200705090301.l4931GUl013413@sheep.berlios.de> Author: hugosantos Date: 2007-05-09 05:00:57 +0200 (Wed, 09 May 2007) New Revision: 21079 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21079&view=rev Added: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf-fbsd.h haiku/trunk/src/libs/compat/freebsd_network/fbsd_busdma_x86.c haiku/trunk/src/libs/compat/freebsd_network/fbsd_ether.c haiku/trunk/src/libs/compat/freebsd_network/fbsd_if_media.c haiku/trunk/src/libs/compat/freebsd_network/fbsd_mbuf.c Removed: haiku/trunk/src/libs/compat/freebsd_network/busdma_machdep.c haiku/trunk/src/libs/compat/freebsd_network/if_media.c Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/types.h haiku/trunk/src/libs/compat/freebsd_network/if.c haiku/trunk/src/libs/compat/freebsd_network/mbuf.c Log: freebsd compat. layer: splited freebsd original code into own files. Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-09 01:28:02 UTC (rev 21078) +++ haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-09 03:00:57 UTC (rev 21079) @@ -9,12 +9,14 @@ Library libfreebsd_network.a : bus.c - busdma_machdep.c callout.c compat.c device.c + fbsd_busdma_x86.c + fbsd_ether.c + fbsd_if_media.c + fbsd_mbuf.c if.c - if_media.c mbuf.c mii.c mutex.c Deleted: haiku/trunk/src/libs/compat/freebsd_network/busdma_machdep.c Added: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf-fbsd.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf-fbsd.h 2007-05-09 01:28:02 UTC (rev 21078) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf-fbsd.h 2007-05-09 03:00:57 UTC (rev 21079) @@ -0,0 +1,106 @@ +/*- + * Copyright (c) 1982, 1986, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)mbuf.h 8.5 (Berkeley) 2/19/95 + * $FreeBSD: src/sys/sys/mbuf.h,v 1.170.2.6 2006/03/23 23:24:32 sam Exp $ + */ +#ifndef _FBSD_COMPAT_SYS_MBUF_FBSD_H_ +#define _FBSD_COMPAT_SYS_MBUF_FBSD_H_ + +/* + * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place + * an object of the specified size at the end of the mbuf, longword aligned. + */ +#define M_ALIGN(m, len) do { \ + (m)->m_data += (MLEN - (len)) & ~(sizeof(long) - 1); \ +} while (0) + +/* + * As above, for mbufs allocated with m_gethdr/MGETHDR + * or initialized by M_COPY_PKTHDR. + */ +#define MH_ALIGN(m, len) do { \ + (m)->m_data += (MHLEN - (len)) & ~(sizeof(long) - 1); \ +} while (0) + + +/* +#define MEXT_IS_REF(m) (((m)->m_ext.ref_cnt != NULL) \ + && (*((m)->m_ext.ref_cnt) > 1)) + */ +#define MEXT_IS_REF(m) 0 + +/* + * Evaluate TRUE if it's safe to write to the mbuf m's data region (this + * can be both the local data payload, or an external buffer area, + * depending on whether M_EXT is set). + */ + +/* +#define M_WRITABLE(m) (!((m)->m_flags & M_RDONLY) && (!((m)->m_flags \ + & M_EXT) || !MEXT_IS_REF(m))) + */ +#define M_WRITABLE(m) (!((m)->m_flags & M_EXT) || !MEXT_IS_REF(m)) + +/* + * Compute the amount of space available + * before the current start of data in an mbuf. + * + * The M_WRITABLE() is a temporary, conservative safety measure: the burden + * of checking writability of the mbuf data area rests solely with the caller. + */ +#define M_LEADINGSPACE(m) \ + ((m)->m_flags & M_EXT ? \ + (M_WRITABLE(m) ? (m)->m_data - (m)->m_ext.ext_buf : 0): \ + (m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat : \ + (m)->m_data - (m)->m_dat) + +/* + * Arrange to prepend space of size plen to mbuf m. + * If a new mbuf must be allocated, how specifies whether to wait. + * If the allocation fails, the original mbuf chain is freed and m is + * set to NULL. + */ +#define M_PREPEND(m, plen, how) do { \ + struct mbuf **_mmp = &(m); \ + struct mbuf *_mm = *_mmp; \ + int _mplen = (plen); \ + int __mhow = (how); \ + \ + MBUF_CHECKSLEEP(how); \ + if (M_LEADINGSPACE(_mm) >= _mplen) { \ + _mm->m_data -= _mplen; \ + _mm->m_len += _mplen; \ + } else \ + _mm = m_prepend(_mm, _mplen, __mhow); \ + if (_mm != NULL && _mm->m_flags & M_PKTHDR) \ + _mm->m_pkthdr.len += _mplen; \ + *_mmp = _mm; \ +} while (0) + +#endif Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h 2007-05-09 01:28:02 UTC (rev 21078) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h 2007-05-09 03:00:57 UTC (rev 21079) @@ -118,79 +118,12 @@ ("%s: no mbuf packet header!", __func__)) #define MBUF_CHECKSLEEP(how) do { } while (0) +#define MBTOM(how) (how) +extern int max_protohdr; -/* - * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place - * an object of the specified size at the end of the mbuf, longword aligned. - */ -#define M_ALIGN(m, len) do { \ - (m)->m_data += (MLEN - (len)) & ~(sizeof(long) - 1); \ -} while (0) +#include -/* - * As above, for mbufs allocated with m_gethdr/MGETHDR - * or initialized by M_COPY_PKTHDR. - */ -#define MH_ALIGN(m, len) do { \ - (m)->m_data += (MHLEN - (len)) & ~(sizeof(long) - 1); \ -} while (0) - - -/* -#define MEXT_IS_REF(m) (((m)->m_ext.ref_cnt != NULL) \ - && (*((m)->m_ext.ref_cnt) > 1)) - */ -#define MEXT_IS_REF(m) 0 - -/* - * Evaluate TRUE if it's safe to write to the mbuf m's data region (this - * can be both the local data payload, or an external buffer area, - * depending on whether M_EXT is set). - */ - -/* -#define M_WRITABLE(m) (!((m)->m_flags & M_RDONLY) && (!((m)->m_flags \ - & M_EXT) || !MEXT_IS_REF(m))) - */ -#define M_WRITABLE(m) (!((m)->m_flags & M_EXT) || !MEXT_IS_REF(m)) - -/* - * Compute the amount of space available - * before the current start of data in an mbuf. - * - * The M_WRITABLE() is a temporary, conservative safety measure: the burden - * of checking writability of the mbuf data area rests solely with the caller. - */ -#define M_LEADINGSPACE(m) \ - ((m)->m_flags & M_EXT ? \ - (M_WRITABLE(m) ? (m)->m_data - (m)->m_ext.ext_buf : 0): \ - (m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat : \ - (m)->m_data - (m)->m_dat) - -/* - * Arrange to prepend space of size plen to mbuf m. - * If a new mbuf must be allocated, how specifies whether to wait. - * If the allocation fails, the original mbuf chain is freed and m is - * set to NULL. - */ -#define M_PREPEND(m, plen, how) do { \ - struct mbuf **_mmp = &(m); \ - struct mbuf *_mm = *_mmp; \ - int _mplen = (plen); \ - int __mhow = (how); \ - \ - MBUF_CHECKSLEEP(how); \ - if (M_LEADINGSPACE(_mm) >= _mplen) { \ - _mm->m_data -= _mplen; \ - _mm->m_len += _mplen; \ - } else \ - _mm = m_prepend(_mm, _mplen, __mhow); \ - if (_mm != NULL && _mm->m_flags & M_PKTHDR) \ - _mm->m_pkthdr.len += _mplen; \ - *_mmp = _mm; \ -} while (0) - #endif #endif Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/types.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/types.h 2007-05-09 01:28:02 UTC (rev 21078) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/types.h 2007-05-09 03:00:57 UTC (rev 21079) @@ -1,6 +1,7 @@ #ifndef _FBSD_COMPAT_SYS_TYPES_H_ #define _FBSD_COMPAT_SYS_TYPES_H_ +#include #include typedef int boolean_t; Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-09 01:28:02 UTC (rev 21078) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-09 03:00:57 UTC (rev 21079) @@ -334,6 +334,7 @@ return (unsigned long)pe.address; } + status_t init_compat_layer() { Copied: haiku/trunk/src/libs/compat/freebsd_network/fbsd_busdma_x86.c (from rev 21078, haiku/trunk/src/libs/compat/freebsd_network/busdma_machdep.c) =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/busdma_machdep.c 2007-05-09 01:28:02 UTC (rev 21078) +++ haiku/trunk/src/libs/compat/freebsd_network/fbsd_busdma_x86.c 2007-05-09 03:00:57 UTC (rev 21079) @@ -0,0 +1,1194 @@ +/*- + * Copyright (c) 1997, 1998 Justin T. Gibbs. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/sys/i386/i386/busdma_machdep.c,v 1.74.2.4 2006/10/21 16:26:53 hrs Exp $"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#define MAX_BPAGES 512 + +/* -hugo */ +#define malloc(a, b, c) kernel_malloc(a, b, c) +#define free(a, b) kernel_free(a, b) +#define contigmalloc(a, b, c, d, e, f, g) kernel_contigmalloc(a, b, c, d, e, f, g) +#define contigfree(a, b, c) kernel_contigfree(a, b, c) +#define __unused +void busdma_swi(void); +void init_bounce_pages(void); +void uninit_bounce_pages(void); +/* */ + +struct bounce_zone; + +struct bus_dma_tag { + bus_dma_tag_t parent; + bus_size_t alignment; + bus_size_t boundary; + bus_addr_t lowaddr; + bus_addr_t highaddr; + bus_dma_filter_t *filter; + void *filterarg; + bus_size_t maxsize; + u_int nsegments; + bus_size_t maxsegsz; + int flags; + int ref_count; + int map_count; + bus_dma_lock_t *lockfunc; + void *lockfuncarg; + bus_dma_segment_t *segments; + struct bounce_zone *bounce_zone; +}; + +struct bounce_page { + vm_offset_t vaddr; /* kva of bounce buffer */ + bus_addr_t busaddr; /* Physical address */ + vm_offset_t datavaddr; /* kva of client data */ + bus_size_t datacount; /* client data count */ + STAILQ_ENTRY(bounce_page) links; +}; + +int busdma_swi_pending; + +struct bounce_zone { + STAILQ_ENTRY(bounce_zone) links; + STAILQ_HEAD(bp_list, bounce_page) bounce_page_list; + int total_bpages; + int free_bpages; + int reserved_bpages; + int active_bpages; + int total_bounced; + int total_deferred; + bus_size_t alignment; + bus_size_t boundary; + bus_addr_t lowaddr; + char zoneid[8]; + char lowaddrid[20]; + struct sysctl_ctx_list sysctl_tree; + struct sysctl_oid *sysctl_tree_top; +}; + +static struct mtx bounce_lock; +static int total_bpages; +static int busdma_zonecount; +static STAILQ_HEAD(, bounce_zone) bounce_zone_list; + +SYSCTL_NODE(_hw, OID_AUTO, busdma, CTLFLAG_RD, 0, "Busdma parameters"); +SYSCTL_INT(_hw_busdma, OID_AUTO, total_bpages, CTLFLAG_RD, &total_bpages, 0, + "Total bounce pages"); + +struct bus_dmamap { + struct bp_list bpages; + int pagesneeded; + int pagesreserved; + bus_dma_tag_t dmat; + void *buf; /* unmapped buffer pointer */ + bus_size_t buflen; /* unmapped buffer length */ + bus_dmamap_callback_t *callback; + void *callback_arg; + STAILQ_ENTRY(bus_dmamap) links; +}; + +static STAILQ_HEAD(, bus_dmamap) bounce_map_waitinglist; +static STAILQ_HEAD(, bus_dmamap) bounce_map_callbacklist; +static struct bus_dmamap nobounce_dmamap; + +static int alloc_bounce_zone(bus_dma_tag_t dmat); +static int alloc_bounce_pages(bus_dma_tag_t dmat, u_int numpages); +static int reserve_bounce_pages(bus_dma_tag_t dmat, bus_dmamap_t map, + int commit); +static bus_addr_t add_bounce_page(bus_dma_tag_t dmat, bus_dmamap_t map, + vm_offset_t vaddr, bus_size_t size); +static void free_bounce_page(bus_dma_tag_t dmat, struct bounce_page *bpage); +static __inline int run_filter(bus_dma_tag_t dmat, bus_addr_t paddr); + +/* + * Return true if a match is made. + * + * To find a match walk the chain of bus_dma_tag_t's looking for 'paddr'. + * + * If paddr is within the bounds of the dma tag then call the filter callback + * to check for a match, if there is no filter callback then assume a match. + */ +static __inline int +run_filter(bus_dma_tag_t dmat, bus_addr_t paddr) +{ + int retval; + + retval = 0; + + do { + if (((paddr > dmat->lowaddr && paddr <= dmat->highaddr) + || ((paddr & (dmat->alignment - 1)) != 0)) + && (dmat->filter == NULL + || (*dmat->filter)(dmat->filterarg, paddr) != 0)) + retval = 1; + + dmat = dmat->parent; + } while (retval == 0 && dmat != NULL); + return (retval); +} + +/* + * Convenience function for manipulating driver locks from busdma (during + * busdma_swi, for example). Drivers that don't provide their own locks + * should specify &Giant to dmat->lockfuncarg. Drivers that use their own + * non-mutex locking scheme don't have to use this at all. + */ +void +busdma_lock_mutex(void *arg, bus_dma_lock_op_t op) +{ + struct mtx *dmtx; + + dmtx = (struct mtx *)arg; + switch (op) { + case BUS_DMA_LOCK: + mtx_lock(dmtx); + break; + case BUS_DMA_UNLOCK: + mtx_unlock(dmtx); + break; + default: + panic("Unknown operation 0x%x for busdma_lock_mutex!", op); + } +} + +/* + * dflt_lock should never get called. It gets put into the dma tag when + * lockfunc == NULL, which is only valid if the maps that are associated + * with the tag are meant to never be defered. + * XXX Should have a way to identify which driver is responsible here. + */ +static void +dflt_lock(void *arg, bus_dma_lock_op_t op) +{ + panic("driver error: busdma dflt_lock called"); +} + +#define BUS_DMA_COULD_BOUNCE BUS_DMA_BUS3 +#define BUS_DMA_MIN_ALLOC_COMP BUS_DMA_BUS4 +/* + * Allocate a device specific dma_tag. + */ +int +bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, + bus_size_t boundary, bus_addr_t lowaddr, + bus_addr_t highaddr, bus_dma_filter_t *filter, + void *filterarg, bus_size_t maxsize, int nsegments, + bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, + void *lockfuncarg, bus_dma_tag_t *dmat) +{ + bus_dma_tag_t newtag; + int error = 0; + + /* Basic sanity checking */ + if (boundary != 0 && boundary < maxsegsz) + maxsegsz = boundary; + + /* Return a NULL tag on failure */ + *dmat = NULL; + + newtag = (bus_dma_tag_t)malloc(sizeof(*newtag), M_DEVBUF, + M_ZERO | M_NOWAIT); + if (newtag == NULL) { + CTR4(KTR_BUSDMA, "%s returned tag %p tag flags 0x%x error %d", + __func__, newtag, 0, error); + return (ENOMEM); + } + + newtag->parent = parent; + newtag->alignment = alignment; + newtag->boundary = boundary; + newtag->lowaddr = trunc_page((vm_paddr_t)lowaddr) + (PAGE_SIZE - 1); + newtag->highaddr = trunc_page((vm_paddr_t)highaddr) + + (PAGE_SIZE - 1); + newtag->filter = filter; + newtag->filterarg = filterarg; + newtag->maxsize = maxsize; + newtag->nsegments = nsegments; + newtag->maxsegsz = maxsegsz; + newtag->flags = flags; + newtag->ref_count = 1; /* Count ourself */ + newtag->map_count = 0; + if (lockfunc != NULL) { + newtag->lockfunc = lockfunc; + newtag->lockfuncarg = lockfuncarg; + } else { + newtag->lockfunc = dflt_lock; + newtag->lockfuncarg = NULL; + } + newtag->segments = NULL; + + /* Take into account any restrictions imposed by our parent tag */ + if (parent != NULL) { + newtag->lowaddr = MIN(parent->lowaddr, newtag->lowaddr); + newtag->highaddr = MAX(parent->highaddr, newtag->highaddr); + if (newtag->boundary == 0) + newtag->boundary = parent->boundary; + else if (parent->boundary != 0) + newtag->boundary = MIN(parent->boundary, + newtag->boundary); + if (newtag->filter == NULL) { + /* + * Short circuit looking at our parent directly + * since we have encapsulated all of its information + */ + newtag->filter = parent->filter; + newtag->filterarg = parent->filterarg; + newtag->parent = parent->parent; + } + if (newtag->parent != NULL) + atomic_add_int(&parent->ref_count, 1); + } + + if (newtag->lowaddr < ptoa((vm_paddr_t)Maxmem) + || newtag->alignment > 1) + newtag->flags |= BUS_DMA_COULD_BOUNCE; + + if (((newtag->flags & BUS_DMA_COULD_BOUNCE) != 0) && + (flags & BUS_DMA_ALLOCNOW) != 0) { + struct bounce_zone *bz; + + /* Must bounce */ + + if ((error = alloc_bounce_zone(newtag)) != 0) { + free(newtag, M_DEVBUF); + return (error); + } + bz = newtag->bounce_zone; + + if (ptoa(bz->total_bpages) < maxsize) { + int pages; + + pages = atop(maxsize) - bz->total_bpages; + + /* Add pages to our bounce pool */ + if (alloc_bounce_pages(newtag, pages) < pages) + error = ENOMEM; + } + /* Performed initial allocation */ + newtag->flags |= BUS_DMA_MIN_ALLOC_COMP; + } + + if (error != 0) { + free(newtag, M_DEVBUF); + } else { + *dmat = newtag; + } + CTR4(KTR_BUSDMA, "%s returned tag %p tag flags 0x%x error %d", + __func__, newtag, (newtag != NULL ? newtag->flags : 0), error); + return (error); +} + +int +bus_dma_tag_destroy(bus_dma_tag_t dmat) +{ + bus_dma_tag_t dmat_copy; + int error; + + error = 0; + dmat_copy = dmat; + + if (dmat != NULL) { + + if (dmat->map_count != 0) { + error = EBUSY; + goto out; + } + + while (dmat != NULL) { + bus_dma_tag_t parent; + + parent = dmat->parent; + atomic_subtract_int(&dmat->ref_count, 1); + if (dmat->ref_count == 0) { + if (dmat->segments != NULL) + free(dmat->segments, M_DEVBUF); + free(dmat, M_DEVBUF); + /* + * Last reference count, so + * release our reference + * count on our parent. + */ + dmat = parent; + } else + dmat = NULL; + } + } +out: + CTR3(KTR_BUSDMA, "%s tag %p error %d", __func__, dmat_copy, error); + return (error); +} + +/* + * Allocate a handle for mapping from kva/uva/physical + * address space into bus device space. + */ +int +bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp) +{ + int error; + + error = 0; + + if (dmat->segments == NULL) { + dmat->segments = (bus_dma_segment_t *)malloc( + sizeof(bus_dma_segment_t) * dmat->nsegments, M_DEVBUF, + M_NOWAIT); + if (dmat->segments == NULL) { + CTR3(KTR_BUSDMA, "%s: tag %p error %d", + __func__, dmat, ENOMEM); + return (ENOMEM); + } + } + + /* + * Bouncing might be required if the driver asks for an active + * exclusion region, a data alignment that is stricter than 1, and/or + * an active address boundary. + */ + if (dmat->flags & BUS_DMA_COULD_BOUNCE) { + + /* Must bounce */ + struct bounce_zone *bz; + int maxpages; + + if (dmat->bounce_zone == NULL) { + if ((error = alloc_bounce_zone(dmat)) != 0) + return (error); + } + bz = dmat->bounce_zone; + + *mapp = (bus_dmamap_t)malloc(sizeof(**mapp), M_DEVBUF, + M_NOWAIT | M_ZERO); + if (*mapp == NULL) { + CTR3(KTR_BUSDMA, "%s: tag %p error %d", + __func__, dmat, ENOMEM); + return (ENOMEM); + } + + /* Initialize the new map */ + STAILQ_INIT(&((*mapp)->bpages)); + + /* + * Attempt to add pages to our pool on a per-instance + * basis up to a sane limit. + */ + if (dmat->alignment > 1) + maxpages = MAX_BPAGES; + else + maxpages = MIN(MAX_BPAGES, Maxmem -atop(dmat->lowaddr)); + if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0 + || (dmat->map_count > 0 && bz->total_bpages < maxpages)) { + int pages; + + pages = MAX(atop(dmat->maxsize), 1); + pages = MIN(maxpages - bz->total_bpages, pages); + pages = MAX(pages, 1); + if (alloc_bounce_pages(dmat, pages) < pages) + error = ENOMEM; + + if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0) { + if (error == 0) + dmat->flags |= BUS_DMA_MIN_ALLOC_COMP; + } else { + error = 0; + } + } + } else { + *mapp = NULL; + } + if (error == 0) + dmat->map_count++; + CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", + __func__, dmat, dmat->flags, error); + return (error); +} + +/* + * Destroy a handle for mapping from kva/uva/physical + * address space into bus device space. + */ +int +bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map) +{ + if (map != NULL && map != &nobounce_dmamap) { + if (STAILQ_FIRST(&map->bpages) != NULL) { + CTR3(KTR_BUSDMA, "%s: tag %p error %d", + __func__, dmat, EBUSY); + return (EBUSY); + } + free(map, M_DEVBUF); + } + dmat->map_count--; + CTR2(KTR_BUSDMA, "%s: tag %p error 0", __func__, dmat); + return (0); +} + + +/* + * Allocate a piece of memory that can be efficiently mapped into + * bus device space based on the constraints lited in the dma tag. + * A dmamap to for use with dmamap_load is also allocated. + */ +int +bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, + bus_dmamap_t *mapp) +{ + int mflags; + + if (flags & BUS_DMA_NOWAIT) + mflags = M_NOWAIT; + else + mflags = M_WAITOK; + if (flags & BUS_DMA_ZERO) + mflags |= M_ZERO; + + /* If we succeed, no mapping/bouncing will be required */ + *mapp = NULL; + + if (dmat->segments == NULL) { + dmat->segments = (bus_dma_segment_t *)malloc( + sizeof(bus_dma_segment_t) * dmat->nsegments, M_DEVBUF, + M_NOWAIT); + if (dmat->segments == NULL) { + CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", + __func__, dmat, dmat->flags, ENOMEM); + return (ENOMEM); + } + } + + /* + * XXX: + * (dmat->alignment < dmat->maxsize) is just a quick hack; the exact + * alignment guarantees of malloc need to be nailed down, and the + * code below should be rewritten to take that into account. + * + * In the meantime, we'll warn the user if malloc gets it wrong. + */ + if ((dmat->maxsize <= PAGE_SIZE) && + (dmat->alignment < dmat->maxsize) && + dmat->lowaddr >= ptoa((vm_paddr_t)Maxmem)) { + *vaddr = malloc(dmat->maxsize, M_DEVBUF, mflags); + } else { + /* + * XXX Use Contigmalloc until it is merged into this facility + * and handles multi-seg allocations. Nobody is doing + * multi-seg allocations yet though. + * XXX Certain AGP hardware does. + */ + *vaddr = contigmalloc(dmat->maxsize, M_DEVBUF, mflags, + 0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : 1ul, + dmat->boundary); + } + if (*vaddr == NULL) { + CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", + __func__, dmat, dmat->flags, ENOMEM); + return (ENOMEM); + } else if ((uintptr_t)*vaddr & (dmat->alignment - 1)) { + printf("bus_dmamem_alloc failed to align memory properly.\n"); + } + CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", + __func__, dmat, dmat->flags, 0); + return (0); +} + +/* + * Free a piece of memory and it's allociated dmamap, that was allocated + * via bus_dmamem_alloc. Make the same choice for free/contigfree. + */ +void +bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map) +{ + /* + * dmamem does not need to be bounced, so the map should be + * NULL + */ + if (map != NULL) + panic("bus_dmamem_free: Invalid map freed\n"); + if ((dmat->maxsize <= PAGE_SIZE) && + (dmat->alignment < dmat->maxsize) && + dmat->lowaddr >= ptoa((vm_paddr_t)Maxmem)) + free(vaddr, M_DEVBUF); + else { + contigfree(vaddr, dmat->maxsize, M_DEVBUF); + } + CTR3(KTR_BUSDMA, "%s: tag %p flags 0x%x", __func__, dmat, dmat->flags); +} + +/* + * Utility function to load a linear buffer. lastaddrp holds state + * between invocations (for multiple-buffer loads). segp contains + * the starting segment on entrace, and the ending segment on exit. + * first indicates if this is the first invocation of this function. + */ +static __inline int +_bus_dmamap_load_buffer(bus_dma_tag_t dmat, + bus_dmamap_t map, + void *buf, bus_size_t buflen, + pmap_t pmap, + int flags, + bus_addr_t *lastaddrp, + bus_dma_segment_t *segs, + int *segp, + int first) +{ + bus_size_t sgsize; + bus_addr_t curaddr, lastaddr, baddr, bmask; + vm_offset_t vaddr; + bus_addr_t paddr; + int needbounce = 0; + int seg; + + if (map == NULL) + map = &nobounce_dmamap; + + if ((map != &nobounce_dmamap && map->pagesneeded == 0) + && ((dmat->flags & BUS_DMA_COULD_BOUNCE) != 0)) { + vm_offset_t vendaddr; + + CTR4(KTR_BUSDMA, "lowaddr= %d Maxmem= %d, boundary= %d, " + "alignment= %d", dmat->lowaddr, ptoa((vm_paddr_t)Maxmem), + dmat->boundary, dmat->alignment); + CTR3(KTR_BUSDMA, "map= %p, nobouncemap= %p, pagesneeded= %d", + map, &nobounce_dmamap, map->pagesneeded); + /* + * Count the number of bounce pages + * needed in order to complete this transfer + */ + vaddr = trunc_page((vm_offset_t)buf); + vendaddr = (vm_offset_t)buf + buflen; + + while (vaddr < vendaddr) { + paddr = pmap_kextract(vaddr); + if (run_filter(dmat, paddr) != 0) { + needbounce = 1; + map->pagesneeded++; + } + vaddr += PAGE_SIZE; + } + CTR1(KTR_BUSDMA, "pagesneeded= %d\n", map->pagesneeded); + } + + /* Reserve Necessary Bounce Pages */ + if (map->pagesneeded != 0) { + mtx_lock(&bounce_lock); + if (flags & BUS_DMA_NOWAIT) { + if (reserve_bounce_pages(dmat, map, 0) != 0) { + mtx_unlock(&bounce_lock); + return (ENOMEM); + } + } else { + if (reserve_bounce_pages(dmat, map, 1) != 0) { + /* Queue us for resources */ + map->dmat = dmat; + map->buf = buf; + map->buflen = buflen; + STAILQ_INSERT_TAIL(&bounce_map_waitinglist, + map, links); + mtx_unlock(&bounce_lock); + return (EINPROGRESS); + } + } + mtx_unlock(&bounce_lock); + } + + vaddr = (vm_offset_t)buf; + lastaddr = *lastaddrp; + bmask = ~(dmat->boundary - 1); + + for (seg = *segp; buflen > 0 ; ) { + /* + * Get the physical address for this segment. + */ + if (pmap) + curaddr = pmap_extract(pmap, vaddr); + else + curaddr = pmap_kextract(vaddr); + + /* + * Compute the segment size, and adjust counts. + */ + sgsize = PAGE_SIZE - ((u_long)curaddr & PAGE_MASK); + if (buflen < sgsize) + sgsize = buflen; + + /* + * Make sure we don't cross any boundaries. + */ + if (dmat->boundary > 0) { + baddr = (curaddr + dmat->boundary) & bmask; + if (sgsize > (baddr - curaddr)) + sgsize = (baddr - curaddr); + } + + if (map->pagesneeded != 0 && run_filter(dmat, curaddr)) + curaddr = add_bounce_page(dmat, map, vaddr, sgsize); + + /* + * Insert chunk into a segment, coalescing with + * previous segment if possible. + */ + if (first) { + segs[seg].ds_addr = curaddr; + segs[seg].ds_len = sgsize; + first = 0; + } else { + if (needbounce == 0 && curaddr == lastaddr && + (segs[seg].ds_len + sgsize) <= dmat->maxsegsz && + (dmat->boundary == 0 || + (segs[seg].ds_addr & bmask) == (curaddr & bmask))) + segs[seg].ds_len += sgsize; + else { + if (++seg >= dmat->nsegments) + break; + segs[seg].ds_addr = curaddr; + segs[seg].ds_len = sgsize; + } + } + + lastaddr = curaddr + sgsize; + vaddr += sgsize; + buflen -= sgsize; + } + + *segp = seg; + *lastaddrp = lastaddr; + + /* + * Did we fit? + */ + return (buflen != 0 ? EFBIG : 0); /* XXX better return value here? */ +} + +/* + * Map the buffer buf into bus space using the dmamap map. + */ +int +bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, + bus_size_t buflen, bus_dmamap_callback_t *callback, + void *callback_arg, int flags) +{ + bus_addr_t lastaddr = 0; + int error, nsegs = 0; + + if (map != NULL) { + flags |= BUS_DMA_WAITOK; + map->callback = callback; + map->callback_arg = callback_arg; + } + + error = _bus_dmamap_load_buffer(dmat, map, buf, buflen, NULL, flags, + &lastaddr, dmat->segments, &nsegs, 1); + + CTR5(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d nsegs %d", + __func__, dmat, dmat->flags, error, nsegs + 1); + + if (error == EINPROGRESS) { + return (error); + } + + if (error) + (*callback)(callback_arg, dmat->segments, 0, error); + else + (*callback)(callback_arg, dmat->segments, nsegs + 1, 0); + + /* + * Return ENOMEM to the caller so that it can pass it up the stack. + * This error only happens when NOWAIT is set, so deferal is disabled. + */ + if (error == ENOMEM) + return (error); + + return (0); +} + + [... truncated: 1683 lines follow ...] From hugosantos at mail.berlios.de Wed May 9 06:22:00 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 9 May 2007 06:22:00 +0200 Subject: [Haiku-commits] r21080 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/sys Message-ID: <200705090422.l494M023017597@sheep.berlios.de> Author: hugosantos Date: 2007-05-09 06:21:47 +0200 (Wed, 09 May 2007) New Revision: 21080 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21080&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/bus.c haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/taskqueue.h haiku/trunk/src/libs/compat/freebsd_network/mbuf.c haiku/trunk/src/libs/compat/freebsd_network/mii.c haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c Log: freebsd compat. layer: added swi taskqueue and a couple more methods that if_xl needs. also marked some as unimplemented so its clearer what is left to be done. Modified: haiku/trunk/src/libs/compat/freebsd_network/bus.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-09 03:00:57 UTC (rev 21079) +++ haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-09 04:21:47 UTC (rev 21080) @@ -326,6 +326,21 @@ } +int +bus_generic_print_child(device_t dev, device_t child) +{ + UNIMPLEMENTED(); + return B_ERROR; +} + + +void +bus_generic_driver_added(device_t dev, driver_t *driver) +{ + UNIMPLEMENTED(); +} + + #define DEBUG_BUS_SPACE_RW #ifdef DEBUG_BUS_SPACE_RW Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-09 03:00:57 UTC (rev 21079) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-09 04:21:47 UTC (rev 21080) @@ -93,6 +93,9 @@ device_t device_add_child(device_t dev, const char *name, int unit); int device_delete_child(device_t dev, device_t child); +int device_is_attached(device_t dev); +int bus_generic_print_child(device_t dev, device_t child); +void bus_generic_driver_added(device_t dev, driver_t *driver); static inline struct sysctl_ctx_list * device_get_sysctl_ctx(device_t dev) Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-09 03:00:57 UTC (rev 21079) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-09 04:21:47 UTC (rev 21080) @@ -90,6 +90,7 @@ enum { FBSD_TASKQUEUES = 1 << 0, FBSD_FAST_TASKQUEUE = 1 << 1, + FBSD_SWI_TASKQUEUE = 1 << 2, }; #define HAIKU_DRIVER_REQUIREMENTS(flags) \ Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/taskqueue.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/taskqueue.h 2007-05-09 03:00:57 UTC (rev 21079) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/taskqueue.h 2007-05-09 04:21:47 UTC (rev 21080) @@ -24,6 +24,8 @@ void taskqueue_thread_enqueue(void *context); extern struct taskqueue *taskqueue_fast; +extern struct taskqueue *taskqueue_swi; + int taskqueue_enqueue_fast(struct taskqueue *queue, struct task *task); struct taskqueue *taskqueue_create_fast(const char *name, int mflags, taskqueue_enqueue_fn enqueue, void *context); Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-09 03:00:57 UTC (rev 21079) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-09 04:21:47 UTC (rev 21080) @@ -225,11 +225,20 @@ int device_delete_child(device_t dev, device_t child) { + UNIMPLEMENTED(); return -1; } int +device_is_attached(device_t dev) +{ + UNIMPLEMENTED(); + return -1; +} + + +int printf(const char *format, ...) { char buf[256]; Modified: haiku/trunk/src/libs/compat/freebsd_network/mbuf.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/mbuf.c 2007-05-09 03:00:57 UTC (rev 21079) +++ haiku/trunk/src/libs/compat/freebsd_network/mbuf.c 2007-05-09 04:21:47 UTC (rev 21080) @@ -190,380 +190,6 @@ } -/* - * Copy data from an mbuf chain starting "off" bytes from the beginning, - * continuing for "len" bytes, into the indicated buffer. - */ -void -m_copydata(const struct mbuf *m, int off, int len, caddr_t cp) -{ - u_int count; - - KASSERT(off >= 0, ("m_copydata, negative off %d", off)); - KASSERT(len >= 0, ("m_copydata, negative len %d", len)); - while (off > 0) { - KASSERT(m != NULL, ("m_copydata, offset > size of mbuf chain")); - if (off < m->m_len) - break; - off -= m->m_len; - m = m->m_next; - } - while (len > 0) { - KASSERT(m != NULL, ("m_copydata, length > size of mbuf chain")); - count = min(m->m_len - off, len); - bcopy(mtod(m, caddr_t) + off, cp, count); - len -= count; - cp += count; - off = 0; - m = m->m_next; - } -} - - -/* - * Concatenate mbuf chain n to m. - * Both chains must be of the same type (e.g. MT_DATA). - * Any m_pkthdr is not updated. - */ -void -m_cat(struct mbuf *m, struct mbuf *n) -{ - while (m->m_next) - m = m->m_next; - while (n) { - if (m->m_flags & M_EXT || - m->m_data + m->m_len + n->m_len >= &m->m_dat[MLEN]) { - /* just join the two chains */ - m->m_next = n; - return; - } - /* splat the data from one into the other */ - bcopy(mtod(n, caddr_t), mtod(m, caddr_t) + m->m_len, - (u_int)n->m_len); - m->m_len += n->m_len; - n = m_free(n); - } -} - - -u_int -m_length(struct mbuf *m0, struct mbuf **last) -{ - struct mbuf *m; - u_int len; - - len = 0; - for (m = m0; m != NULL; m = m->m_next) { - len += m->m_len; - if (m->m_next == NULL) - break; - } - if (last != NULL) - *last = m; - return (len); -} - - -u_int -m_fixhdr(struct mbuf *m0) -{ - u_int len; - - len = m_length(m0, NULL); - m0->m_pkthdr.len = len; - return (len); -} - - -static int -m_tag_copy_chain(struct mbuf *to, struct mbuf *from, int how) -{ - return 1; -} - - -/* - * Duplicate "from"'s mbuf pkthdr in "to". - * "from" must have M_PKTHDR set, and "to" must be empty. - * In particular, this does a deep copy of the packet tags. - */ -static int -m_dup_pkthdr(struct mbuf *to, struct mbuf *from, int how) -{ - MBUF_CHECKSLEEP(how); - /* to->m_flags = (from->m_flags & M_COPYFLAGS) | (to->m_flags & M_EXT); */ - to->m_flags = (to->m_flags & M_EXT); - if ((to->m_flags & M_EXT) == 0) - to->m_data = to->m_pktdat; - to->m_pkthdr = from->m_pkthdr; - /* SLIST_INIT(&to->m_pkthdr.tags); */ - return (m_tag_copy_chain(to, from, MBTOM(how))); -} - - -/* - * Defragment a mbuf chain, returning the shortest possible - * chain of mbufs and clusters. If allocation fails and - * this cannot be completed, NULL will be returned, but - * the passed in chain will be unchanged. Upon success, - * the original chain will be freed, and the new chain - * will be returned. - * - * If a non-packet header is passed in, the original - * mbuf (chain?) will be returned unharmed. - */ -struct mbuf * -m_defrag(struct mbuf *m0, int how) -{ - struct mbuf *m_new = NULL, *m_final = NULL; - int progress = 0, length; - - MBUF_CHECKSLEEP(how); - if (!(m0->m_flags & M_PKTHDR)) - return (m0); - - m_fixhdr(m0); /* Needed sanity check */ - - if (m0->m_pkthdr.len > MHLEN) - m_final = m_getcl(how, MT_DATA, M_PKTHDR); - else - m_final = m_gethdr(how, MT_DATA); - - if (m_final == NULL) - goto nospace; - - if (m_dup_pkthdr(m_final, m0, how) == 0) - goto nospace; - - m_new = m_final; - - while (progress < m0->m_pkthdr.len) { - length = m0->m_pkthdr.len - progress; - if (length > MCLBYTES) - length = MCLBYTES; - - if (m_new == NULL) { - if (length > MLEN) - m_new = m_getcl(how, MT_DATA, 0); - else - m_new = m_get(how, MT_DATA); - if (m_new == NULL) - goto nospace; - } - - m_copydata(m0, progress, length, mtod(m_new, caddr_t)); - progress += length; - m_new->m_len = length; - if (m_new != m_final) - m_cat(m_final, m_new); - m_new = NULL; - } - - m_freem(m0); - m0 = m_final; - return (m0); -nospace: - if (m_final) - m_freem(m_final); - return (NULL); -} - - -void -m_adj(struct mbuf *mp, int req_len) -{ - int len = req_len; - struct mbuf *m; - int count; - - if ((m = mp) == NULL) - return; - if (len >= 0) { - /* - * Trim from head. - */ - while (m != NULL && len > 0) { - if (m->m_len <= len) { - len -= m->m_len; - m->m_len = 0; - m = m->m_next; - } else { - m->m_len -= len; - m->m_data += len; - len = 0; - } - } - m = mp; - if (mp->m_flags & M_PKTHDR) - m->m_pkthdr.len -= (req_len - len); - } else { - /* - * Trim from tail. Scan the mbuf chain, - * calculating its length and finding the last mbuf. - * If the adjustment only affects this mbuf, then just - * adjust and return. Otherwise, rescan and truncate - * after the remaining size. - */ - len = -len; - count = 0; - for (;;) { - count += m->m_len; - if (m->m_next == (struct mbuf *)0) - break; - m = m->m_next; - } - if (m->m_len >= len) { - m->m_len -= len; - if (mp->m_flags & M_PKTHDR) - mp->m_pkthdr.len -= len; - return; - } - count -= len; - if (count < 0) - count = 0; - /* - * Correct length for chain is "count". - * Find the mbuf with last data, adjust its length, - * and toss data from remaining mbufs on chain. - */ - m = mp; - if (m->m_flags & M_PKTHDR) - m->m_pkthdr.len = count; - for (; m; m = m->m_next) { - if (m->m_len >= count) { - m->m_len = count; - if (m->m_next != NULL) { - m_freem(m->m_next); - m->m_next = NULL; - } - break; - } - count -= m->m_len; - } - } -} - - -/* - * Rearange an mbuf chain so that len bytes are contiguous - * and in the data area of an mbuf (so that mtod and dtom - * will work for a structure of size len). Returns the resulting - * mbuf chain on success, frees it and returns null on failure. - * If there is room, it will add up to max_protohdr-len extra bytes to the - * contiguous region in an attempt to avoid being called next time. - */ -struct mbuf * -m_pullup(struct mbuf *n, int len) -{ - struct mbuf *m; - int count; - int space; - - /* - * If first mbuf has no cluster, and has room for len bytes - * without shifting current data, pullup into it, - * otherwise allocate a new mbuf to prepend to the chain. - */ - if ((n->m_flags & M_EXT) == 0 && - n->m_data + len < &n->m_dat[MLEN] && n->m_next) { - if (n->m_len >= len) - return (n); - m = n; - n = n->m_next; - len -= m->m_len; - } else { - if (len > MHLEN) - goto bad; - MGET(m, M_DONTWAIT, n->m_type); - if (m == NULL) - goto bad; - m->m_len = 0; - if (n->m_flags & M_PKTHDR) - M_MOVE_PKTHDR(m, n); - } - space = &m->m_dat[MLEN] - (m->m_data + m->m_len); - do { - count = min(min(max(len, max_protohdr), space), n->m_len); - bcopy(mtod(n, caddr_t), mtod(m, caddr_t) + m->m_len, - (u_int)count); - len -= count; - m->m_len += count; - n->m_len -= count; - space -= count; - if (n->m_len) - n->m_data += count; - else - n = m_free(n); - } while (len > 0 && n); - if (len > 0) { - (void) m_free(m); - goto bad; - } - m->m_next = n; - return (m); -bad: - m_freem(n); - return (NULL); -} - - -/* - * Lesser-used path for M_PREPEND: - * allocate new mbuf to prepend to chain, - * copy junk along. - */ -struct mbuf * -m_prepend(struct mbuf *m, int len, int how) -{ - struct mbuf *mn; - - if (m->m_flags & M_PKTHDR) - MGETHDR(mn, how, m->m_type); - else - MGET(mn, how, m->m_type); - if (mn == NULL) { - m_freem(m); - return (NULL); - } - if (m->m_flags & M_PKTHDR) - M_MOVE_PKTHDR(mn, m); - mn->m_next = m; - m = mn; - if (len < MHLEN) - MH_ALIGN(m, len); - m->m_len = len; - return (m); -} - - -/* - * "Move" mbuf pkthdr from "from" to "to". - * "from" must have M_PKTHDR set, and "to" must be empty. - */ -void -m_move_pkthdr(struct mbuf *to, struct mbuf *from) -{ -#ifdef MAC - /* - * XXXMAC: It could be this should also occur for non-MAC? - */ - if (to->m_flags & M_PKTHDR) - m_tag_delete_chain(to, NULL); -#endif - /* to->m_flags = (from->m_flags & M_COPYFLAGS) | (to->m_flags & M_EXT); */ - /* we don't have M_COPYFLAGS -hugo */ - to->m_flags = to->m_flags & M_EXT; - if ((to->m_flags & M_EXT) == 0) - to->m_data = to->m_pktdat; - to->m_pkthdr = from->m_pkthdr; /* especially tags */ - /* we don't have tags -hugo */ -#if 0 - SLIST_INIT(&from->m_pkthdr.tags); /* purge tags from src */ -#endif - from->m_flags &= ~M_PKTHDR; -} - - status_t init_mbufs() { Modified: haiku/trunk/src/libs/compat/freebsd_network/mii.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/mii.c 2007-05-09 03:00:57 UTC (rev 21079) +++ haiku/trunk/src/libs/compat/freebsd_network/mii.c 2007-05-09 04:21:47 UTC (rev 21080) @@ -23,6 +23,7 @@ mii_phy_probe(device_t dev, device_t *miiDev, ifm_change_cb_t change, ifm_stat_cb_t stat) { + UNIMPLEMENTED(); return -1; } @@ -30,11 +31,13 @@ void mii_tick(struct mii_data *data) { + UNIMPLEMENTED(); } int mii_mediachg(struct mii_data *data) { + UNIMPLEMENTED(); return -1; } @@ -42,4 +45,5 @@ void mii_pollstat(struct mii_data *data) { + UNIMPLEMENTED(); } Modified: haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c 2007-05-09 03:00:57 UTC (rev 21079) +++ haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c 2007-05-09 04:21:47 UTC (rev 21080) @@ -29,6 +29,7 @@ struct taskqueue *taskqueue_fast = NULL; +struct taskqueue *taskqueue_swi = NULL; static struct taskqueue * @@ -296,26 +297,54 @@ status_t init_taskqueues() { + status_t status = B_NO_MEMORY; + if (HAIKU_DRIVER_REQUIRES(FBSD_FAST_TASKQUEUE)) { taskqueue_fast = taskqueue_create_fast("fast taskq", 0, - taskqueue_thread_enqueue, NULL); + taskqueue_thread_enqueue, &taskqueue_fast); if (taskqueue_fast == NULL) return B_NO_MEMORY; - if (taskqueue_start_threads(&taskqueue_fast, 1, B_REAL_TIME_PRIORITY, - "fast taskq") < 0) { - taskqueue_free(taskqueue_fast); - return B_ERROR; + status = taskqueue_start_threads(&taskqueue_fast, 1, + B_REAL_TIME_PRIORITY, "fast taskq"); + if (status < B_OK) + goto err_1; + } + + if (HAIKU_DRIVER_REQUIRES(FBSD_SWI_TASKQUEUE)) { + taskqueue_swi = taskqueue_create_fast("swi taskq", 0, + taskqueue_thread_enqueue, &taskqueue_swi); + if (taskqueue_swi == NULL) { + status = B_NO_MEMORY; + goto err_1; } + + status = taskqueue_start_threads(&taskqueue_swi, 1, + B_REAL_TIME_PRIORITY, "swi taskq"); + if (status < B_OK) + goto err_2; } return B_OK; + +err_2: + if (taskqueue_swi) + taskqueue_free(taskqueue_swi); + +err_1: + if (taskqueue_fast) + taskqueue_free(taskqueue_fast); + + return status; } void uninit_taskqueues() { + if (HAIKU_DRIVER_REQUIRES(FBSD_SWI_TASKQUEUE)) + taskqueue_free(taskqueue_swi); + if (HAIKU_DRIVER_REQUIRES(FBSD_FAST_TASKQUEUE)) taskqueue_free(taskqueue_fast); } From hugosantos at mail.berlios.de Wed May 9 07:37:55 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 9 May 2007 07:37:55 +0200 Subject: [Haiku-commits] r21081 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/net Message-ID: <200705090537.l495bt4Y000565@sheep.berlios.de> Author: hugosantos Date: 2007-05-09 07:37:46 +0200 (Wed, 09 May 2007) New Revision: 21081 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21081&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_var.h haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/if.c Log: freebsd compat. layer: multicast support. Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_var.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_var.h 2007-05-09 04:21:47 UTC (rev 21080) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/net/if_var.h 2007-05-09 05:37:46 UTC (rev 21081) @@ -580,6 +580,9 @@ struct ifnet *ifma_ifp; /* back-pointer to interface */ u_int ifma_refcount; /* reference count */ void *ifma_protospec; /* protocol-specific state, if any */ + + /* haiku additions, save a allocation -hugo */ + struct sockaddr_dl ifma_addr_storage; }; #ifdef _KERNEL Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-09 04:21:47 UTC (rev 21080) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-09 05:37:46 UTC (rev 21081) @@ -309,10 +309,22 @@ case ETHER_ADDMULTI: case ETHER_REMMULTI: - /* TODO */ - UNIMPLEMENTED(); - return B_ERROR; + { + struct sockaddr_dl address; + if (!(ifp->if_flags & IFF_MULTICAST) == 0) + return EOPNOTSUPP; + + memset(&address, 0, sizeof(address)); + address.sdl_family = AF_LINK; + memcpy(LLADDR(&address), arg, ETHER_ADDR_LEN); + + if (op == ETHER_ADDMULTI) + return if_addmulti(ifp, (struct sockaddr *)&address, NULL); + else + return if_delmulti(ifp, (struct sockaddr *)&address); + } + case ETHER_GET_LINK_STATE: { struct ifmediareq mediareq; Modified: haiku/trunk/src/libs/compat/freebsd_network/if.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-09 04:21:47 UTC (rev 21080) +++ haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-09 05:37:46 UTC (rev 21081) @@ -99,6 +99,8 @@ TAILQ_INIT(&ifp->if_prefixhead); TAILQ_INIT(&ifp->if_multiaddrs); + IF_ADDR_LOCK_INIT(ifp); + ifq_init((struct ifqueue *)&ifp->if_snd, ifp->if_xname); } @@ -106,6 +108,7 @@ void if_detach(struct ifnet *ifp) { + IF_ADDR_LOCK_DESTROY(ifp); ifq_uninit((struct ifqueue *)&ifp->if_snd); } @@ -147,7 +150,111 @@ } +static struct ifmultiaddr * +if_findmulti(struct ifnet *ifp, struct sockaddr *_address) +{ + struct sockaddr_dl *address = (struct sockaddr_dl *)_address; + struct ifmultiaddr *ifma; + + TAILQ_FOREACH (ifma, &ifp->if_multiaddrs, ifma_link) { + if (memcmp(LLADDR(address), + LLADDR((struct sockaddr_dl *)ifma->ifma_addr), + ETHER_ADDR_LEN) == 0) + return ifma; + } + + return NULL; +} + + +static struct ifmultiaddr * +_if_addmulti(struct ifnet *ifp, struct sockaddr *address) +{ + struct ifmultiaddr *addr = if_findmulti(ifp, address); + + if (addr != NULL) { + addr->ifma_refcount++; + return addr; + } + + addr = (struct ifmultiaddr *)malloc(sizeof(struct ifmultiaddr)); + if (addr == NULL) + return NULL; + + addr->ifma_lladdr = NULL; + addr->ifma_ifp = ifp; + addr->ifma_protospec = NULL; + + memcpy(&addr->ifma_addr_storage, address, sizeof(struct sockaddr_dl)); + addr->ifma_addr = (struct sockaddr *)&addr->ifma_addr_storage; + + addr->ifma_refcount = 1; + + TAILQ_INSERT_HEAD(&ifp->if_multiaddrs, addr, ifma_link); + + return addr; +} + + int +if_addmulti(struct ifnet *ifp, struct sockaddr *address, + struct ifmultiaddr **out) +{ + struct ifmultiaddr *result; + int refcount = 0; + + IF_ADDR_LOCK(ifp); + result = _if_addmulti(ifp, address); + if (result) + refcount = result->ifma_refcount; + IF_ADDR_UNLOCK(ifp); + + if (result == NULL) + return ENOBUFS; + + if (refcount == 1) + ifp->if_ioctl(ifp, SIOCADDMULTI, NULL); + + if (out) + (*out) = result; + + return 0; +} + + +static void +if_delete_multiaddr(struct ifnet *ifp, struct ifmultiaddr *ifma) +{ + TAILQ_REMOVE(&ifp->if_multiaddrs, ifma, ifma_link); + free(ifma); +} + + +int +if_delmulti(struct ifnet *ifp, struct sockaddr *address) +{ + struct ifmultiaddr *addr; + int deleted = 0; + + IF_ADDR_LOCK(ifp); + addr = if_findmulti(ifp, address); + if (addr != NULL) { + addr->ifma_refcount--; + if (addr->ifma_refcount == 0) { + if_delete_multiaddr(ifp, addr); + deleted = 1; + } + } + IF_ADDR_UNLOCK(ifp); + + if (deleted) + ifp->if_ioctl(ifp, SIOCDELMULTI, NULL); + + return 0; +} + + +int ether_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct rtentry *rt0) { From hugosantos at mail.berlios.de Wed May 9 07:40:46 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 9 May 2007 07:40:46 +0200 Subject: [Haiku-commits] r21082 - haiku/trunk/src/libs/compat/freebsd_network Message-ID: <200705090540.l495ek63000817@sheep.berlios.de> Author: hugosantos Date: 2007-05-09 07:40:39 +0200 (Wed, 09 May 2007) New Revision: 21082 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21082&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c Log: freebsd compat. layer: when open()ing the device, and setting it up, don't clear the device flags (multicast included). Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-09 05:37:46 UTC (rev 21081) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-09 05:40:39 UTC (rev 21082) @@ -136,14 +136,14 @@ struct ifnet *ifp = dev->ifp; struct ifreq ifr; - ifp->if_flags = 0; + ifp->if_flags &= ~IFF_UP; ifp->if_ioctl(ifp, SIOCSIFFLAGS, NULL); memset(&ifr, 0, sizeof(ifr)); ifr.ifr_media = IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, 0); ifp->if_ioctl(ifp, SIOCSIFMEDIA, (caddr_t)&ifr); - ifp->if_flags = IFF_UP; + ifp->if_flags |= IFF_UP; ifp->if_ioctl(ifp, SIOCSIFFLAGS, NULL); } From philippe.houdoin at free.fr Wed May 9 11:28:56 2007 From: philippe.houdoin at free.fr (Philippe Houdoin) Date: Wed, 09 May 2007 11:28:56 +0200 Subject: [Haiku-commits] r21075 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/sys Message-ID: <1178702936.46419458df31a@imp.free.fr> > Log: > freebsd compat. layer: respect requested priority in taskqueue_start_threads. The fact that you've reimplemented BSD's taskqueues feature remind me that the BSD's ACPI OS-specific implementation use it too, and that was the first time I meet these. Our ACPI needed similar feature too. Under BeOS R5, a generic deferred procedure call (dpc) kernel module provides this kind of feature to everyone, reducing memory and file footprint. BeOS USB stack use it. BeOS BONE network stack use it. BeOS (limited) FireWire stack use it. Following the same design (one of our main objective for R1), I've implemented a similar kernel module as our ACPI was waiting for it, which give me tasks queues and dedicated threads calling - outside interrupt context - each task queued, needed by ACPI. It was the first component using this module. And, so far, the only one. I wonder if it could not be re-used by some other components too. It will be better, I think, making a modular kernel actually worth its name... The fact that your freebsd_network compatibility layer export a taskqueue API make it a good candidate. Could you give a look at the very simple DPC kernel module API: headers/os/drivers/dpc.h src/add-ons/kernel/generic/dpc If only ACPI actually use DPC module in the ends, there is no reason to make it an external module anymore. Which will be sad, IMHO, as BeOS kernel modular design was one major selling point to me. Maybe I'm alone, though. - Philippe From bonefish at cs.tu-berlin.de Wed May 9 11:33:06 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Wed, 09 May 2007 11:33:06 +0200 Subject: [Haiku-commits] r21079 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/sys In-Reply-To: <200705090301.l4931GUl013413@sheep.berlios.de> References: <200705090301.l4931GUl013413@sheep.berlios.de> Message-ID: <20070509113306.545.1@cs.tu-berlin.de> On 2007-05-09 at 05:01:16 [+0200], hugosantos at mail.berlios.de wrote: > Author: hugosantos > Date: 2007-05-09 05:00:57 +0200 (Wed, 09 May 2007) > New Revision: 21079 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21079&view=rev > > Added: > haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf-fbsd.h > haiku/trunk/src/libs/compat/freebsd_network/fbsd_busdma_x86.c > haiku/trunk/src/libs/compat/freebsd_network/fbsd_ether.c > haiku/trunk/src/libs/compat/freebsd_network/fbsd_if_media.c > haiku/trunk/src/libs/compat/freebsd_network/fbsd_mbuf.c > Removed: > haiku/trunk/src/libs/compat/freebsd_network/busdma_machdep.c > haiku/trunk/src/libs/compat/freebsd_network/if_media.c > Modified: > haiku/trunk/src/libs/compat/freebsd_network/Jamfile > haiku/trunk/src/libs/compat/freebsd_network/compat.c > haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h > haiku/trunk/src/libs/compat/freebsd_network/compat/sys/types.h > haiku/trunk/src/libs/compat/freebsd_network/if.c > haiku/trunk/src/libs/compat/freebsd_network/mbuf.c > Log: > freebsd compat. layer: splited freebsd original code into own files. > > > Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile > =================================================================== > --- haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-09 > 01:28:02 UTC (rev 21078) > +++ haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-09 > 03:00:57 UTC (rev 21079) > @@ -9,12 +9,14 @@ > > Library libfreebsd_network.a : > bus.c [...] BTW, it is generally recommended to use the Haiku build system specific rules to build high-level targets instead of the standard jam rules. In this case it would be KernelStaticLibrary, which (ATM) adds some header directories and compiler flags. CU, Ingo From bonefish at mail.berlios.de Wed May 9 11:48:35 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 9 May 2007 11:48:35 +0200 Subject: [Haiku-commits] r21083 - haiku/trunk/build/jam Message-ID: <200705090948.l499mZjF019126@sheep.berlios.de> Author: bonefish Date: 2007-05-09 11:48:35 +0200 (Wed, 09 May 2007) New Revision: 21083 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21083&view=rev Modified: haiku/trunk/build/jam/BuildSetup Log: Apparently _GNU_SOURCE doesn't imply 64 bit off_t on all glibc platforms. Funny that it still isn't the default, anyway. Modified: haiku/trunk/build/jam/BuildSetup =================================================================== --- haiku/trunk/build/jam/BuildSetup 2007-05-09 05:40:39 UTC (rev 21082) +++ haiku/trunk/build/jam/BuildSetup 2007-05-09 09:48:35 UTC (rev 21083) @@ -479,8 +479,9 @@ } # Supposing this is a glibc platform, let's try to get features like large - # file support, ISO C 99 definitions, etc. - HOST_DEFINES += _GNU_SOURCE ; + # file support, ISO C 99 definitions, etc. On some platforms we need to + # request 64 bit off_t support explicitely. + HOST_DEFINES += _GNU_SOURCE _FILE_OFFSET_BITS=64 ; # On Linux with xattr support we can use it for our attribute emulation, # which is somewhat more robust. From axeld at mail.berlios.de Wed May 9 14:02:51 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 9 May 2007 14:02:51 +0200 Subject: [Haiku-commits] r21084 - in haiku/trunk/src/add-ons: accelerants/nvidia/engine kernel/drivers/graphics/nvidia Message-ID: <200705091202.l49C2p8Q012325@sheep.berlios.de> Author: axeld Date: 2007-05-09 14:02:49 +0200 (Wed, 09 May 2007) New Revision: 21084 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21084&view=rev Modified: haiku/trunk/src/add-ons/accelerants/nvidia/engine/nv_general.c haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia/driver.c Log: Applied patch provided in ticket #1218 - should enable nVidia 7100 GS cards. Thanks! Modified: haiku/trunk/src/add-ons/accelerants/nvidia/engine/nv_general.c =================================================================== --- haiku/trunk/src/add-ons/accelerants/nvidia/engine/nv_general.c 2007-05-09 09:48:35 UTC (rev 21083) +++ haiku/trunk/src/add-ons/accelerants/nvidia/engine/nv_general.c 2007-05-09 12:02:49 UTC (rev 21084) @@ -553,6 +553,13 @@ sprintf(si->adi.chipset, "NV44"); status = nvxx_general_powerup(); break; + case 0x016a10de: /* Nvidia 7100 GS */ + si->ps.card_type = NV44; + si->ps.card_arch = NV40A; + sprintf(si->adi.name, "Nvidia GeForce 7100 GS"); + sprintf(si->adi.chipset, "NV44"); + status = nvxx_general_powerup(); + break; case 0x016b10de: /* Nvidia unknown FX Go */ case 0x016c10de: /* Nvidia unknown FX Go */ case 0x016d10de: /* Nvidia unknown FX Go */ Modified: haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia/driver.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia/driver.c 2007-05-09 09:48:35 UTC (rev 21083) +++ haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia/driver.c 2007-05-09 12:02:49 UTC (rev 21084) @@ -180,6 +180,7 @@ 0x0167, /* Nvidia GeForce 6200 Go */ 0x0168, /* Nvidia GeForce 6400 Go */ 0x0169, /* Nvidia GeForce 6250 Go */ + 0x016a, /* Nvidia Geforce 7100 GS */ 0x016b, /* Nvidia unknown FX Go */ 0x016c, /* Nvidia unknown FX Go */ 0x016d, /* Nvidia unknown FX Go */ From hugosantos at gmail.com Wed May 9 14:31:05 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Wed, 9 May 2007 13:31:05 +0100 Subject: [Haiku-commits] r21075 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/sys In-Reply-To: <1178702936.46419458df31a@imp.free.fr> References: <1178702936.46419458df31a@imp.free.fr> Message-ID: <9c46321e0705090531n7570958are4ff010caf48db38@mail.gmail.com> Hi Philippe, Like i mentioned in another mail to you, i looked at dpc. I couldn't use it because it doesn't fit the FreeBSD interface. First of all the creation and starting of threads with taskqueues is separate. Also, the number of threads available to the queue might be more than one. But most important, the scheduling method is specifiable, and while some will refer to the thread enqueueing method, other modules might not. The point is i need to mimic FreeBSD functionality and in this particular interface i couldn't reuse whatever was available. I did reuse the network stack timer infrastructure in the 'callout' interface for instance. Regarding modular design, take a look at the network stack, the several components are neatly separated. There are other cases too. I don't think this is something that depends on a single module. Hugo On 5/9/07, Philippe Houdoin wrote: > > Log: > > freebsd compat. layer: respect requested priority in taskqueue_start_threads. > > The fact that you've reimplemented BSD's taskqueues feature remind me that the > BSD's ACPI OS-specific implementation use it too, and that was the first time I > meet these. Our ACPI needed similar feature too. > > Under BeOS R5, a generic deferred procedure call (dpc) kernel module provides > this kind of feature to everyone, reducing memory and file footprint. BeOS USB > stack use it. BeOS BONE network stack use it. BeOS (limited) FireWire stack use > it. > > Following the same design (one of our main objective for R1), I've implemented a > similar kernel module as our ACPI was waiting for it, which give me tasks queues > and dedicated threads calling - outside interrupt context - each task queued, > needed by ACPI. It was the first component using this module. And, so far, the > only one. > > I wonder if it could not be re-used by some other components too. It will be > better, I think, making a modular kernel actually worth its name... > > The fact that your freebsd_network compatibility layer export a taskqueue API > make it a good candidate. > > Could you give a look at the very simple DPC kernel module API: > > headers/os/drivers/dpc.h > src/add-ons/kernel/generic/dpc > > If only ACPI actually use DPC module in the ends, there is no reason to make it > an external module anymore. > Which will be sad, IMHO, as BeOS kernel modular design was one major selling > point to me. Maybe I'm alone, though. > > - Philippe > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From hugosantos at gmail.com Wed May 9 14:31:50 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Wed, 9 May 2007 13:31:50 +0100 Subject: [Haiku-commits] r21079 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/sys In-Reply-To: <20070509113306.545.1@cs.tu-berlin.de> References: <200705090301.l4931GUl013413@sheep.berlios.de> <20070509113306.545.1@cs.tu-berlin.de> Message-ID: <9c46321e0705090531o6f6cd01fl3ef3a8aa3805fd12@mail.gmail.com> Thanks for the pointer Ingo. Hugo On 5/9/07, Ingo Weinhold wrote: > > On 2007-05-09 at 05:01:16 [+0200], hugosantos at mail.berlios.de wrote: > > Author: hugosantos > > Date: 2007-05-09 05:00:57 +0200 (Wed, 09 May 2007) > > New Revision: 21079 > > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21079&view=rev > > > > Added: > > haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf-fbsd.h > > haiku/trunk/src/libs/compat/freebsd_network/fbsd_busdma_x86.c > > haiku/trunk/src/libs/compat/freebsd_network/fbsd_ether.c > > haiku/trunk/src/libs/compat/freebsd_network/fbsd_if_media.c > > haiku/trunk/src/libs/compat/freebsd_network/fbsd_mbuf.c > > Removed: > > haiku/trunk/src/libs/compat/freebsd_network/busdma_machdep.c > > haiku/trunk/src/libs/compat/freebsd_network/if_media.c > > Modified: > > haiku/trunk/src/libs/compat/freebsd_network/Jamfile > > haiku/trunk/src/libs/compat/freebsd_network/compat.c > > haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h > > haiku/trunk/src/libs/compat/freebsd_network/compat/sys/types.h > > haiku/trunk/src/libs/compat/freebsd_network/if.c > > haiku/trunk/src/libs/compat/freebsd_network/mbuf.c > > Log: > > freebsd compat. layer: splited freebsd original code into own files. > > > > > > Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile > > =================================================================== > > --- haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-09 > > 01:28:02 UTC (rev 21078) > > +++ haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-09 > > 03:00:57 UTC (rev 21079) > > @@ -9,12 +9,14 @@ > > > > Library libfreebsd_network.a : > > bus.c > [...] > > BTW, it is generally recommended to use the Haiku build system specific rules > to build high-level targets instead of the standard jam rules. In this case > it would be KernelStaticLibrary, which (ATM) adds some header directories and > compiler flags. > > CU, Ingo > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From hugosantos at mail.berlios.de Wed May 9 14:57:18 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 9 May 2007 14:57:18 +0200 Subject: [Haiku-commits] r21085 - in haiku/trunk/src/add-ons/kernel/network: protocols/icmp protocols/udp stack Message-ID: <200705091257.l49CvIdw018013@sheep.berlios.de> Author: hugosantos Date: 2007-05-09 14:57:00 +0200 (Wed, 09 May 2007) New Revision: 21085 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21085&view=rev Modified: haiku/trunk/src/add-ons/kernel/network/protocols/icmp/icmp.cpp haiku/trunk/src/add-ons/kernel/network/protocols/udp/udp.cpp haiku/trunk/src/add-ons/kernel/network/stack/link.cpp haiku/trunk/src/add-ons/kernel/network/stack/net_socket.cpp Log: network stack: getsockopt/setsockopt are no longer optional for protocols, as suggested by Axel. Modified: haiku/trunk/src/add-ons/kernel/network/protocols/icmp/icmp.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/icmp/icmp.cpp 2007-05-09 12:02:49 UTC (rev 21084) +++ haiku/trunk/src/add-ons/kernel/network/protocols/icmp/icmp.cpp 2007-05-09 12:57:00 UTC (rev 21085) @@ -130,6 +130,24 @@ status_t +icmp_getsockopt(net_protocol *protocol, int level, int option, + void *value, int *length) +{ + return protocol->next->module->getsockopt(protocol->next, level, option, + value, length); +} + + +status_t +icmp_setsockopt(net_protocol *protocol, int level, int option, + const void *value, int length) +{ + return protocol->next->module->setsockopt(protocol->next, level, option, + value, length); +} + + +status_t icmp_bind(net_protocol *protocol, const struct sockaddr *address) { return B_ERROR; @@ -330,8 +348,8 @@ icmp_connect, icmp_accept, icmp_control, - NULL, // getsockopt - NULL, // setsockopt + icmp_getsockopt, + icmp_setsockopt, icmp_bind, icmp_unbind, icmp_listen, Modified: haiku/trunk/src/add-ons/kernel/network/protocols/udp/udp.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/udp/udp.cpp 2007-05-09 12:02:49 UTC (rev 21084) +++ haiku/trunk/src/add-ons/kernel/network/protocols/udp/udp.cpp 2007-05-09 12:57:00 UTC (rev 21085) @@ -1022,6 +1022,24 @@ status_t +udp_getsockopt(net_protocol *protocol, int level, int option, void *value, + int *length) +{ + return protocol->next->module->getsockopt(protocol->next, level, option, + value, length); +} + + +status_t +udp_setsockopt(net_protocol *protocol, int level, int option, + const void *value, int length) +{ + return protocol->next->module->setsockopt(protocol->next, level, option, + value, length); +} + + +status_t udp_bind(net_protocol *protocol, const struct sockaddr *address) { return ((UdpEndpoint *)protocol)->Bind(address); @@ -1218,8 +1236,8 @@ udp_connect, udp_accept, udp_control, - NULL, // getsockopt - NULL, // setsockopt + udp_getsockopt, + udp_setsockopt, udp_bind, udp_unbind, udp_listen, Modified: haiku/trunk/src/add-ons/kernel/network/stack/link.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/stack/link.cpp 2007-05-09 12:02:49 UTC (rev 21084) +++ haiku/trunk/src/add-ons/kernel/network/stack/link.cpp 2007-05-09 12:57:00 UTC (rev 21085) @@ -320,6 +320,24 @@ status_t +link_getsockopt(net_protocol *protocol, int level, int option, void *value, + int *length) +{ + return protocol->next->module->getsockopt(protocol, level, option, + value, length); +} + + +status_t +link_setsockopt(net_protocol *protocol, int level, int option, + const void *value, int length) +{ + return protocol->next->module->setsockopt(protocol, level, option, + value, length); +} + + +status_t link_bind(net_protocol *protocol, const struct sockaddr *address) { // TODO: bind to a specific interface and ethernet type @@ -467,8 +485,8 @@ link_connect, link_accept, link_control, - NULL, // getsockopt - NULL, // setsockopt + link_getsockopt, + link_setsockopt, link_bind, link_unbind, link_listen, Modified: haiku/trunk/src/add-ons/kernel/network/stack/net_socket.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/stack/net_socket.cpp 2007-05-09 12:02:49 UTC (rev 21084) +++ haiku/trunk/src/add-ons/kernel/network/stack/net_socket.cpp 2007-05-09 12:57:00 UTC (rev 21085) @@ -751,14 +751,8 @@ socket_getsockopt(net_socket *socket, int level, int option, void *value, int *_length) { - for (net_protocol *protocol = socket->first_protocol; - protocol; protocol = protocol->next) { - if (protocol->module->getsockopt) - return protocol->module->getsockopt(protocol, level, option, - value, _length); - } - - return socket_get_option(socket, level, option, value, _length); + return socket->first_protocol->module->getsockopt(socket->first_protocol, + level, option, value, _length); } @@ -1069,14 +1063,8 @@ socket_setsockopt(net_socket *socket, int level, int option, const void *value, int length) { - for (net_protocol *protocol = socket->first_protocol; - protocol; protocol = protocol->next) { - if (protocol->module->setsockopt) - return protocol->module->setsockopt(protocol, level, option, - value, length); - } - - return socket_set_option(socket, level, option, value, length); + return socket->first_protocol->module->setsockopt(socket->first_protocol, + level, option, value, length); } From nielx at mail.berlios.de Wed May 9 15:17:20 2007 From: nielx at mail.berlios.de (nielx at BerliOS) Date: Wed, 9 May 2007 15:17:20 +0200 Subject: [Haiku-commits] r21086 - haiku/trunk/src/documentation Message-ID: <200705091317.l49DHKqI021562@sheep.berlios.de> Author: nielx Date: 2007-05-09 15:17:19 +0200 (Wed, 09 May 2007) New Revision: 21086 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21086&view=rev Removed: haiku/trunk/src/documentation/xsl/ Log: Remove unnecessary Doxygen XML to BoostDoc to Docbook From hugosantos at mail.berlios.de Wed May 9 15:20:41 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 9 May 2007 15:20:41 +0200 Subject: [Haiku-commits] r21087 - in haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000: . dev dev/em Message-ID: <200705091320.l49DKfZC022103@sheep.berlios.de> Author: hugosantos Date: 2007-05-09 15:20:14 +0200 (Wed, 09 May 2007) New Revision: 21087 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21087&view=rev Added: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/LICENSE haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/README haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/glue.c haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/if_em.c haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/if_em.h haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/if_em_hw.c haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/if_em_hw.h haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/if_em_osdep.h Modified: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/Jamfile Log: added FreeBSD 6.2's Intel Pro 1000 driver to the tree (original source, unchanged). Modified: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/Jamfile 2007-05-09 13:17:19 UTC (rev 21086) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/Jamfile 2007-05-09 13:20:14 UTC (rev 21087) @@ -1,5 +1,7 @@ SubDir HAIKU_TOP src add-ons kernel drivers network ipro1000 ; +SubInclude HAIKU_TOP src add-ons kernel drivers network ipro1000 dev ; + SetSubDirSupportedPlatformsBeOSCompatible ; # set some additional flags Added: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/Jamfile 2007-05-09 13:17:19 UTC (rev 21086) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/Jamfile 2007-05-09 13:20:14 UTC (rev 21087) @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network ipro1000 dev ; + +SubInclude HAIKU_TOP src add-ons kernel drivers network ipro1000 dev em ; Added: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/Jamfile 2007-05-09 13:17:19 UTC (rev 21086) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/Jamfile 2007-05-09 13:20:14 UTC (rev 21087) @@ -0,0 +1,18 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network ipro1000 dev em ; + +SubDirCcFlags -Wall ; + +UsePrivateHeaders kernel net ; + +UseHeaders [ FDirName $(SUBDIR) .. .. ] : true ; +UseHeaders [ FDirName $(HAIKU_TOP) src libs compat freebsd_network compat ] : true ; + +SubDirCcFlags [ FDefines _KERNEL=1 FBSD_DRIVER=1 EM_FAST_INTR=1 DBG=1 ] ; + +KernelAddon e1000 : + if_em.c + if_em_hw.c + glue.c + : libfreebsd_network.a + ; + Added: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/LICENSE =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/LICENSE 2007-05-09 13:17:19 UTC (rev 21086) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/LICENSE 2007-05-09 13:20:14 UTC (rev 21087) @@ -0,0 +1,31 @@ +$FreeBSD: src/sys/dev/em/LICENSE,v 1.3.2.1 2006/08/08 09:20:26 glebius Exp $ +/*- +Copyright (c) 2001-2005, Intel Corporation +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. Neither the name of the Intel Corporation nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ Added: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/README =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/README 2007-05-09 13:17:19 UTC (rev 21086) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/README 2007-05-09 13:20:14 UTC (rev 21087) @@ -0,0 +1,373 @@ +$FreeBSD: src/sys/dev/em/README,v 1.10.2.1 2006/08/08 09:20:26 glebius Exp $ +FreeBSD* Driver for the Intel(R) PRO/1000 Family of Adapters +============================================================ + +May 2, 2006 + + +Contents +======== + +- Overview +- Identifying Your Adapter +- Building and Installation +- Speed and Duplex Configuration +- Additional Configurations +- Known Limitations +- Support +- License + + +Overview +======== + +This file describes the FreeBSD* driver for the Intel(R) PRO/1000 Family of +Adapters. This driver has been developed for use with FreeBSD, Release 6.x. + +For questions related to hardware requirements, refer to the documentation +supplied with your Intel PRO/1000 adapter. All hardware requirements listed +apply to use with FreeBSD. + + +Identifying Your Adapter +======================== + +For information on how to identify your adapter, go to the Adapter & +Driver ID Guide at: + +http://support.intel.com/support/network/sb/cs-012904.htm + + +For the latest Intel network drivers for FreeBSD, see: + +http://downloadfinder.intel.com/scripts-df-external/support_intel.aspx + + +NOTE: Mobile adapters are not fully supported. +NOTE: The Intel(R) 82562v 10/100 Network Connection only provides 10/100 +support. + +Building and Installation +========================= + +NOTE: The driver can be installed as a dynamic loadable kernel module or + compiled into the kernel. You must have kernel sources installed in + order to compile the driver module. + +In the instructions below, x.x.x is the driver version as indicated in the +name of the driver tar file. + +1. Move the base driver tar file to the directory of your choice. For + example, use /home/username/em or /usr/local/src/em. + +2. Untar/unzip the archive: + + tar xvfz em-x.x.x.tar.gz + + This will create an em-x.x.x directory. + +3. To create a loadable module, perform the following steps. + NOTE: To compile the driver into the kernel, go directly to step 4. + + a. To compile the module + + cd em-x.x.x + make + + b. To install the compiled module in system directory: + + make install + + c. If you want the driver to load automatically when the system is booted: + + 1. Edit /boot/loader.conf, and add the following line: + + if_em_load="YES" + +4. To compile the driver into the kernel: + + cd em-x.x.x/src + + cp if_em* /usr/src/sys/dev/em + + cp Makefile.kernel /usr/src/sys/modules/em/Makefile + + Edit the /usr/src/sys/conf/files file, and add the following lines only if + they don't already exist: + + dev/em/if_em.c optional em + + dev/em/if_em_hw.c optional em + + Remove the following lines from the /usr/src/sys/conf/files file, + if they exist: + + dev/em/if_em_fxhw.c optional em + dev/em/if_em_phy.c optional em + + Edit the kernel configuration file (i.e., GENERIC or MYKERNEL) in + /usr/src/sys/i386/conf, and ensure the following line is present: + + device em + + Compile and install the kernel. The system must be rebooted for the kernel + updates to take effect. For additional information on compiling the + kernel, consult the FreeBSD operating system documentation. + +5. To assign an IP address to the interface, enter the following: + + ifconfig em + +6. Verify that the interface works. Enter the following, where + is the IP address for another machine on the same subnet as the interface + that is being tested: + + ping + +7. To configure the IP address to remain after reboot, edit /etc/rc.conf, + and create the appropriate ifconfig_ementry: + + ifconfig_em="" + + Example usage: + + ifconfig_em0="inet 192.168.10.1 netmask 255.255.255.0" + + NOTE: For assistance, see the ifconfig man page. + + +Speed and Duplex Configuration +============================== + +By default, the adapter auto-negotiates the speed and duplex of the +connection. If there is a specific need, the ifconfig utility can be used to +configure the speed and duplex settings on the adapter. Example usage: + + ifconfig em media 100baseTX mediaopt + full-duplex + + NOTE: Only use mediaopt to set the driver to full-duplex. If mediaopt is + not specified and you are not running at gigabit speed, the driver + defaults to half-duplex. + + +This driver supports the following media type options: + + autoselect - Enables auto-negotiation for speed and duplex. + + 10baseT/UTP - Sets speed to 10 Mbps. Use the ifconfig mediaopt + option to select full-duplex mode. + + 100baseTX - Sets speed to 100 Mbps. Use the ifconfig mediaopt + option to select full-duplex mode. + + 1000baseTX - Sets speed to 1000 Mbps. In this case, the driver + supports only full-duplex mode. + + 1000baseSX - Sets speed to 1000 Mbps. In this case, the driver + supports only full-duplex mode. + +For more information on the ifconfig utility, see the ifconfig man page. + + +Additional Configurations +========================= + +The driver supports Transmit/Receive Checksum Offload and Jumbo Frames on +all but the 82542-based adapters. For specific adapters, refer to the +Identifying Your Adapter section. + + Jumbo Frames + ------------ + To enable Jumbo Frames, use the ifconfig utility to set the Maximum + Transport Unit (MTU) frame size above its default of 1500 bytes. + + The Jumbo Frames MTU range for Intel Adapters is 1500 to 16110. To modify + the setting, enter the following: + + ifconfig em mtu 9000 + + To confirm the MTU used between two specific devices, use: + + route get + + Notes: + + - Only enable Jumbo Frames if your network infrastructure supports them. + + - To enable Jumbo Frames, increase the MTU size on the interface beyond + 1500. + + - The Jumbo Frames setting on the switch must be set to at least 22 bytes + larger than that of the MTU. + + - The maximum MTU setting for Jumbo Frames is 16110. This value coincides + with the maximum Jumbo Frames size of 16128. + + - Some Intel gigabit adapters that support Jumbo Frames have a frame size + limit of 9238 bytes, with a corresponding MTU size limit of 9216 bytes. + The adapters with this limitation are based on the Intel(R) 82571EB, + 82572EI, 82573L and 80003ES2LAN controller. These correspond to the + following product names: + Intel(R) PRO/1000 PT Server Adapter + Intel(R) PRO/1000 PT Desktop Adapter + Intel(R) PRO/1000 PT Network Connection + Intel(R) PRO/1000 PT Dual Port Server Adapter + Intel(R) PRO/1000 PT Dual Port Network Connection + Intel(R) PRO/1000 PF Server Adapter + Intel(R) PRO/1000 PF Network Connection + Intel(R) PRO/1000 PF Dual Port Server Adapter + Intel(R) PRO/1000 PB Server Connection + Intel(R) PRO/1000 PL Network Connection + Intel(R) PRO/1000 EB Network Connection with I/O Acceleration + Intel(R) PRO/1000 EB Backplane Connection with I/O Acceleration + + - Adapters based on the Intel(R) 82542 and 82573V/E controller do not + support Jumbo Frames. These correspond to the following product names: + Intel(R) PRO/1000 Gigabit Server Adapter + Intel(R) PRO/1000 PM Network Connection + + - Using Jumbo Frames at 10 or 100 Mbps may result in poor performance or + loss of link. + + - The following adapters do not support Jumbo Frames: + Intel(R) 82562V 10/100 Network Connection + Intel(R) 82566DM Gigabit Network Connection + Intel(R) 82566DC Gigabit Network Connection + Intel(R) 82566MM Gigabit Network Connection + Intel(R) 82566MC Gigabit Network Connection + + + VLANs + ----- + To create a new VLAN interface: + + ifconfig create + + To associate the VLAN interface with a physical interface and + assign a VLAN ID, IP address, and netmask: + + ifconfig netmask vlan + vlandev + + Example: + + ifconfig vlan10 10.0.0.1 netmask 255.255.255.0 vlan10 vlandev em0 + + In this example, all packets will be marked on egress with 802.1Q VLAN + tags, specifying a VLAN ID of 10. + + To remove a VLAN interface: + + ifconfig destroy + + + Polling + ------- + To enable polling in the driver, add the following options to the kernel + configuration, and then recompile the kernel: + + options DEVICE_POLLING + options HZ=1000 + + At runtime use: + ifconfig em0 polling to turn polling on + Use: + ifconfig em0 -polling to turn polling off + + + Checksum Offload + ---------------- + Checksum offloading is not supported on 82542 Gigabit adapters. + + Checksum offloading supports both TCP and UDP packets and is + supported for both transmit and receive. + + Checksum offloading can be enabled or disabled using ifconfig. + Both transmit and receive offloading will be either enabled or + disabled together. You cannot enable/disable one without the other. + + To enable checksum offloading: + + ifconfig rxcsum + + To disable checksum offloading: + + ifconfig -rxcsum + + To confirm the current setting: + + ifconfig + + Look for the presence or absence of the following line: + + options=3 + + See the ifconfig man page for further information. + + +Known Limitations +================= + + In FreeBSD version 4.x with Symmetric MultiProcessing (SMP), there is a known + issue on some newer hardware. The problem is generic kernel and only in SMP + mode. The workaround is to either use FreeBSD version 4.x in single processor + mode, or use FreeBSD 5.4 or later. + + There are known performance issues with this driver when running UDP traffic + with Jumbo Frames. + + There is a known compatibility issue where time to link is slow or link is not + established between 82541/82547 controllers and some switches. Known switches + include: + Planex FXG-08TE + I-O Data ETG-SH8 + + The driver can be compiled with the following changes: + + Edit ./em.x.x.x/src/if_em.h to uncomment the #define EM_MASTER_SLAVE + from within the comments. For example, change from: + + /* #define EM_MASTER_SLAVE 2 */ + to: + #define EM_MASTER_SLAVE 2 + + Use one of the following options: + 1 = Master mode + 2 = Slave mode + 3 = Auto master/slave + Setting 2 is recommended. + + Recompile the module: + a. To compile the module + cd em-x.x.x + make clean + make + + b. To install the compiled module in system directory: + make install + + +Support +======= + +For general information and support, go to the Intel support website at: + + http://support.intel.com + +If an issue is identified, support is through email only at: +freebsdnic at mailbox.intel.com + + +License +======= + +This software program is released under the terms of a license agreement +between you ('Licensee') and Intel. Do not use or load this software or any +associated materials (collectively, the 'Software') until you have carefully +read the full terms and conditions of the LICENSE located in this software +package. By loading or using the Software, you agree to the terms of this +Agreement. If you do not agree with the terms of this Agreement, do not +install or use the Software. + +* Other names and brands may be claimed as the property of others. Added: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/glue.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/glue.c 2007-05-09 13:17:19 UTC (rev 21086) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/glue.c 2007-05-09 13:20:14 UTC (rev 21087) @@ -0,0 +1,11 @@ +#include + +HAIKU_FBSD_DRIVER_GLUE(e1000, em, pci) + +NO_HAIKU_CHECK_DISABLE_INTERRUPTS() + +#ifdef EM_FAST_INTR + HAIKU_DRIVER_REQUIREMENTS(FBSD_TASKQUEUES | FBSD_FAST_TASKQUEUE); +#else + HAIKU_DRIVER_REQUIREMENTS(0); +#endif Added: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/if_em.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/if_em.c 2007-05-09 13:17:19 UTC (rev 21086) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/if_em.c 2007-05-09 13:20:14 UTC (rev 21087) @@ -0,0 +1,4167 @@ +/************************************************************************** + +Copyright (c) 2001-2006, Intel Corporation +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. Neither the name of the Intel Corporation nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +***************************************************************************/ + +/*$FreeBSD: src/sys/dev/em/if_em.c,v 1.65.2.21 2006/11/10 09:30:27 jfv Exp $*/ + +#ifdef HAVE_KERNEL_OPTION_HEADERS +#include "opt_device_polling.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +/********************************************************************* + * Set this to one to display debug statistics + *********************************************************************/ +int em_display_debug_stats = 0; + +/********************************************************************* + * Driver version + *********************************************************************/ +char em_driver_version[] = "Version - 6.2.9"; + + +/********************************************************************* + * PCI Device ID Table + * + * Used by probe to select devices to load on + * Last field stores an index into em_strings + * Last entry must be all 0s + * + * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index } + *********************************************************************/ + +static em_vendor_info_t em_vendor_info_array[] = +{ + /* Intel(R) PRO/1000 Network Connection */ + { 0x8086, E1000_DEV_ID_82540EM, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82540EM_LOM, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82540EP, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82540EP_LOM, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82540EP_LP, PCI_ANY_ID, PCI_ANY_ID, 0}, + + { 0x8086, E1000_DEV_ID_82541EI, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82541ER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82541ER_LOM, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82541EI_MOBILE, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82541GI, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82541GI_LF, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82541GI_MOBILE, PCI_ANY_ID, PCI_ANY_ID, 0}, + + { 0x8086, E1000_DEV_ID_82542, PCI_ANY_ID, PCI_ANY_ID, 0}, + + { 0x8086, E1000_DEV_ID_82543GC_FIBER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82543GC_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0}, + + { 0x8086, E1000_DEV_ID_82544EI_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82544EI_FIBER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82544GC_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82544GC_LOM, PCI_ANY_ID, PCI_ANY_ID, 0}, + + { 0x8086, E1000_DEV_ID_82545EM_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82545EM_FIBER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82545GM_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82545GM_FIBER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82545GM_SERDES, PCI_ANY_ID, PCI_ANY_ID, 0}, + + { 0x8086, E1000_DEV_ID_82546EB_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82546EB_FIBER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82546EB_QUAD_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82546GB_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82546GB_FIBER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82546GB_SERDES, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82546GB_PCIE, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82546GB_QUAD_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3, + PCI_ANY_ID, PCI_ANY_ID, 0}, + + { 0x8086, E1000_DEV_ID_82547EI, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82547EI_MOBILE, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82547GI, PCI_ANY_ID, PCI_ANY_ID, 0}, + + { 0x8086, E1000_DEV_ID_82571EB_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82571EB_FIBER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82571EB_SERDES, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82571EB_QUAD_COPPER, + PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE, + PCI_ANY_ID, PCI_ANY_ID, 0}, + + { 0x8086, E1000_DEV_ID_82572EI_COPPER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82572EI_FIBER, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82572EI_SERDES, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82572EI, PCI_ANY_ID, PCI_ANY_ID, 0}, + + { 0x8086, E1000_DEV_ID_82573E, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82573E_IAMT, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_82573L, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_80003ES2LAN_COPPER_SPT, + PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_80003ES2LAN_SERDES_SPT, + PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_80003ES2LAN_COPPER_DPT, + PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_80003ES2LAN_SERDES_DPT, + PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_ICH8_IGP_M_AMT, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_ICH8_IGP_AMT, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_ICH8_IGP_C, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_ICH8_IFE, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_ICH8_IFE_GT, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_ICH8_IFE_G, PCI_ANY_ID, PCI_ANY_ID, 0}, + { 0x8086, E1000_DEV_ID_ICH8_IGP_M, PCI_ANY_ID, PCI_ANY_ID, 0}, + + /* required last entry */ + { 0, 0, 0, 0, 0} +}; + +/********************************************************************* + * Table of branding strings for all supported NICs. + *********************************************************************/ + +static char *em_strings[] = { + "Intel(R) PRO/1000 Network Connection" +}; + +/********************************************************************* + * Function prototypes + *********************************************************************/ +static int em_probe(device_t); +static int em_attach(device_t); +static int em_detach(device_t); +static int em_shutdown(device_t); +static int em_suspend(device_t); +static int em_resume(device_t); +static void em_start(struct ifnet *); +static void em_start_locked(struct ifnet *ifp); +static int em_ioctl(struct ifnet *, u_long, caddr_t); +static void em_watchdog(struct adapter *); +static void em_init(void *); +static void em_init_locked(struct adapter *); +static void em_stop(void *); +static void em_media_status(struct ifnet *, struct ifmediareq *); +static int em_media_change(struct ifnet *); +static void em_identify_hardware(struct adapter *); +static int em_allocate_pci_resources(struct adapter *); +static int em_allocate_intr(struct adapter *); +static void em_free_intr(struct adapter *); +static void em_free_pci_resources(struct adapter *); +static void em_local_timer(void *); +static int em_hardware_init(struct adapter *); +static void em_setup_interface(device_t, struct adapter *); +static void em_setup_transmit_structures(struct adapter *); +static void em_initialize_transmit_unit(struct adapter *); +static int em_setup_receive_structures(struct adapter *); +static void em_initialize_receive_unit(struct adapter *); +static void em_enable_intr(struct adapter *); +static void em_disable_intr(struct adapter *); +static void em_free_transmit_structures(struct adapter *); +static void em_free_receive_structures(struct adapter *); +static void em_update_stats_counters(struct adapter *); +static void em_txeof(struct adapter *); +static int em_allocate_receive_structures(struct adapter *); +static int em_allocate_transmit_structures(struct adapter *); +static int em_rxeof(struct adapter *, int); +#ifndef __NO_STRICT_ALIGNMENT +static int em_fixup_rx(struct adapter *); +#endif +static void em_receive_checksum(struct adapter *, struct em_rx_desc *, + struct mbuf *); +static void em_transmit_checksum_setup(struct adapter *, struct mbuf *, + uint32_t *, uint32_t *); +#ifdef EM_TSO +static boolean_t em_tso_setup(struct adapter *, struct mbuf *, u_int32_t *, + uint32_t *); +#endif +static void em_set_promisc(struct adapter *); +static void em_disable_promisc(struct adapter *); +static void em_set_multi(struct adapter *); +static void em_print_hw_stats(struct adapter *); +static void em_update_link_status(struct adapter *); +static int em_get_buf(int i, struct adapter *, struct mbuf *); +static void em_enable_vlans(struct adapter *); +static void em_disable_vlans(struct adapter *); +static int em_encap(struct adapter *, struct mbuf **); +static void em_smartspeed(struct adapter *); +static int em_82547_fifo_workaround(struct adapter *, int); +static void em_82547_update_fifo_head(struct adapter *, int); +static int em_82547_tx_fifo_reset(struct adapter *); +static void em_82547_move_tail(void *); +static int em_dma_malloc(struct adapter *, bus_size_t, + struct em_dma_alloc *, int); +static void em_dma_free(struct adapter *, struct em_dma_alloc *); +static void em_print_debug_info(struct adapter *); +static int em_is_valid_ether_addr(uint8_t *); +static int em_sysctl_stats(SYSCTL_HANDLER_ARGS); +static int em_sysctl_debug_info(SYSCTL_HANDLER_ARGS); +static uint32_t em_fill_descriptors (bus_addr_t address, uint32_t length, + PDESC_ARRAY desc_array); +static int em_sysctl_int_delay(SYSCTL_HANDLER_ARGS); +static void em_add_int_delay_sysctl(struct adapter *, const char *, + const char *, struct em_int_delay_info *, int, int); +static void em_add_rx_process_limit(struct adapter *, const char *, + const char *, int *, int); +#ifdef EM_FAST_INTR +static void em_intr_fast(void *); +static void em_handle_rxtx(void *context, int pending); +static void em_handle_link(void *context, int pending); +#else /* Legacy Interrupt Handling */ +static void em_intr(void *); +#ifdef DEVICE_POLLING +static poll_handler_t em_poll; +#endif /* DEVICE_POLLING */ +#endif /* EM_FAST_INTR */ + +/********************************************************************* + * FreeBSD Device Interface Entry Points + *********************************************************************/ + +static device_method_t em_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, em_probe), + DEVMETHOD(device_attach, em_attach), + DEVMETHOD(device_detach, em_detach), + DEVMETHOD(device_shutdown, em_shutdown), + DEVMETHOD(device_suspend, em_suspend), + DEVMETHOD(device_resume, em_resume), + {0, 0} +}; + +static driver_t em_driver = { + "em", em_methods, sizeof(struct adapter), +}; + +static devclass_t em_devclass; +DRIVER_MODULE(em, pci, em_driver, em_devclass, 0, 0); +MODULE_DEPEND(em, pci, 1, 1, 1); +MODULE_DEPEND(em, ether, 1, 1, 1); + +/********************************************************************* + * Tunable default values. + *********************************************************************/ + +#define E1000_TICKS_TO_USECS(ticks) ((1024 * (ticks) + 500) / 1000) +#define E1000_USECS_TO_TICKS(usecs) ((1000 * (usecs) + 512) / 1024) +#define M_TSO_LEN 66 /* mbuf with just hdr and TSO pkthdr */ + +static int em_tx_int_delay_dflt = E1000_TICKS_TO_USECS(EM_TIDV); +static int em_rx_int_delay_dflt = E1000_TICKS_TO_USECS(EM_RDTR); +static int em_tx_abs_int_delay_dflt = E1000_TICKS_TO_USECS(EM_TADV); +static int em_rx_abs_int_delay_dflt = E1000_TICKS_TO_USECS(EM_RADV); +static int em_rxd = EM_DEFAULT_RXD; +static int em_txd = EM_DEFAULT_TXD; +static int em_smart_pwr_down = FALSE; + +TUNABLE_INT("hw.em.tx_int_delay", &em_tx_int_delay_dflt); +TUNABLE_INT("hw.em.rx_int_delay", &em_rx_int_delay_dflt); +TUNABLE_INT("hw.em.tx_abs_int_delay", &em_tx_abs_int_delay_dflt); +TUNABLE_INT("hw.em.rx_abs_int_delay", &em_rx_abs_int_delay_dflt); +TUNABLE_INT("hw.em.rxd", &em_rxd); +TUNABLE_INT("hw.em.txd", &em_txd); +TUNABLE_INT("hw.em.smart_pwr_down", &em_smart_pwr_down); + +/* How many packets rxeof tries to clean at a time */ +static int em_rx_process_limit = 100; +TUNABLE_INT("hw.em.rx_process_limit", &em_rx_process_limit); + +/********************************************************************* + * Device identification routine + * + * em_probe determines if the driver should be loaded on + * adapter based on PCI vendor/device id of the adapter. + * + * return BUS_PROBE_DEFAULT on success, positive on failure + *********************************************************************/ + +static int +em_probe(device_t dev) +{ + char adapter_name[60]; + uint16_t pci_vendor_id = 0; + uint16_t pci_device_id = 0; + uint16_t pci_subvendor_id = 0; + uint16_t pci_subdevice_id = 0; + em_vendor_info_t *ent; + + INIT_DEBUGOUT("em_probe: begin"); + + pci_vendor_id = pci_get_vendor(dev); + if (pci_vendor_id != EM_VENDOR_ID) + return (ENXIO); + + pci_device_id = pci_get_device(dev); + pci_subvendor_id = pci_get_subvendor(dev); + pci_subdevice_id = pci_get_subdevice(dev); + + ent = em_vendor_info_array; + while (ent->vendor_id != 0) { + if ((pci_vendor_id == ent->vendor_id) && + (pci_device_id == ent->device_id) && + + ((pci_subvendor_id == ent->subvendor_id) || + (ent->subvendor_id == PCI_ANY_ID)) && + + ((pci_subdevice_id == ent->subdevice_id) || + (ent->subdevice_id == PCI_ANY_ID))) { + sprintf(adapter_name, "%s %s", + em_strings[ent->index], + em_driver_version); + device_set_desc_copy(dev, adapter_name); + return (BUS_PROBE_DEFAULT); + } + ent++; + } + + return (ENXIO); +} + +/********************************************************************* + * Device initialization routine + * + * The attach entry point is called when the driver is being loaded. + * This routine identifies the type of hardware, allocates all resources + * and initializes the hardware. + * + * return 0 on success, positive on failure + *********************************************************************/ + +static int +em_attach(device_t dev) +{ + struct adapter *adapter; + int tsize, rsize; + int error = 0; + + INIT_DEBUGOUT("em_attach: begin"); + + adapter = device_get_softc(dev); + adapter->dev = adapter->osdep.dev = dev; + EM_LOCK_INIT(adapter, device_get_nameunit(dev)); + + /* SYSCTL stuff */ + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "debug_info", CTLTYPE_INT|CTLFLAG_RW, adapter, 0, + em_sysctl_debug_info, "I", "Debug Information"); + + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "stats", CTLTYPE_INT|CTLFLAG_RW, adapter, 0, + em_sysctl_stats, "I", "Statistics"); + + callout_init_mtx(&adapter->timer, &adapter->mtx, 0); + callout_init_mtx(&adapter->tx_fifo_timer, &adapter->mtx, 0); + + /* Determine hardware revision */ + em_identify_hardware(adapter); + + /* Set up some sysctls for the tunable interrupt delays */ + em_add_int_delay_sysctl(adapter, "rx_int_delay", + "receive interrupt delay in usecs", &adapter->rx_int_delay, + E1000_REG_OFFSET(&adapter->hw, RDTR), em_rx_int_delay_dflt); + em_add_int_delay_sysctl(adapter, "tx_int_delay", + "transmit interrupt delay in usecs", &adapter->tx_int_delay, + E1000_REG_OFFSET(&adapter->hw, TIDV), em_tx_int_delay_dflt); + if (adapter->hw.mac_type >= em_82540) { + em_add_int_delay_sysctl(adapter, "rx_abs_int_delay", + "receive interrupt delay limit in usecs", + &adapter->rx_abs_int_delay, + E1000_REG_OFFSET(&adapter->hw, RADV), + em_rx_abs_int_delay_dflt); + em_add_int_delay_sysctl(adapter, "tx_abs_int_delay", + "transmit interrupt delay limit in usecs", + &adapter->tx_abs_int_delay, + E1000_REG_OFFSET(&adapter->hw, TADV), + em_tx_abs_int_delay_dflt); + } + + /* Sysctls for limiting the amount of work done in the taskqueue */ + em_add_rx_process_limit(adapter, "rx_processing_limit", + "max number of rx packets to process", &adapter->rx_process_limit, + em_rx_process_limit); + + /* + * Validate number of transmit and receive descriptors. It + * must not exceed hardware maximum, and must be multiple + * of EM_DBA_ALIGN. + */ + if (((em_txd * sizeof(struct em_tx_desc)) % EM_DBA_ALIGN) != 0 || + (adapter->hw.mac_type >= em_82544 && em_txd > EM_MAX_TXD) || + (adapter->hw.mac_type < em_82544 && em_txd > EM_MAX_TXD_82543) || + (em_txd < EM_MIN_TXD)) { + device_printf(dev, "Using %d TX descriptors instead of %d!\n", + EM_DEFAULT_TXD, em_txd); + adapter->num_tx_desc = EM_DEFAULT_TXD; + } else + adapter->num_tx_desc = em_txd; + if (((em_rxd * sizeof(struct em_rx_desc)) % EM_DBA_ALIGN) != 0 || + (adapter->hw.mac_type >= em_82544 && em_rxd > EM_MAX_RXD) || + (adapter->hw.mac_type < em_82544 && em_rxd > EM_MAX_RXD_82543) || + (em_rxd < EM_MIN_RXD)) { + device_printf(dev, "Using %d RX descriptors instead of %d!\n", + EM_DEFAULT_RXD, em_rxd); + adapter->num_rx_desc = EM_DEFAULT_RXD; + } else + adapter->num_rx_desc = em_rxd; + + adapter->hw.autoneg = DO_AUTO_NEG; + adapter->hw.wait_autoneg_complete = WAIT_FOR_AUTO_NEG_DEFAULT; + adapter->hw.autoneg_advertised = AUTONEG_ADV_DEFAULT; + adapter->hw.tbi_compatibility_en = TRUE; + adapter->rx_buffer_len = EM_RXBUFFER_2048; + + adapter->hw.phy_init_script = 1; + adapter->hw.phy_reset_disable = FALSE; + +#ifndef EM_MASTER_SLAVE + adapter->hw.master_slave = em_ms_hw_default; +#else + adapter->hw.master_slave = EM_MASTER_SLAVE; +#endif + /* + * Set the max frame size assuming standard ethernet + * sized frames. + */ + adapter->hw.max_frame_size = + ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN; + + adapter->hw.min_frame_size = + MINIMUM_ETHERNET_PACKET_SIZE + ETHER_CRC_LEN; + + /* + * This controls when hardware reports transmit completion + * status. + */ + adapter->hw.report_tx_early = 1; + if (em_allocate_pci_resources(adapter)) { + device_printf(dev, "Allocation of PCI resources failed\n"); + error = ENXIO; + goto err_pci; + } + + /* Initialize eeprom parameters */ + em_init_eeprom_params(&adapter->hw); + + tsize = roundup2(adapter->num_tx_desc * sizeof(struct em_tx_desc), + EM_DBA_ALIGN); + [... truncated: 16812 lines follow ...] From hugosantos at mail.berlios.de Wed May 9 15:20:57 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 9 May 2007 15:20:57 +0200 Subject: [Haiku-commits] r21088 - in haiku/trunk/src/add-ons/kernel/drivers/network: . 3com 3com/pci Message-ID: <200705091320.l49DKvVG022145@sheep.berlios.de> Author: hugosantos Date: 2007-05-09 15:20:41 +0200 (Wed, 09 May 2007) New Revision: 21088 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21088&view=rev Added: haiku/trunk/src/add-ons/kernel/drivers/network/3com/ haiku/trunk/src/add-ons/kernel/drivers/network/3com/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/ haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/glue.c haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/if_xl.c haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/if_xlreg.h Modified: haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile Log: added FreeBSD 6.2's 3Com 3c90x Etherlink XL PCI driver. The compat. layer still needs a couple things for this one to work. Added: haiku/trunk/src/add-ons/kernel/drivers/network/3com/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/3com/Jamfile 2007-05-09 13:20:14 UTC (rev 21087) +++ haiku/trunk/src/add-ons/kernel/drivers/network/3com/Jamfile 2007-05-09 13:20:41 UTC (rev 21088) @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network 3com ; + +SubInclude HAIKU_TOP src add-ons kernel drivers network 3com pci ; Added: haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/Jamfile 2007-05-09 13:20:14 UTC (rev 21087) +++ haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/Jamfile 2007-05-09 13:20:41 UTC (rev 21088) @@ -0,0 +1,17 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network 3com pci ; + +SubDirCcFlags -Wall ; + +UsePrivateHeaders kernel net ; + +UseHeaders [ FDirName $(SUBDIR) .. ] : true ; +UseHeaders [ FDirName $(HAIKU_TOP) src libs compat freebsd_network compat ] : true ; + +SubDirCcFlags [ FDefines _KERNEL=1 FBSD_DRIVER=1 ] ; + +KernelAddon 3com : + if_xl.c + glue.c + : libfreebsd_network.a + ; + Added: haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/glue.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/glue.c 2007-05-09 13:20:14 UTC (rev 21087) +++ haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/glue.c 2007-05-09 13:20:41 UTC (rev 21088) @@ -0,0 +1,7 @@ +#include + +HAIKU_FBSD_DRIVER_GLUE(3com, xl, pci) + +NO_HAIKU_CHECK_DISABLE_INTERRUPTS() + +HAIKU_DRIVER_REQUIREMENTS(FBSD_TASKQUEUES); Added: haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/if_xl.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/if_xl.c 2007-05-09 13:20:14 UTC (rev 21087) +++ haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/if_xl.c 2007-05-09 13:20:41 UTC (rev 21088) @@ -0,0 +1,3386 @@ +/*- + * Copyright (c) 1997, 1998, 1999 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/sys/pci/if_xl.c,v 1.190.2.10 2006/08/17 00:13:07 yongari Exp $"); + +/* + * 3Com 3c90x Etherlink XL PCI NIC driver + * + * Supports the 3Com "boomerang", "cyclone" and "hurricane" PCI + * bus-master chips (3c90x cards and embedded controllers) including + * the following: + * + * 3Com 3c900-TPO 10Mbps/RJ-45 + * 3Com 3c900-COMBO 10Mbps/RJ-45,AUI,BNC + * 3Com 3c905-TX 10/100Mbps/RJ-45 + * 3Com 3c905-T4 10/100Mbps/RJ-45 + * 3Com 3c900B-TPO 10Mbps/RJ-45 + * 3Com 3c900B-COMBO 10Mbps/RJ-45,AUI,BNC + * 3Com 3c900B-TPC 10Mbps/RJ-45,BNC + * 3Com 3c900B-FL 10Mbps/Fiber-optic + * 3Com 3c905B-COMBO 10/100Mbps/RJ-45,AUI,BNC + * 3Com 3c905B-TX 10/100Mbps/RJ-45 + * 3Com 3c905B-FL/FX 10/100Mbps/Fiber-optic + * 3Com 3c905C-TX 10/100Mbps/RJ-45 (Tornado ASIC) + * 3Com 3c980-TX 10/100Mbps server adapter (Hurricane ASIC) + * 3Com 3c980C-TX 10/100Mbps server adapter (Tornado ASIC) + * 3Com 3cSOHO100-TX 10/100Mbps/RJ-45 (Hurricane ASIC) + * 3Com 3c450-TX 10/100Mbps/RJ-45 (Tornado ASIC) + * 3Com 3c555 10/100Mbps/RJ-45 (MiniPCI, Laptop Hurricane) + * 3Com 3c556 10/100Mbps/RJ-45 (MiniPCI, Hurricane ASIC) + * 3Com 3c556B 10/100Mbps/RJ-45 (MiniPCI, Hurricane ASIC) + * 3Com 3c575TX 10/100Mbps/RJ-45 (Cardbus, Hurricane ASIC) + * 3Com 3c575B 10/100Mbps/RJ-45 (Cardbus, Hurricane ASIC) + * 3Com 3c575C 10/100Mbps/RJ-45 (Cardbus, Hurricane ASIC) + * 3Com 3cxfem656 10/100Mbps/RJ-45 (Cardbus, Hurricane ASIC) + * 3Com 3cxfem656b 10/100Mbps/RJ-45 (Cardbus, Hurricane ASIC) + * 3Com 3cxfem656c 10/100Mbps/RJ-45 (Cardbus, Tornado ASIC) + * Dell Optiplex GX1 on-board 3c918 10/100Mbps/RJ-45 + * Dell on-board 3c920 10/100Mbps/RJ-45 + * Dell Precision on-board 3c905B 10/100Mbps/RJ-45 + * Dell Latitude laptop docking station embedded 3c905-TX + * + * Written by Bill Paul + * Electrical Engineering Department + * Columbia University, New York City + */ +/* + * The 3c90x series chips use a bus-master DMA interface for transfering + * packets to and from the controller chip. Some of the "vortex" cards + * (3c59x) also supported a bus master mode, however for those chips + * you could only DMA packets to/from a contiguous memory buffer. For + * transmission this would mean copying the contents of the queued mbuf + * chain into an mbuf cluster and then DMAing the cluster. This extra + * copy would sort of defeat the purpose of the bus master support for + * any packet that doesn't fit into a single mbuf. + * + * By contrast, the 3c90x cards support a fragment-based bus master + * mode where mbuf chains can be encapsulated using TX descriptors. + * This is similar to other PCI chips such as the Texas Instruments + * ThunderLAN and the Intel 82557/82558. + * + * The "vortex" driver (if_vx.c) happens to work for the "boomerang" + * bus master chips because they maintain the old PIO interface for + * backwards compatibility, but starting with the 3c905B and the + * "cyclone" chips, the compatibility interface has been dropped. + * Since using bus master DMA is a big win, we use this driver to + * support the PCI "boomerang" chips even though they work with the + * "vortex" driver in order to obtain better performance. + * + * This driver is in the /sys/pci directory because it only supports + * PCI-based NICs. + */ + +#ifdef HAVE_KERNEL_OPTION_HEADERS +#include "opt_device_polling.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include + +MODULE_DEPEND(xl, pci, 1, 1, 1); +MODULE_DEPEND(xl, ether, 1, 1, 1); +MODULE_DEPEND(xl, miibus, 1, 1, 1); + +/* "device miibus" required. See GENERIC if you get errors here. */ +#include "miibus_if.h" + +#include + +/* + * TX Checksumming is disabled by default for two reasons: + * - TX Checksumming will occasionally produce corrupt packets + * - TX Checksumming seems to reduce performance + * + * Only 905B/C cards were reported to have this problem, it is possible + * that later chips _may_ be immune. + */ +#define XL905B_TXCSUM_BROKEN 1 + +#ifdef XL905B_TXCSUM_BROKEN +#define XL905B_CSUM_FEATURES 0 +#else +#define XL905B_CSUM_FEATURES (CSUM_IP | CSUM_TCP | CSUM_UDP) +#endif + +/* + * Various supported device vendors/types and their names. + */ +static struct xl_type xl_devs[] = { + { TC_VENDORID, TC_DEVICEID_BOOMERANG_10BT, + "3Com 3c900-TPO Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_BOOMERANG_10BT_COMBO, + "3Com 3c900-COMBO Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_BOOMERANG_10_100BT, + "3Com 3c905-TX Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_BOOMERANG_100BT4, + "3Com 3c905-T4 Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_KRAKATOA_10BT, + "3Com 3c900B-TPO Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_KRAKATOA_10BT_COMBO, + "3Com 3c900B-COMBO Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_KRAKATOA_10BT_TPC, + "3Com 3c900B-TPC Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_CYCLONE_10FL, + "3Com 3c900B-FL Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_HURRICANE_10_100BT, + "3Com 3c905B-TX Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_CYCLONE_10_100BT4, + "3Com 3c905B-T4 Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_CYCLONE_10_100FX, + "3Com 3c905B-FX/SC Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_CYCLONE_10_100_COMBO, + "3Com 3c905B-COMBO Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_TORNADO_10_100BT, + "3Com 3c905C-TX Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_TORNADO_10_100BT_920B, + "3Com 3c920B-EMB Integrated Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_TORNADO_10_100BT_920B_WNM, + "3Com 3c920B-EMB-WNM Integrated Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_HURRICANE_10_100BT_SERV, + "3Com 3c980 Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_TORNADO_10_100BT_SERV, + "3Com 3c980C Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_HURRICANE_SOHO100TX, + "3Com 3cSOHO100-TX OfficeConnect" }, + { TC_VENDORID, TC_DEVICEID_TORNADO_HOMECONNECT, + "3Com 3c450-TX HomeConnect" }, + { TC_VENDORID, TC_DEVICEID_HURRICANE_555, + "3Com 3c555 Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_HURRICANE_556, + "3Com 3c556 Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_HURRICANE_556B, + "3Com 3c556B Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_HURRICANE_575A, + "3Com 3c575TX Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_HURRICANE_575B, + "3Com 3c575B Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_HURRICANE_575C, + "3Com 3c575C Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_HURRICANE_656, + "3Com 3c656 Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_HURRICANE_656B, + "3Com 3c656B Fast Etherlink XL" }, + { TC_VENDORID, TC_DEVICEID_TORNADO_656C, + "3Com 3c656C Fast Etherlink XL" }, + { 0, 0, NULL } +}; + +static int xl_probe(device_t); +static int xl_attach(device_t); +static int xl_detach(device_t); + +static int xl_newbuf(struct xl_softc *, struct xl_chain_onefrag *); +static void xl_stats_update(void *); +static void xl_stats_update_locked(struct xl_softc *); +static int xl_encap(struct xl_softc *, struct xl_chain *, struct mbuf *); +static void xl_rxeof(struct xl_softc *); +static void xl_rxeof_task(void *, int); +static int xl_rx_resync(struct xl_softc *); +static void xl_txeof(struct xl_softc *); +static void xl_txeof_90xB(struct xl_softc *); +static void xl_txeoc(struct xl_softc *); +static void xl_intr(void *); +static void xl_start(struct ifnet *); +static void xl_start_locked(struct ifnet *); +static void xl_start_90xB_locked(struct ifnet *); +static int xl_ioctl(struct ifnet *, u_long, caddr_t); +static void xl_init(void *); +static void xl_init_locked(struct xl_softc *); +static void xl_stop(struct xl_softc *); +static void xl_watchdog(struct ifnet *); +static void xl_shutdown(device_t); +static int xl_suspend(device_t); +static int xl_resume(device_t); + +#ifdef DEVICE_POLLING +static void xl_poll(struct ifnet *ifp, enum poll_cmd cmd, int count); +static void xl_poll_locked(struct ifnet *ifp, enum poll_cmd cmd, int count); +#endif + +static int xl_ifmedia_upd(struct ifnet *); +static void xl_ifmedia_sts(struct ifnet *, struct ifmediareq *); + +static int xl_eeprom_wait(struct xl_softc *); +static int xl_read_eeprom(struct xl_softc *, caddr_t, int, int, int); +static void xl_mii_sync(struct xl_softc *); +static void xl_mii_send(struct xl_softc *, u_int32_t, int); +static int xl_mii_readreg(struct xl_softc *, struct xl_mii_frame *); +static int xl_mii_writereg(struct xl_softc *, struct xl_mii_frame *); + +static void xl_setcfg(struct xl_softc *); +static void xl_setmode(struct xl_softc *, int); +static void xl_setmulti(struct xl_softc *); +static void xl_setmulti_hash(struct xl_softc *); +static void xl_reset(struct xl_softc *); +static int xl_list_rx_init(struct xl_softc *); +static int xl_list_tx_init(struct xl_softc *); +static int xl_list_tx_init_90xB(struct xl_softc *); +static void xl_wait(struct xl_softc *); +static void xl_mediacheck(struct xl_softc *); +static void xl_choose_media(struct xl_softc *sc, int *media); +static void xl_choose_xcvr(struct xl_softc *, int); +static void xl_dma_map_addr(void *, bus_dma_segment_t *, int, int); +static void xl_dma_map_rxbuf(void *, bus_dma_segment_t *, int, bus_size_t, int); +static void xl_dma_map_txbuf(void *, bus_dma_segment_t *, int, bus_size_t, int); +#ifdef notdef +static void xl_testpacket(struct xl_softc *); +#endif + +static int xl_miibus_readreg(device_t, int, int); +static int xl_miibus_writereg(device_t, int, int, int); +static void xl_miibus_statchg(device_t); +static void xl_miibus_mediainit(device_t); + +static device_method_t xl_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, xl_probe), + DEVMETHOD(device_attach, xl_attach), + DEVMETHOD(device_detach, xl_detach), + DEVMETHOD(device_shutdown, xl_shutdown), + DEVMETHOD(device_suspend, xl_suspend), + DEVMETHOD(device_resume, xl_resume), + + /* bus interface */ + DEVMETHOD(bus_print_child, bus_generic_print_child), + DEVMETHOD(bus_driver_added, bus_generic_driver_added), + + /* MII interface */ + DEVMETHOD(miibus_readreg, xl_miibus_readreg), + DEVMETHOD(miibus_writereg, xl_miibus_writereg), + DEVMETHOD(miibus_statchg, xl_miibus_statchg), + DEVMETHOD(miibus_mediainit, xl_miibus_mediainit), + + { 0, 0 } +}; + +static driver_t xl_driver = { + "xl", + xl_methods, + sizeof(struct xl_softc) +}; + +static devclass_t xl_devclass; + +DRIVER_MODULE(xl, cardbus, xl_driver, xl_devclass, 0, 0); +DRIVER_MODULE(xl, pci, xl_driver, xl_devclass, 0, 0); +DRIVER_MODULE(miibus, xl, miibus_driver, miibus_devclass, 0, 0); + +static void +xl_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error) +{ + u_int32_t *paddr; + + paddr = arg; + *paddr = segs->ds_addr; +} + +static void +xl_dma_map_rxbuf(void *arg, bus_dma_segment_t *segs, int nseg, + bus_size_t mapsize, int error) +{ + u_int32_t *paddr; + + if (error) + return; + + KASSERT(nseg == 1, ("xl_dma_map_rxbuf: too many DMA segments")); + paddr = arg; + *paddr = segs->ds_addr; +} + +static void +xl_dma_map_txbuf(void *arg, bus_dma_segment_t *segs, int nseg, + bus_size_t mapsize, int error) +{ + struct xl_list *l; + int i, total_len; + + if (error) + return; + + KASSERT(nseg <= XL_MAXFRAGS, ("too many DMA segments")); + + total_len = 0; + l = arg; + for (i = 0; i < nseg; i++) { + KASSERT(segs[i].ds_len <= MCLBYTES, ("segment size too large")); + l->xl_frag[i].xl_addr = htole32(segs[i].ds_addr); + l->xl_frag[i].xl_len = htole32(segs[i].ds_len); + total_len += segs[i].ds_len; + } + l->xl_frag[nseg - 1].xl_len = htole32(segs[nseg - 1].ds_len | + XL_LAST_FRAG); + l->xl_status = htole32(total_len); + l->xl_next = 0; +} + +/* + * Murphy's law says that it's possible the chip can wedge and + * the 'command in progress' bit may never clear. Hence, we wait + * only a finite amount of time to avoid getting caught in an + * infinite loop. Normally this delay routine would be a macro, + * but it isn't called during normal operation so we can afford + * to make it a function. + */ +static void +xl_wait(struct xl_softc *sc) +{ + register int i; + + for (i = 0; i < XL_TIMEOUT; i++) { + if ((CSR_READ_2(sc, XL_STATUS) & XL_STAT_CMDBUSY) == 0) + break; + } + + if (i == XL_TIMEOUT) + if_printf(sc->xl_ifp, "command never completed!\n"); +} + +/* + * MII access routines are provided for adapters with external + * PHYs (3c905-TX, 3c905-T4, 3c905B-T4) and those with built-in + * autoneg logic that's faked up to look like a PHY (3c905B-TX). + * Note: if you don't perform the MDIO operations just right, + * it's possible to end up with code that works correctly with + * some chips/CPUs/processor speeds/bus speeds/etc but not + * with others. + */ +#define MII_SET(x) \ + CSR_WRITE_2(sc, XL_W4_PHY_MGMT, \ + CSR_READ_2(sc, XL_W4_PHY_MGMT) | (x)) + +#define MII_CLR(x) \ + CSR_WRITE_2(sc, XL_W4_PHY_MGMT, \ + CSR_READ_2(sc, XL_W4_PHY_MGMT) & ~(x)) + +/* + * Sync the PHYs by setting data bit and strobing the clock 32 times. + */ +static void +xl_mii_sync(struct xl_softc *sc) +{ + register int i; + + XL_SEL_WIN(4); + MII_SET(XL_MII_DIR|XL_MII_DATA); + + for (i = 0; i < 32; i++) { + MII_SET(XL_MII_CLK); + MII_SET(XL_MII_DATA); + MII_SET(XL_MII_DATA); + MII_CLR(XL_MII_CLK); + MII_SET(XL_MII_DATA); + MII_SET(XL_MII_DATA); + } +} + +/* + * Clock a series of bits through the MII. + */ +static void +xl_mii_send(struct xl_softc *sc, u_int32_t bits, int cnt) +{ + int i; + + XL_SEL_WIN(4); + MII_CLR(XL_MII_CLK); + + for (i = (0x1 << (cnt - 1)); i; i >>= 1) { + if (bits & i) { + MII_SET(XL_MII_DATA); + } else { + MII_CLR(XL_MII_DATA); + } + MII_CLR(XL_MII_CLK); + MII_SET(XL_MII_CLK); + } +} + +/* + * Read an PHY register through the MII. + */ +static int +xl_mii_readreg(struct xl_softc *sc, struct xl_mii_frame *frame) +{ + int i, ack; + + /* Set up frame for RX. */ + frame->mii_stdelim = XL_MII_STARTDELIM; + frame->mii_opcode = XL_MII_READOP; + frame->mii_turnaround = 0; + frame->mii_data = 0; + + /* Select register window 4. */ + XL_SEL_WIN(4); + + CSR_WRITE_2(sc, XL_W4_PHY_MGMT, 0); + /* Turn on data xmit. */ + MII_SET(XL_MII_DIR); + + xl_mii_sync(sc); + + /* Send command/address info. */ + xl_mii_send(sc, frame->mii_stdelim, 2); + xl_mii_send(sc, frame->mii_opcode, 2); + xl_mii_send(sc, frame->mii_phyaddr, 5); + xl_mii_send(sc, frame->mii_regaddr, 5); + + /* Idle bit */ + MII_CLR((XL_MII_CLK|XL_MII_DATA)); + MII_SET(XL_MII_CLK); + + /* Turn off xmit. */ + MII_CLR(XL_MII_DIR); + + /* Check for ack */ + MII_CLR(XL_MII_CLK); + ack = CSR_READ_2(sc, XL_W4_PHY_MGMT) & XL_MII_DATA; + MII_SET(XL_MII_CLK); + + /* + * Now try reading data bits. If the ack failed, we still + * need to clock through 16 cycles to keep the PHY(s) in sync. + */ + if (ack) { + for (i = 0; i < 16; i++) { + MII_CLR(XL_MII_CLK); + MII_SET(XL_MII_CLK); + } + goto fail; + } + + for (i = 0x8000; i; i >>= 1) { + MII_CLR(XL_MII_CLK); + if (!ack) { + if (CSR_READ_2(sc, XL_W4_PHY_MGMT) & XL_MII_DATA) + frame->mii_data |= i; + } + MII_SET(XL_MII_CLK); + } + +fail: + MII_CLR(XL_MII_CLK); + MII_SET(XL_MII_CLK); + + return (ack ? 1 : 0); +} + +/* + * Write to a PHY register through the MII. + */ +static int +xl_mii_writereg(struct xl_softc *sc, struct xl_mii_frame *frame) +{ + + /* Set up frame for TX. */ + frame->mii_stdelim = XL_MII_STARTDELIM; + frame->mii_opcode = XL_MII_WRITEOP; + frame->mii_turnaround = XL_MII_TURNAROUND; + + /* Select the window 4. */ + XL_SEL_WIN(4); + + /* Turn on data output. */ + MII_SET(XL_MII_DIR); + + xl_mii_sync(sc); + + xl_mii_send(sc, frame->mii_stdelim, 2); + xl_mii_send(sc, frame->mii_opcode, 2); + xl_mii_send(sc, frame->mii_phyaddr, 5); + xl_mii_send(sc, frame->mii_regaddr, 5); + xl_mii_send(sc, frame->mii_turnaround, 2); + xl_mii_send(sc, frame->mii_data, 16); + + /* Idle bit. */ + MII_SET(XL_MII_CLK); + MII_CLR(XL_MII_CLK); + + /* Turn off xmit. */ + MII_CLR(XL_MII_DIR); + + return (0); +} + +static int +xl_miibus_readreg(device_t dev, int phy, int reg) +{ + struct xl_softc *sc; + struct xl_mii_frame frame; + + sc = device_get_softc(dev); + + /* + * Pretend that PHYs are only available at MII address 24. + * This is to guard against problems with certain 3Com ASIC + * revisions that incorrectly map the internal transceiver + * control registers at all MII addresses. This can cause + * the miibus code to attach the same PHY several times over. + */ + if ((sc->xl_flags & XL_FLAG_PHYOK) == 0 && phy != 24) + return (0); + + bzero((char *)&frame, sizeof(frame)); + frame.mii_phyaddr = phy; + frame.mii_regaddr = reg; + + xl_mii_readreg(sc, &frame); + + return (frame.mii_data); +} + +static int +xl_miibus_writereg(device_t dev, int phy, int reg, int data) +{ + struct xl_softc *sc; + struct xl_mii_frame frame; + + sc = device_get_softc(dev); + + if ((sc->xl_flags & XL_FLAG_PHYOK) == 0 && phy != 24) + return (0); + + bzero((char *)&frame, sizeof(frame)); + frame.mii_phyaddr = phy; + frame.mii_regaddr = reg; + frame.mii_data = data; + + xl_mii_writereg(sc, &frame); + + return (0); +} + +static void +xl_miibus_statchg(device_t dev) +{ + struct xl_softc *sc; + struct mii_data *mii; + + sc = device_get_softc(dev); + mii = device_get_softc(sc->xl_miibus); + + xl_setcfg(sc); + + /* Set ASIC's duplex mode to match the PHY. */ + XL_SEL_WIN(3); + if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) + CSR_WRITE_1(sc, XL_W3_MAC_CTRL, XL_MACCTRL_DUPLEX); + else + CSR_WRITE_1(sc, XL_W3_MAC_CTRL, + (CSR_READ_1(sc, XL_W3_MAC_CTRL) & ~XL_MACCTRL_DUPLEX)); +} + +/* + * Special support for the 3c905B-COMBO. This card has 10/100 support + * plus BNC and AUI ports. This means we will have both an miibus attached + * plus some non-MII media settings. In order to allow this, we have to + * add the extra media to the miibus's ifmedia struct, but we can't do + * that during xl_attach() because the miibus hasn't been attached yet. + * So instead, we wait until the miibus probe/attach is done, at which + * point we will get a callback telling is that it's safe to add our + * extra media. + */ +static void +xl_miibus_mediainit(device_t dev) +{ + struct xl_softc *sc; + struct mii_data *mii; + struct ifmedia *ifm; + + sc = device_get_softc(dev); + mii = device_get_softc(sc->xl_miibus); + ifm = &mii->mii_media; + + if (sc->xl_media & (XL_MEDIAOPT_AUI | XL_MEDIAOPT_10FL)) { + /* + * Check for a 10baseFL board in disguise. + */ + if (sc->xl_type == XL_TYPE_905B && + sc->xl_media == XL_MEDIAOPT_10FL) { + if (bootverbose) + if_printf(sc->xl_ifp, + "found 10baseFL\n"); + ifmedia_add(ifm, IFM_ETHER | IFM_10_FL, 0, NULL); + ifmedia_add(ifm, IFM_ETHER | IFM_10_FL|IFM_HDX, 0, + NULL); + if (sc->xl_caps & XL_CAPS_FULL_DUPLEX) + ifmedia_add(ifm, + IFM_ETHER | IFM_10_FL | IFM_FDX, 0, NULL); + } else { + if (bootverbose) + if_printf(sc->xl_ifp, "found AUI\n"); + ifmedia_add(ifm, IFM_ETHER | IFM_10_5, 0, NULL); + } + } + + if (sc->xl_media & XL_MEDIAOPT_BNC) { + if (bootverbose) + if_printf(sc->xl_ifp, "found BNC\n"); + ifmedia_add(ifm, IFM_ETHER | IFM_10_2, 0, NULL); + } +} + +/* + * The EEPROM is slow: give it time to come ready after issuing + * it a command. + */ +static int +xl_eeprom_wait(struct xl_softc *sc) +{ + int i; + + for (i = 0; i < 100; i++) { + if (CSR_READ_2(sc, XL_W0_EE_CMD) & XL_EE_BUSY) + DELAY(162); + else + break; + } + + if (i == 100) { + if_printf(sc->xl_ifp, "eeprom failed to come ready\n"); + return (1); + } + + return (0); +} + +/* + * Read a sequence of words from the EEPROM. Note that ethernet address + * data is stored in the EEPROM in network byte order. + */ +static int +xl_read_eeprom(struct xl_softc *sc, caddr_t dest, int off, int cnt, int swap) +{ + int err = 0, i; + u_int16_t word = 0, *ptr; + +#define EEPROM_5BIT_OFFSET(A) ((((A) << 2) & 0x7F00) | ((A) & 0x003F)) +#define EEPROM_8BIT_OFFSET(A) ((A) & 0x003F) + /* + * XXX: WARNING! DANGER! + * It's easy to accidentally overwrite the rom content! + * Note: the 3c575 uses 8bit EEPROM offsets. + */ + XL_SEL_WIN(0); + + if (xl_eeprom_wait(sc)) + return (1); + + if (sc->xl_flags & XL_FLAG_EEPROM_OFFSET_30) + off += 0x30; + + for (i = 0; i < cnt; i++) { + if (sc->xl_flags & XL_FLAG_8BITROM) + CSR_WRITE_2(sc, XL_W0_EE_CMD, + XL_EE_8BIT_READ | EEPROM_8BIT_OFFSET(off + i)); + else + CSR_WRITE_2(sc, XL_W0_EE_CMD, + XL_EE_READ | EEPROM_5BIT_OFFSET(off + i)); + err = xl_eeprom_wait(sc); + if (err) + break; + word = CSR_READ_2(sc, XL_W0_EE_DATA); + ptr = (u_int16_t *)(dest + (i * 2)); + if (swap) + *ptr = ntohs(word); + else + *ptr = word; + } + + return (err ? 1 : 0); +} + +/* + * NICs older than the 3c905B have only one multicast option, which + * is to enable reception of all multicast frames. + */ +static void +xl_setmulti(struct xl_softc *sc) +{ + struct ifnet *ifp = sc->xl_ifp; + struct ifmultiaddr *ifma; + u_int8_t rxfilt; + int mcnt = 0; + + XL_LOCK_ASSERT(sc); + + XL_SEL_WIN(5); + rxfilt = CSR_READ_1(sc, XL_W5_RX_FILTER); + + if (ifp->if_flags & IFF_ALLMULTI) { + rxfilt |= XL_RXFILTER_ALLMULTI; + CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_SET_FILT|rxfilt); + return; + } + + IF_ADDR_LOCK(ifp); + TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) + mcnt++; + IF_ADDR_UNLOCK(ifp); + + if (mcnt) + rxfilt |= XL_RXFILTER_ALLMULTI; + else + rxfilt &= ~XL_RXFILTER_ALLMULTI; + + CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_SET_FILT|rxfilt); +} + +/* + * 3c905B adapters have a hash filter that we can program. + */ +static void +xl_setmulti_hash(struct xl_softc *sc) +{ + struct ifnet *ifp = sc->xl_ifp; + int h = 0, i; + struct ifmultiaddr *ifma; + u_int8_t rxfilt; + int mcnt = 0; + + XL_LOCK_ASSERT(sc); + + XL_SEL_WIN(5); + rxfilt = CSR_READ_1(sc, XL_W5_RX_FILTER); + + if (ifp->if_flags & IFF_ALLMULTI) { + rxfilt |= XL_RXFILTER_ALLMULTI; + CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_SET_FILT|rxfilt); + return; + } else + rxfilt &= ~XL_RXFILTER_ALLMULTI; + + /* first, zot all the existing hash bits */ + for (i = 0; i < XL_HASHFILT_SIZE; i++) + CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_SET_HASH|i); + + /* now program new ones */ + IF_ADDR_LOCK(ifp); + TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { + if (ifma->ifma_addr->sa_family != AF_LINK) + continue; + /* + * Note: the 3c905B currently only supports a 64-bit hash + * table, which means we really only need 6 bits, but the + * manual indicates that future chip revisions will have a + * 256-bit hash table, hence the routine is set up to + * calculate 8 bits of position info in case we need it some + * day. + * Note II, The Sequel: _CURRENT_ versions of the 3c905B have + * a 256 bit hash table. This means we have to use all 8 bits + * regardless. On older cards, the upper 2 bits will be + * ignored. Grrrr.... + */ + h = ether_crc32_be(LLADDR((struct sockaddr_dl *) + ifma->ifma_addr), ETHER_ADDR_LEN) & 0xFF; + CSR_WRITE_2(sc, XL_COMMAND, + h | XL_CMD_RX_SET_HASH | XL_HASH_SET); + mcnt++; + } + IF_ADDR_UNLOCK(ifp); + + if (mcnt) + rxfilt |= XL_RXFILTER_MULTIHASH; + else + rxfilt &= ~XL_RXFILTER_MULTIHASH; + + CSR_WRITE_2(sc, XL_COMMAND, rxfilt | XL_CMD_RX_SET_FILT); +} + +#ifdef notdef +static void +xl_testpacket(struct xl_softc *sc) +{ + struct mbuf *m; + struct ifnet *ifp = sc->xl_ifp; + + MGETHDR(m, M_DONTWAIT, MT_DATA); + + if (m == NULL) + return; + + bcopy(&IFP2ENADDR(sc->xl_ifp), + mtod(m, struct ether_header *)->ether_dhost, ETHER_ADDR_LEN); + bcopy(&IFP2ENADDR(sc->xl_ifp), + mtod(m, struct ether_header *)->ether_shost, ETHER_ADDR_LEN); + mtod(m, struct ether_header *)->ether_type = htons(3); + mtod(m, unsigned char *)[14] = 0; + mtod(m, unsigned char *)[15] = 0; + mtod(m, unsigned char *)[16] = 0xE3; + m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3; + IFQ_ENQUEUE(&ifp->if_snd, m); + xl_start(ifp); +} +#endif + +static void +xl_setcfg(struct xl_softc *sc) +{ + u_int32_t icfg; + + /*XL_LOCK_ASSERT(sc);*/ + + XL_SEL_WIN(3); + icfg = CSR_READ_4(sc, XL_W3_INTERNAL_CFG); + icfg &= ~XL_ICFG_CONNECTOR_MASK; + if (sc->xl_media & XL_MEDIAOPT_MII || + sc->xl_media & XL_MEDIAOPT_BT4) + icfg |= (XL_XCVR_MII << XL_ICFG_CONNECTOR_BITS); + if (sc->xl_media & XL_MEDIAOPT_BTX) + icfg |= (XL_XCVR_AUTO << XL_ICFG_CONNECTOR_BITS); + + CSR_WRITE_4(sc, XL_W3_INTERNAL_CFG, icfg); + CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_COAX_STOP); +} + +static void +xl_setmode(struct xl_softc *sc, int media) +{ + u_int32_t icfg; + u_int16_t mediastat; + char *pmsg = "", *dmsg = ""; + + XL_LOCK_ASSERT(sc); + + XL_SEL_WIN(4); + mediastat = CSR_READ_2(sc, XL_W4_MEDIA_STATUS); + XL_SEL_WIN(3); + icfg = CSR_READ_4(sc, XL_W3_INTERNAL_CFG); + + if (sc->xl_media & XL_MEDIAOPT_BT) { + if (IFM_SUBTYPE(media) == IFM_10_T) { + pmsg = "10baseT transceiver"; + sc->xl_xcvr = XL_XCVR_10BT; + icfg &= ~XL_ICFG_CONNECTOR_MASK; + icfg |= (XL_XCVR_10BT << XL_ICFG_CONNECTOR_BITS); + mediastat |= XL_MEDIASTAT_LINKBEAT | + XL_MEDIASTAT_JABGUARD; + mediastat &= ~XL_MEDIASTAT_SQEENB; + } + } + + if (sc->xl_media & XL_MEDIAOPT_BFX) { + if (IFM_SUBTYPE(media) == IFM_100_FX) { + pmsg = "100baseFX port"; + sc->xl_xcvr = XL_XCVR_100BFX; + icfg &= ~XL_ICFG_CONNECTOR_MASK; + icfg |= (XL_XCVR_100BFX << XL_ICFG_CONNECTOR_BITS); + mediastat |= XL_MEDIASTAT_LINKBEAT; + mediastat &= ~XL_MEDIASTAT_SQEENB; + } + } + + if (sc->xl_media & (XL_MEDIAOPT_AUI|XL_MEDIAOPT_10FL)) { + if (IFM_SUBTYPE(media) == IFM_10_5) { + pmsg = "AUI port"; + sc->xl_xcvr = XL_XCVR_AUI; + icfg &= ~XL_ICFG_CONNECTOR_MASK; + icfg |= (XL_XCVR_AUI << XL_ICFG_CONNECTOR_BITS); + mediastat &= ~(XL_MEDIASTAT_LINKBEAT | + XL_MEDIASTAT_JABGUARD); + mediastat |= ~XL_MEDIASTAT_SQEENB; + } + if (IFM_SUBTYPE(media) == IFM_10_FL) { + pmsg = "10baseFL transceiver"; + sc->xl_xcvr = XL_XCVR_AUI; + icfg &= ~XL_ICFG_CONNECTOR_MASK; + icfg |= (XL_XCVR_AUI << XL_ICFG_CONNECTOR_BITS); + mediastat &= ~(XL_MEDIASTAT_LINKBEAT | + XL_MEDIASTAT_JABGUARD); + mediastat |= ~XL_MEDIASTAT_SQEENB; + } + } [... truncated: 3197 lines follow ...] From bga at bug-br.org.br Wed May 9 15:23:16 2007 From: bga at bug-br.org.br (Bruno Albuquerque) Date: Wed, 09 May 2007 10:23:16 -0300 Subject: [Haiku-commits] r21087 - in haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000: . dev dev/em In-Reply-To: <200705091320.l49DKfZC022103@sheep.berlios.de> References: <200705091320.l49DKfZC022103@sheep.berlios.de> Message-ID: <4641CB44.4030708@bug-br.org.br> hugosantos at mail.berlios.de wrote: > added FreeBSD 6.2's Intel Pro 1000 driver to the tree (original source, unchanged). Hey Hugo. there are 2 drivers for very common cards that would be great if you could get them working from the BSD sources as the Haiku versions are completelly busted right now: rtl8139 and via-rhine (this one will also enable networking inside Parallels). -Bruno From hugosantos at gmail.com Wed May 9 15:30:32 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Wed, 9 May 2007 14:30:32 +0100 Subject: [Haiku-commits] r21087 - in haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000: . dev dev/em In-Reply-To: <4641CB44.4030708@bug-br.org.br> References: <200705091320.l49DKfZC022103@sheep.berlios.de> <4641CB44.4030708@bug-br.org.br> Message-ID: <9c46321e0705090630g136b16dbu396e9b019b856872@mail.gmail.com> Hey Bruno, Thanks for the hint. I'll have a look at them. I will probably require others to test, but i can check during the day if the available code is enough to support those. Hugo On 5/9/07, Bruno Albuquerque wrote: > hugosantos at mail.berlios.de wrote: > > > added FreeBSD 6.2's Intel Pro 1000 driver to the tree (original source, unchanged). > > Hey Hugo. > > there are 2 drivers for very common cards that would be great if you > could get them working from the BSD sources as the Haiku versions are > completelly busted right now: rtl8139 and via-rhine (this one will also > enable networking inside Parallels). > > -Bruno > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From bga at bug-br.org.br Wed May 9 15:35:24 2007 From: bga at bug-br.org.br (Bruno Albuquerque) Date: Wed, 09 May 2007 10:35:24 -0300 Subject: [Haiku-commits] r21087 - in haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000: . dev dev/em In-Reply-To: <9c46321e0705090630g136b16dbu396e9b019b856872@mail.gmail.com> References: <200705091320.l49DKfZC022103@sheep.berlios.de> <4641CB44.4030708@bug-br.org.br> <9c46321e0705090630g136b16dbu396e9b019b856872@mail.gmail.com> Message-ID: <4641CE1C.5040700@bug-br.org.br> Hugo Santos wrote: > Thanks for the hint. I'll have a look at them. I will probably > require others to test, but i can check during the day if the > available code is enough to support those. Ok. I can test both cards and can even provide you with them (the cards) if you need. BTW, this seems harmless but I getting the following errors when trying to compile a image now: don't know how to make driver.c don't know how to make device.c don't know how to make if_compat.c don't know how to make if_em_osdep.c don't know how to make mempool.c don't know how to make timer.c don't know how to make util.c -Bruno From korli at users.berlios.de Wed May 9 15:41:21 2007 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Wed, 9 May 2007 15:41:21 +0200 Subject: [Haiku-commits] r21087 - in haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000: . dev dev/em In-Reply-To: <200705091320.l49DKfZC022103@sheep.berlios.de> References: <200705091320.l49DKfZC022103@sheep.berlios.de> Message-ID: Hi Hugo, 2007/5/9, hugosantos at mail.berlios.de : > --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/Jamfile 2007-05-09 13:17:19 UTC (rev 21086) > +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/Jamfile 2007-05-09 13:20:14 UTC (rev 21087) > @@ -1,5 +1,7 @@ > SubDir HAIKU_TOP src add-ons kernel drivers network ipro1000 ; > > +SubInclude HAIKU_TOP src add-ons kernel drivers network ipro1000 dev ; > + > SetSubDirSupportedPlatformsBeOSCompatible ; > > # set some additional flags > I could be wrong, but I thought it was better to put the SubInclude rule invocations at the bottom of Jamfiles. Bye, J?r?me From hugosantos at mail.berlios.de Wed May 9 15:49:41 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 9 May 2007 15:49:41 +0200 Subject: [Haiku-commits] r21089 - in haiku/trunk/src: add-ons/kernel/drivers/network/ipro1000/dev/em libs/compat/freebsd_network libs/compat/freebsd_network/compat/sys Message-ID: <200705091349.l49DnfKe025535@sheep.berlios.de> Author: hugosantos Date: 2007-05-09 15:49:05 +0200 (Wed, 09 May 2007) New Revision: 21089 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21089&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/Jamfile haiku/trunk/src/libs/compat/freebsd_network/Jamfile haiku/trunk/src/libs/compat/freebsd_network/compat/sys/callout.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kernel.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mutex.h haiku/trunk/src/libs/compat/freebsd_network/fbsd_busdma_x86.c Log: freebsd compat. layer: fixed a couple warnings, use KernelStaticLibrary as suggested by Ingo. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/Jamfile 2007-05-09 13:20:41 UTC (rev 21088) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/Jamfile 2007-05-09 13:49:05 UTC (rev 21089) @@ -1,7 +1,5 @@ SubDir HAIKU_TOP src add-ons kernel drivers network ipro1000 dev em ; -SubDirCcFlags -Wall ; - UsePrivateHeaders kernel net ; UseHeaders [ FDirName $(SUBDIR) .. .. ] : true ; Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-09 13:20:41 UTC (rev 21088) +++ haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-09 13:49:05 UTC (rev 21089) @@ -7,7 +7,7 @@ SubDirCcFlags [ FDefines _KERNEL=1 KTR=1 ] ; -Library libfreebsd_network.a : +KernelStaticLibrary libfreebsd_network.a : bus.c callout.c compat.c Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/callout.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/callout.h 2007-05-09 13:20:41 UTC (rev 21088) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/callout.h 2007-05-09 13:49:05 UTC (rev 21089) @@ -1,7 +1,7 @@ #ifndef _FBSD_COMPAT_SYS_CALLOUT_H_ #define _FBSD_COMPAT_SYS_CALLOUT_H_ -#include +#include #include #include Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-09 13:20:41 UTC (rev 21088) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-09 13:49:05 UTC (rev 21089) @@ -9,7 +9,12 @@ #define _FBSD_COMPAT_SYS_HAIKU_MODULE_H_ #include /* for device_hooks */ +#include +#include /* mutex, recursive_lock for mtx */ +#include /* net_timer, for callout */ +#undef ASSERT /* private/kernel/debug.h sets it */ + typedef struct device *device_t; typedef struct devclass *devclass_t; Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kernel.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kernel.h 2007-05-09 13:20:41 UTC (rev 21088) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kernel.h 2007-05-09 13:49:05 UTC (rev 21089) @@ -5,8 +5,7 @@ #include #include -#include - +#include #include #define hz 1000000LL Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mutex.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mutex.h 2007-05-09 13:20:41 UTC (rev 21088) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mutex.h 2007-05-09 13:49:05 UTC (rev 21089) @@ -1,7 +1,7 @@ #ifndef _FBSD_COMPAT_SYS_MUTEX_H_ #define _FBSD_COMPAT_SYS_MUTEX_H_ -#include +#include struct mtx { int type; Modified: haiku/trunk/src/libs/compat/freebsd_network/fbsd_busdma_x86.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/fbsd_busdma_x86.c 2007-05-09 13:20:41 UTC (rev 21088) +++ haiku/trunk/src/libs/compat/freebsd_network/fbsd_busdma_x86.c 2007-05-09 13:49:05 UTC (rev 21089) @@ -1000,7 +1000,7 @@ bz->boundary = dmat->boundary; snprintf(bz->zoneid, 8, "zone%d", busdma_zonecount); busdma_zonecount++; - snprintf(bz->lowaddrid, 18, "%lx", (uintmax_t)bz->lowaddr); + snprintf(bz->lowaddrid, 18, "%llx", (uintmax_t)bz->lowaddr); STAILQ_INSERT_TAIL(&bounce_zone_list, bz, links); dmat->bounce_zone = bz; From hugosantos at mail.berlios.de Wed May 9 15:52:24 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 9 May 2007 15:52:24 +0200 Subject: [Haiku-commits] r21090 - haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000 Message-ID: <200705091352.l49DqOjC025649@sheep.berlios.de> Author: hugosantos Date: 2007-05-09 15:52:14 +0200 (Wed, 09 May 2007) New Revision: 21090 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21090&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/Jamfile Log: it seems jam prefer SubInclude to be on the bottom of the Jamfile. suggested by Jerome. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/Jamfile 2007-05-09 13:49:05 UTC (rev 21089) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/Jamfile 2007-05-09 13:52:14 UTC (rev 21090) @@ -1,7 +1,5 @@ SubDir HAIKU_TOP src add-ons kernel drivers network ipro1000 ; -SubInclude HAIKU_TOP src add-ons kernel drivers network ipro1000 dev ; - SetSubDirSupportedPlatformsBeOSCompatible ; # set some additional flags @@ -52,3 +50,5 @@ installed-symlink ; +SubInclude HAIKU_TOP src add-ons kernel drivers network ipro1000 dev ; + From hugosantos at gmail.com Wed May 9 15:52:33 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Wed, 9 May 2007 14:52:33 +0100 Subject: [Haiku-commits] r21087 - in haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000: . dev dev/em In-Reply-To: <4641CE1C.5040700@bug-br.org.br> References: <200705091320.l49DKfZC022103@sheep.berlios.de> <4641CB44.4030708@bug-br.org.br> <9c46321e0705090630g136b16dbu396e9b019b856872@mail.gmail.com> <4641CE1C.5040700@bug-br.org.br> Message-ID: <9c46321e0705090652m18e6792ckb093a963c507c48c@mail.gmail.com> Ups, can you check if its fixed in the last revision please (r21090)? Hugo On 5/9/07, Bruno Albuquerque wrote: > Hugo Santos wrote: > > > Thanks for the hint. I'll have a look at them. I will probably > > require others to test, but i can check during the day if the > > available code is enough to support those. > > Ok. I can test both cards and can even provide you with them (the cards) > if you need. > > BTW, this seems harmless but I getting the following errors when trying > to compile a image now: > > don't know how to make > driver.c > don't know how to make > device.c > don't know how to make > if_compat.c > don't know how to make > if_em_osdep.c > don't know how to make > mempool.c > don't know how to make > timer.c > don't know how to make > util.c > > > > -Bruno > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From hugosantos at gmail.com Wed May 9 15:52:57 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Wed, 9 May 2007 14:52:57 +0100 Subject: [Haiku-commits] r21087 - in haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000: . dev dev/em In-Reply-To: References: <200705091320.l49DKfZC022103@sheep.berlios.de> Message-ID: <9c46321e0705090652u4cf1fe36t8740b65f4708e86d@mail.gmail.com> Thanks for the pointer, at least locally it seems to be affecting the behavior. Hugo On 5/9/07, J?r?me Duval wrote: > Hi Hugo, > > 2007/5/9, hugosantos at mail.berlios.de : > > --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/Jamfile 2007-05-09 13:17:19 UTC (rev 21086) > > +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/Jamfile 2007-05-09 13:20:14 UTC (rev 21087) > > @@ -1,5 +1,7 @@ > > SubDir HAIKU_TOP src add-ons kernel drivers network ipro1000 ; > > > > +SubInclude HAIKU_TOP src add-ons kernel drivers network ipro1000 dev ; > > + > > SetSubDirSupportedPlatformsBeOSCompatible ; > > > > # set some additional flags > > > > > I could be wrong, but I thought it was better to put the SubInclude > rule invocations at the bottom of Jamfiles. > > Bye, > J?r?me > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From hugosantos at gmail.com Wed May 9 15:57:07 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Wed, 9 May 2007 14:57:07 +0100 Subject: [Haiku-commits] r21089 - in haiku/trunk/src: add-ons/kernel/drivers/network/ipro1000/dev/em libs/compat/freebsd_network libs/compat/freebsd_network/compat/sys In-Reply-To: <200705091349.l49DnfKe025535@sheep.berlios.de> References: <200705091349.l49DnfKe025535@sheep.berlios.de> Message-ID: <9c46321e0705090657m6a117489m6e5068fc06b6623@mail.gmail.com> > -SubDirCcFlags -Wall ; > - This wasn't the warning fixing btw :-) I just removed it as it is redundant, the build already adds it. Hugo From mmlr at mail.berlios.de Wed May 9 16:25:17 2007 From: mmlr at mail.berlios.de (mmlr at BerliOS) Date: Wed, 9 May 2007 16:25:17 +0200 Subject: [Haiku-commits] r21091 - haiku/trunk/src/add-ons/kernel/drivers/network Message-ID: <200705091425.l49EPHsR027706@sheep.berlios.de> Author: mmlr Date: 2007-05-09 16:25:17 +0200 (Wed, 09 May 2007) New Revision: 21091 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21091&view=rev Removed: haiku/trunk/src/add-ons/kernel/drivers/network/fxp/ Log: Remove now unused fxp directories. BTW: is there a reason to have those drivers under "haiku_name/dev/freebsd_name/*" instead of directly under "haiku_name/*"? From lexaeusxiii at gmail.com Wed May 9 16:29:22 2007 From: lexaeusxiii at gmail.com (Lexaeus XIII) Date: Wed, 9 May 2007 10:29:22 -0400 Subject: [Haiku-commits] r21087 - in haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000: . dev dev/em In-Reply-To: <9c46321e0705090652u4cf1fe36t8740b65f4708e86d@mail.gmail.com> References: <200705091320.l49DKfZC022103@sheep.berlios.de> <9c46321e0705090652u4cf1fe36t8740b65f4708e86d@mail.gmail.com> Message-ID: <855a5f230705090729i2612e38p128df3a52018a6bd@mail.gmail.com> Hmm, I can't remember if my secondary ethernet card uses the rtl8139 driver or the rtl8169 driver, does the latter even exist? I can't check atm because I'm in class. If it uses rtl8139 I'll be happy to test out the driver if it's implemented. On 5/9/07, Hugo Santos wrote: > > Thanks for the pointer, at least locally it seems to be affecting the > behavior. > > Hugo > > On 5/9/07, J?r?me Duval wrote: > > Hi Hugo, > > > > 2007/5/9, hugosantos at mail.berlios.de : > > > --- > haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/Jamfile > 2007-05-09 13:17:19 UTC (rev 21086) > > > +++ > haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/Jamfile > 2007-05-09 13:20:14 UTC (rev 21087) > > > @@ -1,5 +1,7 @@ > > > SubDir HAIKU_TOP src add-ons kernel drivers network ipro1000 ; > > > > > > +SubInclude HAIKU_TOP src add-ons kernel drivers network ipro1000 dev > ; > > > + > > > SetSubDirSupportedPlatformsBeOSCompatible ; > > > > > > # set some additional flags > > > > > > > > > I could be wrong, but I thought it was better to put the SubInclude > > rule invocations at the bottom of Jamfiles. > > > > Bye, > > J?r?me > > _______________________________________________ > > Haiku-commits mailing list > > Haiku-commits at lists.berlios.de > > https://lists.berlios.de/mailman/listinfo/haiku-commits > > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hugosantos at gmail.com Wed May 9 16:30:40 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Wed, 9 May 2007 15:30:40 +0100 Subject: [Haiku-commits] r21091 - haiku/trunk/src/add-ons/kernel/drivers/network In-Reply-To: <200705091425.l49EPHsR027706@sheep.berlios.de> References: <200705091425.l49EPHsR027706@sheep.berlios.de> Message-ID: <9c46321e0705090730k124c45eevf0d08578582cda23@mail.gmail.com> Hi, I didn't realize a fxp directory was left behind, my bad. Regarding the name, yes there is. Look at pcnet/dev/le/if_le_pci.c for instance, it relies on this naming for its own include files. I also maintain it inside the compat/ directory of freebsd_network, give it a look. This was kept so the original files did not need to be modified. And it's always better to ask directly here than leaving the question in a commit. :-) Hugo On 5/9/07, mmlr at BerliOS wrote: > Author: mmlr > Date: 2007-05-09 16:25:17 +0200 (Wed, 09 May 2007) > New Revision: 21091 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21091&view=rev > > Removed: > haiku/trunk/src/add-ons/kernel/drivers/network/fxp/ > Log: > Remove now unused fxp directories. BTW: is there a reason to have those drivers under "haiku_name/dev/freebsd_name/*" instead of directly under "haiku_name/*"? > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From hugosantos at gmail.com Wed May 9 16:32:02 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Wed, 9 May 2007 15:32:02 +0100 Subject: [Haiku-commits] r21087 - in haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000: . dev dev/em In-Reply-To: <855a5f230705090729i2612e38p128df3a52018a6bd@mail.gmail.com> References: <200705091320.l49DKfZC022103@sheep.berlios.de> <9c46321e0705090652u4cf1fe36t8740b65f4708e86d@mail.gmail.com> <855a5f230705090729i2612e38p128df3a52018a6bd@mail.gmail.com> Message-ID: <9c46321e0705090732i51533758w5b6e96af3b07a6e5@mail.gmail.com> There is a Realtek 8169, that is a gigabit device, Realtek 8139 is 100mbit. Hugo On 5/9/07, Lexaeus XIII wrote: > Hmm, I can't remember if my secondary ethernet card uses the rtl8139 driver > or the rtl8169 driver, does the latter even exist? I can't check atm because > I'm in class. If it uses rtl8139 I'll be happy to test out the driver if > it's implemented. > > > On 5/9/07, Hugo Santos wrote: > > Thanks for the pointer, at least locally it seems to be affecting the > behavior. > > > > Hugo > > > > On 5/9/07, J?r?me Duval wrote: > > > Hi Hugo, > > > > > > 2007/5/9, hugosantos at mail.berlios.de : > > > > --- > haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/Jamfile > 2007-05-09 13:17:19 UTC (rev 21086) > > > > +++ > haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/Jamfile > 2007-05-09 13:20:14 UTC (rev 21087) > > > > @@ -1,5 +1,7 @@ > > > > SubDir HAIKU_TOP src add-ons kernel drivers network ipro1000 ; > > > > > > > > +SubInclude HAIKU_TOP src add-ons kernel drivers network ipro1000 dev > ; > > > > + > > > > SetSubDirSupportedPlatformsBeOSCompatible ; > > > > > > > > # set some additional flags > > > > > > > > > > > > > I could be wrong, but I thought it was better to put the SubInclude > > > rule invocations at the bottom of Jamfiles. > > > > > > Bye, > > > J?r?me > > > _______________________________________________ > > > Haiku-commits mailing list > > > Haiku-commits at lists.berlios.de > > > https://lists.berlios.de/mailman/listinfo/haiku-commits > > > > > _______________________________________________ > > Haiku-commits mailing list > > Haiku-commits at lists.berlios.de > > https://lists.berlios.de/mailman/listinfo/haiku-commits > > > > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > > From bonefish at cs.tu-berlin.de Wed May 9 17:07:56 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Wed, 09 May 2007 17:07:56 +0200 Subject: [Haiku-commits] r21087 - in haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000: . dev dev/em In-Reply-To: <9c46321e0705090652u4cf1fe36t8740b65f4708e86d@mail.gmail.com> References: <200705091320.l49DKfZC022103@sheep.berlios.de> <9c46321e0705090652u4cf1fe36t8740b65f4708e86d@mail.gmail.com> Message-ID: <20070509170756.1265.4@cs.tu-berlin.de> On 2007-05-09 at 15:52:57 [+0200], Hugo Santos wrote: > Thanks for the pointer, at least locally it seems to be affecting the > behavior. Yep, it's vital to put the SubIncludes at the end or you get undesired effects. CU, Ingo From hugosantos at mail.berlios.de Wed May 9 17:27:48 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 9 May 2007 17:27:48 +0200 Subject: [Haiku-commits] r21092 - in haiku/trunk/src: add-ons/kernel/drivers/network/ipro1000/dev/em add-ons/kernel/drivers/network/pcnet/dev/le libs/compat/freebsd_network libs/compat/freebsd_network/compat/dev/mii libs/compat/freebsd_network/compat/sys Message-ID: <200705091527.l49FRmNZ003149@sheep.berlios.de> Author: hugosantos Date: 2007-05-09 17:27:13 +0200 (Wed, 09 May 2007) New Revision: 21092 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21092&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/glue.c haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am79900.c haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/if_le_pci.c haiku/trunk/src/libs/compat/freebsd_network/bus.c haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/mii.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h haiku/trunk/src/libs/compat/freebsd_network/fbsd_mbuf.c haiku/trunk/src/libs/compat/freebsd_network/mbuf.c Log: freebsd compat. layer: a couple more definitions, minimal, mostly adding a new glue method to re-enable device interrupts since if_rl (rtl 8139) will require it. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/glue.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/glue.c 2007-05-09 14:25:17 UTC (rev 21091) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/glue.c 2007-05-09 15:27:13 UTC (rev 21092) @@ -2,7 +2,8 @@ HAIKU_FBSD_DRIVER_GLUE(e1000, em, pci) -NO_HAIKU_CHECK_DISABLE_INTERRUPTS() +NO_HAIKU_CHECK_DISABLE_INTERRUPTS(); +NO_HAIKU_REENABLE_INTERRUPTS(); #ifdef EM_FAST_INTR HAIKU_DRIVER_REQUIREMENTS(FBSD_TASKQUEUES | FBSD_FAST_TASKQUEUE); Modified: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am79900.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am79900.c 2007-05-09 14:25:17 UTC (rev 21091) +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/am79900.c 2007-05-09 15:27:13 UTC (rev 21092) @@ -451,11 +451,11 @@ isr = (*sc->sc_rdcsr)(sc, LE_CSR0); #endif { - cpu_status status; - HAIKU_INTR_REGISTER_ENTER(status); + HAIKU_INTR_REGISTER_STATE; + HAIKU_INTR_REGISTER_ENTER(); isr = sc->sc_lastisr; sc->sc_lastisr = 0; - HAIKU_INTR_REGISTER_LEAVE(status); + HAIKU_INTR_REGISTER_LEAVE(); } #if defined(LEDEBUG) && LEDEBUG > 1 Modified: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c 2007-05-09 14:25:17 UTC (rev 21091) +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c 2007-05-09 15:27:13 UTC (rev 21092) @@ -32,10 +32,10 @@ int HAIKU_CHECK_DISABLE_INTERRUPTS(device_t dev) { struct le_pci_softc *lesc = (struct le_pci_softc *)device_get_softc(dev); - cpu_status status; + HAIKU_INTR_REGISTER_STATE; uint16_t value; - HAIKU_INTR_REGISTER_ENTER(status); + HAIKU_INTR_REGISTER_ENTER(); /* get current flags */ bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, LE_CSR0); @@ -54,7 +54,9 @@ lesc->sc_am79900.lsc.sc_lastisr |= value; } - HAIKU_INTR_REGISTER_LEAVE(status); + HAIKU_INTR_REGISTER_LEAVE(); return value & LE_C0_INTR; } + +NO_HAIKU_REENABLE_INTERRUPTS(); Modified: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/if_le_pci.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/if_le_pci.c 2007-05-09 14:25:17 UTC (rev 21091) +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/if_le_pci.c 2007-05-09 15:27:13 UTC (rev 21092) @@ -195,33 +195,33 @@ le_pci_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) { struct le_pci_softc *lesc = (struct le_pci_softc *)sc; - cpu_status status = 0; + HAIKU_INTR_REGISTER_STATE; if (port == LE_CSR0) - HAIKU_INTR_REGISTER_ENTER(status); + HAIKU_INTR_REGISTER_ENTER(); bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, port); bus_space_barrier(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, 2, BUS_SPACE_BARRIER_WRITE); bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RDP, val); if (port == LE_CSR0) - HAIKU_INTR_REGISTER_LEAVE(status); + HAIKU_INTR_REGISTER_LEAVE(); } static uint16_t le_pci_rdcsr(struct lance_softc *sc, uint16_t port) { struct le_pci_softc *lesc = (struct le_pci_softc *)sc; - cpu_status status = 0; + HAIKU_INTR_REGISTER_STATE; uint16_t value; if (port == LE_CSR0) - HAIKU_INTR_REGISTER_ENTER(status); + HAIKU_INTR_REGISTER_ENTER(); bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, port); bus_space_barrier(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, 2, BUS_SPACE_BARRIER_WRITE); value = bus_space_read_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RDP); if (port == LE_CSR0) - HAIKU_INTR_REGISTER_LEAVE(status); + HAIKU_INTR_REGISTER_LEAVE(); return value; } Modified: haiku/trunk/src/libs/compat/freebsd_network/bus.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-09 14:25:17 UTC (rev 21091) +++ haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-09 15:27:13 UTC (rev 21092) @@ -212,6 +212,7 @@ device_printf(intr->dev, "in soft interrupt handler.\n"); intr->handler(intr->arg); + HAIKU_REENABLE_INTERRUPTS(intr->dev); } return 0; Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/mii.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/mii.h 2007-05-09 14:25:17 UTC (rev 21091) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/mii.h 2007-05-09 15:27:13 UTC (rev 21092) @@ -0,0 +1,206 @@ +/* $NetBSD: mii.h,v 1.9 2001/05/31 03:07:14 thorpej Exp $ */ + +/*- + * Copyright (c) 1997 Manuel Bouyer. All rights reserved. + * + * Modification to match BSD/OS 3.0 MII interface by Jason R. Thorpe, + * Numerical Aerospace Simulation Facility, NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Manuel Bouyer. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/sys/dev/mii/mii.h,v 1.5 2005/01/06 01:42:56 imp Exp $ + */ + +#ifndef _DEV_MII_MII_H_ +#define _DEV_MII_MII_H_ + +/* + * Registers common to all PHYs. + */ + +#define MII_NPHY 32 /* max # of PHYs per MII */ + +/* + * MII commands, used if a device must drive the MII lines + * manually. + */ +#define MII_COMMAND_START 0x01 +#define MII_COMMAND_READ 0x02 +#define MII_COMMAND_WRITE 0x01 +#define MII_COMMAND_ACK 0x02 + +#define MII_BMCR 0x00 /* Basic mode control register (rw) */ +#define BMCR_RESET 0x8000 /* reset */ +#define BMCR_LOOP 0x4000 /* loopback */ +#define BMCR_SPEED0 0x2000 /* speed selection (LSB) */ +#define BMCR_AUTOEN 0x1000 /* autonegotiation enable */ +#define BMCR_PDOWN 0x0800 /* power down */ +#define BMCR_ISO 0x0400 /* isolate */ +#define BMCR_STARTNEG 0x0200 /* restart autonegotiation */ +#define BMCR_FDX 0x0100 /* Set duplex mode */ +#define BMCR_CTEST 0x0080 /* collision test */ +#define BMCR_SPEED1 0x0040 /* speed selection (MSB) */ + +#define BMCR_S10 0x0000 /* 10 Mb/s */ +#define BMCR_S100 BMCR_SPEED0 /* 100 Mb/s */ +#define BMCR_S1000 BMCR_SPEED1 /* 1000 Mb/s */ + +#define BMCR_SPEED(x) ((x) & (BMCR_SPEED0|BMCR_SPEED1)) + +#define MII_BMSR 0x01 /* Basic mode status register (ro) */ +#define BMSR_100T4 0x8000 /* 100 base T4 capable */ +#define BMSR_100TXFDX 0x4000 /* 100 base Tx full duplex capable */ +#define BMSR_100TXHDX 0x2000 /* 100 base Tx half duplex capable */ +#define BMSR_10TFDX 0x1000 /* 10 base T full duplex capable */ +#define BMSR_10THDX 0x0800 /* 10 base T half duplex capable */ +#define BMSR_100T2FDX 0x0400 /* 100 base T2 full duplex capable */ +#define BMSR_100T2HDX 0x0200 /* 100 base T2 half duplex capable */ +#define BMSR_EXTSTAT 0x0100 /* Extended status in register 15 */ +#define BMSR_MFPS 0x0040 /* MII Frame Preamble Suppression */ +#define BMSR_ACOMP 0x0020 /* Autonegotiation complete */ +#define BMSR_RFAULT 0x0010 /* Link partner fault */ +#define BMSR_ANEG 0x0008 /* Autonegotiation capable */ +#define BMSR_LINK 0x0004 /* Link status */ +#define BMSR_JABBER 0x0002 /* Jabber detected */ +#define BMSR_EXTCAP 0x0001 /* Extended capability */ + +/* + * Note that the EXTSTAT bit indicates that there is extended status + * info available in register 15, but 802.3 section 22.2.4.3 also + * states that that all 1000 Mb/s capable PHYs will set this bit to 1. + */ +#if 0 +#define BMSR_MEDIAMASK (BMSR_100T4|BMSR_100TXFDX|BMSR_100TXHDX|BMSR_10TFDX| \ + BMSR_10THDX|BMSR_ANEG) + +#else +/* NetBSD uses: */ +#define BMSR_MEDIAMASK (BMSR_100T4|BMSR_100TXFDX|BMSR_100TXHDX| \ + BMSR_10TFDX|BMSR_10THDX|BMSR_100T2FDX|BMSR_100T2HDX) +#endif + +/* + * Convert BMSR media capabilities to ANAR bits for autonegotiation. + * Note the shift chopps off the BMSR_ANEG bit. + */ +#define BMSR_MEDIA_TO_ANAR(x) (((x) & BMSR_MEDIAMASK) >> 6) + +#define MII_PHYIDR1 0x02 /* ID register 1 (ro) */ + +#define MII_PHYIDR2 0x03 /* ID register 2 (ro) */ +#define IDR2_OUILSB 0xfc00 /* OUI LSB */ +#define IDR2_MODEL 0x03f0 /* vendor model */ +#define IDR2_REV 0x000f /* vendor revision */ + +#define MII_OUI(id1, id2) (((id1) << 6) | ((id2) >> 10)) +#define MII_MODEL(id2) (((id2) & IDR2_MODEL) >> 4) +#define MII_REV(id2) ((id2) & IDR2_REV) + +#define MII_ANAR 0x04 /* Autonegotiation advertisement (rw) */ + /* section 28.2.4.1 and 37.2.6.1 */ +#define ANAR_NP 0x8000 /* Next page (ro) */ +#define ANAR_ACK 0x4000 /* link partner abilities acknowledged (ro) */ +#define ANAR_RF 0x2000 /* remote fault (ro) */ +#define ANAR_FC 0x0400 /* local device supports PAUSE */ +#define ANAR_T4 0x0200 /* local device supports 100bT4 */ +#define ANAR_TX_FD 0x0100 /* local device supports 100bTx FD */ +#define ANAR_TX 0x0080 /* local device supports 100bTx */ +#define ANAR_10_FD 0x0040 /* local device supports 10bT FD */ +#define ANAR_10 0x0020 /* local device supports 10bT */ +#define ANAR_CSMA 0x0001 /* protocol selector CSMA/CD */ + +#define ANAR_X_FD 0x0020 /* local device supports 1000BASE-X FD */ +#define ANAR_X_HD 0x0040 /* local device supports 1000BASE-X HD */ +#define ANAR_X_PAUSE_NONE (0 << 7) +#define ANAR_X_PAUSE_SYM (1 << 7) +#define ANAR_X_PAUSE_ASYM (2 << 7) +#define ANAR_X_PAUSE_TOWARDS (3 << 7) + +#define MII_ANLPAR 0x05 /* Autonegotiation lnk partner abilities (rw) */ + /* section 28.2.4.1 and 37.2.6.1 */ +#define ANLPAR_NP 0x8000 /* Next page (ro) */ +#define ANLPAR_ACK 0x4000 /* link partner accepted ACK (ro) */ +#define ANLPAR_RF 0x2000 /* remote fault (ro) */ +#define ANLPAR_FC 0x0400 /* link partner supports PAUSE */ +#define ANLPAR_T4 0x0200 /* link partner supports 100bT4 */ +#define ANLPAR_TX_FD 0x0100 /* link partner supports 100bTx FD */ +#define ANLPAR_TX 0x0080 /* link partner supports 100bTx */ +#define ANLPAR_10_FD 0x0040 /* link partner supports 10bT FD */ +#define ANLPAR_10 0x0020 /* link partner supports 10bT */ +#define ANLPAR_CSMA 0x0001 /* protocol selector CSMA/CD */ + +#define ANLPAR_X_FD 0x0020 /* local device supports 1000BASE-X FD */ +#define ANLPAR_X_HD 0x0040 /* local device supports 1000BASE-X HD */ +#define ANLPAR_X_PAUSE_MASK (3 << 7) +#define ANLPAR_X_PAUSE_NONE (0 << 7) +#define ANLPAR_X_PAUSE_SYM (1 << 7) +#define ANLPAR_X_PAUSE_ASYM (2 << 7) +#define ANLPAR_X_PAUSE_TOWARDS (3 << 7) + +#define MII_ANER 0x06 /* Autonegotiation expansion (ro) */ + /* section 28.2.4.1 and 37.2.6.1 */ +#define ANER_MLF 0x0010 /* multiple link detection fault */ +#define ANER_LPNP 0x0008 /* link parter next page-able */ +#define ANER_NP 0x0004 /* next page-able */ +#define ANER_PAGE_RX 0x0002 /* Page received */ +#define ANER_LPAN 0x0001 /* link parter autoneg-able */ + +#define MII_ANNP 0x07 /* Autonegotiation next page */ + /* section 28.2.4.1 and 37.2.6.1 */ + +#define MII_ANLPRNP 0x08 /* Autonegotiation link partner rx next page */ + /* section 32.5.1 and 37.2.6.1 */ + + /* This is also the 1000baseT control register */ +#define MII_100T2CR 0x09 /* 100base-T2 control register */ +#define GTCR_TEST_MASK 0xe000 /* see 802.3ab ss. 40.6.1.1.2 */ +#define GTCR_MAN_MS 0x1000 /* enable manual master/slave control */ +#define GTCR_ADV_MS 0x0800 /* 1 = adv. master, 0 = adv. slave */ +#define GTCR_PORT_TYPE 0x0400 /* 1 = DCE, 0 = DTE (NIC) */ +#define GTCR_ADV_1000TFDX 0x0200 /* adv. 1000baseT FDX */ +#define GTCR_ADV_1000THDX 0x0100 /* adv. 1000baseT HDX */ + + /* This is also the 1000baseT status register */ +#define MII_100T2SR 0x0a /* 100base-T2 status register */ +#define GTSR_MAN_MS_FLT 0x8000 /* master/slave config fault */ +#define GTSR_MS_RES 0x4000 /* result: 1 = master, 0 = slave */ +#define GTSR_LRS 0x2000 /* local rx status, 1 = ok */ +#define GTSR_RRS 0x1000 /* remove rx status, 1 = ok */ +#define GTSR_LP_1000TFDX 0x0800 /* link partner 1000baseT FDX capable */ +#define GTSR_LP_1000THDX 0x0400 /* link partner 1000baseT HDX capable */ +#define GTSR_LP_ASM_DIR 0x0200 /* link partner asym. pause dir. capable */ +#define GTSR_IDLE_ERR 0x00ff /* IDLE error count */ + +#define MII_EXTSR 0x0f /* Extended status register */ +#define EXTSR_1000XFDX 0x8000 /* 1000X full-duplex capable */ +#define EXTSR_1000XHDX 0x4000 /* 1000X half-duplex capable */ +#define EXTSR_1000TFDX 0x2000 /* 1000T full-duplex capable */ +#define EXTSR_1000THDX 0x1000 /* 1000T half-duplex capable */ + +#define EXTSR_MEDIAMASK (EXTSR_1000XFDX|EXTSR_1000XHDX| \ + EXTSR_1000TFDX|EXTSR_1000THDX) + +#endif /* _DEV_MII_MII_H_ */ Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-09 14:25:17 UTC (rev 21091) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-09 15:27:13 UTC (rev 21092) @@ -37,7 +37,10 @@ void bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t handle, bus_size_t offset, uint32_t value); +#define bus_space_write_stream_4(t, h, o, v) \ + bus_space_write_4((t), (h), (o), (v)) + #define BUS_SPACE_BARRIER_READ 1 #define BUS_SPACE_BARRIER_WRITE 2 Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-09 14:25:17 UTC (rev 21091) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-09 15:27:13 UTC (rev 21092) @@ -81,8 +81,10 @@ extern spinlock __haiku_intr_spinlock; extern int __haiku_disable_interrupts(device_t dev); +extern void __haiku_reenable_interrupts(device_t dev); #define HAIKU_CHECK_DISABLE_INTERRUPTS __haiku_disable_interrupts +#define HAIKU_REENABLE_INTERRUPTS __haiku_reenable_interrupts #define NO_HAIKU_CHECK_DISABLE_INTERRUPTS() \ int HAIKU_CHECK_DISABLE_INTERRUPTS(device_t dev) { \ @@ -90,6 +92,9 @@ return -1; \ } +#define NO_HAIKU_REENABLE_INTERRUPTS() \ + void HAIKU_REENABLE_INTERRUPTS(device_t dev) {} + extern int __haiku_driver_requirements; enum { @@ -103,16 +108,26 @@ #define HAIKU_DRIVER_REQUIRES(flag) (__haiku_driver_requirements & (flag)) -#define HAIKU_INTR_REGISTER_ENTER(status) do { \ - status = disable_interrupts(); \ - acquire_spinlock(&__haiku_intr_spinlock); \ +#define HAIKU_INTR_REGISTER_STATE \ + cpu_status __haiku_cpu_state = 0 + +#define HAIKU_INTR_REGISTER_ENTER() do { \ + __haiku_cpu_state = disable_interrupts(); \ + acquire_spinlock(&__haiku_intr_spinlock); \ } while (0) -#define HAIKU_INTR_REGISTER_LEAVE(status) do { \ - release_spinlock(&__haiku_intr_spinlock); \ - restore_interrupts(status); \ +#define HAIKU_INTR_REGISTER_LEAVE() do { \ + release_spinlock(&__haiku_intr_spinlock); \ + restore_interrupts(__haiku_cpu_state); \ } while (0) +#define HAIKU_PROTECT_INTR_REGISTER(x) do { \ + HAIKU_INTR_REGISTER_STATE; \ + HAIKU_INTR_REGISTER_ENTER(); \ + x; \ + HAIKU_INTR_REGISTER_LEAVE(); \ +} while (0) + #define DEFINE_CLASS_0(name, driver, methods, size) \ driver_t driver = { #name, methods, size } Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h 2007-05-09 14:25:17 UTC (rev 21091) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h 2007-05-09 15:27:13 UTC (rev 21092) @@ -103,6 +103,11 @@ void m_cat(struct mbuf *m, struct mbuf *n); void m_copydata(const struct mbuf *m, int off, int len, caddr_t cp); +struct ifnet; +struct mbuf *m_devget(char *, int, int, struct ifnet *, + void (*)(char *, caddr_t, u_int)); +void m_copyback(struct mbuf *, int, int, caddr_t); + struct mbuf *m_get(int how, short type); struct mbuf *m_gethdr(int how, short type); void m_clget(struct mbuf *m, int how); @@ -120,6 +125,7 @@ #define MBUF_CHECKSLEEP(how) do { } while (0) #define MBTOM(how) (how) +extern int max_linkhdr; extern int max_protohdr; #include Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-09 14:25:17 UTC (rev 21091) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-09 15:27:13 UTC (rev 21092) @@ -314,6 +314,9 @@ if (area < 0) return NULL; + if (flags & M_ZERO) + memset(addr, 0, size); + driver_printf("(%s) addr = %p, area = %ld, size = %lu\n", name, addr, area, size); Modified: haiku/trunk/src/libs/compat/freebsd_network/fbsd_mbuf.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/fbsd_mbuf.c 2007-05-09 14:25:17 UTC (rev 21091) +++ haiku/trunk/src/libs/compat/freebsd_network/fbsd_mbuf.c 2007-05-09 15:27:13 UTC (rev 21092) @@ -404,3 +404,119 @@ #endif from->m_flags &= ~M_PKTHDR; } + +/* + * Routine to copy from device local memory into mbufs. + * Note that `off' argument is offset into first mbuf of target chain from + * which to begin copying the data to. + */ +struct mbuf * +m_devget(char *buf, int totlen, int off, struct ifnet *ifp, + void (*copy)(char *from, caddr_t to, u_int len)) +{ + struct mbuf *m; + struct mbuf *top = NULL, **mp = ⊤ + int len; + + if (off < 0 || off > MHLEN) + return (NULL); + + while (totlen > 0) { + if (top == NULL) { /* First one, must be PKTHDR */ + if (totlen + off >= MINCLSIZE) { + m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR); + len = MCLBYTES; + } else { + m = m_gethdr(M_DONTWAIT, MT_DATA); + len = MHLEN; + + /* Place initial small packet/header at end of mbuf */ + if (m && totlen + off + max_linkhdr <= MLEN) { + m->m_data += max_linkhdr; + len -= max_linkhdr; + } + } + if (m == NULL) + return NULL; + m->m_pkthdr.rcvif = ifp; + m->m_pkthdr.len = totlen; + } else { + if (totlen + off >= MINCLSIZE) { + m = m_getcl(M_DONTWAIT, MT_DATA, 0); + len = MCLBYTES; + } else { + m = m_get(M_DONTWAIT, MT_DATA); + len = MLEN; + } + if (m == NULL) { + m_freem(top); + return NULL; + } + } + if (off) { + m->m_data += off; + len -= off; + off = 0; + } + m->m_len = len = min(totlen, len); + if (copy) + copy(buf, mtod(m, caddr_t), (u_int)len); + else + bcopy(buf, mtod(m, caddr_t), (u_int)len); + buf += len; + *mp = m; + mp = &m->m_next; + totlen -= len; + } + return (top); +} + +/* + * Copy data from a buffer back into the indicated mbuf chain, + * starting "off" bytes from the beginning, extending the mbuf + * chain if necessary. + */ +void +m_copyback(struct mbuf *m0, int off, int len, caddr_t cp) +{ + int mlen; + struct mbuf *m = m0, *n; + int totlen = 0; + + if (m0 == NULL) + return; + while (off > (mlen = m->m_len)) { + off -= mlen; + totlen += mlen; + if (m->m_next == NULL) { + n = m_get(M_DONTWAIT, m->m_type); + if (n == NULL) + goto out; + bzero(mtod(n, caddr_t), MLEN); + n->m_len = min(MLEN, len + off); + m->m_next = n; + } + m = m->m_next; + } + while (len > 0) { + mlen = min (m->m_len - off, len); + bcopy(cp, off + mtod(m, caddr_t), (u_int)mlen); + cp += mlen; + len -= mlen; + mlen += off; + off = 0; + totlen += mlen; + if (len == 0) + break; + if (m->m_next == NULL) { + n = m_get(M_DONTWAIT, m->m_type); + if (n == NULL) + break; + n->m_len = min(MLEN, len); + m->m_next = n; + } + m = m->m_next; + } +out: if (((m = m0)->m_flags & M_PKTHDR) && (m->m_pkthdr.len < totlen)) + m->m_pkthdr.len = totlen; +} Modified: haiku/trunk/src/libs/compat/freebsd_network/mbuf.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/mbuf.c 2007-05-09 14:25:17 UTC (rev 21091) +++ haiku/trunk/src/libs/compat/freebsd_network/mbuf.c 2007-05-09 15:27:13 UTC (rev 21092) @@ -22,6 +22,7 @@ static object_cache *sMBufCache; static object_cache *sChunkCache; +int max_linkhdr = 16; int max_protohdr = 40 + 20; /* ip6 + tcp */ From hugosantos at mail.berlios.de Wed May 9 17:28:10 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 9 May 2007 17:28:10 +0200 Subject: [Haiku-commits] r21093 - in haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139: . pci Message-ID: <200705091528.l49FSAUX003179@sheep.berlios.de> Author: hugosantos Date: 2007-05-09 17:27:48 +0200 (Wed, 09 May 2007) New Revision: 21093 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21093&view=rev Added: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/glue.c haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/if_rl.c haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/if_rlreg.h Modified: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/Jamfile Log: added FreeBSD 6.2's if_rl (rtl 8139) driver. Mostly original source, just a minimal change to protect the interrupt mask register to more freely enable and disable device interrupts. This driver is still not working, MII support is left, should come soon. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/Jamfile 2007-05-09 15:27:13 UTC (rev 21092) +++ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/Jamfile 2007-05-09 15:27:48 UTC (rev 21093) @@ -55,4 +55,4 @@ # rtl8139.settings : # boot home config settings kernel drivers sample ; - +SubInclude HAIKU_TOP src add-ons kernel drivers network rtl8139 pci ; Added: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/Jamfile 2007-05-09 15:27:13 UTC (rev 21092) +++ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/Jamfile 2007-05-09 15:27:48 UTC (rev 21093) @@ -0,0 +1,15 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network rtl8139 pci ; + +UsePrivateHeaders kernel net ; + +UseHeaders [ FDirName $(SUBDIR) .. ] : true ; +UseHeaders [ FDirName $(HAIKU_TOP) src libs compat freebsd_network compat ] : true ; + +SubDirCcFlags [ FDefines _KERNEL=1 FBSD_DRIVER=1 ] ; + +KernelAddon rtl8139exp : + if_rl.c + glue.c + : libfreebsd_network.a + ; + Added: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/glue.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/glue.c 2007-05-09 15:27:13 UTC (rev 21092) +++ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/glue.c 2007-05-09 15:27:48 UTC (rev 21093) @@ -0,0 +1,23 @@ +#include + +#include + +HAIKU_FBSD_DRIVER_GLUE(rtl8139exp, rl, pci); +HAIKU_DRIVER_REQUIREMENTS(0); + +int +HAIKU_CHECK_DISABLE_INTERRUPTS(device_t dev) { + struct rl_softc *sc = device_get_softc(dev); + + HAIKU_PROTECT_INTR_REGISTER(CSR_WRITE_2(sc, RL_IMR, 0)); + + /* we don't read the status register, so we just assume it was for us. */ + return 1; +} + +void +HAIKU_REENABLE_INTERRUPTS(device_t dev) +{ + struct rl_softc *sc = device_get_softc(dev); + HAIKU_PROTECT_INTR_REGISTER(CSR_WRITE_2(sc, RL_IMR, RL_INTRS)); +} Added: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/if_rl.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/if_rl.c 2007-05-09 15:27:13 UTC (rev 21092) +++ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/if_rl.c 2007-05-09 15:27:48 UTC (rev 21093) @@ -0,0 +1,1808 @@ +/*- + * Copyright (c) 1997, 1998 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/sys/pci/if_rl.c,v 1.152.2.6 2006/10/13 07:39:25 glebius Exp $"); + +/* + * RealTek 8129/8139 PCI NIC driver + * + * Supports several extremely cheap PCI 10/100 adapters based on + * the RealTek chipset. Datasheets can be obtained from + * www.realtek.com.tw. + * + * Written by Bill Paul + * Electrical Engineering Department + * Columbia University, New York City + */ +/* + * The RealTek 8139 PCI NIC redefines the meaning of 'low end.' This is + * probably the worst PCI ethernet controller ever made, with the possible + * exception of the FEAST chip made by SMC. The 8139 supports bus-master + * DMA, but it has a terrible interface that nullifies any performance + * gains that bus-master DMA usually offers. + * + * For transmission, the chip offers a series of four TX descriptor + * registers. Each transmit frame must be in a contiguous buffer, aligned + * on a longword (32-bit) boundary. This means we almost always have to + * do mbuf copies in order to transmit a frame, except in the unlikely + * case where a) the packet fits into a single mbuf, and b) the packet + * is 32-bit aligned within the mbuf's data area. The presence of only + * four descriptor registers means that we can never have more than four + * packets queued for transmission at any one time. + * + * Reception is not much better. The driver has to allocate a single large + * buffer area (up to 64K in size) into which the chip will DMA received + * frames. Because we don't know where within this region received packets + * will begin or end, we have no choice but to copy data from the buffer + * area into mbufs in order to pass the packets up to the higher protocol + * levels. + * + * It's impossible given this rotten design to really achieve decent + * performance at 100Mbps, unless you happen to have a 400Mhz PII or + * some equally overmuscled CPU to drive it. + * + * On the bright side, the 8139 does have a built-in PHY, although + * rather than using an MDIO serial interface like most other NICs, the + * PHY registers are directly accessible through the 8139's register + * space. The 8139 supports autonegotiation, as well as a 64-bit multicast + * filter. + * + * The 8129 chip is an older version of the 8139 that uses an external PHY + * chip. The 8129 has a serial MDIO interface for accessing the MII where + * the 8139 lets you directly access the on-board PHY registers. We need + * to select which interface to use depending on the chip type. + */ + +#ifdef HAVE_KERNEL_OPTION_HEADERS +#include "opt_device_polling.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include + +MODULE_DEPEND(rl, pci, 1, 1, 1); +MODULE_DEPEND(rl, ether, 1, 1, 1); +MODULE_DEPEND(rl, miibus, 1, 1, 1); + +/* "controller miibus0" required. See GENERIC if you get errors here. */ +#include "miibus_if.h" + +/* + * Default to using PIO access for this driver. On SMP systems, + * there appear to be problems with memory mapped mode: it looks like + * doing too many memory mapped access back to back in rapid succession + * can hang the bus. I'm inclined to blame this on crummy design/construction + * on the part of RealTek. Memory mapped mode does appear to work on + * uniprocessor systems though. + */ +#define RL_USEIOSPACE + +#include + +/* + * Various supported device vendors/types and their names. + */ +static struct rl_type rl_devs[] = { + { RT_VENDORID, RT_DEVICEID_8129, RL_8129, + "RealTek 8129 10/100BaseTX" }, + { RT_VENDORID, RT_DEVICEID_8139, RL_8139, + "RealTek 8139 10/100BaseTX" }, + { RT_VENDORID, RT_DEVICEID_8138, RL_8139, + "RealTek 8139 10/100BaseTX CardBus" }, + { RT_VENDORID, RT_DEVICEID_8100, RL_8139, + "RealTek 8100 10/100BaseTX" }, + { ACCTON_VENDORID, ACCTON_DEVICEID_5030, RL_8139, + "Accton MPX 5030/5038 10/100BaseTX" }, + { DELTA_VENDORID, DELTA_DEVICEID_8139, RL_8139, + "Delta Electronics 8139 10/100BaseTX" }, + { ADDTRON_VENDORID, ADDTRON_DEVICEID_8139, RL_8139, + "Addtron Technolgy 8139 10/100BaseTX" }, + { DLINK_VENDORID, DLINK_DEVICEID_530TXPLUS, RL_8139, + "D-Link DFE-530TX+ 10/100BaseTX" }, + { DLINK_VENDORID, DLINK_DEVICEID_690TXD, RL_8139, + "D-Link DFE-690TXD 10/100BaseTX" }, + { NORTEL_VENDORID, ACCTON_DEVICEID_5030, RL_8139, + "Nortel Networks 10/100BaseTX" }, + { COREGA_VENDORID, COREGA_DEVICEID_FETHERCBTXD, RL_8139, + "Corega FEther CB-TXD" }, + { COREGA_VENDORID, COREGA_DEVICEID_FETHERIICBTXD, RL_8139, + "Corega FEtherII CB-TXD" }, + { PEPPERCON_VENDORID, PEPPERCON_DEVICEID_ROLF, RL_8139, + "Peppercon AG ROL-F" }, + { PLANEX_VENDORID, PLANEX_DEVICEID_FNW3800TX, RL_8139, + "Planex FNW-3800-TX" }, + { CP_VENDORID, RT_DEVICEID_8139, RL_8139, + "Compaq HNE-300" }, + { LEVEL1_VENDORID, LEVEL1_DEVICEID_FPC0106TX, RL_8139, + "LevelOne FPC-0106TX" }, + { EDIMAX_VENDORID, EDIMAX_DEVICEID_EP4103DL, RL_8139, + "Edimax EP-4103DL CardBus" }, + { 0, 0, 0, NULL } +}; + +static int rl_attach(device_t); +static int rl_detach(device_t); +static void rl_dma_map_rxbuf(void *, bus_dma_segment_t *, int, int); +static void rl_dma_map_txbuf(void *, bus_dma_segment_t *, int, int); +static void rl_eeprom_putbyte(struct rl_softc *, int); +static void rl_eeprom_getword(struct rl_softc *, int, uint16_t *); +static int rl_encap(struct rl_softc *, struct mbuf * ); +static int rl_list_tx_init(struct rl_softc *); +static int rl_ifmedia_upd(struct ifnet *); +static void rl_ifmedia_sts(struct ifnet *, struct ifmediareq *); +static int rl_ioctl(struct ifnet *, u_long, caddr_t); +static void rl_intr(void *); +static void rl_init(void *); +static void rl_init_locked(struct rl_softc *sc); +static void rl_mii_send(struct rl_softc *, uint32_t, int); +static void rl_mii_sync(struct rl_softc *); +static int rl_mii_readreg(struct rl_softc *, struct rl_mii_frame *); +static int rl_mii_writereg(struct rl_softc *, struct rl_mii_frame *); +static int rl_miibus_readreg(device_t, int, int); +static void rl_miibus_statchg(device_t); +static int rl_miibus_writereg(device_t, int, int, int); +#ifdef DEVICE_POLLING +static void rl_poll(struct ifnet *ifp, enum poll_cmd cmd, int count); +static void rl_poll_locked(struct ifnet *ifp, enum poll_cmd cmd, int count); +#endif +static int rl_probe(device_t); +static void rl_read_eeprom(struct rl_softc *, uint8_t *, int, int, int); +static void rl_reset(struct rl_softc *); +static int rl_resume(device_t); +static void rl_rxeof(struct rl_softc *); +static void rl_setmulti(struct rl_softc *); +static void rl_shutdown(device_t); +static void rl_start(struct ifnet *); +static void rl_start_locked(struct ifnet *); +static void rl_stop(struct rl_softc *); +static int rl_suspend(device_t); +static void rl_tick(void *); +static void rl_txeof(struct rl_softc *); +static void rl_watchdog(struct ifnet *); + +#ifdef RL_USEIOSPACE +#define RL_RES SYS_RES_IOPORT +#define RL_RID RL_PCI_LOIO +#else +#define RL_RES SYS_RES_MEMORY +#define RL_RID RL_PCI_LOMEM +#endif + +static device_method_t rl_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, rl_probe), + DEVMETHOD(device_attach, rl_attach), + DEVMETHOD(device_detach, rl_detach), + DEVMETHOD(device_suspend, rl_suspend), + DEVMETHOD(device_resume, rl_resume), + DEVMETHOD(device_shutdown, rl_shutdown), + + /* bus interface */ + DEVMETHOD(bus_print_child, bus_generic_print_child), + DEVMETHOD(bus_driver_added, bus_generic_driver_added), + + /* MII interface */ + DEVMETHOD(miibus_readreg, rl_miibus_readreg), + DEVMETHOD(miibus_writereg, rl_miibus_writereg), + DEVMETHOD(miibus_statchg, rl_miibus_statchg), + + { 0, 0 } +}; + +static driver_t rl_driver = { + "rl", + rl_methods, + sizeof(struct rl_softc) +}; + +static devclass_t rl_devclass; + +DRIVER_MODULE(rl, pci, rl_driver, rl_devclass, 0, 0); +DRIVER_MODULE(rl, cardbus, rl_driver, rl_devclass, 0, 0); +DRIVER_MODULE(miibus, rl, miibus_driver, miibus_devclass, 0, 0); + +#define EE_SET(x) \ + CSR_WRITE_1(sc, RL_EECMD, \ + CSR_READ_1(sc, RL_EECMD) | x) + +#define EE_CLR(x) \ + CSR_WRITE_1(sc, RL_EECMD, \ + CSR_READ_1(sc, RL_EECMD) & ~x) + +static void +rl_dma_map_rxbuf(void *arg, bus_dma_segment_t *segs, int nseg, int error) +{ + struct rl_softc *sc = arg; + + CSR_WRITE_4(sc, RL_RXADDR, segs->ds_addr & 0xFFFFFFFF); +} + +static void +rl_dma_map_txbuf(void *arg, bus_dma_segment_t *segs, int nseg, int error) +{ + struct rl_softc *sc = arg; + + CSR_WRITE_4(sc, RL_CUR_TXADDR(sc), segs->ds_addr & 0xFFFFFFFF); +} + +/* + * Send a read command and address to the EEPROM, check for ACK. + */ +static void +rl_eeprom_putbyte(struct rl_softc *sc, int addr) +{ + register int d, i; + + d = addr | sc->rl_eecmd_read; + + /* + * Feed in each bit and strobe the clock. + */ + for (i = 0x400; i; i >>= 1) { + if (d & i) { + EE_SET(RL_EE_DATAIN); + } else { + EE_CLR(RL_EE_DATAIN); + } + DELAY(100); + EE_SET(RL_EE_CLK); + DELAY(150); + EE_CLR(RL_EE_CLK); + DELAY(100); + } +} + +/* + * Read a word of data stored in the EEPROM at address 'addr.' + */ +static void +rl_eeprom_getword(struct rl_softc *sc, int addr, uint16_t *dest) +{ + register int i; + uint16_t word = 0; + + /* Enter EEPROM access mode. */ + CSR_WRITE_1(sc, RL_EECMD, RL_EEMODE_PROGRAM|RL_EE_SEL); + + /* + * Send address of word we want to read. + */ + rl_eeprom_putbyte(sc, addr); + + CSR_WRITE_1(sc, RL_EECMD, RL_EEMODE_PROGRAM|RL_EE_SEL); + + /* + * Start reading bits from EEPROM. + */ + for (i = 0x8000; i; i >>= 1) { + EE_SET(RL_EE_CLK); + DELAY(100); + if (CSR_READ_1(sc, RL_EECMD) & RL_EE_DATAOUT) + word |= i; + EE_CLR(RL_EE_CLK); + DELAY(100); + } + + /* Turn off EEPROM access mode. */ + CSR_WRITE_1(sc, RL_EECMD, RL_EEMODE_OFF); + + *dest = word; +} + +/* + * Read a sequence of words from the EEPROM. + */ +static void +rl_read_eeprom(struct rl_softc *sc, uint8_t *dest, int off, int cnt, int swap) +{ + int i; + uint16_t word = 0, *ptr; + + for (i = 0; i < cnt; i++) { + rl_eeprom_getword(sc, off + i, &word); + ptr = (uint16_t *)(dest + (i * 2)); + if (swap) + *ptr = ntohs(word); + else + *ptr = word; + } +} + +/* + * MII access routines are provided for the 8129, which + * doesn't have a built-in PHY. For the 8139, we fake things + * up by diverting rl_phy_readreg()/rl_phy_writereg() to the + * direct access PHY registers. + */ +#define MII_SET(x) \ + CSR_WRITE_1(sc, RL_MII, \ + CSR_READ_1(sc, RL_MII) | (x)) + +#define MII_CLR(x) \ + CSR_WRITE_1(sc, RL_MII, \ + CSR_READ_1(sc, RL_MII) & ~(x)) + +/* + * Sync the PHYs by setting data bit and strobing the clock 32 times. + */ +static void +rl_mii_sync(struct rl_softc *sc) +{ + register int i; + + MII_SET(RL_MII_DIR|RL_MII_DATAOUT); + + for (i = 0; i < 32; i++) { + MII_SET(RL_MII_CLK); + DELAY(1); + MII_CLR(RL_MII_CLK); + DELAY(1); + } +} + +/* + * Clock a series of bits through the MII. + */ +static void +rl_mii_send(struct rl_softc *sc, uint32_t bits, int cnt) +{ + int i; + + MII_CLR(RL_MII_CLK); + + for (i = (0x1 << (cnt - 1)); i; i >>= 1) { + if (bits & i) { + MII_SET(RL_MII_DATAOUT); + } else { + MII_CLR(RL_MII_DATAOUT); + } + DELAY(1); + MII_CLR(RL_MII_CLK); + DELAY(1); + MII_SET(RL_MII_CLK); + } +} + +/* + * Read an PHY register through the MII. + */ +static int +rl_mii_readreg(struct rl_softc *sc, struct rl_mii_frame *frame) +{ + int i, ack; + + /* Set up frame for RX. */ + frame->mii_stdelim = RL_MII_STARTDELIM; + frame->mii_opcode = RL_MII_READOP; + frame->mii_turnaround = 0; + frame->mii_data = 0; + + CSR_WRITE_2(sc, RL_MII, 0); + + /* Turn on data xmit. */ + MII_SET(RL_MII_DIR); + + rl_mii_sync(sc); + + /* Send command/address info. */ + rl_mii_send(sc, frame->mii_stdelim, 2); + rl_mii_send(sc, frame->mii_opcode, 2); + rl_mii_send(sc, frame->mii_phyaddr, 5); + rl_mii_send(sc, frame->mii_regaddr, 5); + + /* Idle bit */ + MII_CLR((RL_MII_CLK|RL_MII_DATAOUT)); + DELAY(1); + MII_SET(RL_MII_CLK); + DELAY(1); + + /* Turn off xmit. */ + MII_CLR(RL_MII_DIR); + + /* Check for ack */ + MII_CLR(RL_MII_CLK); + DELAY(1); + ack = CSR_READ_2(sc, RL_MII) & RL_MII_DATAIN; + MII_SET(RL_MII_CLK); + DELAY(1); + + /* + * Now try reading data bits. If the ack failed, we still + * need to clock through 16 cycles to keep the PHY(s) in sync. + */ + if (ack) { + for(i = 0; i < 16; i++) { + MII_CLR(RL_MII_CLK); + DELAY(1); + MII_SET(RL_MII_CLK); + DELAY(1); + } + goto fail; + } + + for (i = 0x8000; i; i >>= 1) { + MII_CLR(RL_MII_CLK); + DELAY(1); + if (!ack) { + if (CSR_READ_2(sc, RL_MII) & RL_MII_DATAIN) + frame->mii_data |= i; + DELAY(1); + } + MII_SET(RL_MII_CLK); + DELAY(1); + } + +fail: + MII_CLR(RL_MII_CLK); + DELAY(1); + MII_SET(RL_MII_CLK); + DELAY(1); + + return (ack ? 1 : 0); +} + +/* + * Write to a PHY register through the MII. + */ +static int +rl_mii_writereg(struct rl_softc *sc, struct rl_mii_frame *frame) +{ + + /* Set up frame for TX. */ + frame->mii_stdelim = RL_MII_STARTDELIM; + frame->mii_opcode = RL_MII_WRITEOP; + frame->mii_turnaround = RL_MII_TURNAROUND; + + /* Turn on data output. */ + MII_SET(RL_MII_DIR); + + rl_mii_sync(sc); + + rl_mii_send(sc, frame->mii_stdelim, 2); + rl_mii_send(sc, frame->mii_opcode, 2); + rl_mii_send(sc, frame->mii_phyaddr, 5); + rl_mii_send(sc, frame->mii_regaddr, 5); + rl_mii_send(sc, frame->mii_turnaround, 2); + rl_mii_send(sc, frame->mii_data, 16); + + /* Idle bit. */ + MII_SET(RL_MII_CLK); + DELAY(1); + MII_CLR(RL_MII_CLK); + DELAY(1); + + /* Turn off xmit. */ + MII_CLR(RL_MII_DIR); + + return (0); +} + +static int +rl_miibus_readreg(device_t dev, int phy, int reg) +{ + struct rl_softc *sc; + struct rl_mii_frame frame; + uint16_t rval = 0; + uint16_t rl8139_reg = 0; + + sc = device_get_softc(dev); + + if (sc->rl_type == RL_8139) { + /* Pretend the internal PHY is only at address 0 */ + if (phy) { + return (0); + } + switch (reg) { + case MII_BMCR: + rl8139_reg = RL_BMCR; + break; + case MII_BMSR: + rl8139_reg = RL_BMSR; + break; + case MII_ANAR: + rl8139_reg = RL_ANAR; + break; + case MII_ANER: + rl8139_reg = RL_ANER; + break; + case MII_ANLPAR: + rl8139_reg = RL_LPAR; + break; + case MII_PHYIDR1: + case MII_PHYIDR2: + return (0); + /* + * Allow the rlphy driver to read the media status + * register. If we have a link partner which does not + * support NWAY, this is the register which will tell + * us the results of parallel detection. + */ + case RL_MEDIASTAT: + rval = CSR_READ_1(sc, RL_MEDIASTAT); + return (rval); + default: + device_printf(sc->rl_dev, "bad phy register\n"); + return (0); + } + rval = CSR_READ_2(sc, rl8139_reg); + return (rval); + } + + bzero((char *)&frame, sizeof(frame)); + frame.mii_phyaddr = phy; + frame.mii_regaddr = reg; + rl_mii_readreg(sc, &frame); + + return (frame.mii_data); +} + +static int +rl_miibus_writereg(device_t dev, int phy, int reg, int data) +{ + struct rl_softc *sc; + struct rl_mii_frame frame; + uint16_t rl8139_reg = 0; + + sc = device_get_softc(dev); + + if (sc->rl_type == RL_8139) { + /* Pretend the internal PHY is only at address 0 */ + if (phy) { + return (0); + } + switch (reg) { + case MII_BMCR: + rl8139_reg = RL_BMCR; + break; + case MII_BMSR: + rl8139_reg = RL_BMSR; + break; + case MII_ANAR: + rl8139_reg = RL_ANAR; + break; + case MII_ANER: + rl8139_reg = RL_ANER; + break; + case MII_ANLPAR: + rl8139_reg = RL_LPAR; + break; + case MII_PHYIDR1: + case MII_PHYIDR2: + return (0); + break; + default: + device_printf(sc->rl_dev, "bad phy register\n"); + return (0); + } + CSR_WRITE_2(sc, rl8139_reg, data); + return (0); + } + + bzero((char *)&frame, sizeof(frame)); + frame.mii_phyaddr = phy; + frame.mii_regaddr = reg; + frame.mii_data = data; + rl_mii_writereg(sc, &frame); + + return (0); +} + +static void +rl_miibus_statchg(device_t dev) +{ +} + +/* + * Program the 64-bit multicast hash filter. + */ +static void +rl_setmulti(struct rl_softc *sc) +{ + struct ifnet *ifp = sc->rl_ifp; + int h = 0; + uint32_t hashes[2] = { 0, 0 }; + struct ifmultiaddr *ifma; + uint32_t rxfilt; + int mcnt = 0; + + RL_LOCK_ASSERT(sc); + + rxfilt = CSR_READ_4(sc, RL_RXCFG); + + if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { + rxfilt |= RL_RXCFG_RX_MULTI; + CSR_WRITE_4(sc, RL_RXCFG, rxfilt); + CSR_WRITE_4(sc, RL_MAR0, 0xFFFFFFFF); + CSR_WRITE_4(sc, RL_MAR4, 0xFFFFFFFF); + return; + } + + /* first, zot all the existing hash bits */ + CSR_WRITE_4(sc, RL_MAR0, 0); + CSR_WRITE_4(sc, RL_MAR4, 0); + + /* now program new ones */ + IF_ADDR_LOCK(ifp); + TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { + if (ifma->ifma_addr->sa_family != AF_LINK) + continue; + h = ether_crc32_be(LLADDR((struct sockaddr_dl *) + ifma->ifma_addr), ETHER_ADDR_LEN) >> 26; + if (h < 32) + hashes[0] |= (1 << h); + else + hashes[1] |= (1 << (h - 32)); + mcnt++; + } + IF_ADDR_UNLOCK(ifp); + + if (mcnt) + rxfilt |= RL_RXCFG_RX_MULTI; + else + rxfilt &= ~RL_RXCFG_RX_MULTI; + + CSR_WRITE_4(sc, RL_RXCFG, rxfilt); + CSR_WRITE_4(sc, RL_MAR0, hashes[0]); + CSR_WRITE_4(sc, RL_MAR4, hashes[1]); +} + +static void +rl_reset(struct rl_softc *sc) +{ + register int i; + + RL_LOCK_ASSERT(sc); + + CSR_WRITE_1(sc, RL_COMMAND, RL_CMD_RESET); + + for (i = 0; i < RL_TIMEOUT; i++) { + DELAY(10); + if (!(CSR_READ_1(sc, RL_COMMAND) & RL_CMD_RESET)) + break; + } + if (i == RL_TIMEOUT) + device_printf(sc->rl_dev, "reset never completed!\n"); +} + +/* + * Probe for a RealTek 8129/8139 chip. Check the PCI vendor and device + * IDs against our list and return a device name if we find a match. + */ +static int +rl_probe(device_t dev) +{ + struct rl_softc *sc; + struct rl_type *t = rl_devs; + int rid; + uint32_t hwrev; + + sc = device_get_softc(dev); + + while (t->rl_name != NULL) { + if ((pci_get_vendor(dev) == t->rl_vid) && + (pci_get_device(dev) == t->rl_did)) { + /* + * Temporarily map the I/O space + * so we can read the chip ID register. + */ + rid = RL_RID; + sc->rl_res = bus_alloc_resource_any(dev, RL_RES, &rid, + RF_ACTIVE); + if (sc->rl_res == NULL) { + device_printf(dev, + "couldn't map ports/memory\n"); + return (ENXIO); + } + sc->rl_btag = rman_get_bustag(sc->rl_res); + sc->rl_bhandle = rman_get_bushandle(sc->rl_res); + + hwrev = CSR_READ_4(sc, RL_TXCFG) & RL_TXCFG_HWREV; + bus_release_resource(dev, RL_RES, RL_RID, sc->rl_res); + + /* Don't attach to 8139C+ or 8169/8110 chips. */ + if (hwrev == RL_HWREV_8139CPLUS || + (hwrev == RL_HWREV_8169 && + t->rl_did == RT_DEVICEID_8169) || + hwrev == RL_HWREV_8169S || + hwrev == RL_HWREV_8110S) { + t++; + continue; + } + + device_set_desc(dev, t->rl_name); + return (BUS_PROBE_DEFAULT); + } + t++; + } + + return (ENXIO); +} + +/* + * Attach the interface. Allocate softc structures, do ifmedia + * setup and ethernet/BPF attach. + */ +static int +rl_attach(device_t dev) +{ + uint8_t eaddr[ETHER_ADDR_LEN]; + uint16_t as[3]; + struct ifnet *ifp; + struct rl_softc *sc; + struct rl_type *t; + int error = 0, i, rid; + int unit; + uint16_t rl_did = 0; + + sc = device_get_softc(dev); + unit = device_get_unit(dev); + sc->rl_dev = dev; + + mtx_init(&sc->rl_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, + MTX_DEF); + callout_init_mtx(&sc->rl_stat_callout, &sc->rl_mtx, 0); + + pci_enable_busmaster(dev); + + /* Map control/status registers. */ + rid = RL_RID; + sc->rl_res = bus_alloc_resource_any(dev, RL_RES, &rid, RF_ACTIVE); + + if (sc->rl_res == NULL) { + device_printf(dev, "couldn't map ports/memory\n"); + error = ENXIO; + goto fail; + } + +#ifdef notdef + /* + * Detect the Realtek 8139B. For some reason, this chip is very + * unstable when left to autoselect the media + * The best workaround is to set the device to the required + * media type or to set it to the 10 Meg speed. + */ + if ((rman_get_end(sc->rl_res) - rman_get_start(sc->rl_res)) == 0xFF) + device_printf(dev, +"Realtek 8139B detected. Warning, this may be unstable in autoselect mode\n"); +#endif + + sc->rl_btag = rman_get_bustag(sc->rl_res); + sc->rl_bhandle = rman_get_bushandle(sc->rl_res); + + /* Allocate interrupt */ + rid = 0; + sc->rl_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, + RF_SHAREABLE | RF_ACTIVE); + + if (sc->rl_irq == NULL) { + device_printf(dev, "couldn't map interrupt\n"); + error = ENXIO; + goto fail; + } + + /* + * Reset the adapter. Only take the lock here as it's needed in + * order to call rl_reset(). + */ + RL_LOCK(sc); + rl_reset(sc); + RL_UNLOCK(sc); + + sc->rl_eecmd_read = RL_EECMD_READ_6BIT; + rl_read_eeprom(sc, (uint8_t *)&rl_did, 0, 1, 0); + if (rl_did != 0x8129) + sc->rl_eecmd_read = RL_EECMD_READ_8BIT; + + /* + * Get station address from the EEPROM. + */ + rl_read_eeprom(sc, (uint8_t *)as, RL_EE_EADDR, 3, 0); + for (i = 0; i < 3; i++) { + eaddr[(i * 2) + 0] = as[i] & 0xff; + eaddr[(i * 2) + 1] = as[i] >> 8; + } + + /* + * Now read the exact device type from the EEPROM to find + * out if it's an 8129 or 8139. + */ + rl_read_eeprom(sc, (uint8_t *)&rl_did, RL_EE_PCI_DID, 1, 0); + + t = rl_devs; + sc->rl_type = 0; + while(t->rl_name != NULL) { + if (rl_did == t->rl_did) { + sc->rl_type = t->rl_basetype; + break; + } + t++; + } + + if (sc->rl_type == 0) { + device_printf(dev, "unknown device ID: %x\n", rl_did); + error = ENXIO; + goto fail; + } + + /* + * Allocate the parent bus DMA tag appropriate for PCI. + */ +#define RL_NSEG_NEW 32 + error = bus_dma_tag_create(NULL, /* parent */ + 1, 0, /* alignment, boundary */ + BUS_SPACE_MAXADDR_32BIT,/* lowaddr */ + BUS_SPACE_MAXADDR, /* highaddr */ + NULL, NULL, /* filter, filterarg */ + MAXBSIZE, RL_NSEG_NEW, /* maxsize, nsegments */ + BUS_SPACE_MAXSIZE_32BIT,/* maxsegsize */ + BUS_DMA_ALLOCNOW, /* flags */ + NULL, NULL, /* lockfunc, lockarg */ + &sc->rl_parent_tag); + if (error) + goto fail; + + /* + * Now allocate a tag for the DMA descriptor lists. + * All of our lists are allocated as a contiguous block + * of memory. + */ + error = bus_dma_tag_create(sc->rl_parent_tag, /* parent */ + 1, 0, /* alignment, boundary */ + BUS_SPACE_MAXADDR, /* lowaddr */ + BUS_SPACE_MAXADDR, /* highaddr */ + NULL, NULL, /* filter, filterarg */ + RL_RXBUFLEN + 1518, 1, /* maxsize,nsegments */ + BUS_SPACE_MAXSIZE_32BIT,/* maxsegsize */ + BUS_DMA_ALLOCNOW, /* flags */ + NULL, NULL, /* lockfunc, lockarg */ + &sc->rl_tag); + if (error) + goto fail; + + /* + * Now allocate a chunk of DMA-able memory based on the + * tag we just created. + */ + error = bus_dmamem_alloc(sc->rl_tag, + (void **)&sc->rl_cdata.rl_rx_buf, BUS_DMA_NOWAIT | BUS_DMA_ZERO, + &sc->rl_cdata.rl_rx_dmamap); + if (error) { + device_printf(dev, "no memory for list buffers!\n"); + bus_dma_tag_destroy(sc->rl_tag); + sc->rl_tag = NULL; + goto fail; + } + + /* Leave a few bytes before the start of the RX ring buffer. */ + sc->rl_cdata.rl_rx_buf_ptr = sc->rl_cdata.rl_rx_buf; [... truncated: 1863 lines follow ...] From revol at free.fr Wed May 9 17:33:14 2007 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Wed, 09 May 2007 17:33:14 +0200 CEST Subject: [Haiku-commits] =?windows-1252?q?r21091_-_haiku/trunk/src/add-ons?= =?windows-1252?q?/kernel/drivers/network?= In-Reply-To: <200705091425.l49EPHsR027706@sheep.berlios.de> Message-ID: <1126643416-BeMail@laptop> > Remove now unused fxp directories. BTW: is there a reason to have > those > drivers under "haiku_name/dev/freebsd_name/*" instead of directly > under > "haiku_name/*"? > Axel doesn't like Unix shrt nams ? la bcm :) Fran?ois From lexaeusxiii at gmail.com Wed May 9 17:34:07 2007 From: lexaeusxiii at gmail.com (Kyle) Date: Wed, 9 May 2007 11:34:07 -0400 Subject: [Haiku-commits] r21087 - in haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000: . dev dev/em In-Reply-To: <9c46321e0705090732i51533758w5b6e96af3b07a6e5@mail.gmail.com> References: <200705091320.l49DKfZC022103@sheep.berlios.de> <9c46321e0705090652u4cf1fe36t8740b65f4708e86d@mail.gmail.com> <855a5f230705090729i2612e38p128df3a52018a6bd@mail.gmail.com> <9c46321e0705090732i51533758w5b6e96af3b07a6e5@mail.gmail.com> Message-ID: <855a5f230705090834u682b122awd0b7e29bb94cf57f@mail.gmail.com> Ah ok, that's what I have then, not like I see much use out of it since I have a 100mbit network to begin with. On 5/9/07, Hugo Santos wrote: > > There is a Realtek 8169, that is a gigabit device, Realtek 8139 is > 100mbit. > > Hugo > > On 5/9/07, Lexaeus XIII wrote: > > Hmm, I can't remember if my secondary ethernet card uses the rtl8139 > driver > > or the rtl8169 driver, does the latter even exist? I can't check atm > because > > I'm in class. If it uses rtl8139 I'll be happy to test out the driver if > > it's implemented. > > > > > > On 5/9/07, Hugo Santos wrote: > > > Thanks for the pointer, at least locally it seems to be affecting the > > behavior. > > > > > > Hugo > > > > > > On 5/9/07, J?r?me Duval wrote: > > > > Hi Hugo, > > > > > > > > 2007/5/9, hugosantos at mail.berlios.de : > > > > > --- > > haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/Jamfile > > 2007-05-09 13:17:19 UTC (rev 21086) > > > > > +++ > > haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/Jamfile > > 2007-05-09 13:20:14 UTC (rev 21087) > > > > > @@ -1,5 +1,7 @@ > > > > > SubDir HAIKU_TOP src add-ons kernel drivers network ipro1000 ; > > > > > > > > > > +SubInclude HAIKU_TOP src add-ons kernel drivers network ipro1000 > dev > > ; > > > > > + > > > > > SetSubDirSupportedPlatformsBeOSCompatible ; > > > > > > > > > > # set some additional flags > > > > > > > > > > > > > > > > > I could be wrong, but I thought it was better to put the SubInclude > > > > rule invocations at the bottom of Jamfiles. > > > > > > > > Bye, > > > > J?r?me > > > > _______________________________________________ > > > > Haiku-commits mailing list > > > > Haiku-commits at lists.berlios.de > > > > https://lists.berlios.de/mailman/listinfo/haiku-commits > > > > > > > _______________________________________________ > > > Haiku-commits mailing list > > > Haiku-commits at lists.berlios.de > > > https://lists.berlios.de/mailman/listinfo/haiku-commits > > > > > > > > > _______________________________________________ > > Haiku-commits mailing list > > Haiku-commits at lists.berlios.de > > https://lists.berlios.de/mailman/listinfo/haiku-commits > > > > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hugosantos at mail.berlios.de Wed May 9 21:36:01 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 9 May 2007 21:36:01 +0200 Subject: [Haiku-commits] r21094 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/sys Message-ID: <200705091936.l49Ja1Ga007838@sheep.berlios.de> Author: hugosantos Date: 2007-05-09 21:35:38 +0200 (Wed, 09 May 2007) New Revision: 21094 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21094&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/device.h haiku/trunk/src/libs/compat/freebsd_network/if.c Log: freebsd compat. layer: split device structure to handle for miibus devices, added a new network_device. Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-09 15:27:48 UTC (rev 21093) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-09 19:35:38 UTC (rev 21094) @@ -93,6 +93,7 @@ int device_printf(device_t dev, const char *, ...) __printflike(2, 3); void device_set_desc(device_t dev, const char *desc); void device_set_desc_copy(device_t dev, const char *desc); +const char *device_get_desc(device_t dev); device_t device_add_child(device_t dev, const char *name, int unit); int device_delete_child(device_t dev, device_t child); Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-09 15:27:48 UTC (rev 21093) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-09 19:35:38 UTC (rev 21094) @@ -52,33 +52,42 @@ void _fbsd_uninit_driver(driver_t *); extern const char gDriverName[]; +driver_t *__haiku_get_miibus_driver(void); /* we define the driver methods with HAIKU_FBSD_DRIVER_GLUE to * force the rest of the stuff to be linked back with the driver. * While gcc 2.95 packs everything from the static library onto * the final binary, gcc 4.x rightfuly doesn't. */ -#define HAIKU_FBSD_DRIVER_GLUE(publicname, name, busname) \ - extern char *gDevNameList[]; \ - extern device_hooks gDeviceHooks; \ - extern driver_t *DRIVER_MODULE_NAME(name, busname); \ - const char gDriverName[] = #publicname; \ - int32 api_version = B_CUR_DRIVER_API_VERSION; \ - status_t init_hardware() \ - { \ - return _fbsd_init_hardware(DRIVER_MODULE_NAME(name, busname)); \ - } \ - status_t init_driver() \ - { \ - return _fbsd_init_driver(DRIVER_MODULE_NAME(name, busname)); \ - } \ - void uninit_driver() \ - { \ - _fbsd_uninit_driver(DRIVER_MODULE_NAME(name, busname)); \ - } \ - const char **publish_devices() { return (const char **)gDevNameList; } \ - device_hooks *find_device(const char *name) { return &gDeviceHooks; } +#define HAIKU_FBSD_DRIVER_GLUE(publicname, name, busname) \ + extern const char *gDevNameList[]; \ + extern device_hooks gDeviceHooks; \ + extern driver_t *DRIVER_MODULE_NAME(name, busname); \ + const char gDriverName[] = #publicname; \ + int32 api_version = B_CUR_DRIVER_API_VERSION; \ + status_t init_hardware() \ + { \ + return _fbsd_init_hardware(DRIVER_MODULE_NAME(name, busname)); \ + } \ + status_t init_driver() \ + { \ + return _fbsd_init_driver(DRIVER_MODULE_NAME(name, busname)); \ + } \ + void uninit_driver() \ + { _fbsd_uninit_driver(DRIVER_MODULE_NAME(name, busname)); } \ + const char **publish_devices() \ + { return gDevNameList; } \ + device_hooks *find_device(const char *name) \ + { return &gDeviceHooks; } +#define HAIKU_FBSD_MII_DRIVER(name) \ + driver_t *__haiku_get_miibus_driver(device_t dev) \ + { return DRIVER_MODULE_NAME(name, miibus); } + +#define HAIKU_NO_FBSD_MII_DRIVER() \ + driver_t *__haiku_get_miibus_driver(device_t dev) \ + { return NULL; } + extern spinlock __haiku_intr_spinlock; extern int __haiku_disable_interrupts(device_t dev); extern void __haiku_reenable_interrupts(device_t dev); Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-09 15:27:48 UTC (rev 21093) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-09 19:35:38 UTC (rev 21094) @@ -36,8 +36,9 @@ uint32_t pci_read_config(device_t dev, int offset, int size) { - uint32_t value = gPci->read_pci_config(dev->pci_info.bus, - dev->pci_info.device, dev->pci_info.function, offset, size); + uint32_t value = gPci->read_pci_config(NETDEV(dev)->pci_info.bus, + NETDEV(dev)->pci_info.device, NETDEV(dev)->pci_info.function, + offset, size); TRACE_PCI(dev, "pci_read_config(%i, %i) = 0x%lx\n", offset, size, value); return value; } @@ -48,8 +49,9 @@ { TRACE_PCI(dev, "pci_write_config(%i, 0x%lx, %i)\n", offset, value, size); - gPci->write_pci_config(dev->pci_info.bus, dev->pci_info.device, - dev->pci_info.function, offset, size, value); + gPci->write_pci_config(NETDEV(dev)->pci_info.bus, + NETDEV(dev)->pci_info.device, NETDEV(dev)->pci_info.function, + offset, size, value); } @@ -164,14 +166,10 @@ int device_printf(device_t dev, const char *format, ...) { - char devDesc[32]; va_list vl; - snprintf(devDesc, sizeof(devDesc), "%i:%i:%i", (int)dev->pci_info.bus, - (int)dev->pci_info.device, (int)dev->pci_info.function); - va_start(vl, format); - driver_vprintf_etc(devDesc, format, vl); + driver_vprintf_etc(dev->dev_name, format, vl); va_end(vl); return 0; } @@ -193,6 +191,23 @@ const char * +device_get_desc(device_t dev) +{ + return dev->description; +} + + +void +device_sprintf_name(device_t dev, const char *format, ...) +{ + va_list vl; + va_start(vl, format); + vsnprintf(dev->dev_name, sizeof(dev->dev_name), format, vl); + va_end(vl); +} + + +const char * device_get_name(device_t dev) { if (dev) Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-09 15:27:48 UTC (rev 21093) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-09 19:35:38 UTC (rev 21094) @@ -26,8 +26,8 @@ #define MAX_DEVICES 8 -device_t gDevices[MAX_DEVICES]; -char *gDevNameList[MAX_DEVICES + 1]; +struct network_device *gDevices[MAX_DEVICES]; +const char *gDevNameList[MAX_DEVICES + 1]; static device_probe_t *sDeviceProbe; @@ -36,28 +36,47 @@ static device_t +init_device(device_t dev, driver_t *driver) +{ + dev->driver = driver; + dev->softc = malloc(driver->softc_size); + if (dev->softc == NULL) + return NULL; + + return dev; +} + + +static void +uninit_device(device_t dev) +{ + if (dev->flags & DEVICE_DESC_ALLOCED) + free((char *)dev->description); + free(dev->softc); +} + + +static struct network_device * allocate_device(driver_t *driver) { char semName[64]; - device_t dev = (device_t)malloc(sizeof(struct device)); + struct network_device *dev = malloc(sizeof(struct network_device)); if (dev == NULL) return NULL; memset(dev, 0, sizeof(struct device)); - snprintf(semName, sizeof(semName), "%s rcv", gDriverName); - - dev->softc_size = driver->softc_size; - dev->softc = malloc(driver->softc_size); - if (dev->softc == NULL) { + if (init_device(DEVNET(dev), driver) == NULL) { free(dev); return NULL; } + snprintf(semName, sizeof(semName), "%s rcv", gDriverName); + dev->receive_sem = create_sem(0, semName); if (dev->receive_sem < 0) { - free(dev->softc); + uninit_device(DEVNET(dev)); free(dev); return NULL; } @@ -71,13 +90,11 @@ static void -free_device(device_t dev) +free_device(struct network_device *dev) { delete_sem(dev->receive_sem); ifq_uninit(&dev->receive_queue); - free(dev->softc); - if (dev->flags & DEVICE_DESC_ALLOCED) - free((char *)dev->description); + uninit_device(DEVNET(dev)); free(dev); } @@ -100,8 +117,8 @@ static status_t compat_open(const char *name, uint32 flags, void **cookie) { + struct network_device *dev; status_t status; - device_t dev; int i; driver_printf("compat_open(%s, 0x%lx)\n", name, flags); @@ -124,11 +141,11 @@ return B_BUSY; /* some drivers expect the softc to be zero'ed out */ - memset(dev->softc, 0, dev->softc_size); + memset(dev->base.softc, 0, dev->base.driver->softc_size); - status = sDeviceAttach(dev); + status = sDeviceAttach(DEVNET(dev)); if (status != 0) - dev->flags = 0; + atomic_and(&dev->open, 0); driver_printf(" ... status = 0x%ld\n", status); @@ -155,11 +172,11 @@ static status_t compat_close(void *cookie) { - device_t dev = cookie; + struct network_device *dev = cookie; - device_printf(dev, "compat_close()\n"); + device_printf(DEVNET(dev), "compat_close()\n"); - atomic_or(&dev->flags, DEVICE_CLOSED); + atomic_or(&DEVNET(dev)->flags, DEVICE_CLOSED); /* do we need a memory barrier in read() or is the atomic_or * (and the implicit 'lock') enough? */ @@ -173,11 +190,11 @@ static status_t compat_free(void *cookie) { - device_t dev = cookie; + struct network_device *dev = cookie; - device_printf(dev, "compat_free()\n"); + device_printf(DEVNET(dev), "compat_free()\n"); - sDeviceDetach(dev); + sDeviceDetach(DEVNET(dev)); /* XXX empty out the send queue */ @@ -191,24 +208,24 @@ static status_t compat_read(void *cookie, off_t position, void *buf, size_t *numBytes) { + struct network_device *dev = cookie; uint32 semFlags = B_CAN_INTERRUPT; - device_t dev = cookie; status_t status; struct mbuf *mb; size_t len; - driver_printf("compat_read(%p, %lld, %p, [%lu])\n", cookie, position, buf, + device_printf(DEVNET(dev), "compat_read(%lld, %p, [%lu])\n", position, buf, *numBytes); - if (dev->flags & DEVICE_CLOSED) + if (DEVNET(dev)->flags & DEVICE_CLOSED) return B_INTERRUPTED; - if (dev->flags & DEVICE_NON_BLOCK) + if (DEVNET(dev)->flags & DEVICE_NON_BLOCK) semFlags |= B_RELATIVE_TIMEOUT; do { status = acquire_sem_etc(dev->receive_sem, 1, semFlags, 0); - if (dev->flags & DEVICE_CLOSED) + if (DEVNET(dev)->flags & DEVICE_CLOSED) return B_INTERRUPTED; if (status == B_WOULD_BLOCK) { @@ -242,10 +259,10 @@ compat_write(void *cookie, off_t position, const void *buffer, size_t *numBytes) { - device_t dev = cookie; + struct network_device *dev = cookie; struct mbuf *mb; - driver_printf("compat_write(%p, %lld, %p, [%lu])\n", cookie, position, + device_printf(DEVNET(dev), "compat_write(%lld, %p, [%lu])\n", position, buffer, *numBytes); mb = m_getcl(0, MT_DATA, 0); @@ -264,7 +281,7 @@ static status_t compat_control(void *cookie, uint32 op, void *arg, size_t len) { - device_t dev = cookie; + struct network_device *dev = cookie; struct ifnet *ifp = dev->ifp; switch (op) { @@ -282,9 +299,9 @@ if (user_memcpy(&value, arg, sizeof(int32)) < B_OK) return B_BAD_ADDRESS; if (value) - dev->flags |= DEVICE_NON_BLOCK; + DEVNET(dev)->flags |= DEVICE_NON_BLOCK; else - dev->flags &= ~DEVICE_NON_BLOCK; + DEVNET(dev)->flags &= ~DEVICE_NON_BLOCK; return B_OK; } @@ -378,7 +395,7 @@ status_t _fbsd_init_hardware(driver_t *driver) { - struct device fakeDevice; + struct network_device fakeDevice; device_probe_t *probe; int i; @@ -397,12 +414,12 @@ for (i = 0; gPci->get_nth_pci_info(i, &fakeDevice.pci_info) == B_OK; i++) { int result; - result = probe(&fakeDevice); + result = probe(DEVNET(&fakeDevice)); if (result >= 0) { dprintf("%s, found %s at %d\n", gDriverName, - fakeDevice.description, i); - if (fakeDevice.flags & DEVICE_DESC_ALLOCED) - free((char *)fakeDevice.description); + device_get_desc(DEVNET(&fakeDevice)), i); + if (DEVNET(&fakeDevice)->flags & DEVICE_DESC_ALLOCED) + free((char *)DEVNET(&fakeDevice)->description); put_module(B_PCI_MODULE_NAME); return B_OK; } @@ -420,7 +437,7 @@ { int i, ncards = 0; status_t status; - device_t dev; + struct network_device *dev; dprintf("%s: init_driver(%p)\n", gDriverName, driver); @@ -460,14 +477,15 @@ for (i = 0; dev != NULL && gPci->get_nth_pci_info(i, &dev->pci_info) == B_OK; i++) { - if (sDeviceProbe(dev) >= 0) { - snprintf(dev->dev_name, sizeof(dev->dev_name), "net/%s/%i", - gDriverName, ncards); - dprintf("%s, adding %s @%d -> /dev/%s\n", gDriverName, dev->description, - i, dev->dev_name); + device_t base = DEVNET(dev); + if (sDeviceProbe(base) >= 0) { + device_sprintf_name(base, "net/%s/%i", gDriverName, ncards); + dprintf("%s, adding %s @%d -> /dev/%s\n", gDriverName, + device_get_desc(base), i, device_get_name(base)); + gDevices[ncards] = dev; - gDevNameList[ncards] = dev->dev_name; + gDevNameList[ncards] = device_get_name(base); ncards++; if (ncards < MAX_DEVICES) Modified: haiku/trunk/src/libs/compat/freebsd_network/device.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-09 15:27:48 UTC (rev 21093) +++ haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-09 19:35:38 UTC (rev 21094) @@ -25,27 +25,39 @@ struct ifnet; struct device { - pci_info pci_info; char dev_name[128]; - int32 open; + driver_t *driver; + int32 flags; + int unit; + char nameunit[64]; + const char * description; + void * softc; +}; + + +struct network_device { + struct device base; + + pci_info pci_info; + + int32 open; + struct ifqueue receive_queue; sem_id receive_sem; sem_id link_state_sem; struct ifnet * ifp; - - int unit; - char nameunit[64]; - const char * description; - void * softc; - size_t softc_size; }; +#define DEVNET(dev) ((device_t)(&(dev)->base)) +#define NETDEV(base) ((struct network_device *)(base)) + + enum { DEVICE_OPEN = 1 << 0, DEVICE_CLOSED = 1 << 1, @@ -80,16 +92,20 @@ void init_bounce_pages(void); void uninit_bounce_pages(void); -void driver_printf(const char *format, ...) __attribute__ ((format (__printf__, 1, 2))); +void driver_printf(const char *format, ...) + __attribute__ ((format (__printf__, 1, 2))); void driver_vprintf(const char *format, va_list vl); +void device_sprintf_name(device_t dev, const char *format, ...) + __attribute__ ((format (__printf__, 2, 3))); + void ifq_init(struct ifqueue *ifq, const char *name); void ifq_uninit(struct ifqueue *ifq); extern struct net_stack_module_info *gStack; extern pci_module_info *gPci; -extern char *gDevNameList[]; -extern struct device *gDevices[]; +extern const char *gDevNameList[]; +extern struct network_device *gDevices[]; #endif Modified: haiku/trunk/src/libs/compat/freebsd_network/if.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-09 15:27:48 UTC (rev 21093) +++ haiku/trunk/src/libs/compat/freebsd_network/if.c 2007-05-09 19:35:38 UTC (rev 21094) @@ -67,8 +67,8 @@ if (gDevNameList[i] == NULL) panic("unknown interface"); - ifp->if_dev = gDevices[i]; - ifp->if_dev->ifp = ifp; + ifp->if_dev = DEVNET(gDevices[i]); + gDevices[i]->ifp = ifp; } @@ -146,7 +146,8 @@ ifp->if_link_state = link_state; - release_sem_etc(ifp->if_dev->link_state_sem, 1, B_DO_NOT_RESCHEDULE); + release_sem_etc(NETDEV(ifp->if_dev)->link_state_sem, 1, + B_DO_NOT_RESCHEDULE); } @@ -269,8 +270,8 @@ { device_t dev = ifp->if_dev; - IF_ENQUEUE(&dev->receive_queue, m); - release_sem_etc(dev->receive_sem, 1, B_DO_NOT_RESCHEDULE); + IF_ENQUEUE(&NETDEV(dev)->receive_queue, m); + release_sem_etc(NETDEV(dev)->receive_sem, 1, B_DO_NOT_RESCHEDULE); } From hugosantos at mail.berlios.de Wed May 9 21:36:20 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Wed, 9 May 2007 21:36:20 +0200 Subject: [Haiku-commits] r21095 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/dev/mii Message-ID: <200705091936.l49JaKka007877@sheep.berlios.de> Author: hugosantos Date: 2007-05-09 21:36:02 +0200 (Wed, 09 May 2007) New Revision: 21095 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21095&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/miivar.h haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/device.h haiku/trunk/src/libs/compat/freebsd_network/mii.c Log: freebsd compat. layer: implemented miibus_readreg and miibus_writereg, it goes up through the tree until the driver. Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/miivar.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/miivar.h 2007-05-09 19:35:38 UTC (rev 21094) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/miivar.h 2007-05-09 19:36:02 UTC (rev 21095) @@ -189,6 +189,15 @@ #ifdef _KERNEL +int miibus_readreg(device_t dev, int phy, int reg); +int miibus_writereg(device_t dev, int phy, int reg, int data); + +#define MIIBUS_READREG(dev, phy, reg) \ + miibus_readreg((dev), (phy), (reg)) + +#define MIIBUS_WRITEREG(dev, phy, reg, value) \ + miibus_writereg((dev), (phy), (reg), (value)) + #define PHY_READ(p, r) \ MIIBUS_READREG((p)->mii_dev, (p)->mii_phy, (r)) Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-09 19:35:38 UTC (rev 21094) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-09 19:36:02 UTC (rev 21095) @@ -30,19 +30,39 @@ const char *gDevNameList[MAX_DEVICES + 1]; -static device_probe_t *sDeviceProbe; -static device_attach_t *sDeviceAttach; -static device_detach_t *sDeviceDetach; - - static device_t init_device(device_t dev, driver_t *driver) { + device_method_signature_t method = NULL; + int i; + dev->driver = driver; dev->softc = malloc(driver->softc_size); if (dev->softc == NULL) return NULL; + for (i = 0; method == NULL && driver->methods[i].name != NULL; i++) { + device_method_t *mth = &driver->methods[i]; + if (strcmp(mth->name, "device_probe") == 0) + dev->methods.probe = (void *)mth->method; + else if (strcmp(mth->name, "device_attach") == 0) + dev->methods.attach = (void *)mth->method; + else if (strcmp(mth->name, "device_detach") == 0) + dev->methods.detach = (void *)mth->method; + else if (strcmp(mth->name, "device_suspend") == 0) + dev->methods.suspend = (void *)mth->method; + else if (strcmp(mth->name, "device_resume") == 0) + dev->methods.resume = (void *)mth->method; + else if (strcmp(mth->name, "device_shutdown") == 0) + dev->methods.shutdown = (void *)mth->method; + else if (strcmp(mth->name, "miibus_readreg") == 0) + dev->methods.miibus_readreg = (void *)mth->method; + else if (strcmp(mth->name, "miibus_writereg") == 0) + dev->methods.miibus_writereg = (void *)mth->method; + else if (strcmp(mth->name, "miibus_statchg") == 0) + dev->methods.miibus_statchg = (void *)mth->method; + } + return dev; } @@ -143,7 +163,7 @@ /* some drivers expect the softc to be zero'ed out */ memset(dev->base.softc, 0, dev->base.driver->softc_size); - status = sDeviceAttach(DEVNET(dev)); + status = DEVNET(dev)->methods.attach(DEVNET(dev)); if (status != 0) atomic_and(&dev->open, 0); @@ -194,7 +214,7 @@ device_printf(DEVNET(dev), "compat_free()\n"); - sDeviceDetach(DEVNET(dev)); + DEVNET(dev)->methods.detach(DEVNET(dev)); /* XXX empty out the send queue */ @@ -447,10 +467,6 @@ return status; } - sDeviceProbe = (device_probe_t *)_resolve_method(driver, "device_probe"); - sDeviceAttach = (device_attach_t *)_resolve_method(driver, "device_attach"); - sDeviceDetach = (device_detach_t *)_resolve_method(driver, "device_detach"); - dev = allocate_device(driver); if (dev == NULL) goto err_1; @@ -479,7 +495,7 @@ && gPci->get_nth_pci_info(i, &dev->pci_info) == B_OK; i++) { device_t base = DEVNET(dev); - if (sDeviceProbe(base) >= 0) { + if (base->methods.probe(base) >= 0) { device_sprintf_name(base, "net/%s/%i", gDriverName, ncards); dprintf("%s, adding %s @%d -> /dev/%s\n", gDriverName, device_get_desc(base), i, device_get_name(base)); Modified: haiku/trunk/src/libs/compat/freebsd_network/device.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-09 19:35:38 UTC (rev 21094) +++ haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-09 19:36:02 UTC (rev 21095) @@ -25,6 +25,7 @@ struct ifnet; struct device { + struct device * parent; char dev_name[128]; driver_t *driver; @@ -35,6 +36,19 @@ char nameunit[64]; const char * description; void * softc; + + struct { + int (*probe)(device_t dev); + int (*attach)(device_t dev); + int (*detach)(device_t dev); + int (*suspend)(device_t dev); + int (*resume)(device_t dev); + void (*shutdown)(device_t dev); + + int (*miibus_readreg)(device_t, int, int); + int (*miibus_writereg)(device_t, int, int, int); + void (*miibus_statchg)(device_t); + } methods; }; Modified: haiku/trunk/src/libs/compat/freebsd_network/mii.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/mii.c 2007-05-09 19:35:38 UTC (rev 21094) +++ haiku/trunk/src/libs/compat/freebsd_network/mii.c 2007-05-09 19:36:02 UTC (rev 21095) @@ -20,7 +20,33 @@ int -mii_phy_probe(device_t dev, device_t *miiDev, ifm_change_cb_t change, +miibus_readreg(device_t dev, int phy, int reg) +{ + if (dev->methods.miibus_readreg == NULL) { + if (dev->parent == NULL) + panic("miibus_readreg, no support"); + return miibus_readreg(dev->parent, phy, reg); + } + + return dev->methods.miibus_readreg(dev, phy, reg); +} + + +int +miibus_writereg(device_t dev, int phy, int reg, int data) +{ + if (dev->methods.miibus_writereg == NULL) { + if (dev->parent == NULL) + panic("miibus_writereg, no support"); + return miibus_writereg(dev->parent, phy, reg, data); + } + + return dev->methods.miibus_writereg(dev, phy, reg, data); +} + + +int +mii_phy_probe(device_t dev, device_t *mii_dev, ifm_change_cb_t change, ifm_stat_cb_t stat) { UNIMPLEMENTED(); From korli at mail.berlios.de Thu May 10 01:16:20 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Thu, 10 May 2007 01:16:20 +0200 Subject: [Haiku-commits] r21096 - haiku/trunk/src/kits/app Message-ID: <200705092316.l49NGKQt025270@sheep.berlios.de> Author: korli Date: 2007-05-10 01:16:19 +0200 (Thu, 10 May 2007) New Revision: 21096 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21096&view=rev Modified: haiku/trunk/src/kits/app/Messenger.cpp Log: fHandlerToken can be equal to B_PREFERRED_TOKEN Modified: haiku/trunk/src/kits/app/Messenger.cpp =================================================================== --- haiku/trunk/src/kits/app/Messenger.cpp 2007-05-09 19:36:02 UTC (rev 21095) +++ haiku/trunk/src/kits/app/Messenger.cpp 2007-05-09 23:16:19 UTC (rev 21096) @@ -184,7 +184,9 @@ BMessenger::Target(BLooper** _looper) const { BHandler *handler = NULL; - if (IsTargetLocal() && fHandlerToken > B_NULL_TOKEN) { + if (IsTargetLocal() + && (fHandlerToken > B_NULL_TOKEN + || fHandlerToken == B_PREFERRED_TOKEN)) { gDefaultTokens.GetToken(fHandlerToken, B_HANDLER_TOKEN, (void**)&handler); if (_looper) From hugosantos at mail.berlios.de Thu May 10 06:53:15 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Thu, 10 May 2007 06:53:15 +0200 Subject: [Haiku-commits] r21097 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/dev/mii compat/sys Message-ID: <200705100453.l4A4rFbb009328@sheep.berlios.de> Author: hugosantos Date: 2007-05-10 06:52:43 +0200 (Thu, 10 May 2007) New Revision: 21097 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21097&view=rev Added: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/errno.h haiku/trunk/src/libs/compat/freebsd_network/fbsd_mii.c haiku/trunk/src/libs/compat/freebsd_network/fbsd_mii_physubr.c Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile haiku/trunk/src/libs/compat/freebsd_network/bus.c haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/miivar.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/module.h haiku/trunk/src/libs/compat/freebsd_network/device.c haiku/trunk/src/libs/compat/freebsd_network/device.h haiku/trunk/src/libs/compat/freebsd_network/mii.c Log: freebsd compat. layer: MII subsystem (needs testers, more to come). Modified: haiku/trunk/src/libs/compat/freebsd_network/Jamfile =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-09 23:16:19 UTC (rev 21096) +++ haiku/trunk/src/libs/compat/freebsd_network/Jamfile 2007-05-10 04:52:43 UTC (rev 21097) @@ -16,6 +16,8 @@ fbsd_ether.c fbsd_if_media.c fbsd_mbuf.c + fbsd_mii.c + fbsd_mii_physubr.c if.c mbuf.c mii.c Modified: haiku/trunk/src/libs/compat/freebsd_network/bus.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-09 23:16:19 UTC (rev 21096) +++ haiku/trunk/src/libs/compat/freebsd_network/bus.c 2007-05-10 04:52:43 UTC (rev 21097) @@ -327,6 +327,13 @@ } +void +bus_generic_shutdown(device_t dev) +{ + UNIMPLEMENTED(); +} + + int bus_generic_print_child(device_t dev, device_t child) { Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/miivar.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/miivar.h 2007-05-09 23:16:19 UTC (rev 21096) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/dev/mii/miivar.h 2007-05-10 04:52:43 UTC (rev 21097) @@ -189,15 +189,27 @@ #ifdef _KERNEL -int miibus_readreg(device_t dev, int phy, int reg); -int miibus_writereg(device_t dev, int phy, int reg, int data); +int __haiku_miibus_readreg(device_t dev, int phy, int reg); +int __haiku_miibus_writereg(device_t dev, int phy, int reg, int data); +void __haiku_miibus_statchg(device_t dev); +void __haiku_miibus_linkchg(device_t dev); +void __haiku_miibus_mediainit(device_t dev); #define MIIBUS_READREG(dev, phy, reg) \ - miibus_readreg((dev), (phy), (reg)) + __haiku_miibus_readreg((dev), (phy), (reg)) #define MIIBUS_WRITEREG(dev, phy, reg, value) \ - miibus_writereg((dev), (phy), (reg), (value)) + __haiku_miibus_writereg((dev), (phy), (reg), (value)) +#define MIIBUS_STATCHG(dev) \ + __haiku_miibus_statchg(dev) + +#define MIIBUS_LINKCHG(dev) \ + __haiku_miibus_linkchg(dev) + +#define MIIBUS_MEDIAINIT(dev) \ + __haiku_miibus_mediainit(dev) + #define PHY_READ(p, r) \ MIIBUS_READREG((p)->mii_dev, (p)->mii_phy, (r)) Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-09 23:16:19 UTC (rev 21096) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2007-05-10 04:52:43 UTC (rev 21097) @@ -64,6 +64,7 @@ int bus_generic_detach(device_t dev); int bus_generic_suspend(device_t dev); int bus_generic_resume(device_t dev); +void bus_generic_shutdown(device_t dev); typedef void (*driver_intr_t)(void *); @@ -94,12 +95,18 @@ void device_set_desc(device_t dev, const char *desc); void device_set_desc_copy(device_t dev, const char *desc); const char *device_get_desc(device_t dev); +device_t device_get_parent(device_t dev); +void device_set_ivars(device_t dev, void *); +void *device_get_ivars(device_t dev); + device_t device_add_child(device_t dev, const char *name, int unit); int device_delete_child(device_t dev, device_t child); int device_is_attached(device_t dev); int bus_generic_print_child(device_t dev, device_t child); void bus_generic_driver_added(device_t dev, driver_t *driver); +void bus_generic_attach(device_t dev); +int device_set_driver(device_t dev, driver_t *driver); static inline struct sysctl_ctx_list * device_get_sysctl_ctx(device_t dev) Added: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/errno.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/errno.h 2007-05-09 23:16:19 UTC (rev 21096) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/errno.h 2007-05-10 04:52:43 UTC (rev 21097) @@ -0,0 +1,6 @@ +#ifndef _FBSD_COMPAT_SYS_ERRNO_H_ +#define _FBSD_COMPAT_SYS_ERRNO_H_ + +#define EJUSTRETURN (B_ERRORS_END + 1) + +#endif Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-09 23:16:19 UTC (rev 21096) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-10 04:52:43 UTC (rev 21097) @@ -52,7 +52,7 @@ void _fbsd_uninit_driver(driver_t *); extern const char gDriverName[]; -driver_t *__haiku_get_miibus_driver(void); +driver_t *__haiku_get_miibus_driver(device_t dev); /* we define the driver methods with HAIKU_FBSD_DRIVER_GLUE to * force the rest of the stuff to be linked back with the driver. @@ -80,9 +80,10 @@ device_hooks *find_device(const char *name) \ { return &gDeviceHooks; } -#define HAIKU_FBSD_MII_DRIVER(name) \ - driver_t *__haiku_get_miibus_driver(device_t dev) \ - { return DRIVER_MODULE_NAME(name, miibus); } +#define HAIKU_FBSD_MII_DRIVER(name) \ + driver_t *__haiku_get_miibus_driver(device_t dev) \ + { extern driver_t *DRIVER_MODULE_NAME(name, miibus); \ + return DRIVER_MODULE_NAME(name, miibus); } #define HAIKU_NO_FBSD_MII_DRIVER() \ driver_t *__haiku_get_miibus_driver(device_t dev) \ Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/module.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/module.h 2007-05-09 23:16:19 UTC (rev 21096) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/module.h 2007-05-10 04:52:43 UTC (rev 21097) @@ -3,6 +3,7 @@ #define DECLARE_MODULE(name, data, sub, order) +#define MODULE_VERSION(name, version) #define MODULE_DEPEND(module, mdepend, vmin, vpref, vmax) #endif Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-09 23:16:19 UTC (rev 21096) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-10 04:52:43 UTC (rev 21097) @@ -18,7 +18,7 @@ #include #include -// TODO a lot. +#include #define DEBUG_PCI @@ -197,7 +197,28 @@ } +device_t +device_get_parent(device_t dev) +{ + return dev->parent; +} + + void +device_set_ivars(device_t dev, void *ivars) +{ + dev->ivars = ivars; +} + + +void * +device_get_ivars(device_t dev) +{ + return dev->ivars; +} + + +void device_sprintf_name(device_t dev, const char *format, ...) { va_list vl; @@ -237,7 +258,138 @@ } +device_t +init_device(device_t dev, driver_t *driver) +{ + list_init_etc(&dev->children, offsetof(struct device, link)); + + if (driver == NULL) + return dev; + + if (device_set_driver(dev, driver) < 0) + return NULL; + + return dev; +} + + int +device_set_driver(device_t dev, driver_t *driver) +{ + device_method_signature_t method = NULL; + int i; + + dev->softc = malloc(driver->softc_size); + if (dev->softc == NULL) + return -1; + + dev->driver = driver; + + for (i = 0; method == NULL && driver->methods[i].name != NULL; i++) { + device_method_t *mth = &driver->methods[i]; + if (strcmp(mth->name, "device_probe") == 0) + dev->methods.probe = (void *)mth->method; + else if (strcmp(mth->name, "device_attach") == 0) + dev->methods.attach = (void *)mth->method; + else if (strcmp(mth->name, "device_detach") == 0) + dev->methods.detach = (void *)mth->method; + else if (strcmp(mth->name, "device_suspend") == 0) + dev->methods.suspend = (void *)mth->method; + else if (strcmp(mth->name, "device_resume") == 0) + dev->methods.resume = (void *)mth->method; + else if (strcmp(mth->name, "device_shutdown") == 0) + dev->methods.shutdown = (void *)mth->method; + else if (strcmp(mth->name, "miibus_readreg") == 0) + dev->methods.miibus_readreg = (void *)mth->method; + else if (strcmp(mth->name, "miibus_writereg") == 0) + dev->methods.miibus_writereg = (void *)mth->method; + else if (strcmp(mth->name, "miibus_statchg") == 0) + dev->methods.miibus_statchg = (void *)mth->method; + } + + return 0; +} + + +void +uninit_device(device_t dev) +{ + if (dev->flags & DEVICE_DESC_ALLOCED) + free((char *)dev->description); + if (dev->softc) + free(dev->softc); +} + + +static device_t +new_device(driver_t *driver) +{ + device_t dev = malloc(sizeof(struct device)); + if (dev == NULL) + return NULL; + + memset(dev, 0, sizeof(struct device)); + + if (init_device(dev, driver) == NULL) { + free(dev); + return NULL; + } + + return dev; +} + + +device_t +device_add_child(device_t dev, const char *name, int order) +{ + device_t child = NULL; + + if (name != NULL) { + if (strcmp(name, "miibus") == 0) + child = new_device(&miibus_driver); + } else + child = new_device(NULL); + + if (child == NULL) + return NULL; + + child->parent = dev; + list_add_item(&dev->children, child); + + return child; +} + + +void +bus_generic_attach(device_t dev) +{ + device_t child; + + for (child = list_get_first_item(&dev->children); + child; child = list_get_next_item(&dev->children, child)) { + if (child->driver == NULL) { + if (dev->driver == &miibus_driver) { + driver_t *driver = __haiku_get_miibus_driver(dev); + + if (driver) { + device_probe_t *probe = (device_probe_t *) + _resolve_method(driver, "device_probe"); + + if (probe && probe(child) >= 0) + device_set_driver(child, driver); + } + } + + if (dev->driver == NULL) + panic("can't attach unknown driver"); + } + + child->methods.attach(child); + } +} + + +int device_delete_child(device_t dev, device_t child) { UNIMPLEMENTED(); Modified: haiku/trunk/src/libs/compat/freebsd_network/device.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-09 23:16:19 UTC (rev 21096) +++ haiku/trunk/src/libs/compat/freebsd_network/device.c 2007-05-10 04:52:43 UTC (rev 21097) @@ -30,52 +30,6 @@ const char *gDevNameList[MAX_DEVICES + 1]; -static device_t -init_device(device_t dev, driver_t *driver) -{ - device_method_signature_t method = NULL; - int i; - - dev->driver = driver; - dev->softc = malloc(driver->softc_size); - if (dev->softc == NULL) - return NULL; - - for (i = 0; method == NULL && driver->methods[i].name != NULL; i++) { - device_method_t *mth = &driver->methods[i]; - if (strcmp(mth->name, "device_probe") == 0) - dev->methods.probe = (void *)mth->method; - else if (strcmp(mth->name, "device_attach") == 0) - dev->methods.attach = (void *)mth->method; - else if (strcmp(mth->name, "device_detach") == 0) - dev->methods.detach = (void *)mth->method; - else if (strcmp(mth->name, "device_suspend") == 0) - dev->methods.suspend = (void *)mth->method; - else if (strcmp(mth->name, "device_resume") == 0) - dev->methods.resume = (void *)mth->method; - else if (strcmp(mth->name, "device_shutdown") == 0) - dev->methods.shutdown = (void *)mth->method; - else if (strcmp(mth->name, "miibus_readreg") == 0) - dev->methods.miibus_readreg = (void *)mth->method; - else if (strcmp(mth->name, "miibus_writereg") == 0) - dev->methods.miibus_writereg = (void *)mth->method; - else if (strcmp(mth->name, "miibus_statchg") == 0) - dev->methods.miibus_statchg = (void *)mth->method; - } - - return dev; -} - - -static void -uninit_device(device_t dev) -{ - if (dev->flags & DEVICE_DESC_ALLOCED) - free((char *)dev->description); - free(dev->softc); -} - - static struct network_device * allocate_device(driver_t *driver) { @@ -119,7 +73,7 @@ } -static device_method_signature_t +device_method_signature_t _resolve_method(driver_t *driver, const char *name) { device_method_signature_t method = NULL; Modified: haiku/trunk/src/libs/compat/freebsd_network/device.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-09 23:16:19 UTC (rev 21096) +++ haiku/trunk/src/libs/compat/freebsd_network/device.h 2007-05-10 04:52:43 UTC (rev 21097) @@ -16,6 +16,8 @@ #include #include +#include + #include #include @@ -29,6 +31,7 @@ char dev_name[128]; driver_t *driver; + struct list children; int32 flags; @@ -36,6 +39,7 @@ char nameunit[64]; const char * description; void * softc; + void * ivars; struct { int (*probe)(device_t dev); @@ -48,7 +52,11 @@ int (*miibus_readreg)(device_t, int, int); int (*miibus_writereg)(device_t, int, int, int); void (*miibus_statchg)(device_t); + void (*miibus_linkchg)(device_t); + void (*miibus_mediainit)(device_t); } methods; + + struct list_link link; }; @@ -113,6 +121,10 @@ void device_sprintf_name(device_t dev, const char *format, ...) __attribute__ ((format (__printf__, 2, 3))); +device_t init_device(device_t dev, driver_t *driver); +void uninit_device(device_t dev); +device_method_signature_t _resolve_method(driver_t *driver, const char *name); + void ifq_init(struct ifqueue *ifq, const char *name); void ifq_uninit(struct ifqueue *ifq); Added: haiku/trunk/src/libs/compat/freebsd_network/fbsd_mii.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/fbsd_mii.c 2007-05-09 23:16:19 UTC (rev 21096) +++ haiku/trunk/src/libs/compat/freebsd_network/fbsd_mii.c 2007-05-10 04:52:43 UTC (rev 21097) @@ -0,0 +1,394 @@ +/* $NetBSD: mii.c,v 1.12 1999/08/03 19:41:49 drochner Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "device.h" + +#include +__FBSDID("$FreeBSD: src/sys/dev/mii/mii.c,v 1.26.2.1 2006/03/17 20:17:43 glebius Exp $"); + +/* + * MII bus layer, glues MII-capable network interface drivers to sharable + * PHY drivers. This exports an interface compatible with BSD/OS 3.0's, + * plus some NetBSD extensions. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +MODULE_VERSION(miibus, 1); + +#include "miibus_if.h" + +static int miibus_child_location_str(device_t bus, device_t child, char *buf, + size_t buflen); +static int miibus_child_pnpinfo_str(device_t bus, device_t child, char *buf, + size_t buflen); +static int miibus_readreg(device_t, int, int); +static int miibus_writereg(device_t, int, int, int); +static void miibus_statchg(device_t); +static void miibus_linkchg(device_t); +static void miibus_mediainit(device_t); + +static device_method_t miibus_methods[] = { + /* device interface */ + DEVMETHOD(device_probe, miibus_probe), + DEVMETHOD(device_attach, miibus_attach), + DEVMETHOD(device_detach, miibus_detach), + DEVMETHOD(device_shutdown, bus_generic_shutdown), + + /* bus interface */ + DEVMETHOD(bus_print_child, bus_generic_print_child), + DEVMETHOD(bus_driver_added, bus_generic_driver_added), + DEVMETHOD(bus_child_pnpinfo_str, miibus_child_pnpinfo_str), + DEVMETHOD(bus_child_location_str, miibus_child_location_str), + + /* MII interface */ + DEVMETHOD(miibus_readreg, miibus_readreg), + DEVMETHOD(miibus_writereg, miibus_writereg), + DEVMETHOD(miibus_statchg, miibus_statchg), + DEVMETHOD(miibus_linkchg, miibus_linkchg), + DEVMETHOD(miibus_mediainit, miibus_mediainit), + + { 0, 0 } +}; + +devclass_t miibus_devclass; + +driver_t miibus_driver = { + "miibus", + miibus_methods, + sizeof(struct mii_data) +}; + +/* + * Helper function used by network interface drivers, attaches PHYs + * to the network interface driver parent. + */ +int +miibus_probe(device_t dev) +{ + struct mii_attach_args ma, *args; + struct mii_data *mii; + device_t child = NULL, parent; + int bmsr, capmask = 0xFFFFFFFF; + + mii = device_get_softc(dev); + parent = device_get_parent(dev); + LIST_INIT(&mii->mii_phys); + + for (ma.mii_phyno = 0; ma.mii_phyno < MII_NPHY; ma.mii_phyno++) { + /* + * Check to see if there is a PHY at this address. Note, + * many braindead PHYs report 0/0 in their ID registers, + * so we test for media in the BMSR. + */ + bmsr = MIIBUS_READREG(parent, ma.mii_phyno, MII_BMSR); + if (bmsr == 0 || bmsr == 0xffff || + (bmsr & (BMSR_EXTSTAT|BMSR_MEDIAMASK)) == 0) { + /* Assume no PHY at this address. */ + continue; + } + + /* + * Extract the IDs. Braindead PHYs will be handled by + * the `ukphy' driver, as we have no ID information to + * match on. + */ + ma.mii_id1 = MIIBUS_READREG(parent, ma.mii_phyno, + MII_PHYIDR1); + ma.mii_id2 = MIIBUS_READREG(parent, ma.mii_phyno, + MII_PHYIDR2); + + ma.mii_data = mii; + ma.mii_capmask = capmask; + + args = kernel_malloc(sizeof(struct mii_attach_args), + M_DEVBUF, M_NOWAIT); + bcopy((char *)&ma, (char *)args, sizeof(ma)); + child = device_add_child(dev, NULL, -1); + device_set_ivars(child, args); + } + + if (child == NULL) + return(ENXIO); + + device_set_desc(dev, "MII bus"); + + return(0); +} + +int +miibus_attach(device_t dev) +{ + void **v; + ifm_change_cb_t ifmedia_upd; + ifm_stat_cb_t ifmedia_sts; + struct mii_data *mii; + + mii = device_get_softc(dev); + + mii->mii_ifp = NETDEV(device_get_parent(dev))->ifp; + v = device_get_ivars(dev); + ifmedia_upd = v[0]; + ifmedia_sts = v[1]; + ifmedia_init(&mii->mii_media, IFM_IMASK, ifmedia_upd, ifmedia_sts); + bus_generic_attach(dev); + + return(0); +} + +int +miibus_detach(device_t dev) +{ + struct mii_data *mii; + + bus_generic_detach(dev); + mii = device_get_softc(dev); + ifmedia_removeall(&mii->mii_media); + mii->mii_ifp = NULL; + + return(0); +} + +static int +miibus_child_pnpinfo_str(device_t bus, device_t child, char *buf, + size_t buflen) +{ + struct mii_attach_args *maa = device_get_ivars(child); + snprintf(buf, buflen, "oui=0x%x model=0x%x rev=0x%x", + MII_OUI(maa->mii_id1, maa->mii_id2), + MII_MODEL(maa->mii_id2), MII_REV(maa->mii_id2)); + return (0); +} + +static int +miibus_child_location_str(device_t bus, device_t child, char *buf, + size_t buflen) +{ + struct mii_attach_args *maa = device_get_ivars(child); + snprintf(buf, buflen, "phyno=%d", maa->mii_phyno); + return (0); +} + +static int +miibus_readreg(device_t dev, int phy, int reg) +{ + device_t parent; + + parent = device_get_parent(dev); + return(MIIBUS_READREG(parent, phy, reg)); +} + +static int +miibus_writereg(device_t dev, int phy, int reg, int data) +{ + device_t parent; + + parent = device_get_parent(dev); + return(MIIBUS_WRITEREG(parent, phy, reg, data)); +} + +static void +miibus_statchg(device_t dev) +{ + device_t parent; + struct mii_data *mii; + struct ifnet *ifp; + + parent = device_get_parent(dev); + MIIBUS_STATCHG(parent); + + mii = device_get_softc(dev); + + ifp = NETDEV(parent)->ifp; + ifp->if_baudrate = ifmedia_baudrate(mii->mii_media_active); + return; +} + +static void +miibus_linkchg(device_t dev) +{ + struct mii_data *mii; + device_t parent; + int link_state; + + parent = device_get_parent(dev); + MIIBUS_LINKCHG(parent); + + mii = device_get_softc(dev); + + if (mii->mii_media_status & IFM_AVALID) { + if (mii->mii_media_status & IFM_ACTIVE) + link_state = LINK_STATE_UP; + else + link_state = LINK_STATE_DOWN; + } else + link_state = LINK_STATE_UNKNOWN; + + if_link_state_change(NETDEV(parent)->ifp, link_state); +} + +static void +miibus_mediainit(device_t dev) +{ + struct mii_data *mii; + struct ifmedia_entry *m; + int media = 0; + + /* Poke the parent in case it has any media of its own to add. */ + MIIBUS_MEDIAINIT(device_get_parent(dev)); + + mii = device_get_softc(dev); + LIST_FOREACH(m, &mii->mii_media.ifm_list, ifm_list) { + media = m->ifm_media; + if (media == (IFM_ETHER|IFM_AUTO)) + break; + } + + ifmedia_set(&mii->mii_media, media); + + return; +} + +int +mii_phy_probe(device_t dev, device_t *child, ifm_change_cb_t ifmedia_upd, + ifm_stat_cb_t ifmedia_sts) +{ + void **v; + int bmsr, i; + + v = kernel_malloc(sizeof(vm_offset_t) * 2, M_DEVBUF, M_NOWAIT); + if (v == 0) { + return (ENOMEM); + } + v[0] = ifmedia_upd; + v[1] = ifmedia_sts; + *child = device_add_child(dev, "miibus", -1); + device_set_ivars(*child, v); + + for (i = 0; i < MII_NPHY; i++) { + bmsr = MIIBUS_READREG(dev, i, MII_BMSR); + if (bmsr == 0 || bmsr == 0xffff || + (bmsr & (BMSR_EXTSTAT|BMSR_MEDIAMASK)) == 0) { + /* Assume no PHY at this address. */ + continue; + } else + break; + } + + if (i == MII_NPHY) { + device_delete_child(dev, *child); + *child = NULL; + return(ENXIO); + } + + bus_generic_attach(dev); + + return(0); +} + +/* + * Media changed; notify all PHYs. + */ +int +mii_mediachg(struct mii_data *mii) +{ + struct mii_softc *child; + int rv; + + mii->mii_media_status = 0; + mii->mii_media_active = IFM_NONE; + + LIST_FOREACH(child, &mii->mii_phys, mii_list) { + rv = (*child->mii_service)(child, mii, MII_MEDIACHG); + if (rv) + return (rv); + } + return (0); +} + +/* + * Call the PHY tick routines, used during autonegotiation. + */ +void +mii_tick(struct mii_data *mii) +{ + struct mii_softc *child; + + LIST_FOREACH(child, &mii->mii_phys, mii_list) + (void) (*child->mii_service)(child, mii, MII_TICK); +} + +/* + * Get media status from PHYs. + */ +void +mii_pollstat(struct mii_data *mii) +{ + struct mii_softc *child; + + mii->mii_media_status = 0; + mii->mii_media_active = IFM_NONE; + + LIST_FOREACH(child, &mii->mii_phys, mii_list) + (void) (*child->mii_service)(child, mii, MII_POLLSTAT); +} + +/* + * Inform the PHYs that the interface is down. + */ +void +mii_down(struct mii_data *mii) +{ + struct mii_softc *child; + + LIST_FOREACH(child, &mii->mii_phys, mii_list) + mii_phy_down(child); +} Added: haiku/trunk/src/libs/compat/freebsd_network/fbsd_mii_physubr.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/fbsd_mii_physubr.c 2007-05-09 23:16:19 UTC (rev 21096) +++ haiku/trunk/src/libs/compat/freebsd_network/fbsd_mii_physubr.c 2007-05-10 04:52:43 UTC (rev 21097) @@ -0,0 +1,544 @@ +/* $NetBSD: mii_physubr.c,v 1.5 1999/08/03 19:41:49 drochner Exp $ */ + +/*- + * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/sys/dev/mii/mii_physubr.c,v 1.22.2.2 2006/07/29 08:30:12 oleg Exp $"); + +/* + * Subroutines common to all PHYs. + */ + +#include +#include +#include +#include +#include +#include +#include + + +#include +#include + +#include +#include + +#include "miibus_if.h" + +/* + * Media to register setting conversion table. Order matters. + */ +const struct mii_media mii_media_table[MII_NMEDIA] = { + /* None */ + { BMCR_ISO, ANAR_CSMA, + 0, }, + + /* 10baseT */ + { BMCR_S10, ANAR_CSMA|ANAR_10, + 0, }, + + /* 10baseT-FDX */ + { BMCR_S10|BMCR_FDX, ANAR_CSMA|ANAR_10_FD, + 0, }, + + /* 100baseT4 */ + { BMCR_S100, ANAR_CSMA|ANAR_T4, + 0, }, + + /* 100baseTX */ + { BMCR_S100, ANAR_CSMA|ANAR_TX, + 0, }, + + /* 100baseTX-FDX */ + { BMCR_S100|BMCR_FDX, ANAR_CSMA|ANAR_TX_FD, + 0, }, + + /* 1000baseX */ + { BMCR_S1000, ANAR_CSMA, + 0, }, + + /* 1000baseX-FDX */ + { BMCR_S1000|BMCR_FDX, ANAR_CSMA, + 0, }, + + /* 1000baseT */ + { BMCR_S1000, ANAR_CSMA, + GTCR_ADV_1000THDX }, + + /* 1000baseT-FDX */ + { BMCR_S1000, ANAR_CSMA, + GTCR_ADV_1000TFDX }, +}; + +void +mii_phy_setmedia(struct mii_softc *sc) +{ + struct mii_data *mii = sc->mii_pdata; + struct ifmedia_entry *ife = mii->mii_media.ifm_cur; + int bmcr, anar, gtcr; + + if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO) { + if ((PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN) == 0) + (void) mii_phy_auto(sc); + return; + } + + /* + * Table index is stored in the media entry. + */ + + KASSERT(ife->ifm_data >=0 && ife->ifm_data < MII_NMEDIA, + ("invalid ife->ifm_data (0x%x) in mii_phy_setmedia", + ife->ifm_data)); + + anar = mii_media_table[ife->ifm_data].mm_anar; + bmcr = mii_media_table[ife->ifm_data].mm_bmcr; + gtcr = mii_media_table[ife->ifm_data].mm_gtcr; + + if (mii->mii_media.ifm_media & IFM_ETH_MASTER) { + switch (IFM_SUBTYPE(ife->ifm_media)) { + case IFM_1000_T: + gtcr |= GTCR_MAN_MS|GTCR_ADV_MS; + break; [... truncated: 491 lines follow ...] From hugosantos at mail.berlios.de Thu May 10 06:53:24 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Thu, 10 May 2007 06:53:24 +0200 Subject: [Haiku-commits] r21098 - in haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139: . dev dev/mii pci Message-ID: <200705100453.l4A4rOwv009554@sheep.berlios.de> Author: hugosantos Date: 2007-05-10 06:53:02 +0200 (Thu, 10 May 2007) New Revision: 21098 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21098&view=rev Added: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/miidevs.h haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/rlphy.c Modified: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/glue.c Log: rtl8139 (FreeBSD version): added rlphy miibus support, needs testing. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/Jamfile 2007-05-10 04:52:43 UTC (rev 21097) +++ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/Jamfile 2007-05-10 04:53:02 UTC (rev 21098) @@ -55,4 +55,5 @@ # rtl8139.settings : # boot home config settings kernel drivers sample ; +SubInclude HAIKU_TOP src add-ons kernel drivers network rtl8139 dev ; SubInclude HAIKU_TOP src add-ons kernel drivers network rtl8139 pci ; Added: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/Jamfile 2007-05-10 04:52:43 UTC (rev 21097) +++ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/Jamfile 2007-05-10 04:53:02 UTC (rev 21098) @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network rtl8139 dev ; + +SubInclude HAIKU_TOP src add-ons kernel drivers network rtl8139 dev mii ; Added: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/Jamfile 2007-05-10 04:52:43 UTC (rev 21097) +++ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/Jamfile 2007-05-10 04:53:02 UTC (rev 21098) @@ -0,0 +1,13 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network rtl8139 dev mii ; + +UsePrivateHeaders kernel net ; + +UseHeaders [ FDirName $(SUBDIR) .. .. ] : true ; +UseHeaders [ FDirName $(HAIKU_TOP) src libs compat freebsd_network compat ] : true ; + +SubDirCcFlags [ FDefines _KERNEL=1 FBSD_DRIVER=1 ] ; + +KernelStaticLibrary rtl8139exp_mii.a + : rlphy.c + ; + Added: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/miidevs.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/miidevs.h 2007-05-10 04:52:43 UTC (rev 21097) +++ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/miidevs.h 2007-05-10 04:53:02 UTC (rev 21098) @@ -0,0 +1,3 @@ +#define MII_OUI_REALTEK 0x000020 +#define MII_MODEL_REALTEK_RTL8201L 0x0020 +#define MII_STR_REALTEK_RTL8201L "RTL8021L" Added: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/rlphy.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/rlphy.c 2007-05-10 04:52:43 UTC (rev 21097) +++ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/dev/mii/rlphy.c 2007-05-10 04:53:02 UTC (rev 21098) @@ -0,0 +1,350 @@ +/*- + * Copyright (c) 1997, 1998, 1999 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/sys/dev/mii/rlphy.c,v 1.21.2.1 2006/08/08 04:37:18 yongari Exp $"); + +/* + * driver for RealTek 8139 internal PHYs + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include "miidevs.h" + +#include +#include + +#include "miibus_if.h" + +static int rlphy_probe(device_t); +static int rlphy_attach(device_t); + +static device_method_t rlphy_methods[] = { + /* device interface */ + DEVMETHOD(device_probe, rlphy_probe), + DEVMETHOD(device_attach, rlphy_attach), + DEVMETHOD(device_detach, mii_phy_detach), + DEVMETHOD(device_shutdown, bus_generic_shutdown), + { 0, 0 } +}; + +static devclass_t rlphy_devclass; + +static driver_t rlphy_driver = { + "rlphy", + rlphy_methods, + sizeof(struct mii_softc) +}; + +DRIVER_MODULE(rlphy, miibus, rlphy_driver, rlphy_devclass, 0, 0); + +static int rlphy_service(struct mii_softc *, struct mii_data *, int); +static void rlphy_status(struct mii_softc *); + +static int +rlphy_probe(dev) + device_t dev; +{ + struct mii_attach_args *ma; + device_t parent; + + ma = device_get_ivars(dev); + parent = device_get_parent(device_get_parent(dev)); + + /* Test for RealTek 8201L PHY */ + if (MII_OUI(ma->mii_id1, ma->mii_id2) == MII_OUI_REALTEK && + MII_MODEL(ma->mii_id2) == MII_MODEL_REALTEK_RTL8201L) { + device_set_desc(dev, MII_STR_REALTEK_RTL8201L); + return(BUS_PROBE_DEFAULT); + } + + /* + * RealTek PHY doesn't have vendor/device ID registers: + * the rl driver fakes up a return value of all zeros. + */ + if (MII_OUI(ma->mii_id1, ma->mii_id2) != 0 || + MII_MODEL(ma->mii_id2) != 0) + return (ENXIO); + + /* + * Make sure the parent is an `rl' or an `re'. + */ + if (strcmp(device_get_name(parent), "rl") != 0 && + strcmp(device_get_name(parent), "re") != 0) + return (ENXIO); + + device_set_desc(dev, "RealTek internal media interface"); + + return (BUS_PROBE_DEFAULT); +} + +static int +rlphy_attach(dev) + device_t dev; +{ + struct mii_softc *sc; + struct mii_attach_args *ma; + struct mii_data *mii; + + sc = device_get_softc(dev); + ma = device_get_ivars(dev); + sc->mii_dev = device_get_parent(dev); + mii = device_get_softc(sc->mii_dev); + + /* + * The RealTek PHY can never be isolated, so never allow non-zero + * instances! + */ + if (mii->mii_instance != 0) { + device_printf(dev, "ignoring this PHY, non-zero instance\n"); + return(ENXIO); + } + + LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + + sc->mii_inst = mii->mii_instance; + sc->mii_phy = ma->mii_phyno; + sc->mii_service = rlphy_service; + sc->mii_pdata = mii; + mii->mii_instance++; + + sc->mii_flags |= MIIF_NOISOLATE; + +#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL) + +#if 0 /* See above. */ + ADD(IFM_MAKEWORD(IFM_ETHER, IFM_NONE, 0, sc->mii_inst), + BMCR_ISO); +#endif + + ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst), + BMCR_LOOP|BMCR_S100); + + mii_phy_reset(sc); + + sc->mii_capabilities = + PHY_READ(sc, MII_BMSR) & ma->mii_capmask; + device_printf(dev, " "); + mii_add_media(sc); + printf("\n"); +#undef ADD + MIIBUS_MEDIAINIT(sc->mii_dev); + return(0); +} + +static int +rlphy_service(sc, mii, cmd) + struct mii_softc *sc; + struct mii_data *mii; + int cmd; +{ + struct ifmedia_entry *ife = mii->mii_media.ifm_cur; + + /* + * We can't isolate the RealTek PHY, so it has to be the only one! + */ + if (IFM_INST(ife->ifm_media) != sc->mii_inst) + panic("rlphy_service: can't isolate RealTek PHY"); + + switch (cmd) { + case MII_POLLSTAT: + break; + + case MII_MEDIACHG: + /* + * If the interface is not up, don't do anything. + */ + if ((mii->mii_ifp->if_flags & IFF_UP) == 0) + break; + + switch (IFM_SUBTYPE(ife->ifm_media)) { + case IFM_AUTO: + /* + * If we're already in auto mode, just return. + */ + if (PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN) + return (0); + (void) mii_phy_auto(sc); + break; + case IFM_100_T4: + /* + * XXX Not supported as a manual setting right now. + */ + return (EINVAL); + default: + /* + * BMCR data is stored in the ifmedia entry. + */ + PHY_WRITE(sc, MII_ANAR, + mii_anar(ife->ifm_media)); + PHY_WRITE(sc, MII_BMCR, ife->ifm_data); + } + break; + + case MII_TICK: + /* + * Is the interface even up? + */ + if ((mii->mii_ifp->if_flags & IFF_UP) == 0) + return (0); + + /* + * Only used for autonegotiation. + */ + if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) + break; + + /* + * The RealTek PHY's autonegotiation doesn't need to be + * kicked; it continues in the background. + */ + break; + } + + /* Update the media status. */ + rlphy_status(sc); + + /* Callback if something changed. */ + mii_phy_update(sc, cmd); + return (0); +} + +static void +rlphy_status(phy) + struct mii_softc *phy; +{ + struct mii_data *mii = phy->mii_pdata; + int bmsr, bmcr, anlpar; + device_t parent; + + mii->mii_media_status = IFM_AVALID; + mii->mii_media_active = IFM_ETHER; + + bmsr = PHY_READ(phy, MII_BMSR) | PHY_READ(phy, MII_BMSR); + if (bmsr & BMSR_LINK) + mii->mii_media_status |= IFM_ACTIVE; + + bmcr = PHY_READ(phy, MII_BMCR); + if (bmcr & BMCR_ISO) { + mii->mii_media_active |= IFM_NONE; + mii->mii_media_status = 0; + return; + } + + if (bmcr & BMCR_LOOP) + mii->mii_media_active |= IFM_LOOP; + + if (bmcr & BMCR_AUTOEN) { + /* + * NWay autonegotiation takes the highest-order common + * bit of the ANAR and ANLPAR (i.e. best media advertised + * both by us and our link partner). + */ + if ((bmsr & BMSR_ACOMP) == 0) { + /* Erg, still trying, I guess... */ + mii->mii_media_active |= IFM_NONE; + return; + } + + if ((anlpar = PHY_READ(phy, MII_ANAR) & + PHY_READ(phy, MII_ANLPAR))) { + if (anlpar & ANLPAR_T4) + mii->mii_media_active |= IFM_100_T4; + else if (anlpar & ANLPAR_TX_FD) + mii->mii_media_active |= IFM_100_TX|IFM_FDX; + else if (anlpar & ANLPAR_TX) + mii->mii_media_active |= IFM_100_TX; + else if (anlpar & ANLPAR_10_FD) + mii->mii_media_active |= IFM_10_T|IFM_FDX; + else if (anlpar & ANLPAR_10) + mii->mii_media_active |= IFM_10_T; + else + mii->mii_media_active |= IFM_NONE; + return; + } + /* + * If the other side doesn't support NWAY, then the + * best we can do is determine if we have a 10Mbps or + * 100Mbps link. There's no way to know if the link + * is full or half duplex, so we default to half duplex + * and hope that the user is clever enough to manually + * change the media settings if we're wrong. + */ + + + /* + * The RealTek PHY supports non-NWAY link speed + * detection, however it does not report the link + * detection results via the ANLPAR or BMSR registers. + * (What? RealTek doesn't do things the way everyone + * else does? I'm just shocked, shocked I tell you.) + * To determine the link speed, we have to do one + * of two things: + * + * - If this is a standalone RealTek RTL8201(L) PHY, + * we can determine the link speed by testing bit 0 + * in the magic, vendor-specific register at offset + * 0x19. + * + * - If this is a RealTek MAC with integrated PHY, we + * can test the 'SPEED10' bit of the MAC's media status + * register. + */ + parent = device_get_parent(phy->mii_dev); + if (strcmp(device_get_name(parent), "rl") != 0) { + if (PHY_READ(phy, 0x0019) & 0x01) + mii->mii_media_active |= IFM_100_TX; + else + mii->mii_media_active |= IFM_10_T; + } else { + if (PHY_READ(phy, RL_MEDIASTAT) & + RL_MEDIASTAT_SPEED10) + mii->mii_media_active |= IFM_10_T; + else + mii->mii_media_active |= IFM_100_TX; + } + + } else + mii->mii_media_active = mii_media_from_bmcr(bmcr); +} Modified: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/Jamfile 2007-05-10 04:52:43 UTC (rev 21097) +++ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/Jamfile 2007-05-10 04:53:02 UTC (rev 21098) @@ -10,6 +10,6 @@ KernelAddon rtl8139exp : if_rl.c glue.c - : libfreebsd_network.a + : libfreebsd_network.a rtl8139exp_mii.a ; Modified: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/glue.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/glue.c 2007-05-10 04:52:43 UTC (rev 21097) +++ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/glue.c 2007-05-10 04:53:02 UTC (rev 21098) @@ -5,6 +5,8 @@ HAIKU_FBSD_DRIVER_GLUE(rtl8139exp, rl, pci); HAIKU_DRIVER_REQUIREMENTS(0); +HAIKU_FBSD_MII_DRIVER(rlphy); + int HAIKU_CHECK_DISABLE_INTERRUPTS(device_t dev) { struct rl_softc *sc = device_get_softc(dev); From hugosantos at mail.berlios.de Thu May 10 08:03:42 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Thu, 10 May 2007 08:03:42 +0200 Subject: [Haiku-commits] r21099 - in haiku/trunk/src: add-ons/kernel/drivers/network/ipro1000/dev/em add-ons/kernel/drivers/network/pcnet/dev/le libs/compat/freebsd_network libs/compat/freebsd_network/compat/sys Message-ID: <200705100603.l4A63gNK023807@sheep.berlios.de> Author: hugosantos Date: 2007-05-10 08:03:24 +0200 (Thu, 10 May 2007) New Revision: 21099 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21099&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/glue.c haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h Log: freebsd compat. layer: some missing definitions as well as allowing multiple MII modules per driver. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/glue.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/glue.c 2007-05-10 04:53:02 UTC (rev 21098) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro1000/dev/em/glue.c 2007-05-10 06:03:24 UTC (rev 21099) @@ -4,6 +4,7 @@ NO_HAIKU_CHECK_DISABLE_INTERRUPTS(); NO_HAIKU_REENABLE_INTERRUPTS(); +NO_HAIKU_FBSD_MII_DRIVER(); #ifdef EM_FAST_INTR HAIKU_DRIVER_REQUIREMENTS(FBSD_TASKQUEUES | FBSD_FAST_TASKQUEUE); Modified: haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c 2007-05-10 04:53:02 UTC (rev 21098) +++ haiku/trunk/src/add-ons/kernel/drivers/network/pcnet/dev/le/glue.c 2007-05-10 06:03:24 UTC (rev 21099) @@ -8,7 +8,10 @@ HAIKU_FBSD_DRIVER_GLUE(pcnet, le, pci); HAIKU_DRIVER_REQUIREMENTS(0); +NO_HAIKU_FBSD_MII_DRIVER(); +NO_HAIKU_REENABLE_INTERRUPTS(); + /* from if_le_pci.c */ #define PCNET_PCI_RDP 0x10 #define PCNET_PCI_RAP 0x12 @@ -58,5 +61,3 @@ return value & LE_C0_INTR; } - -NO_HAIKU_REENABLE_INTERRUPTS(); Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-10 04:53:02 UTC (rev 21098) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-10 06:03:24 UTC (rev 21099) @@ -52,7 +52,7 @@ void _fbsd_uninit_driver(driver_t *); extern const char gDriverName[]; -driver_t *__haiku_get_miibus_driver(device_t dev); +driver_t **__haiku_get_miibus_drivers(int *count); /* we define the driver methods with HAIKU_FBSD_DRIVER_GLUE to * force the rest of the stuff to be linked back with the driver. @@ -80,14 +80,20 @@ device_hooks *find_device(const char *name) \ { return &gDeviceHooks; } +#define HAIKU_FBSD_RETURN_MII_DRIVER(drivers, driver_count) \ + driver_t **__haiku_get_miibus_drivers(int *count) \ + { \ + (*count) = (driver_count); \ + return (drivers); \ + } + #define HAIKU_FBSD_MII_DRIVER(name) \ - driver_t *__haiku_get_miibus_driver(device_t dev) \ - { extern driver_t *DRIVER_MODULE_NAME(name, miibus); \ - return DRIVER_MODULE_NAME(name, miibus); } + extern driver_t *DRIVER_MODULE_NAME(name, miibus); \ + HAIKU_FBSD_RETURN_MII_DRIVER( \ + &DRIVER_MODULE_NAME(name, miibus), 1) -#define HAIKU_NO_FBSD_MII_DRIVER() \ - driver_t *__haiku_get_miibus_driver(device_t dev) \ - { return NULL; } +#define NO_HAIKU_FBSD_MII_DRIVER() \ + HAIKU_FBSD_RETURN_MII_DRIVER(NULL, 0) extern spinlock __haiku_intr_spinlock; extern int __haiku_disable_interrupts(device_t dev); @@ -96,9 +102,9 @@ #define HAIKU_CHECK_DISABLE_INTERRUPTS __haiku_disable_interrupts #define HAIKU_REENABLE_INTERRUPTS __haiku_reenable_interrupts -#define NO_HAIKU_CHECK_DISABLE_INTERRUPTS() \ - int HAIKU_CHECK_DISABLE_INTERRUPTS(device_t dev) { \ - panic("should never be called."); \ +#define NO_HAIKU_CHECK_DISABLE_INTERRUPTS() \ + int HAIKU_CHECK_DISABLE_INTERRUPTS(device_t dev) { \ + panic("should never be called."); \ return -1; \ } Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-10 04:53:02 UTC (rev 21098) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-10 06:03:24 UTC (rev 21099) @@ -369,15 +369,29 @@ child; child = list_get_next_item(&dev->children, child)) { if (child->driver == NULL) { if (dev->driver == &miibus_driver) { - driver_t *driver = __haiku_get_miibus_driver(dev); + int i, driver_count, driver_cost = INT_MIN; + driver_t **drivers, *driver = NULL; - if (driver) { + drivers = __haiku_get_miibus_drivers(&driver_count); + + for (i = 0; i < driver_count; i++) { device_probe_t *probe = (device_probe_t *) - _resolve_method(driver, "device_probe"); + _resolve_method(drivers[i], "device_probe"); - if (probe && probe(child) >= 0) - device_set_driver(child, driver); + if (probe) { + /* XXX this kinda reverses the original logic */ + int result = probe(child); + if (result >= 0) { + if (driver == NULL || result > driver_cost) { + driver = drivers[i]; + driver_cost = result; + } + } + } } + + if (driver) + device_set_driver(child, driver); } if (dev->driver == NULL) From hugosantos at mail.berlios.de Thu May 10 08:33:49 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Thu, 10 May 2007 08:33:49 +0200 Subject: [Haiku-commits] r21100 - in haiku/trunk/src/libs/compat/freebsd_network: . compat/sys Message-ID: <200705100633.l4A6XnC1025536@sheep.berlios.de> Author: hugosantos Date: 2007-05-10 08:33:35 +0200 (Thu, 10 May 2007) New Revision: 21100 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21100&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kernel.h Log: freebsd compat. layer: another go at multiple MII module support. Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-10 06:03:24 UTC (rev 21099) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/haiku-module.h 2007-05-10 06:33:35 UTC (rev 21100) @@ -52,7 +52,8 @@ void _fbsd_uninit_driver(driver_t *); extern const char gDriverName[]; -driver_t **__haiku_get_miibus_drivers(int *count); +driver_t *__haiku_select_miibus_driver(device_t dev); +driver_t *__haiku_probe_miibus(device_t dev, driver_t *drivers[], int count); /* we define the driver methods with HAIKU_FBSD_DRIVER_GLUE to * force the rest of the stuff to be linked back with the driver. @@ -80,11 +81,10 @@ device_hooks *find_device(const char *name) \ { return &gDeviceHooks; } -#define HAIKU_FBSD_RETURN_MII_DRIVER(drivers, driver_count) \ - driver_t **__haiku_get_miibus_drivers(int *count) \ +#define HAIKU_FBSD_RETURN_MII_DRIVER(drivers, count) \ + driver_t *__haiku_select_miibus_driver(device_t dev) \ { \ - (*count) = (driver_count); \ - return (drivers); \ + return __haiku_probe_miibus(dev, drivers, count); \ } #define HAIKU_FBSD_MII_DRIVER(name) \ Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kernel.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kernel.h 2007-05-10 06:03:24 UTC (rev 21099) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/kernel.h 2007-05-10 06:33:35 UTC (rev 21100) @@ -7,6 +7,7 @@ #include #include +#include #define hz 1000000LL Modified: haiku/trunk/src/libs/compat/freebsd_network/compat.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-10 06:03:24 UTC (rev 21099) +++ haiku/trunk/src/libs/compat/freebsd_network/compat.c 2007-05-10 06:33:35 UTC (rev 21100) @@ -360,6 +360,30 @@ } +driver_t * +__haiku_probe_miibus(device_t dev, driver_t *drivers[], int count) +{ + driver_t *selected = NULL; + int i, selcost = 0; + + for (i = 0; i < count; i++) { + device_probe_t *probe = (device_probe_t *) + _resolve_method(drivers[i], "device_probe"); + if (probe) { + int result = probe(dev); + if (result >= 0) { + if (selected == NULL || result > selcost) { + selected = drivers[i]; + selcost = result; + } + } + } + } + + return selected; +} + + void bus_generic_attach(device_t dev) { @@ -369,27 +393,8 @@ child; child = list_get_next_item(&dev->children, child)) { if (child->driver == NULL) { if (dev->driver == &miibus_driver) { - int i, driver_count, driver_cost = INT_MIN; - driver_t **drivers, *driver = NULL; + driver_t *driver = __haiku_select_miibus_driver(child); - drivers = __haiku_get_miibus_drivers(&driver_count); - - for (i = 0; i < driver_count; i++) { - device_probe_t *probe = (device_probe_t *) - _resolve_method(drivers[i], "device_probe"); - - if (probe) { - /* XXX this kinda reverses the original logic */ - int result = probe(child); - if (result >= 0) { - if (driver == NULL || result > driver_cost) { - driver = drivers[i]; - driver_cost = result; - } - } - } - } - if (driver) device_set_driver(child, driver); } From hugosantos at mail.berlios.de Thu May 10 08:34:05 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Thu, 10 May 2007 08:34:05 +0200 Subject: [Haiku-commits] r21101 - in haiku/trunk/src/add-ons/kernel/drivers/network/3com: . dev dev/mii pci Message-ID: <200705100634.l4A6Y5Se025553@sheep.berlios.de> Author: hugosantos Date: 2007-05-10 08:33:49 +0200 (Thu, 10 May 2007) New Revision: 21101 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21101&view=rev Added: haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/ haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/ haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/bmtphy.c haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/bmtphyreg.h haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/exphy.c haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/miidevs.h haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/ukphy_subr.c Modified: haiku/trunk/src/add-ons/kernel/drivers/network/3com/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/Jamfile haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/glue.c Log: 3com driver, added required MII modules. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/3com/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/3com/Jamfile 2007-05-10 06:33:35 UTC (rev 21100) +++ haiku/trunk/src/add-ons/kernel/drivers/network/3com/Jamfile 2007-05-10 06:33:49 UTC (rev 21101) @@ -1,3 +1,4 @@ SubDir HAIKU_TOP src add-ons kernel drivers network 3com ; +SubInclude HAIKU_TOP src add-ons kernel drivers network 3com dev ; SubInclude HAIKU_TOP src add-ons kernel drivers network 3com pci ; Added: haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/Jamfile 2007-05-10 06:33:35 UTC (rev 21100) +++ haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/Jamfile 2007-05-10 06:33:49 UTC (rev 21101) @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network 3com dev ; + +SubInclude HAIKU_TOP src add-ons kernel drivers network 3com dev mii ; Added: haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/Jamfile 2007-05-10 06:33:35 UTC (rev 21100) +++ haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/Jamfile 2007-05-10 06:33:49 UTC (rev 21101) @@ -0,0 +1,16 @@ +SubDir HAIKU_TOP src add-ons kernel drivers network 3com dev mii ; + +UsePrivateHeaders kernel net ; + +UseHeaders [ FDirName $(SUBDIR) .. .. ] : true ; +UseHeaders [ FDirName $(HAIKU_TOP) src libs compat freebsd_network compat ] : true ; + +SubDirCcFlags [ FDefines _KERNEL=1 FBSD_DRIVER=1 ] ; + +KernelStaticLibrary 3com_mii.a + : + bmtphy.c + exphy.c + ukphy_subr.c + ; + Added: haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/bmtphy.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/bmtphy.c 2007-05-10 06:33:35 UTC (rev 21100) +++ haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/bmtphy.c 2007-05-10 06:33:49 UTC (rev 21101) @@ -0,0 +1,302 @@ +/*- + * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1997 Manuel Bouyer. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Manuel Bouyer. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * from: NetBSD: bmtphy.c,v 1.8 2002/07/03 06:25:50 simonb Exp + * + */ + +#include +__FBSDID("$FreeBSD: src/sys/dev/mii/bmtphy.c,v 1.9.2.1 2006/08/08 04:37:18 yongari Exp $"); + +/* + * Driver for the Broadcom BCM5201/BCM5202 "Mini-Theta" PHYs. This also + * drives the PHY on the 3Com 3c905C. The 3c905C's PHY is described in + * the 3c905C data sheet. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include "miidevs.h" + +#include + +#include "miibus_if.h" + +static int bmtphy_probe(device_t); +static int bmtphy_attach(device_t); + +static device_method_t bmtphy_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, bmtphy_probe), + DEVMETHOD(device_attach, bmtphy_attach), + DEVMETHOD(device_detach, mii_phy_detach), + DEVMETHOD(device_shutdown, bus_generic_shutdown), + + { 0, 0 } +}; + +static devclass_t bmtphy_devclass; + +static driver_t bmtphy_driver = { + "bmtphy", + bmtphy_methods, + sizeof(struct mii_softc) +}; + +DRIVER_MODULE(bmtphy, miibus, bmtphy_driver, bmtphy_devclass, 0, 0); + +static int bmtphy_service(struct mii_softc *, struct mii_data *, int); +static void bmtphy_status(struct mii_softc *); + +static int +bmtphy_probe(device_t dev) +{ + struct mii_attach_args *ma; + int rval; + + ma = device_get_ivars(dev); + rval = BUS_PROBE_DEFAULT; + + if (MII_OUI(ma->mii_id1, ma->mii_id2) != MII_OUI_BROADCOM) + return (ENXIO); + + switch (MII_MODEL(ma->mii_id2)) { + case MII_MODEL_BROADCOM_3C905B: + device_set_desc(dev, MII_STR_BROADCOM_3C905B); + rval = BUS_PROBE_LOW_PRIORITY; /* Let exphy take precedence. */ + break; + case MII_MODEL_BROADCOM_3C905C: + device_set_desc(dev, MII_STR_BROADCOM_3C905C); + rval = BUS_PROBE_LOW_PRIORITY; /* Let exphy take precedence. */ + break; + case MII_MODEL_BROADCOM_BCM5201: + device_set_desc(dev, MII_STR_BROADCOM_BCM5201); + break; + case MII_MODEL_BROADCOM_BCM5221: + device_set_desc(dev, MII_STR_BROADCOM_BCM5221); + break; + case MII_MODEL_BROADCOM_BCM4401: + device_set_desc(dev, MII_STR_BROADCOM_BCM4401); + break; + default: + return (ENXIO); + } + + return (rval); +} + +static int +bmtphy_attach(device_t dev) +{ + struct mii_softc *sc; + struct mii_attach_args *ma; + struct mii_data *mii; + + sc = device_get_softc(dev); + ma = device_get_ivars(dev); + sc->mii_dev = device_get_parent(dev); + mii = device_get_softc(sc->mii_dev); + LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + + sc->mii_inst = mii->mii_instance; + sc->mii_phy = ma->mii_phyno; + sc->mii_service = bmtphy_service; + sc->mii_pdata = mii; + + mii_phy_reset(sc); + + mii->mii_instance++; + + sc->mii_capabilities = + PHY_READ(sc, MII_BMSR) & ma->mii_capmask; + device_printf(dev, " "); + if ((sc->mii_capabilities & BMSR_MEDIAMASK) == 0) + printf("no media present"); + else + mii_phy_add_media(sc); + + printf("\n"); + + MIIBUS_MEDIAINIT(sc->mii_dev); + + return (0); +} + +static int +bmtphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) +{ + struct ifmedia_entry *ife; + int reg; + + ife = mii->mii_media.ifm_cur; + + switch (cmd) { + case MII_POLLSTAT: + /* + * If we're not polling our PHY instance, just return. + */ + if (IFM_INST(ife->ifm_media) != sc->mii_inst) + return (0); + break; + + case MII_MEDIACHG: + /* + * If the media indicates a different PHY instance, + * isolate ourselves. + */ + if (IFM_INST(ife->ifm_media) != sc->mii_inst) { + reg = PHY_READ(sc, MII_BMCR); + PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO); + return (0); + } + + /* + * If the interface is not up, don't do anything. + */ + if ((mii->mii_ifp->if_flags & IFF_UP) == 0) + break; + + mii_phy_setmedia(sc); + break; + + case MII_TICK: + /* + * If we're not currently selected, just return. + */ + if (IFM_INST(ife->ifm_media) != sc->mii_inst) + return (0); + if (mii_phy_tick(sc) == EJUSTRETURN) + return (0); + break; + } + + /* Update the media status. */ + bmtphy_status(sc); + + /* Callback if something changed. */ + mii_phy_update(sc, cmd); + + return (0); +} + +static void +bmtphy_status(struct mii_softc *sc) +{ + struct mii_data *mii; + struct ifmedia_entry *ife; + int bmsr, bmcr, aux_csr; + + mii = sc->mii_pdata; + ife = mii->mii_media.ifm_cur; + + mii->mii_media_status = IFM_AVALID; + mii->mii_media_active = IFM_ETHER; + + bmsr = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR); + aux_csr = PHY_READ(sc, MII_BMTPHY_AUX_CSR); + + if (bmsr & BMSR_LINK) + mii->mii_media_status |= IFM_ACTIVE; + + bmcr = PHY_READ(sc, MII_BMCR); + if (bmcr & BMCR_ISO) { + mii->mii_media_active |= IFM_NONE; + mii->mii_media_status = 0; + return; + } + + if (bmcr & BMCR_LOOP) + mii->mii_media_active |= IFM_LOOP; + + if (bmcr & BMCR_AUTOEN) { + /* + * The media status bits are only valid if autonegotiation + * has completed (or it's disabled). + */ + if ((bmsr & BMSR_ACOMP) == 0) { + /* Erg, still trying, I guess... */ + mii->mii_media_active |= IFM_NONE; + return; + } + + if (aux_csr & AUX_CSR_SPEED) + mii->mii_media_active |= IFM_100_TX; + else + mii->mii_media_active |= IFM_10_T; + if (aux_csr & AUX_CSR_FDX) + mii->mii_media_active |= IFM_FDX; + } else + mii->mii_media_active = ife->ifm_media; +} Added: haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/bmtphyreg.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/bmtphyreg.h 2007-05-10 06:33:35 UTC (rev 21100) +++ haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/bmtphyreg.h 2007-05-10 06:33:49 UTC (rev 21101) @@ -0,0 +1,181 @@ +/*- + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * from NetBSD: bmtphyreg.h,v 1.1 2001/06/02 21:42:10 thorpej Exp + * + * $FreeBSD: src/sys/dev/mii/bmtphyreg.h,v 1.2 2005/01/06 01:42:55 imp Exp $ + */ + +#ifndef _DEV_MII_BMTPHYREG_H_ +#define _DEV_MII_BMTPHYREG_H_ + +/* + * BCM5201/BCM5202 registers. + */ + +#define MII_BMTPHY_AUX_CTL 0x10 /* auxiliary control */ +#define AUX_CTL_TXDIS 0x2000 /* transmitter disable */ +#define AUX_CTL_4B5B_BYPASS 0x0400 /* bypass 4b5b encoder */ +#define AUX_CTL_SCR_BYPASS 0x0200 /* bypass scrambler */ +#define AUX_CTL_NRZI_BYPASS 0x0100 /* bypass NRZI encoder */ +#define AUX_CTL_RXALIGN_BYPASS 0x0080 /* bypass rx symbol alignment */ +#define AUX_CTL_BASEWANDER_DIS 0x0040 /* disable baseline wander correction */ +#define AUX_CTL_FEF_EN 0x0020 /* far-end fault enable */ + + +#define MII_BMTPHY_AUX_STS 0x11 /* auxiliary status */ +#define AUX_STS_FX_MODE 0x0400 /* 100base-FX mode (strap pin) */ +#define AUX_STS_LOCKED 0x0200 /* descrambler locked */ +#define AUX_STS_100BASE_LINK 0x0100 /* 1 = 100base link */ +#define AUX_STS_REMFAULT 0x0080 /* remote fault */ +#define AUX_STS_DISCON_STATE 0x0040 /* disconnect state */ +#define AUX_STS_FCARDET 0x0020 /* false carrier detected */ +#define AUX_STS_BAD_ESD 0x0010 /* bad ESD detected */ +#define AUX_STS_RXERROR 0x0008 /* Rx error detected */ +#define AUX_STS_TXERROR 0x0004 /* Tx error detected */ +#define AUX_STS_LOCKERROR 0x0002 /* lock error detected */ +#define AUX_STS_MLT3ERROR 0x0001 /* MLT3 code error detected */ + + +#define MII_BMTPHY_RXERROR_CTR 0x12 /* 100base-X Rx error counter */ +#define RXERROR_CTR_MASK 0x00ff + + +#define MII_BMTPHY_FCS_CTR 0x13 /* 100base-X false carrier counter */ +#define FCS_CTR_MASK 0x00ff + + +#define MII_BMTPHY_DIS_CTR 0x14 /* 100base-X disconnect counter */ +#define DIS_CTR_MASK 0x00ff + + +#define MII_BMTPHY_PTEST 0x17 /* PTEST */ + + +#define MII_BMTPHY_AUX_CSR 0x18 /* auxiliary control/status */ +#define AUX_CSR_JABBER_DIS 0x8000 /* jabber disable */ +#define AUX_CSR_FLINK 0x4000 /* force 10baseT link pass */ +#define AUX_CSR_HSQ 0x0080 /* SQ high */ +#define AUX_CSR_LSQ 0x0040 /* SQ low */ +#define AUX_CSR_ER1 0x0020 /* edge rate 1 */ +#define AUX_CSR_ER0 0x0010 /* edge rate 0 */ +#define AUX_CSR_ANEG 0x0008 /* auto-negotiation activated */ +#define AUX_CSR_F100 0x0004 /* force 100base */ +#define AUX_CSR_SPEED 0x0002 /* 1 = 100, 0 = 10 */ +#define AUX_CSR_FDX 0x0001 /* full-duplex */ + + +#define MII_BMTPHY_AUX_SS 0x19 /* auxiliary status summary */ +#define AUX_SS_ACOMP 0x8000 /* auto-negotiation complete */ +#define AUX_SS_ACOMP_ACK 0x4000 /* auto-negotiation compl. ack */ +#define AUX_SS_AACK_DET 0x2000 /* auto-neg. ack detected */ +#define AUX_SS_ANLPAD 0x1000 /* auto-neg. link part. ability det */ +#define AUX_SS_ANEG_PAUSE 0x0800 /* pause operation bit */ +#define AUX_SS_HCD 0x0700 /* highest common denominator */ +#define AUX_SS_HCD_NONE 0x0000 /* none */ +#define AUX_SS_HCD_10T 0x0100 /* 10baseT */ +#define AUX_SS_HCD_10T_FDX 0x0200 /* 10baseT-FDX */ +#define AUX_SS_HCD_100TX 0x0300 /* 100baseTX-FDX */ +#define AUX_SS_HCD_100T4 0x0400 /* 100baseT4 */ +#define AUX_SS_HCD_100TX_FDX 0x0500 /* 100baseTX-FDX */ +#define AUX_SS_PDF 0x0080 /* parallel detection fault */ +#define AUX_SS_LPRF 0x0040 /* link partner remote fault */ +#define AUX_SS_LPPR 0x0020 /* link partner page received */ +#define AUX_SS_LPANA 0x0010 /* link partner auto-neg able */ +#define AUX_SS_SPEED 0x0008 /* 1 = 100, 0 = 10 */ +#define AUX_SS_LINK 0x0004 /* link pass */ +#define AUX_SS_ANEN 0x0002 /* auto-neg. enabled */ +#define AUX_SS_JABBER 0x0001 /* jabber detected */ + + +#define MII_BMTPHY_INTR 0x1a /* interrupt register */ +#define INTR_FDX_LED 0x8000 /* full-duplex led enable */ +#define INTR_INTR_EN 0x4000 /* interrupt enable */ +#define INTR_FDX_MASK 0x0800 /* full-dupled intr mask */ +#define INTR_SPD_MASK 0x0400 /* speed intr mask */ +#define INTR_LINK_MASK 0x0200 /* link intr mask */ +#define INTR_INTR_MASK 0x0100 /* master interrupt mask */ +#define INTR_FDX_CHANGE 0x0008 /* full-duplex change */ +#define INTR_SPD_CHANGE 0x0004 /* speed change */ +#define INTR_LINK_CHANGE 0x0002 /* link change */ +#define INTR_INTR_STATUS 0x0001 /* interrupt status */ + + +#define MII_BMTPHY_AUX2 0x1b /* auliliary mode 2 */ +#define AUX2_BLOCK_RXDV 0x0200 /* block RXDV mode enabled */ +#define AUX2_ANPDQ 0x0100 /* auto-neg parallel detection Q mode */ +#define AUX2_TRAFFIC_LED 0x0040 /* traffic meter led enable */ +#define AUX2_FXMTRCV_LED 0x0020 /* force Tx and Rx LEDs */ +#define AUX2_HS_TOKEN 0x0010 /* high-speed token ring mode */ +#define AUX2_AUTO_LP 0x0008 /* auto low-power mode */ +#define AUX2_TWOLINK_LED 0x0004 /* two link LEDs */ +#define AUX2_SQE_DIS 0x0002 /* disable SQE pulse */ + + +#define MII_BMTPHY_AUXERR 0x1c /* auxiliary error */ +#define AUXERR_MANCHESTER 0x0400 /* Manchester code error */ +#define AUXERR_EOF 0x0200 /* EOF detection error */ +#define AUXERR_POLARITY 0x0100 /* polarity inversion */ +#define AUXERR_ANEG 0x0008 /* autonegotiation enabled */ +#define AUXERR_F100 0x0004 /* force 100base */ +#define AUXERR_SPEED 0x0002 /* 1 = 100, 0 = 10 */ +#define AUXERR_FDX 0x0001 /* full-duplex */ + + +#define MII_BMTPHY_AUXMODE 0x1d /* auxiliary mode */ +#define AUXMODE_ACT_LED_DIS 0x0010 /* activity LED disable */ +#define AUXMODE_LINK_LED_DIS 0x0008 /* link LED disable */ +#define AUXMODE_BLOCK_TXEN 0x0002 /* enable block TXEN */ + + +#define MII_BMTPHY_AUXMPHY 0x1e /* auxiliary multiple phy register */ +#define AUXMPHY_HCD_TX_FDX 0x8000 /* res. is 100baseTX-FDX */ +#define AUXMPHY_HCD_T4 0x4000 /* res. is 100baseT4 */ +#define AUXMPHY_HCD_TX 0x2000 /* res. is 100baseTX */ +#define AUXMPHY_HCD_10T_FDX 0x1000 /* res. is 10baseT-FDX */ +#define AUXMPHY_HCD_10T 0x0800 /* res. is 10baseT */ +#define AUXMPHY_RES_ANEG 0x0100 /* restart auto-negotiation */ +#define AUXMPHY_ANEG_COMP 0x0080 /* auto-negotiation complete */ +#define AUXMPHY_ACK_COMP 0x0040 /* acknowledge complete */ +#define AUXMPHY_ACK_DET 0x0020 /* acknowledge detected */ +#define AUXMPHY_ABILITY_DET 0x0010 /* waiting for LP ability */ +#define AUXMPHY_SUPER_ISO 0x0008 /* super-isolate mode */ +#define AUXMPHY_10T_SERIAL 0x0002 /* 10baseT serial mode */ + + +#define MII_BMTPHY_TEST 0x1d /* Broadcom test register */ + + +#endif /* _DEV_MII_BMTPHYREG_H_ */ Added: haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/exphy.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/exphy.c 2007-05-10 06:33:35 UTC (rev 21100) +++ haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/exphy.c 2007-05-10 06:33:49 UTC (rev 21101) @@ -0,0 +1,271 @@ +/* $NetBSD: exphy.c,v 1.16 1999/04/23 04:24:32 thorpej Exp $ */ + +/*- + * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center, and by Frank van der Linden. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1997 Manuel Bouyer. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Manuel Bouyer. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/sys/dev/mii/exphy.c,v 1.19.2.1 2006/08/08 04:37:18 yongari Exp $"); + +/* + * driver for 3Com internal PHYs + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include "miidevs.h" + +#include "miibus_if.h" + +static int exphy_probe(device_t); +static int exphy_attach(device_t); + +static device_method_t exphy_methods[] = { + /* device interface */ + DEVMETHOD(device_probe, exphy_probe), + DEVMETHOD(device_attach, exphy_attach), + DEVMETHOD(device_detach, mii_phy_detach), + DEVMETHOD(device_shutdown, bus_generic_shutdown), + { 0, 0 } +}; + +static devclass_t exphy_devclass; + +static driver_t exphy_driver = { + "xlphy", + exphy_methods, + sizeof(struct mii_softc) +}; + +DRIVER_MODULE(xlphy, miibus, exphy_driver, exphy_devclass, 0, 0); + +static int exphy_service(struct mii_softc *, struct mii_data *, int); +static void exphy_reset(struct mii_softc *); + +static int +exphy_probe(dev) + device_t dev; +{ + struct mii_attach_args *ma; + device_t parent; + + ma = device_get_ivars(dev); + parent = device_get_parent(device_get_parent(dev)); + + /* + * Argh, 3Com PHY reports oui == 0 model == 0! + */ + if ((MII_OUI(ma->mii_id1, ma->mii_id2) != 0 || + MII_MODEL(ma->mii_id2) != 0) && + (MII_OUI(ma->mii_id1, ma->mii_id2) != MII_OUI_BROADCOM || + MII_MODEL(ma->mii_id2) != MII_MODEL_BROADCOM_3C905C)) + return (ENXIO); + + /* + * Make sure the parent is an `ex'. + */ + if (strcmp(device_get_name(parent), "xl") != 0) + return (ENXIO); + + if (MII_OUI(ma->mii_id1, ma->mii_id2) == 0) + device_set_desc(dev, "3Com internal media interface"); + else + device_set_desc(dev, MII_STR_BROADCOM_3C905C); + + return (BUS_PROBE_DEFAULT); +} + +static int +exphy_attach(dev) + device_t dev; +{ + struct mii_softc *sc; + struct mii_attach_args *ma; + struct mii_data *mii; + + sc = device_get_softc(dev); + ma = device_get_ivars(dev); + sc->mii_dev = device_get_parent(dev); + mii = device_get_softc(sc->mii_dev); + + /* + * The 3Com PHY can never be isolated, so never allow non-zero + * instances! + */ + if (mii->mii_instance != 0) { + device_printf(dev, "ignoring this PHY, non-zero instance\n"); + return(ENXIO); + } + + LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + + sc->mii_inst = mii->mii_instance; + sc->mii_phy = ma->mii_phyno; + sc->mii_service = exphy_service; + sc->mii_pdata = mii; + mii->mii_instance++; + + sc->mii_flags |= MIIF_NOISOLATE; + +#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL) + +#if 0 /* See above. */ + ADD(IFM_MAKEWORD(IFM_ETHER, IFM_NONE, 0, sc->mii_inst), + BMCR_ISO); +#endif + + ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst), + BMCR_LOOP|BMCR_S100); + + exphy_reset(sc); + + sc->mii_capabilities = + PHY_READ(sc, MII_BMSR) & ma->mii_capmask; + device_printf(dev, " "); + mii_phy_add_media(sc); + printf("\n"); +#undef ADD + MIIBUS_MEDIAINIT(sc->mii_dev); + return(0); +} + +static int +exphy_service(sc, mii, cmd) + struct mii_softc *sc; + struct mii_data *mii; + int cmd; +{ + struct ifmedia_entry *ife = mii->mii_media.ifm_cur; + + /* + * We can't isolate the 3Com PHY, so it has to be the only one! + */ + if (IFM_INST(ife->ifm_media) != sc->mii_inst) + panic("exphy_service: can't isolate 3Com PHY"); + + switch (cmd) { + case MII_POLLSTAT: + break; + + case MII_MEDIACHG: + /* + * If the interface is not up, don't do anything. + */ + if ((mii->mii_ifp->if_flags & IFF_UP) == 0) + break; + + mii_phy_setmedia(sc); + break; + + case MII_TICK: + /* + * Is the interface even up? + */ + if ((mii->mii_ifp->if_flags & IFF_UP) == 0) + return (0); + + /* + * Only used for autonegotiation. + */ + if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) + break; + + /* + * The 3Com PHY's autonegotiation doesn't need to be + * kicked; it continues in the background. + */ + break; + } + + /* Update the media status. */ + ukphy_status(sc); + + /* Callback if something changed. */ + mii_phy_update(sc, cmd); + return (0); +} + +static void +exphy_reset(struct mii_softc *sc) +{ + + mii_phy_reset(sc); + + /* + * XXX 3Com PHY doesn't set the BMCR properly after + * XXX reset, which breaks autonegotiation. + */ + PHY_WRITE(sc, MII_BMCR, BMCR_S100|BMCR_AUTOEN|BMCR_FDX); +} Added: haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/miidevs.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/miidevs.h 2007-05-10 06:33:35 UTC (rev 21100) +++ haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/miidevs.h 2007-05-10 06:33:49 UTC (rev 21101) @@ -0,0 +1,12 @@ +#define MII_OUI_BROADCOM 0x001018 +#define MII_MODEL_BROADCOM_3C905B 0x0012 +#define MII_MODEL_BROADCOM_3C905C 0x0017 +#define MII_MODEL_BROADCOM_BCM5201 0x0021 +#define MII_MODEL_BROADCOM_BCM5221 0x001e +#define MII_MODEL_BROADCOM_BCM4401 0x0036 + +#define MII_STR_BROADCOM_3C905B "3C905B" +#define MII_STR_BROADCOM_3C905C "3C905C" +#define MII_STR_BROADCOM_BCM5201 "BCM5201" +#define MII_STR_BROADCOM_BCM5221 "BCM5221" +#define MII_STR_BROADCOM_BCM4401 "BCM4401" Added: haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/ukphy_subr.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/ukphy_subr.c 2007-05-10 06:33:35 UTC (rev 21100) +++ haiku/trunk/src/add-ons/kernel/drivers/network/3com/dev/mii/ukphy_subr.c 2007-05-10 06:33:49 UTC (rev 21101) @@ -0,0 +1,129 @@ +/* $NetBSD: ukphy_subr.c,v 1.2 1998/11/05 04:08:02 thorpej Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center, and by Frank van der Linden. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/sys/dev/mii/ukphy_subr.c,v 1.8.8.1 2006/07/19 04:40:26 yongari Exp $"); + +/* + * Subroutines shared by the ukphy driver and other PHY drivers. + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include "miibus_if.h" + +/* + * Media status subroutine. If a PHY driver does media detection simply + * by decoding the NWay autonegotiation, use this routine. + */ +void +ukphy_status(struct mii_softc *phy) +{ + struct mii_data *mii = phy->mii_pdata; + struct ifmedia_entry *ife = mii->mii_media.ifm_cur; + int bmsr, bmcr, anlpar, gtcr, gtsr; + + mii->mii_media_status = IFM_AVALID; + mii->mii_media_active = IFM_ETHER; + + bmsr = PHY_READ(phy, MII_BMSR) | PHY_READ(phy, MII_BMSR); + if (bmsr & BMSR_LINK) + mii->mii_media_status |= IFM_ACTIVE; + + bmcr = PHY_READ(phy, MII_BMCR); + if (bmcr & BMCR_ISO) { + mii->mii_media_active |= IFM_NONE; + mii->mii_media_status = 0; + return; + } + + if (bmcr & BMCR_LOOP) + mii->mii_media_active |= IFM_LOOP; + + if (bmcr & BMCR_AUTOEN) { + /* + * NWay autonegotiation takes the highest-order common + * bit of the ANAR and ANLPAR (i.e. best media advertised + * both by us and our link partner). + */ + if ((bmsr & BMSR_ACOMP) == 0) { + /* Erg, still trying, I guess... */ + mii->mii_media_active |= IFM_NONE; + return; + } + + anlpar = PHY_READ(phy, MII_ANAR) & PHY_READ(phy, MII_ANLPAR); + if ((phy->mii_flags & MIIF_HAVE_GTCR) != 0 && + (phy->mii_extcapabilities & + (EXTSR_1000THDX | EXTSR_1000TFDX)) != 0) { + gtcr = PHY_READ(phy, MII_100T2CR); + gtsr = PHY_READ(phy, MII_100T2SR); + } else + gtcr = gtsr = 0; + + if ((gtcr & GTCR_ADV_1000TFDX) && (gtsr & GTSR_LP_1000TFDX)) + mii->mii_media_active |= IFM_1000_T|IFM_FDX; + else if ((gtcr & GTCR_ADV_1000THDX) && + (gtsr & GTSR_LP_1000THDX)) + mii->mii_media_active |= IFM_1000_T; + else if (anlpar & ANLPAR_T4) + mii->mii_media_active |= IFM_100_T4; + else if (anlpar & ANLPAR_TX_FD) + mii->mii_media_active |= IFM_100_TX|IFM_FDX; + else if (anlpar & ANLPAR_TX) + mii->mii_media_active |= IFM_100_TX; + else if (anlpar & ANLPAR_10_FD) + mii->mii_media_active |= IFM_10_T|IFM_FDX; + else if (anlpar & ANLPAR_10) + mii->mii_media_active |= IFM_10_T; + else + mii->mii_media_active |= IFM_NONE; + } else + mii->mii_media_active = ife->ifm_media; +} Modified: haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/Jamfile 2007-05-10 06:33:35 UTC (rev 21100) +++ haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/Jamfile 2007-05-10 06:33:49 UTC (rev 21101) @@ -12,6 +12,6 @@ KernelAddon 3com : if_xl.c glue.c - : libfreebsd_network.a + : libfreebsd_network.a 3com_mii.a ; Modified: haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/glue.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/glue.c 2007-05-10 06:33:35 UTC (rev 21100) +++ haiku/trunk/src/add-ons/kernel/drivers/network/3com/pci/glue.c 2007-05-10 06:33:49 UTC (rev 21101) @@ -1,7 +1,22 @@ #include -HAIKU_FBSD_DRIVER_GLUE(3com, xl, pci) +HAIKU_FBSD_DRIVER_GLUE(3com, xl, pci); -NO_HAIKU_CHECK_DISABLE_INTERRUPTS() +extern driver_t *DRIVER_MODULE_NAME(bmtphy, miibus); +extern driver_t *DRIVER_MODULE_NAME(xlphy, miibus); -HAIKU_DRIVER_REQUIREMENTS(FBSD_TASKQUEUES); +driver_t *__haiku_select_miibus_driver(device_t dev) +{ + driver_t *drivers[] = { + DRIVER_MODULE_NAME(bmtphy, miibus), + DRIVER_MODULE_NAME(xlphy, miibus) + }; [... truncated: 10 lines follow ...] From hugosantos at mail.berlios.de Thu May 10 08:38:28 2007 From: hugosantos at mail.berlios.de (hugosantos at mail.berlios.de) Date: Thu, 10 May 2007 08:38:28 +0200 Subject: [Haiku-commits] r21102 - haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci Message-ID: <200705100638.l4A6cSUX025793@sheep.berlios.de> Author: hugosantos Date: 2007-05-10 08:38:20 +0200 (Thu, 10 May 2007) New Revision: 21102 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21102&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/glue.c Log: rtl8139exp: lock the softc when re-enabling interrupts so we don't in the middle of a disable/enable interrupts operation. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/glue.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/glue.c 2007-05-10 06:33:49 UTC (rev 21101) +++ haiku/trunk/src/add-ons/kernel/drivers/network/rtl8139/pci/glue.c 2007-05-10 06:38:20 UTC (rev 21102) @@ -21,5 +21,7 @@ HAIKU_REENABLE_INTERRUPTS(device_t dev) { struct rl_softc *sc = device_get_softc(dev); + RL_LOCK(sc); HAIKU_PROTECT_INTR_REGISTER(CSR_WRITE_2(sc, RL_IMR, RL_INTRS)); + RL_UNLOCK(sc); } From axeld at pinc-software.de Thu May 10 09:01:07 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Thu, 10 May 2007 09:01:07 +0200 CEST Subject: [Haiku-commits] r21096 - haiku/trunk/src/kits/app In-Reply-To: <200705092316.l49NGKQt025270@sheep.berlios.de> Message-ID: <1291901590-BeMail@zon> korli at BerliOS wrote: > Log: > fHandlerToken can be equal to B_PREFERRED_TOKEN Did you perceive any problems with the previous version or did you just find it accidently? :-) Bye, Axel. From axeld at pinc-software.de Thu May 10 09:02:41 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Thu, 10 May 2007 09:02:41 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r21101_-_in_haiku/trunk/src/add-o?= =?iso-8859-15?q?ns/kernel/drivers/network/3com=3A_=2E_dev_dev/mii_pci?= In-Reply-To: <200705100634.l4A6Y5Se025553@sheep.berlios.de> Message-ID: <1385120679-BeMail@zon> hugosantos at mail.berlios.de wrote: > Log: > 3com driver, added required MII modules. I thought all the MIIs were part of the FreeBSD MII module? Bye, Axel. From hugosantos at gmail.com Thu May 10 09:14:03 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Thu, 10 May 2007 08:14:03 +0100 Subject: [Haiku-commits] r21101 - in haiku/trunk/src/add-ons/kernel/drivers/network/3com: . dev dev/mii pci In-Reply-To: <1385120679-BeMail@zon> References: <200705100634.l4A6Y5Se025553@sheep.berlios.de> <1385120679-BeMail@zon> Message-ID: <9c46321e0705100014l6fd74375l445abe3f72ab3a14@mail.gmail.com> Hey Axel, They are all individual modules, even though they all sit in the same directory (dev/mii/). By the way, i've only looked briefly at this driver (3com)'s interrupt handling, but it might be a bit too complex for my current handling of disabling/enabling device interrupts. It would be really nice to be able to pull the threading bits to the kernel's interrupt management. By concentrating it there, we would be able to handle this neatly. My proposal would be to add a new install_io_interrupt_handler flag which flagged the handler as "non-fast" or something like that. If any of the rest of the handlers for that particular interrupt processed it, we would ignore the non-fast handlers. If not, we would disable the interrupt and defer the processing to a per-interrupt thread and re-enable the interrupts after all the non-fast handlers executed. This wouldn't have an impact on existing interrupt handlers and would work on shared irq situations. Also, i believe level triggered interrupts are not cleared by the devices before the interrupt is serviced, so disabling the interrupt in the interrupt mask shouldn't make us lose any interrupts. I know some of you feel strongly against this, but hopefully we can reach a compromise. Let me know about your comments. Thanks, Hugo On 5/10/07, Axel D?rfler wrote: > hugosantos at mail.berlios.de wrote: > > Log: > > 3com driver, added required MII modules. > > I thought all the MIIs were part of the FreeBSD MII module? > > Bye, > Axel. > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From korli at users.berlios.de Thu May 10 09:44:56 2007 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Thu, 10 May 2007 09:44:56 +0200 Subject: [Haiku-commits] r21096 - haiku/trunk/src/kits/app In-Reply-To: <1291901590-BeMail@zon> References: <200705092316.l49NGKQt025270@sheep.berlios.de> <1291901590-BeMail@zon> Message-ID: 2007/5/10, Axel D?rfler : > korli at BerliOS wrote: > > Log: > > fHandlerToken can be equal to B_PREFERRED_TOKEN > > Did you perceive any problems with the previous version or did you just > find it accidently? :-) > I can commit my test app : it just constructs a BMessenger with a target BLooper. It was exposed by the destructor of the CannaMethod class. See http://svn.berlios.de/viewcvs/haiku/haiku/trunk/src/add-ons/input_server/methods/canna/CannaMethod.cpp?rev=11769&view=markup Bye, J?r?me From axeld at pinc-software.de Thu May 10 10:16:50 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Thu, 10 May 2007 10:16:50 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r21101_-_in_haiku/trunk/src/add-o?= =?iso-8859-15?q?ns/kernel/drivers/network/3com=3A_=2E_dev_dev/mii_pci?= In-Reply-To: <9c46321e0705100014l6fd74375l445abe3f72ab3a14@mail.gmail.com> Message-ID: <5834628089-BeMail@zon> Hi Hugo, "Hugo Santos" wrote: > They are all individual modules, even though they all sit in the > same directory (dev/mii/). Okay then (I was under the impression every driver could use any MII module) :) > My proposal would be to add a new > install_io_interrupt_handler flag which flagged the handler as > "non-fast" or something like that. If any of the rest of the handlers > for that particular interrupt processed it, we would ignore the > non-fast handlers. If not, we would disable the interrupt and defer > the processing to a per-interrupt thread and re-enable the interrupts > after all the non-fast handlers executed. > > This wouldn't have an impact on existing interrupt handlers and > would work on shared irq situations. Also, i believe level triggered > interrupts are not cleared by the devices before the interrupt is > serviced, so disabling the interrupt in the interrupt mask shouldn't > make us lose any interrupts. While this sounds like the best compromise so far, it still has an impact on shared interrupts (even though it would work): it increases the interrupt latency by an undeterminable amount. IOW it would be an ugly kludge to get FreeBSD drivers running more easily, it would by no means introduce a valid alternative to driver development under Haiku. So if we would agree on this, it would only serve to get more drivers into the tree in the short term - we should still work towards replacing any driver that actually needs this with our own code. That's why I'm not sure it's worth the effort - if ie. the VIA Rhine or RTL8139 drivers need this, we should fix our drivers rather than switching to FreeBSD's. Bye, Axel. From nielx at mail.berlios.de Thu May 10 11:02:46 2007 From: nielx at mail.berlios.de (nielx at BerliOS) Date: Thu, 10 May 2007 11:02:46 +0200 Subject: [Haiku-commits] r21103 - haiku/trunk/docs/user Message-ID: <200705100902.l4A92kNa003306@sheep.berlios.de> Author: nielx Date: 2007-05-10 11:02:45 +0200 (Thu, 10 May 2007) New Revision: 21103 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21103&view=rev Modified: haiku/trunk/docs/user/apidoc.dox Log: Patch by Alan Smale: "I have made the doc header consistent with what the document content specifies it should be. I've rephrased things and corrected typos and spelling. Checked through the grammar and amended some gramatical errors." Modified: haiku/trunk/docs/user/apidoc.dox =================================================================== --- haiku/trunk/docs/user/apidoc.dox 2007-05-10 06:38:20 UTC (rev 21102) +++ haiku/trunk/docs/user/apidoc.dox 2007-05-10 09:02:45 UTC (rev 21103) @@ -1,68 +1,63 @@ -// -// Copyright 2007 Haiku Inc. All rights reserved. -// -// Distributed under the terms of the MIT License. -// -// -// Documentation by: -// Niels Sascha Reedijk -// +/* + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Documentation by: + * Niels Sascha Reedijk + */ /*! \page apidoc Documenting the API - This article explains how to document the API. It's intended audience are the - Haiku developers that want to document their own classes, and also the - members of the API Documentation team who want to brush up the documentation. + This article explains how to document the API. Its intended audience are the + Haiku developers who want to document their own classes, and also the members + of the API Documentation team who want to brush up the documentation. This document is divided into three sections. \ref formalrequirements - describes the demands that are made from the markup and - spacing of the files. \ref commands describes the subset - of Doxygen commands the Haiku API documentation uses, and which commands - are used in which situation. \ref style describes the - writing style that is required. The demands are both on the required sections - in the documentation as well as on the wording of that documentation. + describes the demands that are made from the markup and spacing of the files. + \ref commands describes the subset of Doxygen commands the Haiku API + documentation uses, and which commands are used in which situation. \ref style + describes the required style and structure of the documentation. If you are a developer and you want to prepare the first version of the - documentation for the API documentation team to go over, have a good look - at the formal requirements and the doxygen commands, and have a quick glance - at how to write member and class documentation, since you'll need to know - which information should definately be in the documentation. Aspiring members - or members of the API documentation team should read the third section - carefully, and should also check out some of the finished documentation to - get a good grip on the actual tone, style and contents of the documentation. + documentation for the API documentation team to go over, have a good look at + the formal requirements and the Doxygen commands. In addition, have a quick + glance at how to write member and class documentation, since you'll need to + know which information is mandatory for the documentation. Aspiring members or + members of the API documentation team should read the third section carefully, + and should also check out some of the finished documentation to get a good + grip on the actual tone, style and contents of the documentation. \section formalrequirements Formal Requirements This section describes formal requirements, such as location and naming of the files, the header blocks of files, what blocks of documentation look like - and how to put delimeters to separate different 'blocks' in your source file. + and how to put delimiters to separate different 'blocks' in your source file. \subsection formalrequirements_location Location of the Documentation Source - Doxygen, the tool that we use to generate the marked up documentation, - has an ingenious parser that is able to scan through both header and source - files and that makes it possible to document the API directly in the headers - or the source. However, the Haiku project decided not to put the - documentation in either location, and opt for the third option Doxygen gives: - to put the documentation in separate files. + Doxygen, the tool that we use to generate the marked up documentation, has an + ingenious parser that is able to scan through both header and source files + making it possible to document the API directly in the headers or the source. + However, the Haiku project have decided not to put the documentation in either + location, and opt for the third option Doxygen provides: to put the + documentation into separate files. - \note The reasons to not put the - documentation in the header files are twofold. First of all, it would - unnecesarily add much cruft to the headers that the compiler will have to - parse unneededly. File access and speed isn't BeOS and Haiku's best quality. - The second reason is that the system headers are included throughout the - tree. It's a waste of electricity to have everybody recompile the entire tree - if someone fixes a typo in the documentation. Likewise, the reason to not put - the documentation in the source is that it unnecesarily clutters up that - source. By not using direct documentation we lose some advantages, like the - fact that developers might be inclined to update the documentation quicker - if they change a method, but as you will see we'll have some methods in place - to prevent that to a certain extend. + \note The reasons to not put the documentation in the header files are + twofold. First of all, it would add unnecessary cruft to the headers that + the compiler will needlessly have to parse. File access and speed isn't BeOS + and Haiku's best quality. The second reason is that the system headers are + included throughout the tree. It's a waste of electricity to have everybody + recompile the entire tree if someone fixes a typo in the documentation. + Likewise, the reason to not put the documentation in the source code is that + it unnecessarily clutters up that file. By not using direct documentation we + lose some advantages, like the fact that developers might be inclined to + update the documentation quicker if they change a method, but as you will + see we'll have some methods in place to prevent that to a certain extent. - There are a few aspects to naming and location of files: + There are a few aspects to the naming and locations of files: -# Most important, documentation files \b mirror header files. This not only - means that they get the same name, but also that the order of the methods, + means that they get the same name, but also that the order of the methods, variables, functions, etc. will have to be the same. -# The root directory of the public API headers is at \c /trunk/headers/os. In a similar vein, the root of the documentation files is at @@ -75,12 +70,12 @@ \subsection formalrequirements_headerblock The Header Block Every documentation file will begin with the header block. It's basically a - copyright block, with a reference to the author(s) and with the revision - against which the documentaton was written. + copyright block, with a reference to the author(s) and against which revision + the documentation was written. \verbatim /* - * Copyright 2007 Haiku, Inc. All rights reserved. + * Copyright 2007 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Documentation by: @@ -88,15 +83,15 @@ * Corresponds to: * /trunk/headers/os/support/String.h rev 19731 * /trunk/src/kits/support/String.cpp rev 19731 - * / + */ \endverbatim The example above has a few elements that you should take note of: - -# The header is put in a standard C comment, which are enclosed between + -# The header is put in a standard C comment, which is enclosed between \c /* and \c *\/. -# Every line starts with a whitespace and an asterix, followed by another space. If the text is part of a category, such as Documentation - by, put three spaces after the delimeter. + by, put three spaces after the delimiter. -# We start with a copyright notice. The first line is empty, then the copyright notice, then the line on \e MIT, followed by an empty line. -# Then there is a label Documentation by:, which is followed by @@ -104,23 +99,23 @@ -# The final part is underneath the label Corresponds to:. Underneath there is a list of files and their svn revisions that the current documentation is known to correspond with. - -# The header block ends with the \c *\/, where the asterix is alligned with - with the ones above it. + -# The header block ends with the \c *\/, where the asterix is aligned with + the ones above it. \subsection formalrequirements_blocks Blocks - Blocks are the basic units of documentation for Doxygen. At first it will - feel like overkill to use blocks, but realize that Doxygen was initially - designed to operate on header and source files, and then the blocks of - documentation would be before the definition or declaration of the - methods, functions, etcetera. Doxygen is used to blocks and that's why we - need to reproduce them in our \c dox files. + Blocks are the basic units of documentation for Doxygen. At first it will feel + like overkill to use blocks, but realize that Doxygen was initially designed + to operate on header and source files, and then the blocks of documentation + would be before the definition or declaration of the methods, functions, + etcetera. Doxygen is used to operating on blocks, and that's why we need to + reproduce them in our \c dox files. Blocks should adhere to the following standards: -# All blocks open with \c /*! and close with \c * / - -# The documentation is in between these markers. - -# All the contents in between the markers is indended by two spaces. - -# The maximum width of contents between blocks is 80 columns. Try not + -# The documentation is placed in between these markers. + -# All the contents in between the markers is indented by two spaces. + -# The maximum width of the contents between blocks is 80 columns. Try not to cross this limit, because it will severely limit readability. Example: @@ -133,41 +128,40 @@ \retval true The item was appended. \retval false Item was not appended, since resizing the list failed. \sa AddItem(void *item, int32 index) -* / +*/ \endverbatim - \note Doxygen also allows to use single line comments, starting with \c //!, - however, we won't use these \b except in case of group markers, which you + \note Doxygen also allows the use of single line comments, starting with + \c //!, however, we won't use these \b except for group markers, which you can read more about in the next section. - \subsection formalrequirements_delimeters Delimeters + \subsection formalrequirements_delimiters Delimiters - Many of the header files in the Haiku API just document one class or one - group of functions. However, there might want to come a time that you come - across a more complex header and for the sake of clarity of your \c dox file - you want to mark the sections. Use the standard delimiter marker for this, - which consists of five slashes, a space, the title of the section, a space - and another five slashes. Like this: ///// Global Functions /////. + Many of the header files in the Haiku API just document one class or one group + of functions. However, there be a time when you come across a more complex + header and for the sake of clarity in your \c dox file you want to mark the + sections. Use the standard delimiter marker for this, which consists of five + slashes, a space, the title of the section, a space and another five slashes. + Like this: ///// Global Functions /////. \note This is only for the source files and for you as documenter. It will not show up in the actual generated documentation! \section commands Doxygen Commands - This section describes all the Doxygen commands that will be used in the - Haiku API documentation. As a rule, Doxygen commands start with a backslash - (\\) and are followed by whitespace (such as a space or a newline), with the - exception of group markers, which will be discussed later on. The commands - can be divided into several categories, which will be described in the - following subsections. + This section describes all the Doxygen commands that will be used in the Haiku + API documentation. As a rule, Doxygen commands start with a backslash (\\) and + are followed by whitespace (such as a space or a newline), with the exception + of group markers; this is discussed in more detail later on. The commands can + be divided into several categories, which are described in the following + subsections. \note This section does not discuss which commands you should actually use in documentation. See the next section on \ref style - on that. This section merely explains the different groupings and + for that. This section merely explains the different groupings and syntaxes of commands. - Most commands accept an argument. Arguments can be either of these three - types: + Most commands accept an argument. Arguments can be one of these three types: - \ - The argument is a single word. - (until the end of the line) - The argument runs until the end of the line. - {paragraph} - The argument runs for an entire paragraph. A paragraph is @@ -187,8 +181,8 @@ documentation block would be one of the following commands: - \c \\class \ \n - Tells doxygen that the following section is going to be on - the class as specified by \a name. + Tells Doxygen that the following section is going to be on the class as + specified by \a name. - \c \\fn (function declaration) \n This block is going to be about the function that corresponds to the given declaration. Please note that the declaration is what you find in the source @@ -203,7 +197,7 @@ This block is going to be about the typedef indicated by the declaration. Copy the declaration exactly, including the leading \c typedef keyword. - \c \\struct \ \n - Tells doxygen the section is going to be on the \c struct indicated by + Tells Doxygen the section is going to be on the \c struct indicated by \a name. - \c \\def \ \n This block is going to be about the \c \#define with the identifier \a name. @@ -214,7 +208,7 @@ \subsection commands_sections Sections in Member Documentation If you have a look at the output that Doxygen generates, you can see that - there are recuring sections in the documentation. Documentation that belongs + there are recurring sections in the documentation. Documentation that belongs to a certain section should be placed after a command that marks the start of that section. All the commands take a paragraph as answer. A paragraph ends with a whitespace, or with a command that marks a new section. Note that @@ -223,11 +217,11 @@ following: - \c \\brief {brief description} \n - This is the only \b obligatory section. Every member should have at least + This is the only \b mandatory section. Every member should have at least a brief description. - \c \\param \ {parameter description} \n This section describes a parameter with the name \a parameter-name. The - parameter name must match the function declaration, since doxygen will + parameter name must match the function declaration, since Doxygen will check if all the documented parameters exist. - \c \\return {description of the return value} \n This section describes the return value. This is a totally free form @@ -238,7 +232,8 @@ This section contains references to other parts of the documentation. There are also a number of things that can be used in pages and member - documentation. See the style section to find out which one to use when. + documentation. See the style section to find out the appropriate situations in + which to use them. - \c \\note {text} - \c \\attention {text} @@ -247,19 +242,19 @@ \subsection commands_markup Markup - Sometimes you might certain text to have a special markup, to make words - stand out, but also if you want to have example code within the documentation - you'll need a special markup. Doxygen defines three types of commands. - There are commands that work on single words, commands that work on longer - phrases and commands that define blocks. Basically, the single letter + Sometimes you might require certain text to have a special markup, to make + words stand out, but also if you want to have example code within the + documentation you'll need a special markup. Doxygen defines three types of + commands. There are commands that work on single words, commands that work on + longer phrases and commands that define blocks. Basically, the single letter commands are commands that work on a the next word. If you need to mark - multiple words or sentences, use the HTML-style commands. Finally, for - blocks of code or blocks of text that need to be in "typewriter" font, use - the block commands. Have a look at the listing: + multiple words or sentences, use the HTML-style commands. Finally, for blocks + of code or blocks of text that need to be in "typewriter" font, use the block + commands. Have a look at the following listing: - \c \\a \n Use to refer to parameters or arguments in a running text, for example - when refering to parameters in method descriptions. + when referring to parameters in method descriptions. - Bold text - For single words, use \c \\b. - For multiple words, enclose between the \c \ and \c \<\\b\> tags. @@ -268,11 +263,12 @@ a monospace, or typewriter, font. There are a few options - \c \\c for single words. - \c \ and \c \<\\tt\> for multiple words or phrases - - The commands \c \\verbatim and \c \\endverbatim. Everything between these two - commands will be put in a distinct block that stands out from the rest of the - text. - - The commands \c \\code and \c \\endcode do the same, but Doxygen will parse the - contents and try to mark up the code to make it look just a bit nicer. + - The commands \c \\verbatim and \c \\endverbatim. Everything between these + two commands will be put in a distinct block that stands out from the rest + of the text. + - The commands \c \\code and \c \\endcode do the same, but Doxygen will + parse the contents and try to mark up the code to make it look a little bit + nicer. - Emphasis - \c \\e for single words. - \c \ and \c \<\\em\> for phrases. @@ -284,7 +280,7 @@ since they're not members, some of the structuring commands won't work. Important to know is that a page is the complete length of the block, so dividing it up in subsections by starting new blocks will not work. Instead, - doxygen provides some commands to structure text on a page. + Doxygen provides some commands to structure text on a page. First of all, you define a new page by using the \c \\page command. This command takes two arguments: a \c \ and (a title). The name @@ -295,20 +291,20 @@ For more complicated pages, you might want to divide the page up in sections. Use the \c \\section command to define a new section. It takes the same arguments as \c \\page, namely the \c \ and the (title). If - you need a deeper hierarchy you may sue \c \\subsection and + you need a deeper hierarchy you may use \c \\subsection and \c \\subsubsection, again, both with the same syntax. If you need to distinguish between sections in subsubsections, you are able to use \c \\paragraph, which takes the same arguments. \note Before and after each of the commands above, you need to have an empty - line for readability. It is not necessary to indent sections and subsections - more than the normal two spaces, as long as you keep the section markers - clear. + line so as to provide readability. It is not necessary to indent sections + and subsections more than the normal two spaces, as long as you keep the + section markers clear. - \warning If you are entering the realm of subsections and subsubsections, + \warning If you are entering the realm of subsections and sub-subsections, think about the nature of your page. Either it needs to be split up into multiple pages, or what you're writing is too complex and would be better - off as a big tutorial on the Haiku website. + off as a big tutorial on the Haiku website. If you are creating multiple pages that are related, you will be able to structure them in a tree by using the \c \\subpage command. This will rank @@ -327,7 +323,7 @@ \note If you are looking on how to add classes to kits, see \ref commands_miscellaneous and have a look at the \c \\ingroup command. - Groups of members are preceeded by a block that describes what the group is + Groups of members are preceded by a block that describes what the group is about. You are required to give each group of members at least a name. Have a look at the example: @@ -336,7 +332,7 @@ \\name Appending Methods These methods append things to the object. -* / +*/ //! \@{ @@ -345,12 +341,12 @@ //! \@} \endverbatim - The block preceeding the block opening marker, //! \@{, contains a + The block preceding the block opening marker, //! \@{, contains a \c \\name command and a paragraph that gives a description. The header block can be as long or short as you want, but please don't make it too long. See the \ref style section on how to effectively write group headers. The members that you want to belong to the group are between the group opening - and closure markers. + and closing markers. \note Group headers don't have a \c \\brief description. @@ -361,10 +357,10 @@ commands. The first one is \c \\n. This commands sort of belongs to the category of - markup commands. It basically forces a newline. Because doxygen parses - paragraphs as continuous, it's not possible to mark up the text using returns - in the documentation. \c \\n forces a newline in the output. So in HTML it - will be translated into a \c \. + markup commands. It basically forces a newline. Because Doxygen parses + paragraphs as a single contiguous entity, it's not possible to mark up the + text using carriage returns in the documentation. \c \\n forces a newline in + the output. So in HTML it will be translated into a \c \. Sometimes there are some parts of the API that you don't want to be visible. Since Doxygen extracts all the public and protected members from a class, @@ -383,8 +379,8 @@ Modules are defined in the main book, and you can add classes to them by using the \c \\ingroup command. This commands adds the class to the module - and groups it on a separate page. At this moment, the group handling is till - to be worked out. For now, add the classes to the kit they belong in. In the + and groups it on a separate page. At this moment, the group handling has yet + to be finalised. For now, add the classes to the kit they belong in. In the future this might change. Finally, it is a good idea to link between parts of the documentation. There @@ -399,10 +395,11 @@ \section style Writing Guidelines This final section will present guidelines for the actual writing of the - documentation. Both the structure of the documentation, which sections to - use when, and the style of the writing will be discussed. Before diverging - into the requirements for file and class descriptions, member descriptions and pages, - there are some general remarks that apply to all types of documentation. + documentation. Both the structure of the documentation, which sections to use + when, and the style of the writing will be discussed. Before diverging into + the requirements for file and class descriptions, member descriptions and + pages, there are some general remarks that apply to all types of + documentation. First of all, everything you write should be in proper English sentences. Spelling, grammar, punctuation, make sure you adhere to the @@ -418,38 +415,38 @@ \remarks It isn't the goal to create dry, legal-style documentation. Just try to find a balance. Read through documentation that's already been - approved to get a hint of what you should be aiming at. + approved to get a hint of what you should be aiming for. \remarks If you are having a problem with phrasing certain things, put it down in such a way that it says everything it needs to. A proofreader might - be able to put it in better words. + then be able to rephrase it to a better style. Throughout the documentation you might want to provide hints, warnings or remarks that might interrupt the flow of the text, or that need to visually stand out from the rest. Doxygen provides commands for paragraphs that display remarks, warnings, notes and points of attention. You can use these commands in case you meet one or more of the following requirements: - - The point is for a specific audience, such as beginners in - the Haiku API. Notes on what to read first, or mistakes that can be made - by beginners will not be for the entire audience, and such should be - separated. These kinds of notes should be at the end of blocks. + - The point is for a specific audience, such as beginners in the Haiku API. + Notes on what to read first, or mistakes that may be made by beginners will + not be for the entire audience, and such should be separated. These kinds of + notes should be at the end of blocks. - The point needs to visually stand out. This is especially the case with remarks, but could also apply for other types. - The point is not completely relevant to the text and therefore should be separated so that it doesn't interrupt the main flow. - This listing shows which one to use when: + This listing shows which one to use for which situation: - \c \\attention - Used when the developer is bound to make a mistake, when the API is - ambiguous. The difference to a warning is that warnings warn for things - that are the developer's fault, and attention blocks warn for things that - might go wrong because of the way the API is structured. + ambiguous. The difference between this and a warning is that warnings warn + about things that are the developers fault, and attention blocks warn + about things that might go wrong because of the way the API is structured. - Used to warn for abuse of the API that might be caused by the way the - internals of the system are structured. + internals of the system are structured. - \c \\warning - - Used to warn developers for using the API in a certain way. Warnings + - Used to warn developers about using the API in a certain way. Warnings apply especially to new developers that aren't completely familiar with the API and that might want to abuse it. For example, the thread safety - of BString requires a warning. + of BString requires a warning. - \c \\note - Used to place references to other documentation that might not be directly related to the text. For example, BLooper will have a direct @@ -458,13 +455,13 @@ the class. - Can also be used for useful hints or notes that somehow need to stand out from the rest of the text. - - Remarks interact with the text, notes add something unmentioned to it. - \c \\remarks - Remarks are small notes that would interrupt the flow of the text. For example, if you in a text ignore a certain condition that is so extremely rare and uncommon, you can put a remark at the end of the text to tell that you have been lying. - - Remarks interact with the text, notes add something unmentioned to it. + - Remarks interact with the text whereas notes add something unmentioned to + it. \subsection style_files File Descriptions @@ -480,20 +477,19 @@ \file String.h \brief Defines the BString class and global operators and functions for handling strings. -* / +*/ /*! \file SupportDefs.h \brief Defines basic types and definitions for the Haiku API. -* / +*/ \endverbatim The first statement defines what the block is about, namely the header file. The second element is the \c \\brief remark on what it contains. The first file defines the BString class and some global operators. You can see that reflected in the description. SupportDefs.h does not define classes, but - rather a range of different functions and defines, so the text refers to - that. + rather a range of different functions and defines, so the text refers to that. \remarks \\brief documentation for files is about what it \e implements, as header files are passive (whereas members and functions are active). Thus, @@ -501,12 +497,12 @@ \subsection style_classes Class Descriptions - Classes are the basic building blocks in the Haiku API and as such will have + Classes are the basic building blocks in the Haiku API and as such have extensive documentation. This section will go over the actual class description. This section will present a list of items you should think about - when writing the class description. This doesn't mean you'll have to put - every item in, it merely serves as a guiding principle that helps organise - your thoughts. Have a look at the list: + when writing the class description. This doesn't mean you'll have to include + every item, it merely serves as a guiding principle that helps organise your + thoughts. Have a look at the list: -# The \c \\brief description is \b obligatory. This description describes what it is. For example, BDataIO: "Abstract interface for objects that @@ -519,13 +515,13 @@ sure that a developer in the first few paragraphs can judge if what he wants to do can be done with this class. -# One or more paragraphs that show how this class ties in with the rest - of the kit or the API. What objects does it work with, how does it interact + of the kit or the API. What objects does it work with, how it interacts with the servers, etcetera. -# One or more paragraphs that give a concrete example or use case. Keep it - tidy and selfcontained. Remember, an example can tell more than a few - paragraphs of text. - -# End with a list of references to other classes, functions, pages, etc. - might be of interest for the reader. + tidy and self contained. Remember, an example can illustrate better than a + few paragraphs of text. + -# End with a list of references to other classes, functions, pages, etc. that + might be of interest to the reader. When documenting classes, don't be to exhaustive. Avoid becoming a tutorial or a complete guide. This documentation is for reference only. If you want to @@ -539,7 +535,7 @@ \subsection style_members Members and Functions - Members and functions share the same basic doxygen syntax, and they can be + Members and functions share the same basic Doxygen syntax, and they can be documented in a similar way. That's why this section deals with them together. Documenting members is probably the main thing you'll do when writing the actual documentation. There are some guidelines as to how, but the actual @@ -554,9 +550,9 @@ clear description. The description starts with a capital letter and ends with a dot. Don't write the description saying what the method does, like "Starts the timer", but rather as what it will do: "Start the timer." - -# If the brief description doesn't cover all the method or function does, - then you can add a few paragraphs that explain it in more depth. Don't be - to verbose, and use an example to illustrate points. Point out any + -# If the brief description doesn't cover all of what the method or function + does, then you can add a few paragraphs that explain it in more depth. Don't + be too verbose, and use an example to illustrate points. Point out any potential misunderstandings or problems you expect developers to have, but don't repeat the class documentation too much. -# You are obliged to then document all the parameters. Use the \c \\param @@ -566,17 +562,18 @@ return. In case of fixed values, have a look at \c \\retval. You'll use this one when the return type is a bool or a status_t. In case of something else, use \c \\return. You can also combine these two. For example, a - method that returns a lenght (positive) or an error code (negative). + method that returns a length (positive) or an error code (negative). -# Use \c \\see if you have any references to other methods, classes or global functions. At least document all the overloaded methods. Also add methods that do the opposite of this method, or methods that are intimately related. - In case of overloaded members, you'll need to make a decision. If you need - to copy too much information, you might resort to put in one paragraph with - the text "This is an overloaded member function, and differs from \ only - by the type of parameter it takes." That will keep the copying down and will - point developers right to the place where they can get more documentation. + In case of overloaded members, you'll need to make a decision. If you need to + copy too much information, you might resort to putting it in one paragraph + with the text "This is an overloaded member function, and differs from + \ only by the type of parameter it takes." That will keep the copying + down and will point developers right to the place where they can get more + documentation. Again, like class descriptions, you'll have to find a good middle-ground between too much information, and too little. Again, write for the broadest @@ -586,32 +583,32 @@ \subsection style_variables Enumerations, Variables and Defines This section helps you document (member) variables and defines that define - constant, as well as enumerations and their values. If you need to document + constants, as well as enumerations and their values. If you need to document a \c \#define macro that takes arguments, have a look at \ref style_members . The \c \\brief description of all these types follow a similar structure. - They are a short phrase that mentions what the variable contains. Example: + They are a short phrase that mention what the variable contains. Example: \verbatim /*! \var char* BString::fPrivateData \brief BString's storage for data. - This member is deprecated and might even go \c private in future releases. + This member is deprecated and might even become \c private in future releases. - If you are planning to derive from this object and you want to manipulate the raw - string data, please have a look at LockBuffer() and UnlockBuffer(). -* / + If you are planning to derive from this object and you want to manipulate the + raw string data, please have a look at LockBuffer() and UnlockBuffer(). +*/ \endverbatim The variables you are going to encounter are either \c public or \c protected member variables, or global variables that have a certain significance. In the case of member variables, you'll need to document what - they mean and how the developer should manipulate it. If the class is one - that is meant to be derived from, make sure that in the - description of the variable you mention how it interacts with the others, and - how the developer should make sure that the internal coherence of the data - and code members of the inherited class is maintained. + they mean and how the developer should manipulate them. If the class is one + that is meant to be derived from, make sure that in the description of the + variable you mention how it interacts with the others, and how the developer + should make sure that the internal coherence of the data and code members of + the inherited class is maintained. Global variables will mostly be constants. If so, document what they stand for and what they might be used for, as well as which classes and functions @@ -641,39 +638,38 @@ \subsection style_groups Groups - If you subdivide members of classes into groups, you have the ability to - apply some general information that will be listed above the listing of the - members in that group. See the section \ref commands_grouping on how to - define groups. This section is on what to put in the header block. + If you subdivide members of classes into groups, you have the ability to apply + some general information that will be listed above the listing of the members + in that group. See the section \ref commands_grouping on how to define groups. + This section is on what to put in the header block. First of all, it's probably a good idea to give your group a name. This name will be printed as a title and will enhance the clarity of what the group - contains. If you put the \c \\name command as the first command of a - group, the rest of the words on that line will be used as title. You should - chose simple titles, no more than three words. + contains. If you put the \c \\name command as the first command of a group, + the rest of the words on that line will be used as the title. You should + choose simple titles of no more than three words. It's possible to add one or two paragraphs of information. These paragraphs should contain some quick notes on which of the members in that group to use - for what cause. See it as a quick subdivision which a developer could use - as a guide to see which method he actually wants to use. Don't go on - describing the methods in detail though, that's what the member documentation - is about. Have a look at the example: + for what purpose. See it as a quick subdivision that a developer could use as + a guide to see which method he actually wants to use. Don't go on describing + the methods in detail though, that's what the member documentation is about. + Have a look at the example: \verbatim /*! \name Comparison Methods - There are two different comparison methods. First of all there - is the whole range of operators that return a boolean value, secondly - there are methods that return an integer value, both case sensitive - and case insensitive. + There are two different comparison methods. First of all there is the whole + range of operators that return a boolean value, secondly there are methods + that return an integer value, both case sensitive and case insensitive. There are also global comparison operators and global compare functions. You might need these in case you have a sort routine that takes a generic comparison function, such as BList::SortItems(). - See the String.h documentation file to see the specifics, though basically - there are the same as implemented in this class. -* / + See the String.h documentation file to see the specifics, as they are + basically the same as implemented in this class. +*/ \endverbatim Straight, to the point, gives no more information than necessary. Divides @@ -681,4 +677,4 @@ might be looking for. The hard limit is two (short) paragraphs. Using more will not improve clarity. -*/ \ No newline at end of file +*/ From axeld at pinc-software.de Thu May 10 11:16:06 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Thu, 10 May 2007 11:16:06 +0200 CEST Subject: [Haiku-commits] r21103 - haiku/trunk/docs/user In-Reply-To: <200705100902.l4A92kNa003306@sheep.berlios.de> Message-ID: <9390421956-BeMail@zon> nielx at BerliOS wrote: > + * Documentation by: > + * Niels Sascha Reedijk How about "Authors" and two tabs after the "*" and before the author name, just like in all other license headers, too? Bye, Axel. From axeld at mail.berlios.de Thu May 10 11:17:51 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 10 May 2007 11:17:51 +0200 Subject: [Haiku-commits] r21104 - haiku/trunk/src/kits/app Message-ID: <200705100917.l4A9Hpol004745@sheep.berlios.de> Author: axeld Date: 2007-05-10 11:17:51 +0200 (Thu, 10 May 2007) New Revision: 21104 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21104&view=rev Modified: haiku/trunk/src/kits/app/Messenger.cpp Log: Made IsTargetLocal() a lot faster by using BPrivate::current_team() which caches the team ID. Modified: haiku/trunk/src/kits/app/Messenger.cpp =================================================================== --- haiku/trunk/src/kits/app/Messenger.cpp 2007-05-10 09:02:45 UTC (rev 21103) +++ haiku/trunk/src/kits/app/Messenger.cpp 2007-05-10 09:17:51 UTC (rev 21104) @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005, Haiku. + * Copyright 2001-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -161,9 +161,7 @@ bool BMessenger::IsTargetLocal() const { - thread_info info; - return get_thread_info(find_thread(NULL), &info) == B_OK - && fTeam == info.team; + return BPrivate::current_team() == fTeam; } From niels.reedijk at gmail.com Thu May 10 11:24:33 2007 From: niels.reedijk at gmail.com (Niels Reedijk) Date: Thu, 10 May 2007 11:24:33 +0200 Subject: [Haiku-commits] Fwd: r21103 - haiku/trunk/docs/user In-Reply-To: <9390421956-BeMail@zon> References: <200705100902.l4A92kNa003306@sheep.berlios.de> <9390421956-BeMail@zon> Message-ID: <507d86c0705100224u77b3d846r582a7833c6d8d9d9@mail.gmail.com> 2007/5/10, Axel D?rfler : > nielx at BerliOS wrote: > > + * Documentation by: > > + * Niels Sascha Reedijk > > How about "Authors" and two tabs after the "*" and before the author > name, just like in all other license headers, too? Forwarding to haiku-doc list for discussion. Niels From axeld at mail.berlios.de Thu May 10 16:13:39 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 10 May 2007 16:13:39 +0200 Subject: [Haiku-commits] r21105 - in haiku/trunk: headers/os/drivers/bus headers/os/drivers/bus/scsi src/add-ons/kernel/bus_managers/ide src/add-ons/kernel/bus_managers/scsi src/add-ons/kernel/drivers/disk/scsi/scsi_cd src/add-ons/kernel/drivers/disk/scsi/scsi_dsk src/add-ons/kernel/generic/scsi_periph Message-ID: <200705101413.l4AEDdNP011348@sheep.berlios.de> Author: axeld Date: 2007-05-10 16:13:37 +0200 (Thu, 10 May 2007) New Revision: 21105 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21105&view=rev Modified: haiku/trunk/headers/os/drivers/bus/SCSI.h haiku/trunk/headers/os/drivers/bus/scsi/scsi_cmds.h haiku/trunk/headers/os/drivers/bus/scsi/scsi_periph.h haiku/trunk/src/add-ons/kernel/bus_managers/ide/atapi.c haiku/trunk/src/add-ons/kernel/bus_managers/ide/dma.c haiku/trunk/src/add-ons/kernel/bus_managers/ide/emulation.c haiku/trunk/src/add-ons/kernel/bus_managers/ide/pio.c haiku/trunk/src/add-ons/kernel/bus_managers/ide/scsi2ata.c haiku/trunk/src/add-ons/kernel/bus_managers/scsi/device_scan.c haiku/trunk/src/add-ons/kernel/bus_managers/scsi/devices.c haiku/trunk/src/add-ons/kernel/bus_managers/scsi/dma_buffer.c haiku/trunk/src/add-ons/kernel/bus_managers/scsi/emulation.c haiku/trunk/src/add-ons/kernel/bus_managers/scsi/scatter_gather.c haiku/trunk/src/add-ons/kernel/bus_managers/scsi/scsi_internal.h haiku/trunk/src/add-ons/kernel/bus_managers/scsi/scsi_io.c haiku/trunk/src/add-ons/kernel/drivers/disk/scsi/scsi_cd/device.c haiku/trunk/src/add-ons/kernel/drivers/disk/scsi/scsi_cd/scsi_cd.c haiku/trunk/src/add-ons/kernel/drivers/disk/scsi/scsi_dsk/device.c haiku/trunk/src/add-ons/kernel/generic/scsi_periph/block.c haiku/trunk/src/add-ons/kernel/generic/scsi_periph/io.c haiku/trunk/src/add-ons/kernel/generic/scsi_periph/removable.c haiku/trunk/src/add-ons/kernel/generic/scsi_periph/scsi_periph.c haiku/trunk/src/add-ons/kernel/generic/scsi_periph/sync.c Log: * Cleaned up SCSI headers a bit. * scsi_cmds.h declared several variables instead of naming enums. * the CD-ROM standard retrieval was broken (always checked index 0). Modified: haiku/trunk/headers/os/drivers/bus/SCSI.h =================================================================== --- haiku/trunk/headers/os/drivers/bus/SCSI.h 2007-05-10 09:17:51 UTC (rev 21104) +++ haiku/trunk/headers/os/drivers/bus/SCSI.h 2007-05-10 14:13:37 UTC (rev 21105) @@ -1,11 +1,11 @@ /* - * Copyright 2004-2006, Haiku, Inc. All RightsReserved. + * Copyright 2004-2007, Haiku, Inc. All RightsReserved. * Copyright 2002/03, Thomas Kurschel. All rights reserved. * * Distributed under the terms of the MIT License. */ -#ifndef _SCSI_BUSMANAGER_H_ -#define _SCSI_BUSMANAGER_H_ +#ifndef _SCSI_BUSMANAGER_H +#define _SCSI_BUSMANAGER_H /* SCSI bus manager interface @@ -26,7 +26,7 @@ Something about requests involving data transfer: you can either specify the virtual address in of CCB (in which case it must be continuous), or store a pointer to a S/G list that contains physical addresses in - /. If is non-Null, is ignored. + /. If is non-Null, is ignored. The S/G list must be in kernel space because the request can be executed in a different thread context. This is also the reason why the S/G list has to contain physical addresses. For obvious reason, the data buffer specified @@ -108,8 +108,7 @@ // structure of one scsi i/o CCB (command control block) -typedef struct scsi_ccb -{ +typedef struct scsi_ccb { struct scsi_ccb *next, *prev; // internal uchar subsys_status; // Returned subsystem status @@ -126,14 +125,14 @@ sem_id completion_sem; uint8 cdb[SCSI_MAX_CDB_SIZE]; // command data block - uchar cdb_len; // length of command in bytes + uchar cdb_length; // length of command in bytes int64 sort; // value of command to sort on (<0 means n/a) bigtime_t timeout; // timeout - 0 = use default uchar *data; // pointer to data - const physical_entry *sg_list; // SG list - uint16 sg_cnt; // number of SG entries - uint32 data_len; // length of data + const physical_entry *sg_list; // scatter/gather list + uint16 sg_count; // number of S/G entries + uint32 data_length; // length of data int32 data_resid; // data transfer residual length: 2's comp uchar sense[SCSI_MAX_SENSE_SIZE]; // autosense data @@ -151,10 +150,10 @@ // original data before command emulation was applied uint8 orig_cdb[SCSI_MAX_CDB_SIZE]; - uchar orig_cdb_len; - const physical_entry *orig_sg_list; - uint16 orig_sg_cnt; - uint32 orig_data_len; + uchar orig_cdb_length; + const physical_entry *orig_sg_list; + uint16 orig_sg_count; + uint32 orig_data_length; // private SIM data uchar sim_state; // set to zero when request is submitted first time @@ -249,8 +248,7 @@ // Path inquiry, extended by BeOS XPT_EXTENDED_PATH_INQ parameters -typedef struct -{ +typedef struct { uchar version_num; /* Version number for the SIM/HBA */ uchar hba_inquiry; /* Mimic of INQ byte 7 for the HBA */ uchar hba_misc; /* Misc HBA feature flags */ @@ -457,4 +455,4 @@ } scsi_sim_interface; -#endif /* _SCSI_BUSMANAGER_H_ */ +#endif /* _SCSI_BUSMANAGER_H */ Modified: haiku/trunk/headers/os/drivers/bus/scsi/scsi_cmds.h =================================================================== --- haiku/trunk/headers/os/drivers/bus/scsi/scsi_cmds.h 2007-05-10 09:17:51 UTC (rev 21104) +++ haiku/trunk/headers/os/drivers/bus/scsi/scsi_cmds.h 2007-05-10 14:13:37 UTC (rev 21105) @@ -1,19 +1,18 @@ /* -** Copyright 2002/03, Thomas Kurschel. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2004-2007, Haiku, Inc. All RightsReserved. + * Copyright 2002/03, Thomas Kurschel. All rights reserved. + * + * Distributed under the terms of the MIT License. + */ +#ifndef _SCSI_CMDS_H +#define _SCSI_CMDS_H -/* - Part of Open SCSI bus manager +// SCSI commands and their data structures and constants - SCSI commands and their data structures and constants -*/ -#ifndef __SCSI_CMDS_H__ -#define __SCSI_CMDS_H__ - #include + // always keep in mind that SCSI is big-endian !!! #define SCSI_STD_TIMEOUT 10 @@ -122,7 +121,6 @@ #define SCSIS_ASC_REMOVAL_PREVENTED 0x5302 // medium removal prevented #define SCSIS_ASC_REMOVAL_REQUESTED 0x5a01 // operator requests medium removal - // some scsi op-codes #define SCSI_OP_TUR 0x00 #define SCSI_OP_REQUEST_SENSE 0x03 @@ -165,17 +163,17 @@ // INQUIRY typedef struct scsi_cmd_inquiry { - uint8 opcode; + uint8 opcode; LBITFIELD8_3( - EVPD : 1, // enhanced vital product data - res1_1 : 4, - LUN : 3 + evpd : 1, // enhanced vital product data + _res1_1 : 4, + lun : 3 ); - uint8 page_code; - uint8 res3; - uint8 allocation_length; - uint8 control; -} scsi_cmd_inquiry; + uint8 page_code; + uint8 _res3; + uint8 allocation_length; + uint8 control; +} _PACKED scsi_cmd_inquiry; typedef struct scsi_res_inquiry { LBITFIELD8_2( @@ -183,60 +181,56 @@ device_qualifier : 3 ); LBITFIELD8_2( - device_type_modifier : 7, // obsolete, normally set to zero - RMB : 1 // 1 = removable medium + device_type_modifier : 7, // obsolete, normally set to zero + removable_medium : 1 ); - LBITFIELD8_3( // 0 always means "not conforming" - ANSI_version : 3, // 1 for SCSI-1, 2 for SCSI-2 etc. - ECMA_version : 3, - ISO_version : 2 + LBITFIELD8_3( // 0 always means "not conforming" + ansi_version : 3, // 1 for SCSI-1, 2 for SCSI-2 etc. + ecma_version : 3, + iso_version : 2 ); LBITFIELD8_4( - response_data_format : 4, // 2 = SCSI/2 compliant - res3_4 : 2, - TrmIOP : 1, // 1 = supports TERMINATE I/O PROCESS - AENC : 1 // processor devices only : - // Asynchronous Event Notification Capable + response_data_format : 4, // 2 = SCSI/2 compliant + _res3_4 : 2, + term_iop : 1, // 1 = supports TERMINATE I/O PROCESS + async_enc : 1 // processor devices only : + // Asynchronous Event Notification Capable ); - uint8 additional_length; // total (whished) length = this + 4 - uint8 res5; - uint8 res6; + uint8 additional_length; // total (whished) length = this + 4 + uint8 _res5; + uint8 _res6; LBITFIELD8_8( - SftRe : 1, // 0 = soft reset leads to hard reset - CmdQue : 1, // 1 = supports tagged command queuing - res7_2 : 1, - Linked : 1, // 1 = supports linked commands - Sync : 1, // 1 = supports synchronous transfers - WBus16 : 1, // 1 = supports 16 bit transfers - WBus32 : 1, // 1 = supports 32 bit transfers - RelAdr : 1 // 1 = supports relative addr. for linking + soft_reset : 1, // 0 = soft reset leads to hard reset + cmd_queue : 1, // 1 = supports tagged command queuing + _res7_2 : 1, + linked : 1, // 1 = supports linked commands + sync : 1, // 1 = supports synchronous transfers + write_bus16 : 1, // 1 = supports 16 bit transfers + write_bus32 : 1, // 1 = supports 32 bit transfers + relative_address : 1 // 1 = supports relative addr. for linking ); - char vendor_ident[8]; // 8 - char product_ident[16]; // 16 - char product_rev[4]; // 32 - + char vendor_ident[8]; + char product_ident[16]; + char product_rev[4]; + // XPT doesn't return following data on XPT_GDEV_TYPE - uint8 vendor_spec[20]; // 36 - uint8 res56[2]; // 56 - - struct { - uint8 high; - uint8 low; - } version_descriptor[8]; // array of supported standards - - uint8 res74[22]; // 74 - - /* additional vendor specific data */ // 96 -} scsi_res_inquiry; + uint8 vendor_spec[20]; + uint8 _res56[2]; -enum { + uint16 version_descriptor[8]; // array of supported standards, big endian + + uint8 _res74[22]; + /* additional vendor specific data */ +} _PACKED scsi_res_inquiry; + +enum scsi_peripheral_qualifier { scsi_periph_qual_connected = 0, scsi_periph_qual_not_connected = 2, scsi_periph_qual_not_connectable = 3 // value 1 is reserved, values of 4 and above are vendor-specific -} scsi_peripheral_qualifier; +}; -enum { +enum scsi_device_type { scsi_dev_direct_access = 0, scsi_dev_sequential_access = 1, scsi_dev_printer = 2, @@ -254,131 +248,112 @@ scsi_dev_simplified_direct_access = 0xe, scsi_dev_optical_card = 0xf, scsi_dev_unknown = 0x1f // used for scsi_periph_qual_not_connectable -} scsi_device_type; +}; // vital product data: unit serial number page #define SCSI_PAGE_USN 0x80 -typedef struct scsi_page_USN { +typedef struct scsi_page_usn { LBITFIELD8_2( device_type : 5, device_qualifier : 3 ); - uint8 page_code; - uint8 res2; - - uint8 page_length; // total size = this + 3 - char PSN[1]; // size according to page_length -} scsi_page_USN; + uint8 page_code; + uint8 _res2; + uint8 _page_length; // total size = this + 3 + char psn[1]; // size according to page_length +} _PACKED scsi_page_usn; + // READ CAPACITY typedef struct scsi_cmd_read_capacity { - uint8 opcode; + uint8 opcode; LBITFIELD8_3( - RelAdr : 1, // relative address - res1_1 : 4, - LUN : 3 + relative_address : 1, // relative address + _res1_1 : 4, + lun : 3 ); - uint8 top_LBA; - uint8 high_LBA; - uint8 mid_LBA; - uint8 low_LBA; - uint8 res6[2]; + uint32 lba; + uint8 _res6[2]; LBITFIELD8_2( - PMI : 1, // partial medium indicator - res8_1 : 7 + pmi : 1, // partial medium indicator + _res8_1 : 7 ); - uint8 control; -} scsi_cmd_read_capacity; + uint8 control; +} _PACKED scsi_cmd_read_capacity; typedef struct scsi_res_read_capacity { - uint8 top_LBA; - uint8 high_LBA; - uint8 mid_LBA; - uint8 low_LBA; - uint8 top_block_size; // in bytes - uint8 high_block_size; - uint8 mid_block_size; - uint8 low_block_size; -} scsi_res_read_capacity; + uint32 lba; // big endian + uint32 block_size; // in bytes +} _PACKED scsi_res_read_capacity; // READ (6), WRITE (6) typedef struct scsi_cmd_rw_6 { - uint8 opcode; + uint8 opcode; LBITFIELD8_2( - high_LBA : 5, - LUN : 3 + high_lba : 5, + lun : 3 ); - uint8 mid_LBA; - uint8 low_LBA; - uint8 length; // 0 = 256 blocks - uint8 control; -} scsi_cmd_rw_6; + uint8 mid_lba; + uint8 low_lba; + uint8 length; // 0 = 256 blocks + uint8 control; +} _PACKED scsi_cmd_rw_6; // READ (10), WRITE (10) typedef struct scsi_cmd_rw_10 { - uint8 opcode; + uint8 opcode; LBITFIELD8_5( - RelAdr : 1, // relative address - res1_1 : 2, - FUA : 1, // force unit access (1 = safe, cacheless access) - DPO : 1, // disable page out (1 = not worth caching) - LUN : 3 + relative_address : 1, // relative address + _res1_1 : 2, + force_unit_access : 1, // force unit access (1 = safe, cacheless access) + disable_page_out : 1, // disable page out (1 = not worth caching) + lun : 3 ); - uint8 top_LBA; - uint8 high_LBA; - uint8 mid_LBA; - uint8 low_LBA; - uint8 res6; - uint8 high_length; // 0 = no block - uint8 low_length; - uint8 control; -} scsi_cmd_rw_10; + uint32 lba; // big endian + uint8 _res6; + uint16 length; // 0 = no block + uint8 control; +} _PACKED scsi_cmd_rw_10; // READ (12), WRITE (12) typedef struct scsi_cmd_rw_12 { - uint8 opcode; + uint8 opcode; LBITFIELD8_5( - RelAdr : 1, // relative address - res1_1 : 2, - FUA : 1, // force unit access (1 = safe, cacheless access) - DPO : 1, // disable page out (1 = not worth caching) - LUN : 3 + relative_address : 1, // relative address + _res1_1 : 2, + force_unit_access : 1, // force unit access (1 = safe, cacheless access) + disable_page_out : 1, // disable page out (1 = not worth caching) + lun : 3 ); - uint8 top_LBA; - uint8 high_LBA; - uint8 mid_LBA; - uint8 low_LBA; - uint8 top_length; // 0 = no block - uint8 high_length; - uint8 mid_length; - uint8 low_length; - uint8 res10; - uint8 control; -} scsi_cmd_rw_12; + uint32 lba; // big endian + uint32 length; // 0 = no block + uint8 _res10; + uint8 control; +} _PACKED scsi_cmd_rw_12; // REQUEST SENSE typedef struct scsi_cmd_request_sense { - uint8 opcode; + uint8 opcode; LBITFIELD8_2( - res1_0 : 5, - LUN : 3 + _res1_0 : 5, + lun : 3 ); - uint8 res2[2]; - uint8 alloc_length; - uint8 control; -} scsi_cmd_request_sense; + uint8 _res2[2]; + uint8 allocation_length; + uint8 control; +} _PACKED scsi_cmd_request_sense; // sense data structures @@ -455,127 +430,124 @@ res15_0 : 7, SKSV : 1 ); - uint8 high_progress; // 0 = start, 0xffff = almost finished - uint8 low_progress; + uint16 progress; // 0 = start, 0xffff = almost finished } format_progress; } sense_key_spec; // starting with offset 18 there are additional sense byte -} scsi_sense; +} _PACKED scsi_sense; // PREVENT ALLOW typedef struct scsi_cmd_prevent_allow { - uint8 opcode; + uint8 opcode; LBITFIELD8_2( - res1_0 : 5, - LUN : 3 + _res1_0 : 5, + lun : 3 ); - uint8 res2[2]; + uint8 _res2[2]; LBITFIELD8_2( prevent : 1, // 1 - prevent medium removal, 0 - allow removal - res4_1 : 7 + _res4_1 : 7 ); - uint8 control; -} scsi_cmd_prevent_allow; + uint8 control; +} _PACKED scsi_cmd_prevent_allow; // START STOP UNIT typedef struct scsi_cmd_ssu { - uint8 opcode; + uint8 opcode; LBITFIELD8_3( - immed : 1, // 1 - return immediately, 0 - return on completion - res1_1 : 4, - LUN : 3 + immediately : 1, // 1 - return immediately, 0 - return on completion + _res1_1 : 4, + lun : 3 ); uint8 res2[2]; LBITFIELD8_3( start : 1, // 1 - load+start, i.e. allow, 0 - eject+stop, i.e. deny - LoEj : 1, // 1 - include loading/ejecting, 0 - only to allow/deny - res4_2 : 6 + load_eject : 1, // 1 - include loading/ejecting, 0 - only to allow/deny + _res4_2 : 6 ); - uint8 control; -} scsi_cmd_ssu; + uint8 control; +} _PACKED scsi_cmd_ssu; // MODE SELECT (6) typedef struct scsi_cmd_mode_select_6 { - uint8 opcode; + uint8 opcode; LBITFIELD8_4( - SP : 1, // 1 = save pages to non-volatile memory - res1_1 : 3, - PF : 1, // 0 = old SCSI-1; 1 = new SCSI-2 format - LUN : 3 + save_pages : 1, // 1 = save pages to non-volatile memory + _res1_1 : 3, + pf : 1, // 0 = old SCSI-1; 1 = new SCSI-2 format + lun : 3 ); - uint8 res2[2]; - uint8 param_list_length; // data size - uint8 control; -} scsi_cmd_mode_select_6; + uint8 _res2[2]; + uint8 param_list_length; // data size + uint8 control; +} _PACKED scsi_cmd_mode_select_6; // MODE SENSE (6) typedef struct scsi_cmd_mode_sense_6 { - uint8 opcode; + uint8 opcode; LBITFIELD8_4( - res1_0 : 3, - DBD : 1, // disable block descriptors - res1_4 : 1, - LUN : 3 + _res1_0 : 3, + disable_block_desc : 1, // disable block descriptors + _res1_4 : 1, + lun : 3 ); LBITFIELD8_2( page_code : 6, - PC : 2 // page control field + page_control : 2 // page control field ); - uint8 res3; - uint8 allocation_length; // maximum amount of data - uint8 control; -} scsi_cmd_mode_sense_6; + uint8 _res3; + uint8 allocation_length; // maximum amount of data + uint8 control; +} _PACKED scsi_cmd_mode_sense_6; // MODE SELECT (10) typedef struct scsi_cmd_mode_select_10 { - uint8 opcode; + uint8 opcode; LBITFIELD8_4( - SP : 1, // 1 = save pages to non-volatile memory - res1_1 : 3, - PF : 1, // 0 = old SCSI-1; 1 = new SCSI-2 format - LUN : 3 + save_pages : 1, // 1 = save pages to non-volatile memory + _res1_1 : 3, + pf : 1, // 0 = old SCSI-1; 1 = new SCSI-2 format + lun : 3 ); - uint8 res2[5]; - uint8 high_param_list_length; // data size - uint8 low_param_list_length; - uint8 control; -} scsi_cmd_mode_select_10; + uint8 _res2[5]; + uint16 param_list_length; // data size, big endian + uint8 control; +} _PACKED scsi_cmd_mode_select_10; // MODE SENSE (10) typedef struct scsi_cmd_mode_sense_10 { - uint8 opcode; + uint8 opcode; LBITFIELD8_4( - res1_0 : 3, - DBD : 1, // disable block descriptors - res1_4 : 1, - LUN : 3 + _res1_0 : 3, + disable_block_desc : 1, // disable block descriptors + _res1_4 : 1, + lun : 3 ); LBITFIELD8_2( page_code : 6, - PC : 2 // page control field + page_control : 2 // page control field ); - uint8 res3[4]; - uint8 high_allocation_length; // maximum amount of data - uint8 low_allocation_length; - uint8 control; -} scsi_cmd_mode_sense_10; + uint8 _res3[4]; + uint16 allocation_length; // maximum amount of data, big endian + uint8 control; +} _PACKED scsi_cmd_mode_sense_10; - -// possible contents of PC +// possible contents of page control (PC) #define SCSI_MODE_SENSE_PC_CURRENT 0 -#define SCSI_MODE_SENSE_PC_CHANGABLE 1 // changable field are filled with "1" +#define SCSI_MODE_SENSE_PC_CHANGABLE 1 + // changable field are filled with "1" #define SCSI_MODE_SENSE_PC_DEFAULT 2 #define SCSI_MODE_SENSE_PC_SAVED 3 @@ -584,60 +556,58 @@ // header of mode data; followed by block descriptors and mode pages typedef struct scsi_mode_param_header_6 { - uint8 mode_data_len; // total length excluding this byte - uint8 medium_type; - uint8 dev_spec_parameter; - uint8 block_desc_len; // total length of all transmitted block descriptors -} scsi_mode_param_header_6; + uint8 mode_data_length; // total length excluding this byte + uint8 medium_type; + uint8 dev_spec_parameter; + uint8 block_desc_length; // total length of all transmitted block descriptors +} _PACKED scsi_mode_param_header_6; typedef struct scsi_mode_param_header_10 { - uint8 high_mode_data_len; // total length excluding these two bytes - uint8 low_mode_data_len; - uint8 medium_type; - uint8 dev_spec_parameter; - uint8 res4[2]; - uint8 high_block_desc_len; // total length of all transmitted block descriptors - uint8 low_block_desc_len; -} scsi_mode_param_header_10; + uint16 mode_data_length; // total length excluding these two bytes + uint8 medium_type; + uint8 dev_spec_parameter; + uint8 _res4[2]; + uint16 block_desc_length; // total length of all transmitted block descriptors +} _PACKED scsi_mode_param_header_10; // content of dev_spec_parameter for direct access devices typedef struct scsi_mode_param_dev_spec_da { LBITFIELD8_4( - res0_0 : 4, - DPOFUA : 1, // 1 = supports DPO and FUA, see READ (10) (sense only) - res0_6 : 1, - WP : 1 // write protected (sense only) + _res0_0 : 4, + dpo_fua : 1, // 1 = supports DPO and FUA, see READ (10) (sense only) + _res0_6 : 1, + write_protected : 1 // write protected (sense only) ); -} scsi_mode_param_dev_spec_da; +} _PACKED scsi_mode_param_dev_spec_da; typedef struct scsi_mode_param_block_desc { - uint8 density; // density code of area - uint8 high_numblocks; // size of this area in blocks - uint8 med_numblocks; // 0 = all remaining blocks - uint8 low_numblocks; - uint8 res4; - uint8 high_blocklen; // block size - uint8 med_blocklen; - uint8 low_blocklen; -} scsi_mode_param_block_desc; + uint8 density; // density code of area + uint8 high_numblocks; // size of this area in blocks + uint8 med_numblocks; // 0 = all remaining blocks + uint8 low_numblocks; + uint8 _res4; + uint8 high_blocklen; // block size + uint8 med_blocklen; + uint8 low_blocklen; +} _PACKED scsi_mode_param_block_desc; // header of a mode pages typedef struct scsi_modepage_header { LBITFIELD8_3( page_code : 6, - res0_6 : 1, + _res0_6 : 1, PS : 1 // 1 = page can be saved (only valid for MODE SENSE) ); - uint8 page_length; // size of page excluding this common header -} scsi_modepage_header; + uint8 page_length; // size of page excluding this common header +} _PACKED scsi_modepage_header; // control mode page #define SCSI_MODEPAGE_CONTROL 0xa -typedef struct scsi_modepage_contr { +typedef struct scsi_modepage_control { scsi_modepage_header header; LBITFIELD8_2( RLEC : 1, // Report Log Exception Condition @@ -663,7 +633,7 @@ uint8 res5; uint8 high_AEN_holdoff; // ready AEN hold off period - delay in ms between uint8 low_AEN_holdoff; // initialization and AEN -} scsi_modepage_contr; +} scsi_modepage_control; // values for QAM #define SCSI_QAM_RESTRICTED 0 @@ -677,22 +647,22 @@ typedef struct scsi_modepage_audio { scsi_modepage_header header; LBITFIELD8_4( - res2_0 : 1, - SOTC : 1, // Stop On Track Crossing - // 0 - stop according transfer length, 1 - stop at end of track - IMMED : 1, // must be one - res2_3 : 5 + _res2_0 : 1, + stop_on_track_crossing : 1, // Stop On Track Crossing + // 0 - stop according transfer length, 1 - stop at end of track + immediately : 1, // must be one + _res2_3 : 5 ); - uint8 res3[3]; - uint8 obs6[2]; + uint8 _res3[3]; + uint8 _obsolete6[2]; struct { LBITFIELD8_2( channel : 4, // select channel to connect to this port - res0_4 : 4 + _res0_4 : 4 ); uint8 volume; } ports[4]; -} scsi_modepage_audio; +} _PACKED scsi_modepage_audio; // connection between output port and audio channel #define SCSI_CHANNEL_SEL_MUTED 0 // mute port @@ -705,36 +675,35 @@ // TUR typedef struct scsi_cmd_tur { - uint8 opcode; + uint8 opcode; LBITFIELD8_2( - res1_0 : 5, - LUN : 3 + _res1_0 : 5, + lun : 3 ); - uint8 res3[3]; - uint8 control; -} scsi_cmd_tur; + uint8 _res3[3]; + uint8 control; +} _PACKED scsi_cmd_tur; // READ_TOC typedef struct scsi_cmd_read_toc { - uint8 opcode; + uint8 opcode; LBITFIELD8_4( - res1_0 : 1, - TIME : 1, // true, to use TIME format, false for LBA format - res1_2 : 3, - LUN : 3 + _res1_0 : 1, + time : 1, // true, to use MSF format, false for LBA format + _res1_2 : 3, + lun : 3 ); LBITFIELD8_2( format : 4, // see below - res2_4 : 4 + _res2_4 : 4 ); - uint8 res3[3]; - uint8 track; // (starting) track - uint8 high_allocation_length; // maximum amount of data - uint8 low_allocation_length; - uint8 control; -} scsi_cmd_read_toc; + uint8 _res3[3]; + uint8 track; // (starting) track + uint16 allocation_length; // maximum amount of data (big endian) + uint8 control; +} _PACKED scsi_cmd_read_toc; // values of in TOC command #define SCSI_TOC_FORMAT_TOC 0 // all TOCs starting with (0xaa for lead-out) @@ -746,60 +715,54 @@ // general structure of response typedef struct scsi_toc_general { - uint8 high_data_len; // total length - 2 - uint8 low_data_len; - uint8 first; // first track/session/reserved - uint8 last; // last one + uint16 data_length; // big endian, total length - 2 + uint8 first; // first track/session/reserved + uint8 last; // last one // remainder are parameter list descriptors -} scsi_toc_general; +} _PACKED scsi_toc_general; // definition of CD-ROM LBA -typedef struct scsi_cd_lba { - uint8 top; - uint8 high; - uint8 mid; - uint8 low; -} scsi_cd_lba; +typedef uint32 scsi_cd_lba; // big endian // definition of CD-ROM MSF time typedef struct scsi_cd_msf { - uint8 reserved; - uint8 minute; - uint8 second; - uint8 frame; -} scsi_cd_msf; + uint8 _reserved; + uint8 minute; + uint8 second; + uint8 frame; +} _PACKED scsi_cd_msf; // definition of Track Number address format -typedef struct scsi_cd_tno { - uint8 res0[3]; - uint8 track; -} scsi_cd_tno; +typedef struct scsi_cd_track_number { + uint8 _res0[3]; + uint8 track; +} _PACKED scsi_cd_track_number; // one track for SCSI_TOC_FORMAT_TOC typedef struct scsi_toc_track { - uint8 res0; + uint8 _res0; LBITFIELD8_2( - CONTROL : 4, - ADR : 4 + control : 4, + adr : 4 ); - uint8 track_number; // track number (hex) - uint8 res3; + uint8 track_number; // track number (hex) + uint8 _res3; union { // start of track (time or LBA, see TIME of command) scsi_cd_lba lba; scsi_cd_msf time; } start; -} scsi_toc_track; +} _PACKED scsi_toc_track; // possible value of ADR-field (described Q-channel content) -enum { +enum scsi_adr { scsi_adr_none = 0, // no Q-channel mode info scsi_adr_position = 1, // Q-channel encodes current position data scsi_adr_mcn = 2, // Q-channel encodes Media Catalog Number scsi_adr_isrc = 3 // Q-channel encodes ISRC -} scsi_adr; +}; // value of Q-channel control field (CONTROL) -enum { +enum scsi_q_control { scsi_q_control_2audio = 0, // stereo audio scsi_q_control_2audio_preemp = 1, // stereo audio with 50/15?s pre-emphasis scsi_q_control_1audio = 8, // audio (reserved in CD-R/W) @@ -808,75 +771,72 @@ scsi_q_control_data_incr = 5, // data, recorded incremental scsi_q_control_ddcd = 4, // DDCD data scsi_q_control_copy_perm = 2 // copy permitted (or-ed with value above) -} scsi_q_control; +}; // format SCSI_TOC_FORMAT_TOC typedef struct scsi_toc_toc { - uint8 high_data_len; // total length - 2 (independant of actual size) - uint8 low_data_len; - uint8 first_track; // first track (hex) - uint8 last_track; // last track (hex) - + uint16 data_length; // big endian, total length - 2 + uint8 first_track; // first track + uint8 last_track; // last track + scsi_toc_track tracks[1]; // one entry per track -} scsi_toc_toc; +} _PACKED scsi_toc_toc; // READ SUB-CHANNEL typedef struct scsi_cmd_read_subchannel { - uint8 opcode; + uint8 opcode; LBITFIELD8_4( - res1_0 : 1, - TIME : 1, // true, to use TIME format, false for LBA format - res1_2 : 3, - LUN : 3 + _res1_0 : 1, + time : 1, // true, to use MSF format, false for LBA format + _res1_2 : 3, + lun : 3 ); LBITFIELD8_3( - res2_0 : 6, - SUBQ : 1, // 1 - return Q sub-channel data - res2_7 : 1 + _res2_0 : 6, + subq : 1, // 1 - return Q sub-channel data + _res2_7 : 1 ); - uint8 parameter_list; // see below - uint8 res4[2]; - uint8 track; // track number (hex) - uint8 high_allocation_length; // maximum amount of data - uint8 low_allocation_length; - uint8 control; -} scsi_cmd_read_subchannel; + uint8 parameter_list; // see below + uint8 _res4[2]; + uint8 track; // track number (hex) + uint16 allocation_length; // maximum amount of data, big endian + uint8 control; +} _PACKED scsi_cmd_read_subchannel; // values of parameter_list -enum { +enum scsi_sub_channel_parameter_list { scsi_sub_channel_parameter_list_cd_pos = 1, // CD current position scsi_sub_channel_parameter_list_mcn = 2, // Media Catalog Number scsi_sub_channel_parameter_list_isrc = 3 // Track International Standard Recording Code -} scsi_sub_channel_parameter_list; +}; // header of response typedef struct scsi_subchannel_data_header { - uint8 res0; - uint8 audio_status; // see below - uint8 high_data_len; // total length - 4 - uint8 low_data_len; -} scsi_subchannel_data_header; + uint8 _res0; + uint8 audio_status; // see below + uint16 data_length; // total length - 4, big endian +} _PACKED scsi_subchannel_data_header; // possible audio_status -enum { +enum scsi_audio_status { scsi_audio_status_not_supported = 0, scsi_audio_status_playing = 0x11, scsi_audio_status_paused = 0x12, scsi_audio_status_completed = 0x13, scsi_audio_status_error_stop = 0x14, scsi_audio_status_no_status = 0x15 -} scsi_audio_status; +}; typedef struct scsi_cd_current_position { - uint8 format_code; // always 1 + uint8 format_code; // always 1 LBITFIELD8_2( - CONTROL : 4, // see scsi_q_control - ADR : 4 // see scsi_adr + control : 4, // see scsi_q_control [... truncated: 3416 lines follow ...] From hugosantos at gmail.com Thu May 10 16:25:09 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Thu, 10 May 2007 15:25:09 +0100 Subject: [Haiku-commits] r21101 - in haiku/trunk/src/add-ons/kernel/drivers/network/3com: . dev dev/mii pci In-Reply-To: <5834628089-BeMail@zon> References: <9c46321e0705100014l6fd74375l445abe3f72ab3a14@mail.gmail.com> <5834628089-BeMail@zon> Message-ID: <9c46321e0705100725i14825a96wb05e639e51bec904@mail.gmail.com> Hey Axel, On 5/10/07, Axel D?rfler wrote: > While this sounds like the best compromise so far, it still has an > impact on shared interrupts (even though it would work): it increases > the interrupt latency by an undeterminable amount. IOW it would be an > ugly kludge to get FreeBSD drivers running more easily, it would by no > means introduce a valid alternative to driver development under Haiku. > So if we would agree on this, it would only serve to get more drivers > into the tree in the short term - we should still work towards > replacing any driver that actually needs this with our own code. That's > why I'm not sure it's worth the effort - if ie. the VIA Rhine or > RTL8139 drivers need this, we should fix our drivers rather than > switching to FreeBSD's. I love kruft just as much as the next guy. :-) However, i think we need a realistic stance here. I've seen more than once FreeBSD drivers considered a "temporary solution" and i think people should detract from this idea. Although it certainly is a nice target to have all "native" drivers, i think we should be better off spending our time making Haiku work and as well as people expect it to be. The amount of hardware supported is certainly a part of that experience, however, as long as it works it is really not that important if the drivers are "native" or "ported", as long as the end result is a stable and fast platform. Also, considering the current API which hides away the internal buffer management of the driver, etc, i don't consider this much of a porting effort but more of a framework that allows freebsd drivers to be integrated as native. We should not ignore the user base of the freebsd drivers, which is certainly larger than that of haiku's, and thus the drivers are more tested and probably more stable as well. Trying to duplicate that effort, is if you ask me a bit of a waste of time, but people are free to waste their time as they wish. :-) Just some food for thought, Hugo From korli at mail.berlios.de Thu May 10 21:54:19 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Thu, 10 May 2007 21:54:19 +0200 Subject: [Haiku-commits] r21106 - haiku/trunk/src/servers/input Message-ID: <200705101954.l4AJsJ2J018136@sheep.berlios.de> Author: korli Date: 2007-05-10 21:54:18 +0200 (Thu, 10 May 2007) New Revision: 21106 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21106&view=rev Modified: haiku/trunk/src/servers/input/AddOnManager.cpp Log: remove filters and methods from their lists when unregistering fixes bug #1215 Modified: haiku/trunk/src/servers/input/AddOnManager.cpp =================================================================== --- haiku/trunk/src/servers/input/AddOnManager.cpp 2007-05-10 14:13:37 UTC (rev 21105) +++ haiku/trunk/src/servers/input/AddOnManager.cpp 2007-05-10 19:54:18 UTC (rev 21106) @@ -248,6 +248,8 @@ filter_info *pinfo; for (fFilterList.Rewind(); fFilterList.GetNext(&pinfo);) { if (!strcmp(pinfo->ref.name, ref.name)) { + BAutolock lock2(InputServer::gInputFilterListLocker); + InputServer::gInputFilterList.RemoveItem(pinfo->filter); delete pinfo->filter; if (pinfo->addon_image >= B_OK) unload_add_on(pinfo->addon_image); @@ -256,9 +258,11 @@ } } } else if (pathString.FindFirst("input_server/methods") > 0) { - method_info *pinfo; + method_info *pinfo = NULL; for (fMethodList.Rewind(); fMethodList.GetNext(&pinfo);) { if (!strcmp(pinfo->ref.name, ref.name)) { + BAutolock lock2(InputServer::gInputMethodListLocker); + InputServer::gInputMethodList.RemoveItem(pinfo->method); delete pinfo->method; if (pinfo->addon_image >= B_OK) unload_add_on(pinfo->addon_image); @@ -271,7 +275,7 @@ // we remove the method replicant BDeskbar().RemoveItem(REPLICANT_CTL_NAME); gInputServer->SetMethodReplicant(NULL); - } else { + } else if (pinfo != NULL) { BMessage msg(IS_REMOVE_METHOD); msg.AddInt32("cookie", (uint32)pinfo->method); if (gInputServer->MethodReplicant()) From jackburton at mail.berlios.de Thu May 10 22:40:49 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Thu, 10 May 2007 22:40:49 +0200 Subject: [Haiku-commits] r21107 - haiku/trunk/src/kits/interface Message-ID: <200705102040.l4AKenOW022587@sheep.berlios.de> Author: jackburton Date: 2007-05-10 22:40:48 +0200 (Thu, 10 May 2007) New Revision: 21107 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21107&view=rev Modified: haiku/trunk/src/kits/interface/ListView.cpp Log: Check if we have a window before drawing the item in BListView::_Deselect() Modified: haiku/trunk/src/kits/interface/ListView.cpp =================================================================== --- haiku/trunk/src/kits/interface/ListView.cpp 2007-05-10 19:54:18 UTC (rev 21106) +++ haiku/trunk/src/kits/interface/ListView.cpp 2007-05-10 20:40:48 UTC (rev 21107) @@ -1323,8 +1323,9 @@ if (index < 0 || index >= CountItems()) return false; - BAutolock locker(Window()); - if (Window() && !locker.IsLocked()) + BWindow *window = Window(); + BAutolock locker(window); + if (window && !locker.IsLocked()) return false; BListItem *item = ItemAt(index); @@ -1346,7 +1347,7 @@ fLastSelected = _CalcLastSelected(index); } - if (bounds.Intersects(frame)) + if (window && bounds.Intersects(frame)) DrawItem(ItemAt(index), frame, true); } From axeld at pinc-software.de Thu May 10 23:24:26 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Thu, 10 May 2007 23:24:26 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r21101_-_in_haiku/trunk/src/add-o?= =?iso-8859-15?q?ns/kernel/drivers/network/3com=3A_=2E_dev_dev/mii_pci?= In-Reply-To: <9c46321e0705100725i14825a96wb05e639e51bec904@mail.gmail.com> Message-ID: <16575426222-BeMail@zon> "Hugo Santos" wrote: > > While this sounds like the best compromise so far, it still has an > > impact on shared interrupts (even though it would work): it > > increases > > the interrupt latency by an undeterminable amount. [...] > I love kruft just as much as the next guy. :-) However, i think we > need a realistic stance here. I've seen more than once FreeBSD > drivers > considered a "temporary solution" and i think people should detract > from this idea. [...] > Trying to duplicate that effort, is if you ask me a bit of a waste of > time, but people are free to waste their time as they wish. :-) It sounds like you misinterpreted me: I'm not saying that FreeBSD drivers in general are a temporary solution - I'm saying that *if* we introduce this interrupt threading stuff into Haiku, that drivers actually using them are a temporary solution for the reasons I've outlined. Low latency is a feature we shouldn't easily sacrifice. Bye, Axel. From hugosantos at gmail.com Fri May 11 00:10:31 2007 From: hugosantos at gmail.com (Hugo Santos) Date: Thu, 10 May 2007 23:10:31 +0100 Subject: [Haiku-commits] r21101 - in haiku/trunk/src/add-ons/kernel/drivers/network/3com: . dev dev/mii pci In-Reply-To: <16575426222-BeMail@zon> References: <9c46321e0705100725i14825a96wb05e639e51bec904@mail.gmail.com> <16575426222-BeMail@zon> Message-ID: <9c46321e0705101510m4569fb16t87368e68cb17aa7f@mail.gmail.com> On 5/10/07, Axel D?rfler wrote: > It sounds like you misinterpreted me: I'm not saying that FreeBSD > drivers in general are a temporary solution - I'm saying that *if* we > introduce this interrupt threading stuff into Haiku, that drivers > actually using them are a temporary solution for the reasons I've > outlined. Low latency is a feature we shouldn't easily sacrifice. Oh, indeed, i'm sorry. And i agree. Hugo From axeld at mail.berlios.de Fri May 11 11:16:08 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 11 May 2007 11:16:08 +0200 Subject: [Haiku-commits] r21108 - haiku/trunk/src/system/kernel/fs Message-ID: <200705110916.l4B9G88g007105@sheep.berlios.de> Author: axeld Date: 2007-05-11 11:16:08 +0200 (Fri, 11 May 2007) New Revision: 21108 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21108&view=rev Modified: haiku/trunk/src/system/kernel/fs/pipefs.cpp Log: * Added a name hash to pipefs; this should speedup the lookup when more pipes are used at the same time. * Added a TODO item: pipefs entries aren't deleted yet after usage! Modified: haiku/trunk/src/system/kernel/fs/pipefs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/pipefs.cpp 2007-05-10 20:40:48 UTC (rev 21107) +++ haiku/trunk/src/system/kernel/fs/pipefs.cpp 2007-05-11 09:16:08 UTC (rev 21108) @@ -1,5 +1,5 @@ /* - * Copyright 2003-2006, Axel D?rfler, axeld at pinc-software.de. + * Copyright 2003-2007, Axel D?rfler, axeld at pinc-software.de. * Distributed under the terms of the MIT License. */ @@ -25,10 +25,8 @@ #include #include +// TODO: pipefs entries aren't deleted automatically after usage yet! -// ToDo: handles file names suboptimally - it has all file names -// in a singly linked list, no hash lookups or whatever. - //#define TRACE_PIPEFS #ifdef TRACE_PIPEFS # define TRACE(x) dprintf x @@ -108,7 +106,7 @@ void Unlock(); Inode *Lookup(vnode_id id); - Inode *FindNode(const char *name); + Inode *Lookup(const char *name); Inode *CreateNode(Inode *parent, const char *name, int32 type); status_t DeleteNode(Inode *inode, bool forceDelete = false); status_t RemoveNode(Inode *directory, const char *name); @@ -132,6 +130,7 @@ Inode *fRootNode; vnode_id fNextNodeID; hash_table *fNodeHash; + hash_table *fNameHash; // root directory contents - we don't support other directories Inode *fFirstEntry; @@ -182,6 +181,10 @@ status_t Select(uint8 event, uint32 ref, selectsync *sync); status_t Deselect(uint8 event, selectsync *sync); + static int32 NameHashNextOffset(); + static uint32 name_hash_func(void *_node, const void *_key, uint32 range); + static int name_compare_func(void *_node, const void *_key); + static int32 HashNextOffset(); static uint32 hash_func(void *_node, const void *_key, uint32 range); static int compare_func(void *_node, const void *_key); @@ -189,6 +192,7 @@ private: Inode *fNext; Inode *fHashNext; + Inode *fNameHashNext; vnode_id fID; int32 fType; const char *fName; @@ -297,6 +301,7 @@ fRootNode(NULL), fNextNodeID(0), fNodeHash(NULL), + fNameHash(NULL), fFirstEntry(NULL), fFirstDirCookie(NULL) { @@ -308,6 +313,11 @@ if (fNodeHash == NULL) return; + fNameHash = hash_init(PIPEFS_HASH_SIZE, Inode::NameHashNextOffset(), + &Inode::name_compare_func, &Inode::name_hash_func); + if (fNameHash == NULL) + return; + // create the root vnode fRootNode = CreateNode(NULL, "", S_IFDIR | 0777); if (fRootNode == NULL) @@ -321,6 +331,9 @@ if (fRootNode) put_vnode(ID(), fRootNode->ID()); + if (fNameHash != NULL) + hash_uninit(fNameHash); + if (fNodeHash != NULL) { // delete all of the inodes struct hash_iterator i; @@ -380,6 +393,7 @@ InsertNode(inode); hash_insert(fNodeHash, inode); + hash_insert(fNameHash, inode); publish_vnode(ID(), inode->ID(), inode); if (fRootNode != NULL) @@ -394,6 +408,7 @@ { // remove it from the global hash table hash_remove(fNodeHash, inode); + hash_remove(fNameHash, inode); if (fRootNode != NULL) fRootNode->SetModificationTime(time(NULL)); @@ -428,8 +443,7 @@ } -/* makes sure none of the dircookies point to the vnode passed in */ - +/*! Makes sure none of the dircookies point to the vnode passed in */ void Volume::UpdateDirCookies(Inode *inode) { @@ -450,17 +464,13 @@ Inode * -Volume::FindNode(const char *name) +Volume::Lookup(const char *name) { if (!strcmp(name, ".") || !strcmp(name, "..")) return fRootNode; - for (Inode *inode = fFirstEntry; inode; inode = inode->Next()) { - if (!strcmp(inode->Name(), name)) - return inode; - } - return NULL; + return (Inode *)hash_lookup(fNameHash, name); } @@ -504,7 +514,7 @@ status_t status = B_OK; - Inode *inode = FindNode(name); + Inode *inode = Lookup(name); if (inode == NULL) status = B_ENTRY_NOT_FOUND; else if (S_ISDIR(inode->Type())) @@ -842,6 +852,40 @@ } +int32 +Inode::NameHashNextOffset() +{ + Inode *inode; + return (addr_t)&inode->fNameHashNext - (addr_t)inode; +} + + +uint32 +Inode::name_hash_func(void *_node, const void *_key, uint32 range) +{ + Inode *inode = (Inode *)_node; + const char *key = (const char *)_key; + + if (inode != NULL) + return hash_hash_string(inode->Name()) % range; + + return hash_hash_string(key) % range; +} + + +int +Inode::name_compare_func(void *_node, const void *_key) +{ + Inode *inode = (Inode *)_node; + const char *key = (const char *)_key; + + if (!strcmp(inode->Name(), key)) + return 0; + + return -1; +} + + status_t Inode::Select(uint8 event, uint32 ref, selectsync *sync) { @@ -1053,7 +1097,7 @@ volume->Lock(); // look it up - Inode *inode = volume->FindNode(name); + Inode *inode = volume->Lookup(name); if (inode == NULL) { status = B_ENTRY_NOT_FOUND; goto err; @@ -1171,7 +1215,7 @@ Inode *directory = (Inode *)_dir; status_t status = B_OK; - Inode *inode = volume->FindNode(name); + Inode *inode = volume->Lookup(name); if (inode != NULL && (openMode & O_EXCL) != 0) { status = B_FILE_EXISTS; goto err; From axeld at mail.berlios.de Fri May 11 14:25:03 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 11 May 2007 14:25:03 +0200 Subject: [Haiku-commits] r21109 - in haiku/trunk/src/add-ons/kernel/file_systems: . cdda Message-ID: <200705111225.l4BCP3FN003089@sheep.berlios.de> Author: axeld Date: 2007-05-11 14:25:02 +0200 (Fri, 11 May 2007) New Revision: 21109 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21109&view=rev Added: haiku/trunk/src/add-ons/kernel/file_systems/cdda/ haiku/trunk/src/add-ons/kernel/file_systems/cdda/Jamfile haiku/trunk/src/add-ons/kernel/file_systems/cdda/Lock.h haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp Modified: haiku/trunk/src/add-ons/kernel/file_systems/Jamfile Log: Start of a CDDA file system (replacement for cdda as part of BeOS): * doesn't do anything useful yet, but it compiles (and should be mountable). * CDDA test app "cdda_text" will dump the table of contents as well as eventually existing CD-Text - if I had known only so few titles in my collection would come with those, I probably wouldn't have gone through it (if the samples I used are representable, it's about 1/10th of the CDs I have) :-) * cdda_text compiles on BeOS, so if you have known CD-Text CDs, please test it and report eventual problems - the test app already tries to beautify the names as much as possible. Usage is "cdda_text ". * The test app will be removed later, so better test now ;) Modified: haiku/trunk/src/add-ons/kernel/file_systems/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/Jamfile 2007-05-11 09:16:08 UTC (rev 21108) +++ haiku/trunk/src/add-ons/kernel/file_systems/Jamfile 2007-05-11 12:25:02 UTC (rev 21109) @@ -2,6 +2,7 @@ SubInclude HAIKU_TOP src add-ons kernel file_systems dos ; SubInclude HAIKU_TOP src add-ons kernel file_systems bfs ; +SubInclude HAIKU_TOP src add-ons kernel file_systems cdda ; SubInclude HAIKU_TOP src add-ons kernel file_systems googlefs ; SubInclude HAIKU_TOP src add-ons kernel file_systems iso9660 ; SubInclude HAIKU_TOP src add-ons kernel file_systems nfs ; Added: haiku/trunk/src/add-ons/kernel/file_systems/cdda/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/Jamfile 2007-05-11 09:16:08 UTC (rev 21108) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/Jamfile 2007-05-11 12:25:02 UTC (rev 21109) @@ -0,0 +1,13 @@ +SubDir HAIKU_TOP src add-ons kernel file_systems cdda ; + +UsePrivateHeaders [ FDirName kernel ] ; +UsePrivateHeaders [ FDirName kernel disk_device_manager ] ; +UsePrivateHeaders [ FDirName storage ] ; + +KernelAddon cdda : + kernel_interface.cpp + ; + +SimpleTest cdda_text : + cdda.cpp + : be ; Added: haiku/trunk/src/add-ons/kernel/file_systems/cdda/Lock.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/Lock.h 2007-05-11 09:16:08 UTC (rev 21108) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/Lock.h 2007-05-11 12:25:02 UTC (rev 21109) @@ -0,0 +1,96 @@ +/* + * Copyright 2001-2007, Axel D?rfler, axeld at pinc-software.de. + * This file may be used under the terms of the MIT License. + */ +#ifndef LOCK_H +#define LOCK_H + + +#include + + +#define USE_BENAPHORE + // if defined, benaphores are used for the Semaphore class + +class Semaphore { + public: + Semaphore(const char *name) + : +#ifdef USE_BENAPHORE + fSemaphore(create_sem(0, name)), + fCount(1) +#else + fSemaphore(create_sem(1, name)) +#endif + { + } + + ~Semaphore() + { + delete_sem(fSemaphore); + } + + status_t InitCheck() + { + if (fSemaphore < B_OK) + return fSemaphore; + + return B_OK; + } + + status_t Lock() + { +#ifdef USE_BENAPHORE + if (atomic_add(&fCount, -1) <= 0) +#endif + return acquire_sem(fSemaphore); +#ifdef USE_BENAPHORE + return B_OK; +#endif + } + + status_t Unlock() + { +#ifdef USE_BENAPHORE + if (atomic_add(&fCount, 1) < 0) +#endif + return release_sem(fSemaphore); +#ifdef USE_BENAPHORE + return B_OK; +#endif + } + + private: + sem_id fSemaphore; +#ifdef USE_BENAPHORE + vint32 fCount; +#endif +}; + +// a convenience class to lock a Semaphore object + +class Locker { + public: + Locker(Semaphore &lock) + : fLock(lock) + { + fStatus = lock.Lock(); + } + + ~Locker() + { + if (fStatus == B_OK) + fLock.Unlock(); + } + + status_t Status() const + { + return fStatus; + } + + private: + Semaphore &fLock; + status_t fStatus; +}; + +#endif /* LOCK_H */ Added: haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp 2007-05-11 09:16:08 UTC (rev 21108) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp 2007-05-11 12:25:02 UTC (rev 21109) @@ -0,0 +1,532 @@ +/* + * Copyright 2007, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + */ + + +#include +#include + +#include +#include +#include +#include +#include + +#define kFramesPerSecond 75 +#define kFramesPerMinute (kFramesPerSecond * 60) + +struct cdtext_pack_data { + uint8 id; + uint8 track; + uint8 number; + uint8 character_position : 4; + uint8 block_number : 3; + uint8 double_byte : 1; + char text[12]; + uint8 crc[2]; +} _PACKED; + + +static const uint8 kMaxTracks = 0x63; +enum { + kTrackID = 0x80, + kArtistID = 0x81, + kMessageID = 0x85, +}; + +struct cdtext { + char *artist; + char *album; + char *titles[kMaxTracks]; + char *artists[kMaxTracks]; + uint8 track_count; + char *genre; +}; + + +// #pragma mark - string functions + + +bool +is_garbage(char c) +{ + return isspace(c) || c == '-' || c == '/' || c == '\\'; +} + + +void +sanitize_string(char *string) +{ + if (string == NULL) + return; + + // strip garbage at the start + + uint32 length = strlen(string); + uint32 garbage = 0; + while (is_garbage(string[garbage])) { + garbage++; + } + + length -= garbage; + if (garbage) + memmove(string, string + garbage, length + 1); + + // strip garbage from the end + + while (length > 1 && isspace(string[length - 1])) { + string[--length] = '\0'; + } +} + + +//! Finds the first occurrence of \a find in \a string, ignores case. +static char* +find_string(const char *string, const char *find) +{ + if (string == NULL || find == NULL) + return NULL; + + char first = tolower(find[0]); + if (first == '\0') + return (char *)string; + + int32 findLength = strlen(find) - 1; + find++; + + for (; string[0]; string++) { + if (tolower(string[0]) != first) + continue; + if (strncasecmp(string + 1, find, findLength) == 0) + return (char *)string; + } + + return NULL; +} + + +void +cut_string(char *string, char *cut) +{ + if (string == NULL || cut == NULL) + return; + + char *found = find_string(string, cut); + if (found != NULL) { + uint32 foundLength = strlen(found); + uint32 cutLength = strlen(cut); + memmove(found, found + cutLength, foundLength + 1 - cutLength); + } +} + + +void +sanitize_album(cdtext &text) +{ + cut_string(text.album, text.artist); + sanitize_string(text.album); + + if ((text.artist == NULL || !text.artist[0]) && text.album != NULL) { + // try to extract artist from album + char *space = strstr(text.album, " "); + if (space != NULL) { + space[0] = '\0'; + text.artist = text.album; + text.album = strdup(space + 2); + + sanitize_string(text.artist); + sanitize_string(text.album); + } + } +} + + +void +sanitize_titles(cdtext &text) +{ + for (uint8 i = 0; i < text.track_count; i++) { + cut_string(text.titles[i], "(Album Version)"); + sanitize_string(text.titles[i]); + sanitize_string(text.artists[i]); + if (!strcasecmp(text.artists[i], text.artist)) { + // if the title artist is the same as the main artist, remove it + free(text.artists[i]); + text.artists[i] = NULL; + } + + if (text.titles[i] != NULL && text.titles[i][0] == '\t' && i > 0) + text.titles[i] = strdup(text.titles[i - 1]); + } +} + + +bool +single_case(const char *string, bool &upper, bool &first) +{ + if (string == NULL) + return true; + + while (string[0]) { + while (!isalpha(string[0])) { + string++; + } + + if (first) { + upper = isupper(string[0]) != 0; + first = false; + } else if ((isupper(string[0]) != 0) ^ upper) + return false; + + string++; + } + + return true; +} + + +void +capitalize_string(char *string) +{ + if (string == NULL) + return; + + bool newWord = isalpha(string[0]) || isspace(string[0]); + while (string[0]) { + if (isalpha(string[0])) { + if (newWord) { + string[0] = toupper(string[0]); + newWord = false; + } else + string[0] = tolower(string[0]); + } else if (string[0] != '\'') + newWord = true; + + string++; + } +} + + +void +correct_case(cdtext &text) +{ + // check if all titles share a single case + bool first = true; + bool upper; + if (!single_case(text.album, upper, first) + || !single_case(text.artist, upper, first)) + return; + + for (int32 i = 0; i < text.track_count; i++) { + if (!single_case(text.titles[i], upper, first) + || !single_case(text.artists[i], upper, first)) + return; + } + + // If we get here, everything has a single case; we fix that + // and capitalize each word + + capitalize_string(text.album); + capitalize_string(text.artist); + for (int32 i = 0; i < text.track_count; i++) { + capitalize_string(text.titles[i]); + capitalize_string(text.artists[i]); + } +} + + +// #pragma mark - CD-Text + + +bool +is_string_id(uint8 id) +{ + return id >= kTrackID && id <= kMessageID; +} + + +bool +parse_pack_data(cdtext_pack_data *&pack, uint32 &packLeft, + cdtext_pack_data *&lastPack, uint8 &id, uint8 &track, uint8 &state, + char *buffer, size_t &length) +{ + if (packLeft < sizeof(cdtext_pack_data)) + return false; + + uint8 number = pack->number; + size_t size = length; + + if (state != 0) { + // we had a terminated string and a missing track + track++; + memcpy(buffer, lastPack->text + state, 12 - state); + if (pack->track - track == 1) + state = 0; + else + state += strnlen(buffer, 12 - state); + return true; + } + + id = pack->id; + track = pack->track; + buffer[0] = '\0'; + length = 0; + + size_t position = pack->character_position; + if (position > 0 && lastPack != NULL) { + memcpy(buffer, &lastPack->text[12 - position], position); + length = position; + } + + while (id == pack->id && track == pack->track) { +#if 1 + printf("%u.%u.%u, %u.%u.%u, ", pack->id, pack->track, pack->number, + pack->double_byte, pack->block_number, pack->character_position); + for (int32 i = 0; i < 12; i++) { + if (isprint(pack->text[i])) + putchar(pack->text[i]); + } + putchar('\n'); +#endif + if (is_string_id(id)) { + // TODO: support double byte characters + if (length + 12 < size) { + memcpy(buffer + length, pack->text, 12); + length += 12; + } + } + + packLeft -= sizeof(cdtext_pack_data); + if (packLeft < sizeof(cdtext_pack_data)) + return false; + + lastPack = pack; + number++; + pack++; + + if (pack->number != number) + return false; + } + + if (id == pack->id) { + length -= pack->character_position; + if (length >= size) + length = size - 1; + buffer[length] = '\0'; + + if (pack->track > lastPack->track + 1) { + // there is a missing track + for (int32 i = 0; i < 12; i++) { + if (lastPack->text[i] == '\0') { + state = i + (lastPack->double_byte ? 2 : 1); + break; + } + } + } + } + + // TODO: convert text to UTF-8 + return true; +} + + +void +dump_cdtext(cdtext_pack_data *pack, size_t packLength) +{ + cdtext_pack_data *lastPack = NULL; + char buffer[256]; + uint8 state = 0; + cdtext text; + + memset(&text, 0, sizeof(cdtext)); + + while (true) { + size_t length = sizeof(buffer); + uint8 id, track; + + if (!parse_pack_data(pack, packLength, lastPack, id, track, + state, buffer, length)) + break; + + switch (id) { + case kTrackID: + if (track == 0) { + if (text.album == NULL) + text.album = strdup(buffer); + } else if (track <= kMaxTracks) { + if (text.titles[track - 1] == NULL) + text.titles[track - 1] = strdup(buffer); + if (track > text.track_count) + text.track_count = track; + } + break; + + case kArtistID: + if (track == 0) { + if (text.artist == NULL) + text.artist = strdup(buffer); + } else if (track <= kMaxTracks) { + if (text.artists[track - 1] == NULL) + text.artists[track - 1] = strdup(buffer); + } + break; + + default: + if (is_string_id(id)) + printf("UNKNOWN %u: \"%s\"\n", id, buffer); + break; + } + } + + sanitize_string(text.artist); + sanitize_album(text); + sanitize_titles(text); + correct_case(text); + + if (text.album) + printf("Album: \"%s\"\n", text.album); + if (text.artist) + printf("Artist: \"%s\"\n", text.artist); + for (uint8 i = 0; i < text.track_count; i++) { + printf("Track %02u: \"%s\"%s%s%s\n", i + 1, text.titles[i], + text.artists[i] ? " (" : "", text.artists[i] ? text.artists[i] : "", + text.artists[i] ? ")" : ""); + } +} + + +void +dump_toc(scsi_toc_toc *toc) +{ + int32 numTracks = toc->last_track + 1 - toc->first_track; + + for (int32 i = 0; i < numTracks; i++) { + scsi_toc_track& track = toc->tracks[i]; + scsi_cd_msf& next = toc->tracks[i + 1].start.time; + // the last track is always lead-out + scsi_cd_msf& start = toc->tracks[i].start.time; + scsi_cd_msf length; + + uint64 diff = next.minute * kFramesPerMinute + + next.second * kFramesPerSecond + next.frame + - start.minute * kFramesPerMinute + - start.second * kFramesPerSecond - start.frame; + length.minute = diff / kFramesPerMinute; + length.second = (diff % kFramesPerMinute) / kFramesPerSecond; + length.frame = diff % kFramesPerSecond; + + printf("%02u. %02u:%02u.%02u (length %02u:%02u.%02u)\n", + track.track_number, start.minute, start.second, start.frame, + length.minute, length.second, length.frame); + } +} + + +status_t +read_table_of_contents(int fd, uint32 track, uint8 format, uint8 *buffer, + size_t bufferSize) +{ + raw_device_command raw; + uint8 senseData[1024]; + + memset(&raw, 0, sizeof(raw_device_command)); + memset(senseData, 0, sizeof(senseData)); + memset(buffer, 0, bufferSize); + + scsi_cmd_read_toc &toc = *(scsi_cmd_read_toc*)&raw.command; + toc.opcode = SCSI_OP_READ_TOC; + toc.time = 1; + toc.format = format; + toc.track = track; + toc.allocation_length = B_HOST_TO_BENDIAN_INT16(bufferSize); + + raw.command_length = 10; + raw.flags = B_RAW_DEVICE_DATA_IN | B_RAW_DEVICE_REPORT_RESIDUAL + | B_RAW_DEVICE_SHORT_READ_VALID; + raw.scsi_status = 0; + raw.cam_status = 0; + raw.data = buffer; + raw.data_length = bufferSize; + raw.timeout = 10000000LL; // 10 secs + raw.sense_data = senseData; + raw.sense_data_length = sizeof(senseData); + + if (ioctl(fd, B_RAW_DEVICE_COMMAND, &raw) == 0) { + if (raw.scsi_status == 0 && raw.cam_status == 1) { + puts("success!\n"); + } else { + puts("failure!\n"); + } + } + + return 0; +} + + +void +dump_block(const uint8 *buffer, int size, const char *prefix) +{ + int i; + + for (i = 0; i < size;) + { + int start = i; + + printf(prefix); + for (; i < start+16; i++) + { + if (!(i % 4)) + printf(" "); + + if (i >= size) + printf(" "); + else + printf("%02x", *(unsigned char *)(buffer + i)); + } + printf(" "); + + for (i = start; i < start + 16; i++) + { + if (i < size) + { + char c = buffer[i]; + + if (c < 30) + printf("."); + else + printf("%c", c); + } + else + break; + } + printf("\n"); + } +} + + +int +main(int argc, char** argv) +{ + int fd = open(argv[1], O_RDONLY); + if (fd < 0) + return -1; + + uint8 buffer[1024]; + scsi_toc_general *header = (scsi_toc_general *)buffer; + + read_table_of_contents(fd, 1, SCSI_TOC_FORMAT_TOC, buffer, sizeof(buffer)); + header->data_length = B_BENDIAN_TO_HOST_INT16(header->data_length); + printf("TOC header %u, %d, %d\n", header->data_length, header->first, header->last); + //dump_block(buffer, header->data_length + 2, "TOC"); + dump_toc((scsi_toc_toc *)buffer); + + read_table_of_contents(fd, 1, SCSI_TOC_FORMAT_CD_TEXT, buffer, sizeof(buffer)); + read_table_of_contents(fd, 1, SCSI_TOC_FORMAT_CD_TEXT, buffer, sizeof(buffer)); + header->data_length = B_BENDIAN_TO_HOST_INT16(header->data_length); + printf("TEXT header %u, %d, %d\n", header->data_length, header->first, header->last); + //dump_block(buffer, header->data_length + 2, "TEXT"); + + dump_cdtext((cdtext_pack_data *)(buffer + 4), header->data_length - 2); + + close(fd); +} Added: haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp 2007-05-11 09:16:08 UTC (rev 21108) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp 2007-05-11 12:25:02 UTC (rev 21109) @@ -0,0 +1,826 @@ +/* + * Copyright 2007, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + */ + + +#include "Lock.h" + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + + +//#define TRACE_CDDA +#ifdef TRACE_CDDA +# define TRACE(x) dprintf x +#else +# define TRACE(x) +#endif + + +class Volume; +class Inode; +struct dir_cookie; + +class Volume { + public: + Volume(mount_id id); + ~Volume(); + + status_t InitCheck(); + mount_id ID() const { return fID; } + Inode &RootNode() const { return *fRootNode; } + + status_t Mount(const char* device); + int Device() const { return fDevice; } + vnode_id GetNextNodeID() { return fNextID++; } + + const char *Name() const { return fName; } + status_t SetName(const char *name); + + Semaphore &Lock(); + + Inode *Find(vnode_id id); + Inode *Find(const char *name); + + Inode *FirstEntry() const { return fFirstEntry; } + off_t NumBlocks() const { return fNumBlocks; } + + private: + Inode *_CreateNode(Inode *parent, const char *name, int32 type); + + Semaphore fLock; + int fDevice; + mount_id fID; + Inode *fRootNode; + vnode_id fNextID; + char *fName; + off_t fNumBlocks; + + // root directory contents - we don't support other directories + Inode *fFirstEntry; +}; + + +class Inode { + public: + Inode(Volume *volume, Inode *parent, const char *name, int32 type); + ~Inode(); + + status_t InitCheck(); + vnode_id ID() const { return fID; } + + const char *Name() const { return fName; } + status_t SetName(const char* name); + + int32 Type() const + { return fType; } + gid_t GroupID() const + { return fGroupID; } + uid_t UserID() const + { return fUserID; } + time_t CreationTime() const + { return fCreationTime; } + time_t ModificationTime() const + { return fModificationTime; } + off_t Size() const + { return fSize; } + + Inode *Next() const { return fNext; } + void SetNext(Inode *inode) { fNext = inode; } + + private: + Inode *fNext; + vnode_id fID; + int32 fType; + const char *fName; + gid_t fGroupID; + uid_t fUserID; + time_t fCreationTime; + time_t fModificationTime; + off_t fSize; +}; + + +struct dir_cookie { + Inode *current; + int state; // iteration state +}; + +// directory iteration states +enum { + ITERATION_STATE_DOT = 0, + ITERATION_STATE_DOT_DOT = 1, + ITERATION_STATE_OTHERS = 2, + ITERATION_STATE_BEGIN = ITERATION_STATE_DOT, +}; + +struct file_cookie { + int open_mode; +}; + + +Volume::Volume(mount_id id) + : + fLock("cdda"), + fDevice(-1), + fID(id), + fRootNode(NULL), + fNextID(1), + fName(NULL), + fNumBlocks(0), + fFirstEntry(NULL) +{ + // create the root vnode + fRootNode = _CreateNode(NULL, "", S_IFDIR | 0777); +} + + +Volume::~Volume() +{ + close(fDevice); + + // put_vnode on the root to release the ref to it + if (fRootNode) + put_vnode(ID(), fRootNode->ID()); + + Inode *inode, *next; + + for (inode = fFirstEntry; inode != NULL; inode = next) { + next = inode->Next(); + delete inode; + } +} + + +status_t +Volume::InitCheck() +{ + if (fLock.InitCheck() < B_OK + || fRootNode == NULL) + return B_ERROR; + + return B_OK; +} + + +status_t +Volume::Mount(const char* device) +{ + fDevice = open(device, O_RDONLY); + if (fDevice < 0) + return errno; + + return B_OK; +} + + +Semaphore& +Volume::Lock() +{ + return fLock; +} + + +Inode * +Volume::_CreateNode(Inode *parent, const char *name, int32 type) +{ + Inode *inode = new Inode(this, parent, name, type); + if (inode == NULL) + return NULL; + + if (inode->InitCheck() != B_OK) { + delete inode; + return NULL; + } + + if (S_ISREG(type)) { + inode->SetNext(fFirstEntry); + fFirstEntry = inode; + } + + publish_vnode(ID(), inode->ID(), inode); + return inode; +} + + +Inode * +Volume::Find(vnode_id id) +{ + for (Inode *inode = fFirstEntry; inode != NULL; inode = inode->Next()) { + if (inode->ID() == id) + return inode; + } + + return NULL; +} + + +Inode * +Volume::Find(const char *name) +{ + if (!strcmp(name, ".") + || !strcmp(name, "..")) + return fRootNode; + + for (Inode *inode = fFirstEntry; inode != NULL; inode = inode->Next()) { + if (!strcmp(inode->Name(), name)) + return inode; + } + + return NULL; +} + + +status_t +Volume::SetName(const char *name) +{ + return B_ERROR; +} + + +// #pragma mark - + + +Inode::Inode(Volume *volume, Inode *parent, const char *name, int32 type) + : + fNext(NULL) +{ + fName = strdup(name); + if (fName == NULL) + return; + + fID = volume->GetNextNodeID(); + fType = type; + + fUserID = geteuid(); + fGroupID = parent ? parent->GroupID() : getegid(); + + fCreationTime = fModificationTime = time(NULL); +} + + +Inode::~Inode() +{ + free(const_cast(fName)); +} + + +status_t +Inode::InitCheck() +{ + if (fName == NULL) + return B_NO_MEMORY; + + return B_OK; +} + + +status_t +Inode::SetName(const char* name) +{ + return B_ERROR; +} + + +// #pragma mark - module API + + +static status_t +cdda_mount(mount_id id, const char *device, uint32 flags, const char *args, + fs_volume *_volume, vnode_id *_rootVnodeID) +{ + TRACE(("cdda_mount: entry\n")); + + Volume *volume = new Volume(id); + if (volume == NULL) + return B_NO_MEMORY; + + status_t status = volume->InitCheck(); + if (status == B_OK) + status = volume->Mount(device); + + if (status < B_OK) { + delete volume; + return status; + } + + *_rootVnodeID = volume->RootNode().ID(); + *_volume = volume; + + return B_OK; +} + [... truncated: 504 lines follow ...] From bonefish at mail.berlios.de Fri May 11 20:14:47 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Fri, 11 May 2007 20:14:47 +0200 Subject: [Haiku-commits] r21110 - haiku/trunk/src/tests/kits/interface/layout Message-ID: <200705111814.l4BIElR0020686@sheep.berlios.de> Author: bonefish Date: 2007-05-11 20:14:47 +0200 (Fri, 11 May 2007) New Revision: 21110 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21110&view=rev Added: haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp Modified: haiku/trunk/src/tests/kits/interface/layout/Jamfile Log: The beginnings of an app for testing the layout constraints of individual widgets. Modified: haiku/trunk/src/tests/kits/interface/layout/Jamfile =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/Jamfile 2007-05-11 12:25:02 UTC (rev 21109) +++ haiku/trunk/src/tests/kits/interface/layout/Jamfile 2007-05-11 18:14:47 UTC (rev 21110) @@ -8,8 +8,15 @@ be ; +SimpleTest WidgetLayoutTest : + WidgetLayoutTest.cpp + : + be +; + if $(TARGET_PLATFORM) = libbe_test { - HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : LayoutTest1 + HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) + : LayoutTest1 WidgetLayoutTest : tests!apps ; } Added: haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp 2007-05-11 12:25:02 UTC (rev 21109) +++ haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp 2007-05-11 18:14:47 UTC (rev 21110) @@ -0,0 +1,773 @@ +/* + * Copyright 2007, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + + +// internal messages +enum { + MSG_2D_SLIDER_VALUE_CHANGED = '2dsv', +}; + + +// missing operators in BPoint + +BPoint +operator-(const BPoint& p) +{ + return BPoint(-p.x, -p.y); +} + + +BPoint +operator+(const BPoint& p, const BSize& size) +{ + return BPoint(p.x + size.width, p.y + size.height); +} + + +// View +class View { +public: + View(BRect frame) + : fFrame(frame), + fContainer(NULL), + fParent(NULL), + fChildren(), + fViewColor(B_TRANSPARENT_32_BIT) + { + } + + virtual ~View() + { + // delete children + for (int32 i = CountChildren() - 1; i >= 0; i--) + delete RemoveChild(i); + } + + virtual void SetFrame(BRect frame) + { + if (frame != fFrame && frame.IsValid()) { + BRect oldFrame(frame); + Invalidate(); + fFrame = frame; + Invalidate(); + + FrameChanged(oldFrame, frame); + } + } + + BRect Frame() const + { + return fFrame; + } + + BRect Bounds() const + { + return BRect(fFrame).OffsetToCopy(B_ORIGIN); + } + + void SetLocation(BPoint location) + { + SetFrame(fFrame.OffsetToCopy(location)); + } + + BPoint Location() const + { + return fFrame.LeftTop(); + } + + void SetSize(BSize size) + { + BRect frame(fFrame); + frame.right = frame.left + size.width; + frame.bottom = frame.top + size.height; + SetFrame(frame); + } + + BSize Size() const + { + return BSize(Frame()); + } + + BPoint LocationInContainer() const + { + BPoint location = fFrame.LeftTop(); + return (fParent ? fParent->LocationInContainer() + location : location); + } + + BRect FrameInContainer() const + { + BRect frame(fFrame); + return frame.OffsetToCopy(LocationInContainer()); + } + + BPoint ConvertFromContainer(BPoint point) const + { + return point - LocationInContainer(); + } + + BRect ConvertFromContainer(BRect rect) const + { + return rect.OffsetBySelf(-LocationInContainer()); + } + + BPoint ConvertToContainer(BPoint point) const + { + return point + LocationInContainer(); + } + + BRect ConvertToContainer(BRect rect) const + { + return rect.OffsetBySelf(LocationInContainer()); + } + + View* Parent() const + { + return fParent; + } + + BView* Container() const + { + return fContainer; + } + + bool AddChild(View* child) + { + if (!child) + return false; + + if (child->Parent() || child->Container()) { + fprintf(stderr, "View::AddChild(): view %p already has a parent " + "or is the container view\n", child); + return false; + } + + if (!fChildren.AddItem(child)) + return false; + + child->_AddedToParent(this); + + child->Invalidate(); + + return true; + } + + bool RemoveChild(View* child) + { + if (!child) + return false; + + return RemoveChild(IndexOfChild(child)); + } + + View* RemoveChild(int32 index) + { + if (index < 0 || index >= fChildren.CountItems()) + return NULL; + + View* child = ChildAt(index); + child->Invalidate(); + child->_RemovingFromParent(); + fChildren.RemoveItem(index); + + return child; + } + + int32 CountChildren() const + { + return fChildren.CountItems(); + } + + View* ChildAt(int32 index) const + { + return (View*)fChildren.ItemAt(index); + } + + View* ChildAt(BPoint point) const + { + for (int32 i = 0; View* child = ChildAt(i); i++) { + if (child->Frame().Contains(point)) + return child; + } + + return NULL; + } + + View* AncestorAt(BPoint point, BPoint* localPoint = NULL) const + { + if (!Bounds().Contains(point)) + return NULL; + + View* view = const_cast(this); + + // Iterate deeper down the hierarchy, until we reach a view that + // doesn't have a child at the location. + while (true) { + View* child = view->ChildAt(point); + if (!child) { + if (localPoint) + *localPoint = point; + return view; + } + + view = child; + point -= view->Frame().LeftTop(); + } + } + + int32 IndexOfChild(View* child) const + { + return (child ? fChildren.IndexOf(child) : -1); + } + + void Invalidate(BRect rect) + { + if (fContainer) { + rect = rect & Bounds(); + fContainer->Invalidate(rect.OffsetByCopy(LocationInContainer())); + } + } + + void Invalidate() + { + Invalidate(Bounds()); + } + + void SetViewColor(rgb_color color) + { + fViewColor = color; + } + + virtual void Draw(BView* container, BRect updateRect) + { + } + + virtual void MouseDown(BPoint where, uint32 buttons, int32 modifiers) + { + } + + virtual void MouseUp(BPoint where, uint32 buttons, int32 modifiers) + { + } + + virtual void MouseMoved(BPoint where, uint32 buttons, int32 modifiers) + { + } + + virtual void AddedToContainer() + { + } + + virtual void RemovingFromContainer() + { + } + + virtual void FrameChanged(BRect oldFrame, BRect newFrame) + { + } + +protected: + virtual void _AddedToParent(View* parent) + { + fParent = parent; + + if (parent->Container()) { + Invalidate(); + _AddedToContainer(parent->Container()); + } + } + + virtual void _RemovingFromParent() + { + if (fContainer) + _RemovingFromContainer(); + + fParent = NULL; + } + + virtual void _AddedToContainer(BView* container) + { + fContainer = container; + + AddedToContainer(); + + for (int32 i = 0; View* child = ChildAt(i); i++) + child->_AddedToContainer(fContainer); + } + + virtual void _RemovingFromContainer() + { + for (int32 i = 0; View* child = ChildAt(i); i++) + child->_RemovingFromContainer(); + + RemovingFromContainer(); + + fContainer = NULL; + } + + void _Draw(BView* container, BRect updateRect) + { +//printf("%p->View::_Draw(): ", this); +//updateRect.PrintToStream(); + + // compute the clipping region + BRegion region(Bounds()); + for (int32 i = 0; View* child = ChildAt(i); i++) + region.Exclude(child->Frame()); + + if (region.Frame().IsValid()) { + // set the clipping region + container->ConstrainClippingRegion(®ion); + + // draw the background, if it isn't transparent + if (fViewColor.alpha != 0) { + container->SetLowColor(fViewColor); + container->FillRect(updateRect, B_SOLID_LOW); + } + + // draw this view + Draw(container, updateRect); + + // revert the clipping region + region.Set(Bounds()); + container->ConstrainClippingRegion(®ion); + } + + // draw the children + if (CountChildren() > 0) { + container->PushState(); + + for (int32 i = 0; View* child = ChildAt(i); i++) { + BRect childFrame = child->Frame(); + BRect childUpdateRect = updateRect & childFrame; + if (childUpdateRect.IsValid()) { + // set origin + childUpdateRect.OffsetBy(-childFrame.LeftTop()); + container->SetOrigin(childFrame.LeftTop()); + + // draw + child->_Draw(container, childUpdateRect); + } + } + + container->PopState(); + } + } + +private: + BRect fFrame; + BView* fContainer; + View* fParent; + BList fChildren; + rgb_color fViewColor; +}; + + +// ViewContainer +class ViewContainer : public BView, public View { +public: + ViewContainer(BRect frame) + : BView(frame, "view container", B_FOLLOW_NONE, B_WILL_DRAW), + View(frame.OffsetToCopy(B_ORIGIN)), + fMouseFocus(NULL) + { + BView::SetViewColor(B_TRANSPARENT_32_BIT); + _AddedToContainer(this); + } + + virtual void Draw(BRect updateRect) + { + View::_Draw(this, updateRect); + } + + virtual void MouseDown(BPoint where) + { +//printf("ViewContainer::MouseDown((%f, %f))\n", where.x, where.y); + // get mouse buttons and modifiers + uint32 buttons; + int32 modifiers; + _GetButtonsAndModifiers(buttons, modifiers); + + // get mouse focus + if (!fMouseFocus && (buttons & B_PRIMARY_MOUSE_BUTTON)) + fMouseFocus = AncestorAt(where); +//printf(" mouse focus: %p (this: %p)\n", fMouseFocus, this); + + // call hook + if (fMouseFocus) { + fMouseFocus->MouseDown(fMouseFocus->ConvertFromContainer(where), + buttons, modifiers); + } + } + + virtual void MouseUp(BPoint where) + { +//printf("ViewContainer::MouseUp((%f, %f))\n", where.x, where.y); + if (!fMouseFocus) + return; + + // get mouse buttons and modifiers + uint32 buttons; + int32 modifiers; + _GetButtonsAndModifiers(buttons, modifiers); + + // call hook + if (fMouseFocus) { + fMouseFocus->MouseUp(fMouseFocus->ConvertFromContainer(where), + buttons, modifiers); + } + + // unset the mouse focus when the primary button has been released + if (!(buttons & B_PRIMARY_MOUSE_BUTTON)) + fMouseFocus = NULL; + } + + virtual void MouseMoved(BPoint where, uint32 code, const BMessage* message) + { +//printf("ViewContainer::MouseMoved((%f, %f))\n", where.x, where.y); + if (!fMouseFocus) + return; + + // get mouse buttons and modifiers + uint32 buttons; + int32 modifiers; + _GetButtonsAndModifiers(buttons, modifiers); + + // call hook + if (fMouseFocus) { + fMouseFocus->MouseMoved(fMouseFocus->ConvertFromContainer(where), + buttons, modifiers); + } + } + + virtual void Draw(BView* container, BRect updateRect) + { + } + + virtual void MouseDown(BPoint where, uint32 buttons, int32 modifiers) + { + } + + virtual void MouseUp(BPoint where, uint32 buttons, int32 modifiers) + { + } + + virtual void MouseMoved(BPoint where, uint32 buttons, int32 modifiers) + { + } + +private: + void _GetButtonsAndModifiers(uint32& buttons, int32& modifiers) + { + buttons = 0; + modifiers = 0; + + if (BMessage* message = Window()->CurrentMessage()) { + if (message->FindInt32("buttons", (int32*)&buttons) != B_OK) + buttons = 0; + if (message->FindInt32("modifiers", modifiers) != B_OK) + modifiers = 0; + } + } + +private: + View* fMouseFocus; +}; + + +// TwoDimensionalSliderView +class TwoDimensionalSliderView : public View, public BInvoker { +public: + TwoDimensionalSliderView(BMessage* message = NULL, + BMessenger target = BMessenger()) + : View(BRect(0, 0, 4, 4)), + BInvoker(message, target), + fMinLocation(0, 0), + fMaxLocation(0, 0), + fDragging(false) + { + SetViewColor((rgb_color){0, 120, 0, 255}); + } + + void SetLocationRange(BPoint minLocation, BPoint maxLocation) + { + if (maxLocation.x < minLocation.x) + maxLocation.x = minLocation.x; + if (maxLocation.y < minLocation.y) + maxLocation.y = minLocation.y; + + fMinLocation = minLocation; + fMaxLocation = maxLocation; + + // force valid value + SetValue(Value()); + } + + BPoint MinLocation() const + { + return fMinLocation; + } + + BPoint MaxLocation() const + { + return fMaxLocation; + } + + BPoint Value() const + { + return Location() - fMinLocation; + } + + void SetValue(BPoint value) + { + BPoint location = fMinLocation + value; + if (location.x < fMinLocation.x) + location.x = fMinLocation.x; + if (location.y < fMinLocation.y) + location.y = fMinLocation.y; + if (location.x > fMaxLocation.x) + location.x = fMaxLocation.x; + if (location.y > fMaxLocation.y) + location.y = fMaxLocation.y; + + if (location != Location()) { + SetFrame(Frame().OffsetToCopy(location)); + + // send the message + if (Message()) { + BMessage message(*Message()); + message.AddPoint("value", Value()); + InvokeNotify(&message); + } + } + } + + virtual void MouseDown(BPoint where, uint32 buttons, int32 modifiers) + { + if (fDragging) + return; + + fOriginalLocation = Frame().LeftTop(); + fOriginalPoint = ConvertToContainer(where); + fDragging = true; + } + + virtual void MouseUp(BPoint where, uint32 buttons, int32 modifiers) + { + if (!fDragging || (buttons & B_PRIMARY_MOUSE_BUTTON)) + return; + + fDragging = false; + } + + virtual void MouseMoved(BPoint where, uint32 buttons, int32 modifiers) + { + if (!fDragging) + return; + + BPoint moved = ConvertToContainer(where) - fOriginalPoint; + SetValue(fOriginalLocation - fMinLocation + moved); + } + +private: + BPoint fMinLocation; + BPoint fMaxLocation; + bool fDragging; + BPoint fOriginalPoint; + BPoint fOriginalLocation; +}; + + +// WrapperView +class WrapperView : public View { +public: + WrapperView(BRect frame, BView* view) + : View(frame), + fView(view), + fInsets(1, 1, 1, 1) + { + SetViewColor((rgb_color){255, 0, 0, 255}); + } + + BView* GetView() const + { + return fView; + } + + BSize MinSize() const + { + return _FromViewSize(fView->MinSize()); + } + + BSize MaxSize() const + { + return _FromViewSize(fView->MaxSize()); + } + + BSize PreferredSize() const + { + return _FromViewSize(fView->PreferredSize()); + } + + virtual void AddedToContainer() + { + _UpdateViewFrame(); + + Container()->AddChild(fView); + } + + virtual void RemovingFromContainer() + { + Container()->RemoveChild(fView); + } + + virtual void FrameChanged(BRect oldFrame, BRect newFrame) + { + _UpdateViewFrame(); + } + +private: + void _UpdateViewFrame() + { + BRect frame(_ViewFrameInContainer()); + fView->MoveTo(frame.LeftTop()); + fView->ResizeTo(frame.Width(), frame.Height()); + } + + BRect _ViewFrame() const + { + BRect viewFrame(Bounds()); + viewFrame.left += fInsets.left; + viewFrame.top += fInsets.top; + viewFrame.right -= fInsets.right; + viewFrame.bottom -= fInsets.bottom; + + return viewFrame; + } + + BRect _ViewFrameInContainer() const + { + return ConvertToContainer(_ViewFrame()); + } + + BSize _FromViewSize(BSize size) const + { + float horizontalInsets = fInsets.left + fInsets.right - 1; + float verticalInsets = fInsets.top + fInsets.bottom - 1; + return BSize(BLayoutUtils::AddDistances(size.width, horizontalInsets), + BLayoutUtils::AddDistances(size.height, verticalInsets)); + } + +private: + BView* fView; + BRect fInsets; +}; + + +// TestWindow +class TestWindow : public BWindow { +public: + TestWindow() + : BWindow(BRect(100, 100, 700, 500), "Widget Layout", + B_TITLED_WINDOW, + B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE | B_NOT_RESIZABLE + | B_NOT_ZOOMABLE) + { + ViewContainer* viewContainer = new ViewContainer(Bounds()); + viewContainer->View::SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + AddChild(viewContainer); + + View* view = new View(BRect(10, 10, 400, 300)); + viewContainer->View::AddChild(view); + view->SetViewColor((rgb_color){200, 200, 240, 255}); + + // wrapper view + fWrapperView = new WrapperView(BRect(10, 10, 100, 100), + new BButton(BRect(0, 0, 9, 9), "test button", "Ooh, press me!", + (BMessage*)NULL, B_FOLLOW_NONE, + B_WILL_DRAW | B_NAVIGABLE | B_FULL_UPDATE_ON_RESIZE)); +fWrapperView->GetView()->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); + view->AddChild(fWrapperView); + fWrapperView->SetSize(fWrapperView->PreferredSize()); + + // slider view + fSliderView = new TwoDimensionalSliderView( + new BMessage(MSG_2D_SLIDER_VALUE_CHANGED), this); + fSliderView->SetLocationRange(BPoint(30, 40), BPoint(150, 130)); + view->AddChild(fSliderView); + + _UpdateSliderConstraints(); + } + + virtual void MessageReceived(BMessage* message) + { + switch (message->what) { + case MSG_2D_SLIDER_VALUE_CHANGED: + { +// message->PrintToStream(); + BPoint sliderLocation(fSliderView->Location()); + BPoint wrapperLocation(fWrapperView->Location()); + BSize size(sliderLocation.x - wrapperLocation.x - 1, + sliderLocation.y - wrapperLocation.y - 1); + fWrapperView->SetSize(size); + break; + } + + default: + BWindow::MessageReceived(message); + break; + } + } + +private: + void _UpdateSliderConstraints() + { + BPoint wrapperLocation(fWrapperView->Location()); + BSize minWrapperSize(fWrapperView->MinSize()); + BSize maxWrapperSize(fWrapperView->MaxSize()); + + BPoint minSliderLocation = wrapperLocation + minWrapperSize + + BPoint(1, 1); + BPoint maxSliderLocation = wrapperLocation + maxWrapperSize + + BPoint(1, 1); + + BSize sliderSize(fSliderView->Size()); + BSize parentSize(fSliderView->Parent()->Size()); + if (maxSliderLocation.x + sliderSize.width > parentSize.width) + maxSliderLocation.x = parentSize.width - sliderSize.width; + if (maxSliderLocation.y + sliderSize.height > parentSize.height) + maxSliderLocation.y = parentSize.height - sliderSize.height; + + fSliderView->SetLocationRange(minSliderLocation, maxSliderLocation); + } + +private: + WrapperView* fWrapperView; + TwoDimensionalSliderView* fSliderView; +}; + + +int +main() +{ + BApplication app("application/x-vnd.haiku.widget-layout-test"); + + BWindow* window = new TestWindow; + window->Show(); + + app.Run(); + + return 0; +} From mmu_man at mail.berlios.de Sat May 12 00:21:29 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Sat, 12 May 2007 00:21:29 +0200 Subject: [Haiku-commits] r21111 - haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam Message-ID: <200705112221.l4BMLTbD012007@sheep.berlios.de> Author: mmu_man Date: 2007-05-12 00:21:29 +0200 (Sat, 12 May 2007) New Revision: 21111 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21111&view=rev Modified: haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamStreamingDeframer.cpp Log: fix crash in debug info Modified: haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamStreamingDeframer.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamStreamingDeframer.cpp 2007-05-11 18:14:47 UTC (rev 21110) +++ haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamStreamingDeframer.cpp 2007-05-11 22:21:29 UTC (rev 21111) @@ -34,7 +34,7 @@ int bufsize = size; bool detach = false; bool discard = false; - PRINT((CH "(%p, %d); state=%s framesz=%u queued=%u" CT, buffer, size, (fState==ST_SYNC)?"sync":"frame", (size_t)fCurrentFrame->Position(), (size_t)fInputBuff.Position())); + PRINT((CH "(%p, %d); state=%s framesz=%u queued=%u" CT, buffer, size, (fState==ST_SYNC)?"sync":"frame", (size_t)(fCurrentFrame?(fCurrentFrame->Position()):-1), (size_t)fInputBuff.Position())); if (!fCurrentFrame) { BAutolock l(fLocker); if (fFrames.CountItems() < MAXFRAMEBUF) From jackburton at mail.berlios.de Sat May 12 10:46:57 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Sat, 12 May 2007 10:46:57 +0200 Subject: [Haiku-commits] r21112 - in haiku/trunk: headers/private/interface src/kits/interface Message-ID: <200705120846.l4C8kvUn010349@sheep.berlios.de> Author: jackburton Date: 2007-05-12 10:46:56 +0200 (Sat, 12 May 2007) New Revision: 21112 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21112&view=rev Modified: haiku/trunk/headers/private/interface/PictureDataWriter.h haiku/trunk/src/kits/interface/PictureDataWriter.cpp Log: Added error checking using exceptions Modified: haiku/trunk/headers/private/interface/PictureDataWriter.h =================================================================== --- haiku/trunk/headers/private/interface/PictureDataWriter.h 2007-05-11 22:21:29 UTC (rev 21111) +++ haiku/trunk/headers/private/interface/PictureDataWriter.h 2007-05-12 08:46:56 UTC (rev 21112) @@ -64,11 +64,11 @@ protected: - status_t WriteData(const void *data, size_t size); - template status_t Write(const T &data) { return WriteData(&data, sizeof(data)); } - - status_t BeginOp(const int16 &op); - status_t EndOp(); + // throw a status_t on error + void BeginOp(const int16 &op); + void EndOp(); + void WriteData(const void *data, size_t size); + template void Write(const T &data) { WriteData(&data, sizeof(data)); } private: BPositionIO *fData; Modified: haiku/trunk/src/kits/interface/PictureDataWriter.cpp =================================================================== --- haiku/trunk/src/kits/interface/PictureDataWriter.cpp 2007-05-11 22:21:29 UTC (rev 21111) +++ haiku/trunk/src/kits/interface/PictureDataWriter.cpp 2007-05-12 08:46:56 UTC (rev 21112) @@ -32,6 +32,8 @@ status_t PictureDataWriter::SetTo(BPositionIO *data) { + if (data == NULL) + return B_BAD_VALUE; fData = data; return B_OK; } @@ -40,9 +42,13 @@ status_t PictureDataWriter::WriteSetOrigin(const BPoint &point) { - BeginOp(B_PIC_SET_ORIGIN); - Write(point); - EndOp(); + try { + BeginOp(B_PIC_SET_ORIGIN); + Write(point); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -50,13 +56,17 @@ status_t PictureDataWriter::WriteInvertRect(const BRect &rect) { - WriteSetDrawingMode(B_OP_INVERT); - - BeginOp(B_PIC_FILL_RECT); - Write(rect); - EndOp(); + try { + WriteSetDrawingMode(B_OP_INVERT); + + BeginOp(B_PIC_FILL_RECT); + Write(rect); + EndOp(); - WriteSetDrawingMode(B_OP_COPY); + WriteSetDrawingMode(B_OP_COPY); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -64,9 +74,13 @@ status_t PictureDataWriter::WriteSetDrawingMode(const drawing_mode &mode) { - BeginOp(B_PIC_SET_DRAWING_MODE); - Write((int16)mode); - EndOp(); + try { + BeginOp(B_PIC_SET_DRAWING_MODE); + Write((int16)mode); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -74,9 +88,13 @@ status_t PictureDataWriter::WriteSetPenSize(const float &penSize) { - BeginOp(B_PIC_SET_PEN_SIZE); - Write(penSize); - EndOp(); + try { + BeginOp(B_PIC_SET_PEN_SIZE); + Write(penSize); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -84,11 +102,15 @@ status_t PictureDataWriter::WriteSetLineMode(const cap_mode &cap, const join_mode &join, const float &miterLimit) { - BeginOp(B_PIC_SET_LINE_MODE); - Write((int16)cap); - Write((int16)join); - Write(miterLimit); - EndOp(); + try { + BeginOp(B_PIC_SET_LINE_MODE); + Write((int16)cap); + Write((int16)join); + Write(miterLimit); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -96,9 +118,13 @@ status_t PictureDataWriter::WriteSetScale(const float &scale) { - BeginOp(B_PIC_SET_SCALE); - Write(scale); - EndOp(); + try { + BeginOp(B_PIC_SET_SCALE); + Write(scale); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -106,9 +132,13 @@ status_t PictureDataWriter::WriteSetHighColor(const rgb_color &color) { - BeginOp(B_PIC_SET_FORE_COLOR); - Write(color); - EndOp(); + try { + BeginOp(B_PIC_SET_FORE_COLOR); + Write(color); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -116,9 +146,13 @@ status_t PictureDataWriter::WriteSetLowColor(const rgb_color &color) { - BeginOp(B_PIC_SET_BACK_COLOR); - Write(color); - EndOp(); + try { + BeginOp(B_PIC_SET_BACK_COLOR); + Write(color); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -126,9 +160,13 @@ status_t PictureDataWriter::WriteDrawRect(const BRect &rect, const bool &fill) { - BeginOp(fill ? B_PIC_FILL_RECT : B_PIC_STROKE_RECT); - Write(rect); - EndOp(); + try { + BeginOp(fill ? B_PIC_FILL_RECT : B_PIC_STROKE_RECT); + Write(rect); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -136,10 +174,14 @@ status_t PictureDataWriter::WriteDrawRoundRect(const BRect &rect, const BPoint &radius, const bool &fill) { - BeginOp(fill ? B_PIC_FILL_ROUND_RECT : B_PIC_STROKE_ROUND_RECT); - Write(rect); - Write(radius); - EndOp(); + try { + BeginOp(fill ? B_PIC_FILL_ROUND_RECT : B_PIC_STROKE_ROUND_RECT); + Write(rect); + Write(radius); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -147,9 +189,13 @@ status_t PictureDataWriter::WriteDrawEllipse(const BRect &rect, const bool &fill) { - BeginOp(fill ? B_PIC_FILL_ELLIPSE : B_PIC_STROKE_ELLIPSE); - Write(rect); - EndOp(); + try { + BeginOp(fill ? B_PIC_FILL_ELLIPSE : B_PIC_STROKE_ELLIPSE); + Write(rect); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -158,12 +204,16 @@ PictureDataWriter::WriteDrawArc(const BPoint ¢er, const BPoint &radius, const float &startTheta, const float &arcTheta, const bool &fill) { - BeginOp(fill ? B_PIC_FILL_ARC : B_PIC_STROKE_ARC); - Write(center); - Write(radius); - Write(startTheta); - Write(arcTheta); - EndOp(); + try { + BeginOp(fill ? B_PIC_FILL_ARC : B_PIC_STROKE_ARC); + Write(center); + Write(radius); + Write(startTheta); + Write(arcTheta); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -171,10 +221,14 @@ status_t PictureDataWriter::WriteStrokeLine(const BPoint &start, const BPoint &end) { - BeginOp(B_PIC_STROKE_LINE); - Write(start); - Write(end); - EndOp(); + try { + BeginOp(B_PIC_STROKE_LINE); + Write(start); + Write(end); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -183,17 +237,21 @@ PictureDataWriter::WriteDrawString(const BPoint &where, const char *string, const int32 &length, const escapement_delta &escapement) { - BeginOp(B_PIC_SET_PEN_LOCATION); - Write(where); - EndOp(); - - BeginOp(B_PIC_DRAW_STRING); - Write(escapement.space); - Write(escapement.nonspace); - //WriteData(string, length + 1); // TODO: is string 0 terminated? why is length given? - WriteData(string, length); - Write(0); - EndOp(); + try { + BeginOp(B_PIC_SET_PEN_LOCATION); + Write(where); + EndOp(); + + BeginOp(B_PIC_DRAW_STRING); + Write(escapement.space); + Write(escapement.nonspace); + //WriteData(string, length + 1); // TODO: is string 0 terminated? why is length given? + WriteData(string, length); + Write(0); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -203,12 +261,16 @@ PictureDataWriter::WriteDrawShape(const int32 &opCount, const void *opList, const int32 &ptCount, const void *ptList, const bool &fill) { - BeginOp(fill ? B_PIC_FILL_SHAPE : B_PIC_STROKE_SHAPE); - Write(opCount); - Write(ptCount); - WriteData(opList, opCount * sizeof(uint32)); - WriteData(ptList, ptCount * sizeof(BPoint)); - EndOp(); + try { + BeginOp(fill ? B_PIC_FILL_SHAPE : B_PIC_STROKE_SHAPE); + Write(opCount); + Write(ptCount); + WriteData(opList, opCount * sizeof(uint32)); + WriteData(ptList, ptCount * sizeof(BPoint)); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -221,16 +283,20 @@ { if (length != height * bytesPerRow) debugger("PictureDataWriter::WriteDrawBitmap: invalid length"); - BeginOp(B_PIC_DRAW_PIXELS); - Write(srcRect); - Write(dstRect); - Write(width); - Write(height); - Write(bytesPerRow); - Write(colorSpace); - Write(flags); - WriteData(data, length); - EndOp(); + try { + BeginOp(B_PIC_DRAW_PIXELS); + Write(srcRect); + Write(dstRect); + Write(width); + Write(height); + Write(bytesPerRow); + Write(colorSpace); + Write(flags); + WriteData(data, length); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -258,9 +324,13 @@ status_t PictureDataWriter::WriteSetFontSpacing(const int32 &spacing) { - BeginOp(B_PIC_SET_FONT_SPACING); - Write(spacing); - EndOp(); + try { + BeginOp(B_PIC_SET_FONT_SPACING); + Write(spacing); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -268,9 +338,13 @@ status_t PictureDataWriter::WriteSetFontSize(const float &size) { - BeginOp(B_PIC_SET_FONT_SIZE); - Write(size); - EndOp(); + try { + BeginOp(B_PIC_SET_FONT_SIZE); + Write(size); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -278,9 +352,13 @@ status_t PictureDataWriter::WriteSetFontRotation(const float &rotation) { - BeginOp(B_PIC_SET_FONT_ROTATE); - Write(rotation); - EndOp(); + try { + BeginOp(B_PIC_SET_FONT_ROTATE); + Write(rotation); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -288,9 +366,13 @@ status_t PictureDataWriter::WriteSetFontEncoding(const int32 &encoding) { - BeginOp(B_PIC_SET_FONT_ENCODING); - Write(encoding); - EndOp(); + try { + BeginOp(B_PIC_SET_FONT_ENCODING); + Write(encoding); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -298,9 +380,13 @@ status_t PictureDataWriter::WriteSetFontFlags(const int32 &flags) { - BeginOp(B_PIC_SET_FONT_FLAGS); - Write(flags); - EndOp(); + try { + BeginOp(B_PIC_SET_FONT_FLAGS); + Write(flags); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -308,9 +394,13 @@ status_t PictureDataWriter::WriteSetFontShear(const int32 &shear) { - BeginOp(B_PIC_SET_FONT_SHEAR); - Write(shear); - EndOp(); + try { + BeginOp(B_PIC_SET_FONT_SHEAR); + Write(shear); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -318,9 +408,13 @@ status_t PictureDataWriter::WriteSetFontFace(const int32 &face) { - BeginOp(B_PIC_SET_FONT_FACE); - Write(face); - EndOp(); + try { + BeginOp(B_PIC_SET_FONT_FACE); + Write(face); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -328,8 +422,12 @@ status_t PictureDataWriter::WritePushState() { - BeginOp(B_PIC_PUSH_STATE); - EndOp(); + try { + BeginOp(B_PIC_PUSH_STATE); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } @@ -337,29 +435,38 @@ status_t PictureDataWriter::WritePopState() { - BeginOp(B_PIC_POP_STATE); - EndOp(); + try { + BeginOp(B_PIC_POP_STATE); + EndOp(); + } catch (status_t &status) { + return status; + } return B_OK; } // private -status_t +void PictureDataWriter::BeginOp(const int16 &op) { + if (fData == NULL) + throw B_NO_INIT; + fStack.push(fData->Position()); fData->Write(&op, sizeof(op)); // Init the size of the opcode block to 0 size_t size = 0; fData->Write(&size, sizeof(size)); - return B_OK; } -status_t +void PictureDataWriter::EndOp() { + if (fData == NULL) + throw B_NO_INIT; + off_t curPos = fData->Position(); off_t stackPos = fStack.top(); fStack.pop(); @@ -374,12 +481,15 @@ fData->Seek(stackPos + sizeof(int16), SEEK_SET); fData->Write(&size, sizeof(size)); fData->Seek(curPos, SEEK_SET); - return B_OK; } -status_t +void PictureDataWriter::WriteData(const void *data, size_t size) { - return fData->Write(data, size); + ssize_t result = fData->Write(data, size); + if (result < 0) + throw (status_t)result; + if (result != size) + throw B_IO_ERROR; } From marcusoverhagen at arcor.de Sat May 12 13:28:15 2007 From: marcusoverhagen at arcor.de (Marcus Overhagen) Date: Sat, 12 May 2007 13:28:15 +0200 (CEST) Subject: [Haiku-commits] r21112 - in haiku/trunk: headers/private/interface In-Reply-To: <200705120846.l4C8kvUn010349@sheep.berlios.de> References: <200705120846.l4C8kvUn010349@sheep.berlios.de> Message-ID: <26378110.1178969295007.JavaMail.ngmail@webmail16> I don't think that throwing of a B_ERROR (int) can be caught with a catch (status_t) ----- Original Nachricht ---- Von: jackburton at BerliOS An: haiku-commits at lists.berlios.de Datum: 12.05.2007 10:46 Betreff: [Haiku-commits] r21112 - in haiku/trunk: headers/private/interface src/kits/interface > Author: jackburton > Date: 2007-05-12 10:46:56 +0200 (Sat, 12 May 2007) > New Revision: 21112 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21112&view=rev > > Modified: > haiku/trunk/headers/private/interface/PictureDataWriter.h > haiku/trunk/src/kits/interface/PictureDataWriter.cpp > Log: > Added error checking using exceptions > Viel oder wenig? Schnell oder langsam? Unbegrenzt surfen + telefonieren ohne Zeit- und Volumenbegrenzung? DAS TOP ANGEBOT JETZT bei Arcor: g?nstig und schnell mit DSL - das All-Inclusive-Paket f?r clevere Doppel-Sparer, nur 39,85 ? inkl. DSL- und ISDN-Grundgeb?hr! http://www.arcor.de/rd/emf-dsl-2 From bonefish at cs.tu-berlin.de Sat May 12 14:29:15 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Sat, 12 May 2007 14:29:15 +0200 Subject: [Haiku-commits] r21112 - in haiku/trunk: headers/private/interface In-Reply-To: <26378110.1178969295007.JavaMail.ngmail@webmail16> References: <200705120846.l4C8kvUn010349@sheep.berlios.de> <26378110.1178969295007.JavaMail.ngmail@webmail16> Message-ID: <20070512142915.1196.6@cs.tu-berlin.de> On 2007-05-12 at 13:28:15 [+0200], Marcus Overhagen wrote: > > I don't think that throwing of a B_ERROR (int) can be caught with a catch > (status_t) Yep. Best consequently use a macro like: #define THROW_ERROR(error) throw ((status_t)(error)) CU, Ingo From bonefish at cs.tu-berlin.de Sat May 12 14:31:29 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Sat, 12 May 2007 14:31:29 +0200 Subject: [Haiku-commits] r21112 - in haiku/trunk: headers/private/interface In-Reply-To: <20070512142915.1196.6@cs.tu-berlin.de> References: <200705120846.l4C8kvUn010349@sheep.berlios.de> <26378110.1178969295007.JavaMail.ngmail@webmail16> <20070512142915.1196.6@cs.tu-berlin.de> Message-ID: <20070512143129.1267.7@cs.tu-berlin.de> On 2007-05-12 at 14:29:15 [+0200], Ingo Weinhold wrote: > > On 2007-05-12 at 13:28:15 [+0200], Marcus Overhagen > wrote: > > > > I don't think that throwing of a B_ERROR (int) can be caught with a catch > > (status_t) > > Yep. Best consequently use a macro like: > > #define THROW_ERROR(error) throw ((status_t)(error)) Oh, I forgot to add: I think the Tracker sources have the same problem. CU, Ingo From korli at mail.berlios.de Sat May 12 15:37:03 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Sat, 12 May 2007 15:37:03 +0200 Subject: [Haiku-commits] r21113 - haiku/trunk/src/apps/installer Message-ID: <200705121337.l4CDb3wt013891@sheep.berlios.de> Author: korli Date: 2007-05-12 15:37:02 +0200 (Sat, 12 May 2007) New Revision: 21113 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21113&view=rev Modified: haiku/trunk/src/apps/installer/CopyEngine.cpp haiku/trunk/src/apps/installer/CopyEngine.h haiku/trunk/src/apps/installer/DrawButton.cpp haiku/trunk/src/apps/installer/DrawButton.h haiku/trunk/src/apps/installer/InstallerApp.cpp haiku/trunk/src/apps/installer/InstallerApp.h haiku/trunk/src/apps/installer/InstallerCopyLoopControl.cpp haiku/trunk/src/apps/installer/InstallerCopyLoopControl.h haiku/trunk/src/apps/installer/InstallerWindow.cpp haiku/trunk/src/apps/installer/InstallerWindow.h haiku/trunk/src/apps/installer/PackageViews.cpp haiku/trunk/src/apps/installer/PackageViews.h haiku/trunk/src/apps/installer/PartitionMenuItem.cpp haiku/trunk/src/apps/installer/PartitionMenuItem.h Log: code style update now mount the target partition before copying Modified: haiku/trunk/src/apps/installer/CopyEngine.cpp =================================================================== --- haiku/trunk/src/apps/installer/CopyEngine.cpp 2007-05-12 08:46:56 UTC (rev 21112) +++ haiku/trunk/src/apps/installer/CopyEngine.cpp 2007-05-12 13:37:02 UTC (rev 21113) @@ -16,37 +16,41 @@ #include #include -//#define COPY_TRACE +#define COPY_TRACE #ifdef COPY_TRACE #define CALLED() printf("CALLED %s\n",__PRETTY_FUNCTION__) +#define ERR2(x, y...) fprintf(stderr, "CopyEngine: "x" %s\n", y, strerror(err)) +#define ERR(x) fprintf(stderr, "CopyEngine: "x" %s\n", strerror(err)) #else #define CALLED() +#define ERR(x) +#define ERR2(x, y...) #endif const char BOOT_PATH[] = "/boot"; extern void SizeAsString(off_t size, char *string); -class SourceVisitor : public BDiskDeviceVisitor +class SourceVisitor : public BDiskDeviceVisitor { -public: - SourceVisitor(BMenu *menu); - virtual bool Visit(BDiskDevice *device); - virtual bool Visit(BPartition *partition, int32 level); -private: - BMenu *fMenu; + public: + SourceVisitor(BMenu *menu); + virtual bool Visit(BDiskDevice *device); + virtual bool Visit(BPartition *partition, int32 level); + private: + BMenu *fMenu; }; class TargetVisitor : public BDiskDeviceVisitor { -public: - TargetVisitor(BMenu *menu); - virtual bool Visit(BDiskDevice *device); - virtual bool Visit(BPartition *partition, int32 level); -private: - void MakeLabel(BPartition *partition, char *label, char *menuLabel); - BMenu *fMenu; + public: + TargetVisitor(BMenu *menu); + virtual bool Visit(BDiskDevice *device); + virtual bool Visit(BPartition *partition, int32 level); + private: + void MakeLabel(BPartition *partition, char *label, char *menuLabel); + BMenu *fMenu; }; @@ -67,7 +71,9 @@ CALLED(); switch (msg->what) { case ENGINE_START: - Start(fWindow->GetSourceMenu(), fWindow->GetTargetMenu()); + status_t err = Start(fWindow->GetSourceMenu(), fWindow->GetTargetMenu()); + if (err != B_OK) + ERR("Start failed"); break; } } @@ -91,7 +97,7 @@ command += bootPath.Path(); command += "/InstallerInitScript "; command += path.Path(); - SetStatusMessage("Starting Installation."); + SetStatusMessage("Starting Installation."); system(command.String()); } @@ -105,22 +111,23 @@ command += bootPath.Path(); command += "/InstallerFinishScript "; command += path.Path(); - SetStatusMessage("Finishing Installation."); + SetStatusMessage("Finishing Installation."); system(command.String()); } -void +status_t CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu) { CALLED(); + status_t err = B_OK; PartitionMenuItem *targetItem = (PartitionMenuItem *)targetMenu->FindMarked(); PartitionMenuItem *srcItem = (PartitionMenuItem *)srcMenu->FindMarked(); if (!srcItem || !targetItem) { - fprintf(stderr, "bad menu items\n"); - return; + ERR("bad menu items\n"); + return B_BAD_VALUE; } - + // check if target is initialized // ask if init or mount as is @@ -130,49 +137,75 @@ BVolume targetVolume; if (fDDRoster.GetPartitionWithID(targetItem->ID(), &device, &partition) == B_OK) { - if (partition->GetVolume(&targetVolume)!=B_OK) - return; - if (partition->GetMountPoint(&targetDirectory)!=B_OK) - return; + if (!partition->IsMounted()) { + if ((err = partition->Mount()) < B_OK) { + SetStatusMessage("The disk can't be mounted. Please choose a different disk."); + ERR("BPartition::Mount"); + return err; + } + } + if ((err = partition->GetVolume(&targetVolume)) != B_OK) { + ERR("BPartition::GetVolume"); + return err; + } + if ((err = partition->GetMountPoint(&targetDirectory)) != B_OK) { + ERR("BPartition::GetMountPoint"); + return err; + } } else if (fDDRoster.GetDeviceWithID(targetItem->ID(), &device) == B_OK) { - if (device.GetVolume(&targetVolume)!=B_OK) - return; - if (device.GetMountPoint(&targetDirectory)!=B_OK) - return; - } else - return; // shouldn't happen + if (!device.IsMounted()) { + if ((err = device.Mount()) < B_OK) { + SetStatusMessage("The disk can't be mounted. Please choose a different disk."); + ERR("BDiskDevice::Mount"); + return err; + } + } + if ((err = device.GetVolume(&targetVolume)) != B_OK) { + ERR("BDiskDevice::GetVolume"); + return err; + } + if ((err = device.GetMountPoint(&targetDirectory)) != B_OK) { + ERR("BDiskDevice::GetMountPoint"); + return err; + } + } else + return B_ERROR; // shouldn't happen // check if target has enough space - if ((fSpaceRequired > 0 && targetVolume.FreeBytes() < fSpaceRequired) + if ((fSpaceRequired > 0 && targetVolume.FreeBytes() < fSpaceRequired) && ((new BAlert("", "The destination disk may not have enough space. Try choosing a different disk or \ choose to not install optional items.", "Try installing anyway", "Cancel", 0, - B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) { - return; + B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) { + return B_OK; } BPath srcDirectory; - if (fDDRoster.GetPartitionWithID(srcItem->ID(), &device, &partition) == B_OK) { - if (partition->GetMountPoint(&srcDirectory)!=B_OK) - return; - } else if (fDDRoster.GetDeviceWithID(srcItem->ID(), &device) == B_OK) { - if (device.GetMountPoint(&srcDirectory)!=B_OK) - return; - } else - return; // shouldn't happen - + if (fDDRoster.GetPartitionWithID(srcItem->ID(), &device, &partition) == B_OK) { + if ((err = partition->GetMountPoint(&srcDirectory)) != B_OK) { + ERR("BPartition::GetMountPoint"); + return err; + } + } else if (fDDRoster.GetDeviceWithID(srcItem->ID(), &device) == B_OK) { + if ((err = device.GetMountPoint(&srcDirectory)) != B_OK) { + ERR("BDiskDevice::GetMountPoint"); + return err; + } + } else + return B_ERROR; // shouldn't happen + // check not installing on itself if (strcmp(srcDirectory.Path(), targetDirectory.Path()) == 0) { SetStatusMessage("You can't install the contents of a disk onto itself. Please choose a different disk."); - return; + return B_OK; } - + // check not installing on boot volume - if ((strncmp(BOOT_PATH, targetDirectory.Path(), strlen(BOOT_PATH)) == 0) + if ((strncmp(BOOT_PATH, targetDirectory.Path(), strlen(BOOT_PATH)) == 0) && ((new BAlert("", "Are you sure you want to install onto the current boot disk? \ The installer will have to reboot your machine if you proceed.", "OK", "Cancel", 0, - B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) { + B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) { SetStatusMessage("Installation stopped."); - return; + return B_OK; } LaunchInitScript(targetDirectory); @@ -188,7 +221,7 @@ srcDir.SetTo(srcDirectory.Path()); BDirectory packageDir; int32 count = fPackages->CountItems(); - for (int32 i=0; i(fPackages->ItemAt(i)); packageDir.SetTo(&srcDir, p->Folder()); CopyFolder(packageDir, targetDir); @@ -206,7 +239,7 @@ CopyEngine::CopyFolder(BDirectory &srcDir, BDirectory &targetDir) { BEntry entry; - status_t status; + status_t err; while (srcDir.GetNextEntry(&entry) == B_OK) { char name[B_FILE_NAME_LENGTH]; entry.GetName(name); @@ -214,11 +247,11 @@ continue; Undo undo; - status = FSCopyFolder(&entry, &targetDir, fControl, NULL, false, undo); - if (status != B_OK) { + err = FSCopyFolder(&entry, &targetDir, fControl, NULL, false, undo); + if (err != B_OK) { BPath path; entry.GetPath(&path); - fprintf(stderr, "error while copying %s : %s\n", path.Path(), strerror(status)); + ERR2("error while copying %s", path.Path()); } } } @@ -257,17 +290,17 @@ bool SourceVisitor::Visit(BDiskDevice *device) { - if (!device->ContentType() || strcmp(device->ContentType(), kPartitionTypeBFS)!=0) + if (!device->ContentType() || strcmp(device->ContentType(), kPartitionTypeBFS) != 0) return false; BPath path; - if (device->GetPath(&path)==B_OK) - printf("SourceVisitor::Visit(BDiskDevice *) : %s type:%s, contentType:%s\n", + if (device->GetPath(&path) == B_OK) + printf("SourceVisitor::Visit(BDiskDevice *) : %s type:%s, contentType:%s\n", path.Path(), device->Type(), device->ContentType()); PartitionMenuItem *item = new PartitionMenuItem(NULL, device->ContentName(), NULL, new BMessage(SRC_PARTITION), device->ID()); if (device->IsMounted()) { BPath mountPoint; device->GetMountPoint(&mountPoint); - if (strcmp(BOOT_PATH, mountPoint.Path())==0) + if (strcmp(BOOT_PATH, mountPoint.Path()) == 0) item->SetMarked(true); } fMenu->AddItem(item); @@ -278,17 +311,17 @@ bool SourceVisitor::Visit(BPartition *partition, int32 level) { - if (!partition->ContentType() || strcmp(partition->ContentType(), kPartitionTypeBFS)!=0) + if (!partition->ContentType() || strcmp(partition->ContentType(), kPartitionTypeBFS) != 0) return false; BPath path; - if (partition->GetPath(&path)==B_OK) + if (partition->GetPath(&path) == B_OK) printf("SourceVisitor::Visit(BPartition *) : %s\n", path.Path()); printf("SourceVisitor::Visit(BPartition *) : %s\n", partition->Name()); PartitionMenuItem *item = new PartitionMenuItem(NULL, partition->ContentName(), NULL, new BMessage(SRC_PARTITION), partition->ID()); if (partition->IsMounted()) { BPath mountPoint; partition->GetMountPoint(&mountPoint); - if (strcmp(BOOT_PATH, mountPoint.Path())==0) + if (strcmp(BOOT_PATH, mountPoint.Path()) == 0) item->SetMarked(true); } fMenu->AddItem(item); @@ -308,7 +341,7 @@ if (device->IsReadOnly() || device->IsReadOnlyMedia()) return false; BPath path; - if (device->GetPath(&path)==B_OK) + if (device->GetPath(&path) == B_OK) printf("TargetVisitor::Visit(BDiskDevice *) : %s\n", path.Path()); char label[255], menuLabel[255]; MakeLabel(device, label, menuLabel); @@ -323,7 +356,7 @@ if (partition->IsReadOnly()) return false; BPath path; - if (partition->GetPath(&path)==B_OK) + if (partition->GetPath(&path) == B_OK) printf("TargetVisitor::Visit(BPartition *) : %s\n", path.Path()); printf("TargetVisitor::Visit(BPartition *) : %s\n", partition->Name()); char label[255], menuLabel[255]; @@ -341,9 +374,9 @@ BPath path; if (partition->Parent()) partition->Parent()->GetPath(&path); - + sprintf(label, "%s - %s [%s] [%s partition:%li]", partition->ContentName(), size, partition->ContentType(), - path.Path(), partition->ID()); + path.Path(), partition->ID()); sprintf(menuLabel, "%s - %s [%s]", partition->ContentName(), size, partition->ContentType()); } Modified: haiku/trunk/src/apps/installer/CopyEngine.h =================================================================== --- haiku/trunk/src/apps/installer/CopyEngine.h 2007-05-12 08:46:56 UTC (rev 21112) +++ haiku/trunk/src/apps/installer/CopyEngine.h 2007-05-12 13:37:02 UTC (rev 21113) @@ -20,24 +20,24 @@ const uint32 ENGINE_START = 'eSRT'; class CopyEngine : public BLooper { -public: - CopyEngine(InstallerWindow *window); - void MessageReceived(BMessage *msg); - void SetStatusMessage(char *status); - void Start(BMenu *srcMenu, BMenu *targetMenu); - void ScanDisksPartitions(BMenu *srcMenu, BMenu *targetMenu); - void SetPackagesList(BList *list); - void SetSpaceRequired(off_t bytes) { fSpaceRequired = bytes; }; -private: - void LaunchInitScript(BPath &path); - void LaunchFinishScript(BPath &path); - void CopyFolder(BDirectory &srcDir, BDirectory &targetDir); - - InstallerWindow *fWindow; - BDiskDeviceRoster fDDRoster; - InstallerCopyLoopControl *fControl; - BList *fPackages; - off_t fSpaceRequired; + public: + CopyEngine(InstallerWindow *window); + void MessageReceived(BMessage *msg); + void SetStatusMessage(char *status); + status_t Start(BMenu *srcMenu, BMenu *targetMenu); + void ScanDisksPartitions(BMenu *srcMenu, BMenu *targetMenu); + void SetPackagesList(BList *list); + void SetSpaceRequired(off_t bytes) { fSpaceRequired = bytes; }; + private: + void LaunchInitScript(BPath &path); + void LaunchFinishScript(BPath &path); + void CopyFolder(BDirectory &srcDir, BDirectory &targetDir); + + InstallerWindow *fWindow; + BDiskDeviceRoster fDDRoster; + InstallerCopyLoopControl *fControl; + BList *fPackages; + off_t fSpaceRequired; }; #endif /* _CopyEngine_h */ Modified: haiku/trunk/src/apps/installer/DrawButton.cpp =================================================================== --- haiku/trunk/src/apps/installer/DrawButton.cpp 2007-05-12 08:46:56 UTC (rev 21112) +++ haiku/trunk/src/apps/installer/DrawButton.cpp 2007-05-12 13:37:02 UTC (rev 21113) @@ -9,7 +9,7 @@ #include "DrawButton.h" DrawButton::DrawButton(BRect frame, const char *name, const char *labelOn, const char* labelOff, - BMessage *msg, int32 resize, int32 flags) + BMessage *msg, int32 resize, int32 flags) : PaneSwitch(frame, name, "", resize, flags) { fLabelOn = strdup(labelOn); @@ -28,7 +28,7 @@ void DrawButton::Draw(BRect update) { - BPoint point(18,9); + BPoint point(18, 9); if (Value()) { DrawString(fLabelOn, point); } else { Modified: haiku/trunk/src/apps/installer/DrawButton.h =================================================================== --- haiku/trunk/src/apps/installer/DrawButton.h 2007-05-12 08:46:56 UTC (rev 21112) +++ haiku/trunk/src/apps/installer/DrawButton.h 2007-05-12 13:37:02 UTC (rev 21113) @@ -12,15 +12,15 @@ class DrawButton : public PaneSwitch { -public: - DrawButton(BRect frame, const char *name, const char *labelOn, const char* labelOff, - BMessage *msg, int32 resize = B_FOLLOW_LEFT|B_FOLLOW_TOP, - int32 flags = B_WILL_DRAW | B_NAVIGABLE); - ~DrawButton(void); - - void Draw(BRect update); -private: - char* fLabelOn, *fLabelOff; + public: + DrawButton(BRect frame, const char *name, const char *labelOn, const char* labelOff, + BMessage *msg, int32 resize = B_FOLLOW_LEFT | B_FOLLOW_TOP, + int32 flags = B_WILL_DRAW | B_NAVIGABLE); + ~DrawButton(void); + + void Draw(BRect update); + private: + char *fLabelOn, *fLabelOff; }; #endif Modified: haiku/trunk/src/apps/installer/InstallerApp.cpp =================================================================== --- haiku/trunk/src/apps/installer/InstallerApp.cpp 2007-05-12 08:46:56 UTC (rev 21112) +++ haiku/trunk/src/apps/installer/InstallerApp.cpp 2007-05-12 13:37:02 UTC (rev 21113) @@ -28,30 +28,30 @@ InstallerApp::InstallerApp() : BApplication(APP_SIG) { - BRect windowFrame(0,0,INSTALLER_RIGHT, 160); + BRect windowFrame(0, 0, INSTALLER_RIGHT, 160); BRect frame = BScreen().Frame(); - windowFrame.OffsetBy((frame.Width() - windowFrame.Width())/2, - frame.Height()/2 - windowFrame.Height()/4 - 113); + windowFrame.OffsetBy((frame.Width() - windowFrame.Width()) / 2, + frame.Height() / 2 - windowFrame.Height() / 4 - 113); fWindow = new InstallerWindow(windowFrame); // show the EULA BAlert *alert = new BAlert("", EULA_TEXT, " Disagree ", " Agree ", NULL, - B_WIDTH_FROM_WIDEST, B_EMPTY_ALERT); + B_WIDTH_FROM_WIDEST, B_EMPTY_ALERT); BTextView *alertView = alert->TextView(); - alertView->SetViewColor(255,255,255); + alertView->SetViewColor(255, 255, 255); BView *parent = alertView->Parent(); alertView->RemoveSelf(); - alertView->MoveBy(3,7); - alertView->ResizeTo(460,283); + alertView->MoveBy(3, 7); + alertView->ResizeTo(460, 283); alertView->SetResizingMode(B_FOLLOW_ALL_SIDES); - alert->ResizeTo(500,350); + alert->ResizeTo(500, 350); BScrollView *scroll = new BScrollView("", alertView, B_FOLLOW_ALL_SIDES, B_FRAME_EVENTS, false, true, B_FANCY_BORDER); parent->AddChild(scroll); BRect alertFrame = alert->Frame(); - alertFrame.OffsetTo((frame.Width() - alertFrame.Width())/2, - (frame.Height() - alertFrame.Height())/2); + alertFrame.OffsetTo((frame.Width() - alertFrame.Width()) / 2, + (frame.Height() - alertFrame.Height()) / 2); alert->MoveTo(alertFrame.LeftTop()); - if (alert->Go()!=1) + if (alert->Go() != 1) PostMessage(B_QUIT_REQUESTED); } @@ -68,7 +68,7 @@ view->GetFont(&font); font.SetSize(18); - font.SetFace(B_BOLD_FACE); + font.SetFace(B_BOLD_FACE); view->SetFontAndColor(0, 14, &font); alert->Go(); @@ -79,6 +79,6 @@ void InstallerApp::ReadyToRun() { - + } Modified: haiku/trunk/src/apps/installer/InstallerApp.h =================================================================== --- haiku/trunk/src/apps/installer/InstallerApp.h 2007-05-12 08:46:56 UTC (rev 21112) +++ haiku/trunk/src/apps/installer/InstallerApp.h 2007-05-12 13:37:02 UTC (rev 21113) @@ -10,15 +10,15 @@ #include "InstallerWindow.h" class InstallerApp : public BApplication { -public: - InstallerApp(); + public: + InstallerApp(); -public: - virtual void AboutRequested(); - virtual void ReadyToRun(); - -private: - InstallerWindow *fWindow; + public: + virtual void AboutRequested(); + virtual void ReadyToRun(); + + private: + InstallerWindow *fWindow; }; #endif /* _InstallerApp_h */ Modified: haiku/trunk/src/apps/installer/InstallerCopyLoopControl.cpp =================================================================== --- haiku/trunk/src/apps/installer/InstallerCopyLoopControl.cpp 2007-05-12 08:46:56 UTC (rev 21112) +++ haiku/trunk/src/apps/installer/InstallerCopyLoopControl.cpp 2007-05-12 13:37:02 UTC (rev 21113) @@ -14,9 +14,9 @@ } -bool +bool InstallerCopyLoopControl::FileError(const char *message, const char *name, status_t error, - bool allowContinue) + bool allowContinue) { char buffer[512]; sprintf(buffer, message, name, strerror(error)); @@ -29,11 +29,11 @@ B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go(); return false; } - -void -InstallerCopyLoopControl::UpdateStatus(const char *name, entry_ref ref, int32 count, - bool optional) + +void +InstallerCopyLoopControl::UpdateStatus(const char *name, entry_ref ref, int32 count, + bool optional) { if (name) { BMessage msg(STATUS_MESSAGE); @@ -45,17 +45,17 @@ } -bool +bool InstallerCopyLoopControl::CheckUserCanceled() { return false; } -InstallerCopyLoopControl::OverwriteMode -InstallerCopyLoopControl::OverwriteOnConflict(const BEntry *srcEntry, - const char *destName, const BDirectory *destDir, bool srcIsDir, - bool dstIsDir) +InstallerCopyLoopControl::OverwriteMode +InstallerCopyLoopControl::OverwriteOnConflict(const BEntry *srcEntry, + const char *destName, const BDirectory *destDir, bool srcIsDir, + bool dstIsDir) { if (srcIsDir && dstIsDir) return kMerge; @@ -64,34 +64,34 @@ } -bool +bool InstallerCopyLoopControl::SkipEntry(const BEntry *, bool file) { return false; } -void +void InstallerCopyLoopControl::ChecksumChunk(const char *block, size_t size) { } -bool +bool InstallerCopyLoopControl::ChecksumFile(const entry_ref *ref) { return true; } -bool +bool InstallerCopyLoopControl::SkipAttribute(const char *attributeName) { return false; } -bool +bool InstallerCopyLoopControl::PreserveAttribute(const char *attributeName) { return false; Modified: haiku/trunk/src/apps/installer/InstallerCopyLoopControl.h =================================================================== --- haiku/trunk/src/apps/installer/InstallerCopyLoopControl.h 2007-05-12 08:46:56 UTC (rev 21112) +++ haiku/trunk/src/apps/installer/InstallerCopyLoopControl.h 2007-05-12 13:37:02 UTC (rev 21113) @@ -13,32 +13,32 @@ class InstallerCopyLoopControl : public CopyLoopControl { -public: + public: InstallerCopyLoopControl(InstallerWindow *window); virtual ~InstallerCopyLoopControl() {}; - + virtual bool FileError(const char *message, const char *name, status_t error, bool allowContinue); - virtual void UpdateStatus(const char *name, entry_ref ref, int32 count, + virtual void UpdateStatus(const char *name, entry_ref ref, int32 count, bool optional = false); virtual bool CheckUserCanceled(); - virtual OverwriteMode OverwriteOnConflict(const BEntry *srcEntry, - const char *destName, const BDirectory *destDir, bool srcIsDir, + virtual OverwriteMode OverwriteOnConflict(const BEntry *srcEntry, + const char *destName, const BDirectory *destDir, bool srcIsDir, bool dstIsDir); virtual bool SkipEntry(const BEntry *, bool file); - + virtual void ChecksumChunk(const char *block, size_t size); virtual bool ChecksumFile(const entry_ref *); virtual bool SkipAttribute(const char *attributeName); virtual bool PreserveAttribute(const char *attributeName); - -private: - InstallerWindow *fWindow; - BMessenger fMessenger; + + private: + InstallerWindow *fWindow; + BMessenger fMessenger; }; #endif Modified: haiku/trunk/src/apps/installer/InstallerWindow.cpp =================================================================== --- haiku/trunk/src/apps/installer/InstallerWindow.cpp 2007-05-12 08:46:56 UTC (rev 21112) +++ haiku/trunk/src/apps/installer/InstallerWindow.cpp 2007-05-12 13:37:02 UTC (rev 21113) @@ -28,8 +28,8 @@ class LogoView : public BBox { public: - LogoView(const BRect &r); - ~LogoView(void); + LogoView(const BRect &r); + ~LogoView(void); virtual void Draw(BRect update); private: BBitmap *fLogo; @@ -38,7 +38,7 @@ LogoView::LogoView(const BRect &r) - : BBox(r, "logoview", B_FOLLOW_LEFT|B_FOLLOW_TOP, B_WILL_DRAW, B_NO_BORDER) + : BBox(r, "logoview", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW, B_NO_BORDER) { fLogo = BTranslationUtils::GetBitmap('PNG ', "haikulogo.png"); if (fLogo) { @@ -69,13 +69,13 @@ fLastTargetItem(NULL) { fCopyEngine = new CopyEngine(this); - + BRect bounds = Bounds(); bounds.bottom += 1; bounds.right += 1; fBackBox = new BBox(bounds, NULL, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER); AddChild(fBackBox); - + BRect logoRect = fBackBox->Bounds(); logoRect.left += 1; logoRect.top = 12; @@ -84,53 +84,53 @@ LogoView *logoView = new LogoView(logoRect); fBackBox->AddChild(logoView); - BRect statusRect(bounds.right-222, logoRect.top+2, bounds.right-14, logoRect.bottom - B_H_SCROLL_BAR_HEIGHT+4); + BRect statusRect(bounds.right - 222, logoRect.top + 2, bounds.right - 14, logoRect.bottom - B_H_SCROLL_BAR_HEIGHT + 4); BRect textRect(statusRect); textRect.OffsetTo(B_ORIGIN); - textRect.InsetBy(2,2); + textRect.InsetBy(2, 2); fStatusView = new BTextView(statusRect, "statusView", textRect, be_plain_font, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); fStatusView->MakeEditable(false); fStatusView->MakeSelectable(false); - - BScrollView *scroll = new BScrollView("statusScroll", fStatusView, B_FOLLOW_LEFT|B_FOLLOW_TOP, B_WILL_DRAW|B_FRAME_EVENTS); - fBackBox->AddChild(scroll); - fBeginButton = new BButton(BRect(bounds.right-90, bounds.bottom-35, bounds.right-11, bounds.bottom-11), + BScrollView *scroll = new BScrollView("statusScroll", fStatusView, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_FRAME_EVENTS); + fBackBox->AddChild(scroll); + + fBeginButton = new BButton(BRect(bounds.right - 90, bounds.bottom - 35, bounds.right - 11, bounds.bottom - 11), "begin_button", "Begin", new BMessage(BEGIN_MESSAGE), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); fBeginButton->MakeDefault(true); fBackBox->AddChild(fBeginButton); - fSetupButton = new BButton(BRect(bounds.left+11, bounds.bottom-35, - bounds.left + be_plain_font->StringWidth("Setup partitions") + 36, bounds.bottom-22), - "setup_button", "Setup partitions" B_UTF8_ELLIPSIS, new BMessage(SETUP_MESSAGE), B_FOLLOW_LEFT|B_FOLLOW_BOTTOM); + fSetupButton = new BButton(BRect(bounds.left + 11, bounds.bottom - 35, + bounds.left + be_plain_font->StringWidth("Setup partitions") + 36, bounds.bottom - 22), + "setup_button", "Setup partitions" B_UTF8_ELLIPSIS, new BMessage(SETUP_MESSAGE), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); fBackBox->AddChild(fSetupButton); fSetupButton->Hide(); - fPackagesView = new PackagesView(BRect(bounds.left+12, bounds.top+4, bounds.right-15-B_V_SCROLL_BAR_WIDTH, bounds.bottom-61), "packages_view"); + fPackagesView = new PackagesView(BRect(bounds.left + 12, bounds.top + 4, bounds.right - 15 - B_V_SCROLL_BAR_WIDTH, bounds.bottom - 61), "packages_view"); fPackagesScrollView = new BScrollView("packagesScroll", fPackagesView, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW, false, true); fBackBox->AddChild(fPackagesScrollView); fPackagesScrollView->Hide(); - fDrawButton = new DrawButton(BRect(bounds.left+12, bounds.bottom-33, bounds.left+120, bounds.bottom-20), + fDrawButton = new DrawButton(BRect(bounds.left + 12, bounds.bottom - 33, bounds.left + 120, bounds.bottom - 20), "options_button", "Fewer options", "More options", new BMessage(SHOW_BOTTOM_MESSAGE)); fBackBox->AddChild(fDrawButton); fDestMenu = new BPopUpMenu("scanning" B_UTF8_ELLIPSIS, true, false); fSrcMenu = new BPopUpMenu("scanning" B_UTF8_ELLIPSIS, true, false); - BRect fieldRect(bounds.left+50, bounds.top+70, bounds.right-13, bounds.top+90); + BRect fieldRect(bounds.left + 50, bounds.top + 70, bounds.right - 13, bounds.top + 90); fSrcMenuField = new BMenuField(fieldRect, "srcMenuField", - "Install from: ", fSrcMenu); - fSrcMenuField->SetDivider(bounds.right-274); + "Install from: ", fSrcMenu); + fSrcMenuField->SetDivider(bounds.right - 274); fSrcMenuField->SetAlignment(B_ALIGN_RIGHT); fBackBox->AddChild(fSrcMenuField); - fieldRect.OffsetBy(0,23); + fieldRect.OffsetBy(0, 23); fDestMenuField = new BMenuField(fieldRect, "destMenuField", "Onto: ", fDestMenu); - fDestMenuField->SetDivider(bounds.right-274); + fDestMenuField->SetDivider(bounds.right - 274); fDestMenuField->SetAlignment(B_ALIGN_RIGHT); fBackBox->AddChild(fDestMenuField); @@ -149,7 +149,7 @@ fDriveSetupLaunched = be_roster->IsRunning(DRIVESETUP_SIG); be_roster->StartWatching(this); - + PostMessage(START_SCAN); } @@ -166,7 +166,7 @@ case START_SCAN: StartScan(); break; - case BEGIN_MESSAGE: + case BEGIN_MESSAGE: { BList *list = new BList(); int32 size = 0; @@ -219,17 +219,17 @@ case B_SOME_APP_QUIT: { const char *signature; - if (msg->FindString("be:signature", &signature)==B_OK - && strcasecmp(signature, DRIVESETUP_SIG)==0) { + if (msg->FindString("be:signature", &signature) == B_OK + && strcasecmp(signature, DRIVESETUP_SIG) == 0) { fDriveSetupLaunched = msg->what == B_SOME_APP_LAUNCHED; DisableInterface(fDriveSetupLaunched); if (fDriveSetupLaunched) SetStatusMessage("Running DriveSetup" B_UTF8_ELLIPSIS "\nClose DriveSetup to continue with the\ninstallation."); else StartScan(); - } - break; - } + } + break; + } default: BWindow::MessageReceived(msg); break; @@ -240,7 +240,7 @@ InstallerWindow::QuitRequested() { if (fDriveSetupLaunched) { - (new BAlert("driveSetup", + (new BAlert("driveSetup", "Please close the DriveSetup window before closing the\nInstaller window.", "OK"))->Go(); return false; } @@ -250,7 +250,7 @@ } -void +void InstallerWindow::ShowBottom() { if (fDrawButton->Value()) { @@ -276,7 +276,7 @@ void InstallerWindow::LaunchDriveSetup() { - if (be_roster->Launch(DRIVESETUP_SIG)!=B_OK) + if (be_roster->Launch(DRIVESETUP_SIG) != B_OK) fprintf(stderr, "There was an error while launching DriveSetup\n"); } @@ -324,7 +324,7 @@ else fSrcMenuField->MenuItem()->SetLabel(((PartitionMenuItem *)fSrcMenu->ItemAt(0))->MenuLabel()); } - + PartitionMenuItem *item2 = (PartitionMenuItem *)fDestMenu->FindMarked(); if (item2) { fDestMenuField->MenuItem()->SetLabel(item2->MenuLabel()); @@ -335,7 +335,7 @@ fDestMenuField->MenuItem()->SetLabel(((PartitionMenuItem *)fDestMenu->ItemAt(0))->MenuLabel()); } char message[255]; - sprintf(message, "Press the Begin button to install from '%s' onto '%s'", + sprintf(message, "Press the Begin button to install from '%s' onto '%s'", item1 ? item1->Name() : "null", item2 ? item2->Name() : "null"); SetStatusMessage(message); } @@ -355,25 +355,25 @@ BDiskDevice device; BPartition *partition; if (roster.GetPartitionWithID(item->ID(), &device, &partition) == B_OK) { - if (partition->GetMountPoint(&directory)!=B_OK) + if (partition->GetMountPoint(&directory) != B_OK) return; } else if (roster.GetDeviceWithID(item->ID(), &device) == B_OK) { - if (device.GetMountPoint(&directory)!=B_OK) + if (device.GetMountPoint(&directory) != B_OK) return; - } else + } else return; // shouldn't happen #else BPath directory = "/BeOS 5 PE Max Edition V3.1 beta"; #endif - + directory.Append(PACKAGES_DIRECTORY); BDirectory dir(directory.Path()); - if (dir.InitCheck()!=B_OK) + if (dir.InitCheck() != B_OK) return; BEntry packageEntry; BList packages; - while (dir.GetNextEntry(&packageEntry)==B_OK) { + while (dir.GetNextEntry(&packageEntry) == B_OK) { Package *package = Package::PackageFromEntry(packageEntry); if (package) { packages.AddItem(package); @@ -382,11 +382,11 @@ packages.SortItems(ComparePackages); fPackagesView->AddPackages(packages, new BMessage(PACKAGE_CHECKBOX)); - PostMessage(PACKAGE_CHECKBOX); + PostMessage(PACKAGE_CHECKBOX); } -int +int InstallerWindow::ComparePackages(const void *firstArg, const void *secondArg) { const Group *group1 = *static_cast(firstArg); Modified: haiku/trunk/src/apps/installer/InstallerWindow.h =================================================================== --- haiku/trunk/src/apps/installer/InstallerWindow.h 2007-05-12 08:46:56 UTC (rev 21112) +++ haiku/trunk/src/apps/installer/InstallerWindow.h 2007-05-12 13:37:02 UTC (rev 21113) @@ -25,39 +25,39 @@ const char PACKAGES_DIRECTORY[] = "_packages_"; class InstallerWindow : public BWindow { -public: - InstallerWindow(BRect frameRect); - virtual ~InstallerWindow(); + public: + InstallerWindow(BRect frameRect); + virtual ~InstallerWindow(); - virtual void MessageReceived(BMessage *msg); - virtual bool QuitRequested(); - BMenu *GetSourceMenu() { return fSrcMenu; }; - BMenu *GetTargetMenu() { return fDestMenu; }; -private: - void DisableInterface(bool disable); - void LaunchDriveSetup(); - void PublishPackages(); - void ShowBottom(); - void StartScan(); - void AdjustMenus(); - void SetStatusMessage(const char *text); - static int ComparePackages(const void *firstArg, const void *secondArg); - BBox *fBackBox; - BButton *fBeginButton, *fSetupButton; - DrawButton *fDrawButton; - bool fDriveSetupLaunched; - BTextView *fStatusView; - BMenu* fSrcMenu, *fDestMenu; - BMenuField* fSrcMenuField, *fDestMenuField; - PackagesView *fPackagesView; - BScrollView *fPackagesScrollView; - BStringView *fSizeView; + virtual void MessageReceived(BMessage *msg); + virtual bool QuitRequested(); + BMenu *GetSourceMenu() { return fSrcMenu; }; + BMenu *GetTargetMenu() { return fDestMenu; }; + private: + void DisableInterface(bool disable); + void LaunchDriveSetup(); + void PublishPackages(); + void ShowBottom(); + void StartScan(); + void AdjustMenus(); + void SetStatusMessage(const char *text); + static int ComparePackages(const void *firstArg, const void *secondArg); + BBox *fBackBox; + BButton *fBeginButton, *fSetupButton; + DrawButton *fDrawButton; + bool fDriveSetupLaunched; + BTextView *fStatusView; + BMenu* fSrcMenu, *fDestMenu; + BMenuField* fSrcMenuField, *fDestMenuField; + PackagesView *fPackagesView; + BScrollView *fPackagesScrollView; + BStringView *fSizeView; - BBitmap *fLogo; - BPoint fDrawPoint; - CopyEngine *fCopyEngine; - BString fLastStatus; - BMenuItem *fLastSrcItem, *fLastTargetItem; + BBitmap *fLogo; + BPoint fDrawPoint; + CopyEngine *fCopyEngine; + BString fLastStatus; + BMenuItem *fLastSrcItem, *fLastTargetItem; }; #endif /* _InstallerWindow_h */ Modified: haiku/trunk/src/apps/installer/PackageViews.cpp =================================================================== --- haiku/trunk/src/apps/installer/PackageViews.cpp 2007-05-12 08:46:56 UTC (rev 21112) +++ haiku/trunk/src/apps/installer/PackageViews.cpp 2007-05-12 13:37:02 UTC (rev 21113) @@ -56,7 +56,7 @@ Package::~Package() { - delete fIcon; + delete fIcon; } @@ -66,7 +66,7 @@ char folder[B_FILE_NAME_LENGTH]; entry.GetName(folder); BDirectory directory(&entry); - if (directory.InitCheck()!=B_OK) + if (directory.InitCheck() != B_OK) return NULL; Package *package = new Package(folder); bool alwaysOn; @@ -74,17 +74,17 @@ [... truncated: 268 lines follow ...] From korli at mail.berlios.de Sat May 12 15:40:08 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Sat, 12 May 2007 15:40:08 +0200 Subject: [Haiku-commits] r21114 - haiku/trunk/src/apps/installer Message-ID: <200705121340.l4CDe8t0014093@sheep.berlios.de> Author: korli Date: 2007-05-12 15:40:07 +0200 (Sat, 12 May 2007) New Revision: 21114 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21114&view=rev Modified: haiku/trunk/src/apps/installer/CopyEngine.cpp Log: trace was enabled Modified: haiku/trunk/src/apps/installer/CopyEngine.cpp =================================================================== --- haiku/trunk/src/apps/installer/CopyEngine.cpp 2007-05-12 13:37:02 UTC (rev 21113) +++ haiku/trunk/src/apps/installer/CopyEngine.cpp 2007-05-12 13:40:07 UTC (rev 21114) @@ -16,7 +16,7 @@ #include #include -#define COPY_TRACE +//#define COPY_TRACE #ifdef COPY_TRACE #define CALLED() printf("CALLED %s\n",__PRETTY_FUNCTION__) #define ERR2(x, y...) fprintf(stderr, "CopyEngine: "x" %s\n", y, strerror(err)) From bonefish at mail.berlios.de Sat May 12 17:43:04 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 12 May 2007 17:43:04 +0200 Subject: [Haiku-commits] r21115 - haiku/trunk/src/tests/kits/interface/layout Message-ID: <200705121543.l4CFh4Kx028268@sheep.berlios.de> Author: bonefish Date: 2007-05-12 17:43:04 +0200 (Sat, 12 May 2007) New Revision: 21115 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21115&view=rev Modified: haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp Log: * Correctly request mouse events on mouse down. * Display the min, max, preferred, and current size of the tested widget. * Some cleanup. Modified: haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp 2007-05-12 13:40:07 UTC (rev 21114) +++ haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp 2007-05-12 15:43:04 UTC (rev 21115) @@ -3,6 +3,7 @@ * All rights reserved. Distributed under the terms of the MIT License. */ +#include #include #include @@ -11,6 +12,7 @@ #include #include #include +#include #include #include @@ -394,16 +396,17 @@ virtual void MouseDown(BPoint where) { -//printf("ViewContainer::MouseDown((%f, %f))\n", where.x, where.y); // get mouse buttons and modifiers uint32 buttons; int32 modifiers; _GetButtonsAndModifiers(buttons, modifiers); // get mouse focus - if (!fMouseFocus && (buttons & B_PRIMARY_MOUSE_BUTTON)) + if (!fMouseFocus && (buttons & B_PRIMARY_MOUSE_BUTTON)) { fMouseFocus = AncestorAt(where); -//printf(" mouse focus: %p (this: %p)\n", fMouseFocus, this); + if (fMouseFocus) + SetMouseEventMask(B_POINTER_EVENTS); + } // call hook if (fMouseFocus) { @@ -414,7 +417,6 @@ virtual void MouseUp(BPoint where) { -//printf("ViewContainer::MouseUp((%f, %f))\n", where.x, where.y); if (!fMouseFocus) return; @@ -436,7 +438,6 @@ virtual void MouseMoved(BPoint where, uint32 code, const BMessage* message) { -//printf("ViewContainer::MouseMoved((%f, %f))\n", where.x, where.y); if (!fMouseFocus) return; @@ -676,6 +677,106 @@ }; +// StringView +class StringView : public View { +public: + StringView(BRect frame, const char* string) + : View(frame), + fString(string), + fAlignment(B_ALIGN_LEFT), + fStringAscent(0), + fStringDescent(0), + fStringWidth(0) + { + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + fTextColor = (rgb_color){ 0, 0, 0, 255 }; + } + + void SetString(const char* string) + { + fString = string; + + _UpdateStringMetrics(); + Invalidate(); + } + + void SetAlignment(alignment align) + { + if (align != fAlignment) { + fAlignment = align; + Invalidate(); + } + } + + void SetTextColor(rgb_color color) + { + fTextColor = color; + Invalidate(); + } + + BSize PreferredSize() const + { + return BSize(fStringWidth - 1, fStringAscent + fStringDescent - 1); + } + + virtual void AddedToContainer() + { + _UpdateStringMetrics(); + } + + virtual void Draw(BView* container, BRect updateRect) + { + BSize size(Size()); + int widthDiff = (int)size.width + 1 - (int)fStringWidth; + int heightDiff = (int)size.height + 1 + - (int)(fStringAscent + (int)fStringDescent); + BPoint base; + + // horizontal alignment + switch (fAlignment) { + case B_ALIGN_RIGHT: + base.x = widthDiff; + break; + case B_ALIGN_LEFT: + default: + base.x = 0; + break; + } + + base.y = heightDiff / 2 + fStringAscent; + + container->SetHighColor(fTextColor); + container->DrawString(fString.String(), base); + } + +private: + void _UpdateStringMetrics() + { + BView* container = Container(); + if (!container) + return; + + BFont font; + container->GetFont(&font); + + font_height fh; + font.GetHeight(&fh); + + fStringAscent = ceilf(fh.ascent); + fStringDescent = ceilf(fh.descent); + fStringWidth = font.StringWidth(fString.String()); + } + +private: + BString fString; + alignment fAlignment; + rgb_color fTextColor; + float fStringAscent; + float fStringDescent; + float fStringWidth; +}; + + // TestWindow class TestWindow : public BWindow { public: @@ -685,12 +786,13 @@ B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE | B_NOT_RESIZABLE | B_NOT_ZOOMABLE) { - ViewContainer* viewContainer = new ViewContainer(Bounds()); - viewContainer->View::SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - AddChild(viewContainer); + fViewContainer = new ViewContainer(Bounds()); + fViewContainer->View::SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + AddChild(fViewContainer); - View* view = new View(BRect(10, 10, 400, 300)); - viewContainer->View::AddChild(view); + BRect rect(10, 10, 400, 300); + View* view = new View(rect); + fViewContainer->View::AddChild(view); view->SetViewColor((rgb_color){200, 200, 240, 255}); // wrapper view @@ -709,6 +811,71 @@ view->AddChild(fSliderView); _UpdateSliderConstraints(); + + // size labels + + // min label + rect.top = rect.bottom + 10; + rect.bottom = rect.top + 10; + StringView* minLabel = new StringView(rect, "min: "); + minLabel->SetAlignment(B_ALIGN_RIGHT); + fViewContainer->View::AddChild(minLabel); + minLabel->SetSize(minLabel->PreferredSize()); + BRect minFrame(minLabel->Frame()); + + // max label + rect = minFrame.OffsetToCopy(minFrame.LeftBottom() + BPoint(0, 8)); + StringView* maxLabel = new StringView(rect, "max: "); + maxLabel->SetAlignment(B_ALIGN_RIGHT); + fViewContainer->View::AddChild(maxLabel); + maxLabel->SetSize(maxLabel->PreferredSize()); + BRect maxFrame(maxLabel->Frame()); + + // preferred label + rect = maxFrame.OffsetToCopy(maxFrame.LeftBottom() + BPoint(0, 8)); + StringView* preferredLabel = new StringView(rect, "preferred: "); + preferredLabel->SetAlignment(B_ALIGN_RIGHT); + fViewContainer->View::AddChild(preferredLabel); + preferredLabel->SetSize(preferredLabel->PreferredSize()); + BRect preferredFrame(preferredLabel->Frame()); + + // preferred label + rect = preferredFrame.OffsetToCopy(preferredFrame.LeftBottom() + + BPoint(0, 8)); + StringView* currentLabel = new StringView(rect, "current: "); + currentLabel->SetAlignment(B_ALIGN_RIGHT); + fViewContainer->View::AddChild(currentLabel); + currentLabel->SetSize(currentLabel->PreferredSize()); + BRect currentFrame(currentLabel->Frame()); + + float labelWidth = max_c(minFrame.Width(), maxFrame.Width()); + labelWidth = max_c(labelWidth, preferredFrame.Width()); + labelWidth = max_c(labelWidth, currentFrame.Width()); + BSize labelSize(labelWidth, minLabel->Size().height); + minLabel->SetSize(labelSize); + maxLabel->SetSize(labelSize); + preferredLabel->SetSize(labelSize); + currentLabel->SetSize(labelSize); + + // size views + + // min + _CreateSizeViews(minFrame.LeftTop() + BPoint(labelWidth + 1, 0), + fMinWidthView, fMinHeightView); + + // max + _CreateSizeViews(maxFrame.LeftTop() + BPoint(labelWidth + 1, 0), + fMaxWidthView, fMaxHeightView); + + // preferred + _CreateSizeViews(preferredFrame.LeftTop() + BPoint(labelWidth + 1, 0), + fPreferredWidthView, fPreferredHeightView); + + // current + _CreateSizeViews(currentFrame.LeftTop() + BPoint(labelWidth + 1, 0), + fCurrentWidthView, fCurrentHeightView); + + _UpdateSizeViews(); } virtual void MessageReceived(BMessage* message) @@ -722,6 +889,7 @@ BSize size(sliderLocation.x - wrapperLocation.x - 1, sliderLocation.y - wrapperLocation.y - 1); fWrapperView->SetSize(size); + _UpdateSizeViews(); break; } @@ -753,9 +921,73 @@ fSliderView->SetLocationRange(minSliderLocation, maxSliderLocation); } + void _CreateSizeViews(BPoint location, StringView*& widthView, + StringView*& heightView) + { + // width view + BRect rect(location, location + BPoint(10, 10)); + widthView = new StringView(rect, "9999999999.9"); + widthView->SetAlignment(B_ALIGN_RIGHT); + fViewContainer->View::AddChild(widthView); + widthView->SetSize(widthView->PreferredSize()); + + // "," label + rect = widthView->Frame(); + rect.OffsetTo(rect.RightTop() + BPoint(1, 0)); + StringView* labelView = new StringView(rect, ", "); + fViewContainer->View::AddChild(labelView); + labelView->SetSize(labelView->PreferredSize()); + + // height view + rect = labelView->Frame(); + rect.OffsetTo(rect.RightTop() + BPoint(1, 0)); + heightView = new StringView(rect, "9999999999.9"); + heightView->SetAlignment(B_ALIGN_RIGHT); + fViewContainer->View::AddChild(heightView); + heightView->SetSize(heightView->PreferredSize()); + } + + void _UpdateSizeView(StringView* view, float size) + { + char buffer[32]; + if (size < B_SIZE_UNLIMITED) { + sprintf(buffer, "%.1f", size); + view->SetString(buffer); + } else + view->SetString("unlimited"); + } + + void _UpdateSizeViews(StringView* widthView, StringView* heightView, + BSize size) + { + _UpdateSizeView(widthView, size.width); + _UpdateSizeView(heightView, size.height); + } + + void _UpdateSizeViews() + { + _UpdateSizeViews(fMinWidthView, fMinHeightView, + fWrapperView->GetView()->MinSize()); + _UpdateSizeViews(fMaxWidthView, fMaxHeightView, + fWrapperView->GetView()->MaxSize()); + _UpdateSizeViews(fPreferredWidthView, fPreferredHeightView, + fWrapperView->GetView()->PreferredSize()); + _UpdateSizeViews(fCurrentWidthView, fCurrentHeightView, + BRect(fWrapperView->GetView()->Frame())); + } + private: + ViewContainer* fViewContainer; WrapperView* fWrapperView; TwoDimensionalSliderView* fSliderView; + StringView* fMinWidthView; + StringView* fMinHeightView; + StringView* fMaxWidthView; + StringView* fMaxHeightView; + StringView* fPreferredWidthView; + StringView* fPreferredHeightView; + StringView* fCurrentWidthView; + StringView* fCurrentHeightView; }; From bonefish at mail.berlios.de Sat May 12 17:49:02 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 12 May 2007 17:49:02 +0200 Subject: [Haiku-commits] r21116 - in haiku/trunk: headers/os/interface src/kits/interface Message-ID: <200705121549.l4CFn2VO028939@sheep.berlios.de> Author: bonefish Date: 2007-05-12 17:49:01 +0200 (Sat, 12 May 2007) New Revision: 21116 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21116&view=rev Modified: haiku/trunk/headers/os/interface/Point.h haiku/trunk/src/kits/interface/Point.cpp Log: Cleanup. Modified: haiku/trunk/headers/os/interface/Point.h =================================================================== --- haiku/trunk/headers/os/interface/Point.h 2007-05-12 15:43:04 UTC (rev 21115) +++ haiku/trunk/headers/os/interface/Point.h 2007-05-12 15:49:01 UTC (rev 21116) @@ -1,49 +1,19 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, OpenBeOS -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: Point.h -// Author: Frans van Nispen -// Description: BPoint represents a single x,y coordinate. -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Frans van Nispen + */ #ifndef _POINT_H #define _POINT_H -// Standard Includes ----------------------------------------------------------- - -// System Includes ------------------------------------------------------------- #include #include -// Project Includes ------------------------------------------------------------ -// Local Includes -------------------------------------------------------------- - -// Local Defines --------------------------------------------------------------- - -// Globals --------------------------------------------------------------------- - - class BRect; -// BPoint class ---------------------------------------------------------------- class BPoint { public: float x; @@ -67,48 +37,47 @@ bool operator!=(const BPoint &p) const; bool operator==(const BPoint &p) const; }; -//------------------------------------------------------------------------------ extern _IMPEXP_BE const BPoint B_ORIGIN; // returns (0,0) -//------------------------------------------------------------------------------ -inline BPoint::BPoint() + +inline +BPoint::BPoint() { x = y = 0; } -//------------------------------------------------------------------------------ -inline BPoint::BPoint(float X, float Y) + + +inline +BPoint::BPoint(float X, float Y) { x = X; y = Y; } -//------------------------------------------------------------------------------ -inline BPoint::BPoint(const BPoint& pt) + + +inline +BPoint::BPoint(const BPoint& pt) { x = pt.x; y = pt.y; } -//------------------------------------------------------------------------------ -inline BPoint &BPoint::operator=(const BPoint& from) + + +inline BPoint & +BPoint::operator=(const BPoint& from) { x = from.x; y = from.y; return *this; } -//------------------------------------------------------------------------------ -inline void BPoint::Set(float X, float Y) + + +inline void +BPoint::Set(float X, float Y) { x = X; y = Y; } -//------------------------------------------------------------------------------ #endif // _POINT_H - -/* - * $Log $ - * - * $Id $ - * - */ - Modified: haiku/trunk/src/kits/interface/Point.cpp =================================================================== --- haiku/trunk/src/kits/interface/Point.cpp 2007-05-12 15:43:04 UTC (rev 21115) +++ haiku/trunk/src/kits/interface/Point.cpp 2007-05-12 15:49:01 UTC (rev 21116) @@ -1,36 +1,17 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2004, Haiku -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: Point.cpp -// Author: Frans van Nispen -// Description: BPoint represents a single x,y coordinate. -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Frans van Nispen + */ -// Standard Includes ----------------------------------------------------------- +#include + #include #include -// System Includes ------------------------------------------------------------- #include -#include #include From bonefish at mail.berlios.de Sat May 12 18:15:20 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 12 May 2007 18:15:20 +0200 Subject: [Haiku-commits] r21117 - in haiku/trunk: headers/os/interface src/kits/interface Message-ID: <200705121615.l4CGFKVQ001999@sheep.berlios.de> Author: bonefish Date: 2007-05-12 18:15:20 +0200 (Sat, 12 May 2007) New Revision: 21117 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21117&view=rev Modified: haiku/trunk/headers/os/interface/Point.h haiku/trunk/src/kits/interface/Point.cpp Log: Added unary - operator. Modified: haiku/trunk/headers/os/interface/Point.h =================================================================== --- haiku/trunk/headers/os/interface/Point.h 2007-05-12 15:49:01 UTC (rev 21116) +++ haiku/trunk/headers/os/interface/Point.h 2007-05-12 16:15:20 UTC (rev 21117) @@ -29,6 +29,7 @@ void ConstrainTo(BRect r); void PrintToStream() const; + BPoint operator-() const; BPoint operator+(const BPoint &p) const; BPoint operator-(const BPoint &p) const; BPoint& operator+=(const BPoint &p); Modified: haiku/trunk/src/kits/interface/Point.cpp =================================================================== --- haiku/trunk/src/kits/interface/Point.cpp 2007-05-12 15:49:01 UTC (rev 21116) +++ haiku/trunk/src/kits/interface/Point.cpp 2007-05-12 16:15:20 UTC (rev 21117) @@ -34,6 +34,13 @@ BPoint +BPoint::operator-() const +{ + return BPoint(-x, -y); +} + + +BPoint BPoint::operator+(const BPoint& p) const { return BPoint(x + p.x, y + p.y); From bonefish at mail.berlios.de Sat May 12 18:19:24 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 12 May 2007 18:19:24 +0200 Subject: [Haiku-commits] r21118 - in haiku/trunk: headers/os/interface src/kits/interface Message-ID: <200705121619.l4CGJOAJ003148@sheep.berlios.de> Author: bonefish Date: 2007-05-12 18:19:24 +0200 (Sat, 12 May 2007) New Revision: 21118 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21118&view=rev Modified: haiku/trunk/headers/os/interface/Rect.h haiku/trunk/src/kits/interface/Rect.cpp Log: Cleanup. Modified: haiku/trunk/headers/os/interface/Rect.h =================================================================== --- haiku/trunk/headers/os/interface/Rect.h 2007-05-12 16:15:20 UTC (rev 21117) +++ haiku/trunk/headers/os/interface/Rect.h 2007-05-12 16:19:24 UTC (rev 21118) @@ -1,28 +1,10 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2005, Haiku -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: Rect.h -// Author: Frans van Nispen (xlr8 at tref.nl) -// Description: BRect represents a rectangular area. -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Frans van Nispen + */ #ifndef _RECT_H #define _RECT_H @@ -109,24 +91,28 @@ return *(const BPoint *)&left; } + inline BPoint BRect::RightBottom() const { return *(const BPoint *)&right; } + inline BPoint BRect::LeftBottom() const { return BPoint(left, bottom); } + inline BPoint BRect::RightTop() const { return BPoint(right, top); } + inline BRect::BRect() { @@ -134,6 +120,7 @@ bottom = right = -1; } + inline BRect::BRect(float l, float t, float r, float b) { @@ -143,6 +130,7 @@ bottom = b; } + inline BRect::BRect(const BRect &r) { @@ -152,6 +140,7 @@ bottom = r.bottom; } + inline BRect::BRect(BPoint leftTop, BPoint rightBottom) { @@ -161,6 +150,7 @@ bottom = rightBottom.y; } + inline BRect & BRect::operator=(const BRect& from) { @@ -171,6 +161,7 @@ return *this; } + inline void BRect::Set(float l, float t, float r, float b) { @@ -180,30 +171,35 @@ bottom = b; } + inline bool BRect::IsValid() const { return left <= right && top <= bottom; } + inline int32 BRect::IntegerWidth() const { return (int32)ceil(right - left); } + inline float BRect::Width() const { return right - left; } + inline int32 BRect::IntegerHeight() const { return (int32)ceil(bottom - top); } + inline float BRect::Height() const { Modified: haiku/trunk/src/kits/interface/Rect.cpp =================================================================== --- haiku/trunk/src/kits/interface/Rect.cpp 2007-05-12 16:15:20 UTC (rev 21117) +++ haiku/trunk/src/kits/interface/Rect.cpp 2007-05-12 16:19:24 UTC (rev 21118) @@ -1,72 +1,48 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2004, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: Rect.cpp -// Author: Frans van Nispen (xlr8 at tref.nl) -// Description: BRect represents a rectangular area. -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Frans van Nispen + */ -// Standard Includes ----------------------------------------------------------- #include -// System Includes ------------------------------------------------------------- #include -// Project Includes ------------------------------------------------------------ -// Local Includes -------------------------------------------------------------- - -// Local Defines --------------------------------------------------------------- - -// Globals --------------------------------------------------------------------- - - void BRect::SetLeftTop(const BPoint p) { left = p.x; top = p.y; } -//------------------------------------------------------------------------------ + + void BRect::SetRightBottom(const BPoint p) { right = p.x; bottom = p.y; } -//------------------------------------------------------------------------------ + + void BRect::SetLeftBottom(const BPoint p) { left = p.x; bottom = p.y; } -//------------------------------------------------------------------------------ + + void BRect::SetRightTop(const BPoint p) { right = p.x; top = p.y; } -//------------------------------------------------------------------------------ + + void BRect::InsetBy(BPoint point) { @@ -75,7 +51,8 @@ top += point.y; bottom -= point.y; } -//------------------------------------------------------------------------------ + + void BRect::InsetBy(float dx, float dy) { @@ -84,21 +61,24 @@ top += dy; bottom -= dy; } -//------------------------------------------------------------------------------ + + BRect& BRect::InsetBySelf(BPoint point) { InsetBy(point); return *this; } -//------------------------------------------------------------------------------ + + BRect& BRect::InsetBySelf(float dx, float dy) { InsetBy(dx, dy); return *this; } -//------------------------------------------------------------------------------ + + BRect BRect::InsetByCopy(BPoint point) { @@ -106,7 +86,8 @@ copy.InsetBy(point); return copy; } -//------------------------------------------------------------------------------ + + BRect BRect::InsetByCopy(float dx, float dy) { @@ -114,7 +95,8 @@ copy.InsetBy(dx, dy); return copy; } -//------------------------------------------------------------------------------ + + void BRect::OffsetBy(BPoint point) { @@ -123,7 +105,8 @@ top += point.y; bottom += point.y; } -//------------------------------------------------------------------------------ + + void BRect::OffsetBy(float dx, float dy) { @@ -132,21 +115,24 @@ top += dy; bottom += dy; } -//------------------------------------------------------------------------------ + + BRect& BRect::OffsetBySelf(BPoint point) { OffsetBy(point); return *this; } -//------------------------------------------------------------------------------ + + BRect& BRect::OffsetBySelf(float dx, float dy) { OffsetBy(dx, dy); return *this; } -//------------------------------------------------------------------------------ + + BRect BRect::OffsetByCopy(BPoint point) { @@ -154,7 +140,8 @@ copy.OffsetBy(point); return copy; } -//------------------------------------------------------------------------------ + + BRect BRect::OffsetByCopy(float dx, float dy) { @@ -162,7 +149,8 @@ copy.OffsetBy(dx, dy); return copy; } -//------------------------------------------------------------------------------ + + void BRect::OffsetTo(BPoint point) { @@ -171,7 +159,8 @@ bottom = (bottom - top) + point.y; top = point.y; } -//------------------------------------------------------------------------------ + + void BRect::OffsetTo(float x, float y) { @@ -180,21 +169,24 @@ bottom = (bottom - top) + y; top=y; } -//------------------------------------------------------------------------------ + + BRect& BRect::OffsetToSelf(BPoint point) { OffsetTo(point); return *this; } -//------------------------------------------------------------------------------ + + BRect& BRect::OffsetToSelf(float dx, float dy) { OffsetTo(dx, dy); return *this; } -//------------------------------------------------------------------------------ + + BRect BRect::OffsetToCopy(BPoint point) { @@ -202,7 +194,8 @@ copy.OffsetTo(point); return copy; } -//------------------------------------------------------------------------------ + + BRect BRect::OffsetToCopy(float dx, float dy) { @@ -210,40 +203,46 @@ copy.OffsetTo(dx, dy); return copy; } -//------------------------------------------------------------------------------ + + void BRect::PrintToStream() const { printf("BRect(l:%.1f, t:%.1f, r:%.1f, b:%.1f)\n", left, top, right, bottom); } -//------------------------------------------------------------------------------ + + bool BRect::operator==(BRect rect) const { return left == rect.left && right == rect.right && top == rect.top && bottom == rect.bottom; } -//------------------------------------------------------------------------------ + + bool BRect::operator!=(BRect rect) const { return !(*this == rect); } -//------------------------------------------------------------------------------ + + BRect BRect::operator&(BRect rect) const { return BRect(max_c(left, rect.left), max_c(top, rect.top), min_c(right, rect.right), min_c(bottom, rect.bottom)); } -//------------------------------------------------------------------------------ + + BRect BRect::operator|(BRect rect) const { return BRect(min_c(left, rect.left), min_c(top, rect.top), max_c(right, rect.right), max_c(bottom, rect.bottom)); } -//------------------------------------------------------------------------------ + + bool BRect::Intersects(BRect rect) const { @@ -253,27 +252,19 @@ return !(rect.left > right || rect.right < left || rect.top > bottom || rect.bottom < top); } -//------------------------------------------------------------------------------ + + bool BRect::Contains(BPoint point) const { return point.x >= left && point.x <= right && point.y >= top && point.y <= bottom; } -//------------------------------------------------------------------------------ + + bool BRect::Contains(BRect rect) const { return rect.left >= left && rect.right <= right && rect.top >= top && rect.bottom <= bottom; } -//------------------------------------------------------------------------------ - - -/* - * $Log $ - * - * $Id $ - * - */ - From bonefish at mail.berlios.de Sat May 12 18:24:18 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 12 May 2007 18:24:18 +0200 Subject: [Haiku-commits] r21119 - haiku/trunk/headers/os/interface Message-ID: <200705121624.l4CGOIF9003574@sheep.berlios.de> Author: bonefish Date: 2007-05-12 18:24:18 +0200 (Sat, 12 May 2007) New Revision: 21119 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21119&view=rev Modified: haiku/trunk/headers/os/interface/Size.h Log: Some more spacing. Modified: haiku/trunk/headers/os/interface/Size.h =================================================================== --- haiku/trunk/headers/os/interface/Size.h 2007-05-12 16:19:24 UTC (rev 21118) +++ haiku/trunk/headers/os/interface/Size.h 2007-05-12 16:24:18 UTC (rev 21119) @@ -10,11 +10,13 @@ #include #include + enum { B_SIZE_UNSET = -1, B_SIZE_UNLIMITED = 1024 * 1024 * 1024, }; + class BSize { public: float width; @@ -52,6 +54,7 @@ { } + // copy constructor inline BSize::BSize(const BSize& other) @@ -60,6 +63,7 @@ { } + // constructor inline BSize::BSize(float width, float height) @@ -68,6 +72,7 @@ { } + // constructor inline BSize::BSize(const BRect& rect) @@ -76,6 +81,7 @@ { } + // Width inline float BSize::Width() const @@ -83,6 +89,7 @@ return width; } + // Height inline float BSize::Height() const @@ -90,6 +97,7 @@ return height; } + // SetWidth inline void BSize::SetWidth(float width) @@ -97,6 +105,7 @@ this->width = width; } + // SetHeight inline void BSize::SetHeight(float height) @@ -104,6 +113,7 @@ this->height = height; } + // IntegerWidth inline int32 BSize::IntegerWidth() const @@ -111,6 +121,7 @@ return (int32)width; } + // IntegerHeight inline int32 BSize::IntegerHeight() const @@ -118,6 +129,7 @@ return (int32)height; } + // IsWidthSet inline bool BSize::IsWidthSet() const @@ -125,6 +137,7 @@ return width != B_SIZE_UNSET; } + // IsHeightSet inline bool BSize::IsHeightSet() const @@ -132,6 +145,7 @@ return height != B_SIZE_UNSET; } + // == inline bool BSize::operator==(const BSize& other) const @@ -139,6 +153,7 @@ return (width == other.width && height == other.height); } + // != inline bool BSize::operator!=(const BSize& other) const @@ -146,6 +161,7 @@ return !(*this == other); } + // = inline BSize& BSize::operator=(const BSize& other) From bonefish at mail.berlios.de Sat May 12 18:50:19 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 12 May 2007 18:50:19 +0200 Subject: [Haiku-commits] r21120 - in haiku/trunk: headers/os/interface src/kits/interface Message-ID: <200705121650.l4CGoJUE005138@sheep.berlios.de> Author: bonefish Date: 2007-05-12 18:50:16 +0200 (Sat, 12 May 2007) New Revision: 21120 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21120&view=rev Modified: haiku/trunk/headers/os/interface/Rect.h haiku/trunk/headers/os/interface/Size.h haiku/trunk/src/kits/interface/CardLayout.cpp haiku/trunk/src/kits/interface/SplitLayout.cpp haiku/trunk/src/kits/interface/SplitLayout.h haiku/trunk/src/kits/interface/TwoDimensionalLayout.cpp Log: Removed the BSize(const BRect&) constructor and added BRect::Size() instead. Also added a BRect(BPoint, BSize) constructor. Modified: haiku/trunk/headers/os/interface/Rect.h =================================================================== --- haiku/trunk/headers/os/interface/Rect.h 2007-05-12 16:24:18 UTC (rev 21119) +++ haiku/trunk/headers/os/interface/Rect.h 2007-05-12 16:50:16 UTC (rev 21120) @@ -11,6 +11,7 @@ #include #include +#include #include @@ -26,6 +27,7 @@ BRect(const BRect &r); BRect(float l, float t, float r, float b); BRect(BPoint lt, BPoint rb); + BRect(BPoint leftTop, BSize size); BRect &operator=(const BRect &r); void Set(float l, float t, float r, float b); @@ -72,12 +74,14 @@ BRect operator&(BRect r) const; BRect operator|(BRect r) const; - bool Intersects(BRect r) const; bool IsValid() const; float Width() const; int32 IntegerWidth() const; float Height() const; int32 IntegerHeight() const; + BSize Size() const; + + bool Intersects(BRect r) const; bool Contains(BPoint p) const; bool Contains(BRect r) const; }; @@ -151,6 +155,16 @@ } +inline +BRect::BRect(BPoint leftTop, BSize size) + : left(leftTop.x), + top(leftTop.y), + right(leftTop.x + size.width), + bottom(leftTop.y + size.height) +{ +} + + inline BRect & BRect::operator=(const BRect& from) { @@ -206,4 +220,11 @@ return bottom - top; } +inline BSize +BRect::Size() const +{ + return BSize(right - left, bottom - top); +} + + #endif // _RECT_H Modified: haiku/trunk/headers/os/interface/Size.h =================================================================== --- haiku/trunk/headers/os/interface/Size.h 2007-05-12 16:24:18 UTC (rev 21119) +++ haiku/trunk/headers/os/interface/Size.h 2007-05-12 16:50:16 UTC (rev 21120) @@ -7,7 +7,6 @@ #include -#include #include @@ -25,7 +24,6 @@ inline BSize(); inline BSize(const BSize& other); inline BSize(float width, float height); - inline BSize(const BRect& rect); inline float Width() const; inline float Height() const; @@ -73,15 +71,6 @@ } -// constructor -inline -BSize::BSize(const BRect& rect) - : width(rect.Width()), - height(rect.Height()) -{ -} - - // Width inline float BSize::Width() const Modified: haiku/trunk/src/kits/interface/CardLayout.cpp =================================================================== --- haiku/trunk/src/kits/interface/CardLayout.cpp 2007-05-12 16:24:18 UTC (rev 21119) +++ haiku/trunk/src/kits/interface/CardLayout.cpp 2007-05-12 16:50:16 UTC (rev 21120) @@ -167,7 +167,7 @@ { _ValidateMinMax(); - BSize size = BSize(View()->Bounds()); + BSize size = View()->Bounds().Size(); size.width = max_c(size.width, fMin.width); size.height = max_c(size.height, fMin.height); Modified: haiku/trunk/src/kits/interface/SplitLayout.cpp =================================================================== --- haiku/trunk/src/kits/interface/SplitLayout.cpp 2007-05-12 16:24:18 UTC (rev 21119) +++ haiku/trunk/src/kits/interface/SplitLayout.cpp 2007-05-12 16:50:16 UTC (rev 21120) @@ -470,7 +470,7 @@ _ValidateMinMax(); // layout the elements - BSize size = _SubtractInsets(BSize(View()->Bounds())); + BSize size = _SubtractInsets(View()->Bounds().Size()); fHorizontalLayouter->Layout(fHorizontalLayoutInfo, size.width); Layouter* verticalLayouter; @@ -562,7 +562,7 @@ return false; // Things shouldn't be draggable, if we have a >= max layout. - BSize size = _SubtractInsets(BSize(View()->Frame())); + BSize size = _SubtractInsets(View()->Frame().Size()); if (fOrientation == B_HORIZONTAL && size.width >= fMax.width || fOrientation == B_VERTICAL && size.height >= fMax.height) { return false; @@ -757,7 +757,7 @@ info->max = item->MaxSize(); if (item->HasHeightForWidth()) { - BSize size = _SubtractInsets(BSize(View()->Frame())); + BSize size = _SubtractInsets(View()->Frame().Size()); float minHeight, maxHeight; item->GetHeightForWidth(size.width, &minHeight, &maxHeight, NULL); info->min.height = max_c(info->min.height, minHeight); Modified: haiku/trunk/src/kits/interface/SplitLayout.h =================================================================== --- haiku/trunk/src/kits/interface/SplitLayout.h 2007-05-12 16:24:18 UTC (rev 21119) +++ haiku/trunk/src/kits/interface/SplitLayout.h 2007-05-12 16:50:16 UTC (rev 21120) @@ -5,8 +5,11 @@ #ifndef _SPLIT_LAYOUT_H #define _SPLIT_LAYOUT_H + #include +#include + namespace BPrivate { namespace Layout { class Layouter; Modified: haiku/trunk/src/kits/interface/TwoDimensionalLayout.cpp =================================================================== --- haiku/trunk/src/kits/interface/TwoDimensionalLayout.cpp 2007-05-12 16:24:18 UTC (rev 21119) +++ haiku/trunk/src/kits/interface/TwoDimensionalLayout.cpp 2007-05-12 16:50:16 UTC (rev 21120) @@ -341,7 +341,7 @@ _ValidateMinMax(); // layout the horizontal/vertical elements - BSize size = SubtractInsets(BSize(View()->Frame())); + BSize size = SubtractInsets(View()->Frame().Size()); printf("BTwoDimensionalLayout::LayoutView(%p): size: (%.1f, %.1f)\n", View(), size.width, size.height); From bonefish at mail.berlios.de Sat May 12 19:01:42 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 12 May 2007 19:01:42 +0200 Subject: [Haiku-commits] r21121 - in haiku/trunk: headers/os/interface src/kits/interface Message-ID: <200705121701.l4CH1gqI019725@sheep.berlios.de> Author: bonefish Date: 2007-05-12 19:01:41 +0200 (Sat, 12 May 2007) New Revision: 21121 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21121&view=rev Modified: haiku/trunk/headers/os/interface/Button.h haiku/trunk/src/kits/interface/Button.cpp Log: BButton needs B_FULL_UPDATE_ON_RESIZE despite the fact that it isn't resizable by default. Modified: haiku/trunk/headers/os/interface/Button.h =================================================================== --- haiku/trunk/headers/os/interface/Button.h 2007-05-12 16:50:16 UTC (rev 21120) +++ haiku/trunk/headers/os/interface/Button.h 2007-05-12 17:01:41 UTC (rev 21121) @@ -51,10 +51,12 @@ const char *label, BMessage *message, uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_WILL_DRAW | B_NAVIGABLE); + uint32 flags = B_WILL_DRAW | B_NAVIGABLE + | B_FULL_UPDATE_ON_RESIZE); BButton(const char* name, const char* label, BMessage *message, - uint32 flags = B_WILL_DRAW | B_NAVIGABLE); + uint32 flags = B_WILL_DRAW | B_NAVIGABLE + | B_FULL_UPDATE_ON_RESIZE); BButton(const char* label, BMessage *message); virtual ~BButton(); Modified: haiku/trunk/src/kits/interface/Button.cpp =================================================================== --- haiku/trunk/src/kits/interface/Button.cpp 2007-05-12 16:50:16 UTC (rev 21120) +++ haiku/trunk/src/kits/interface/Button.cpp 2007-05-12 17:01:41 UTC (rev 21121) @@ -21,7 +21,8 @@ BButton::BButton(BRect frame, const char *name, const char *label, BMessage *message, uint32 resizingMode, uint32 flags) - : BControl(frame, name, label, message, resizingMode, flags | B_WILL_DRAW), + : BControl(frame, name, label, message, resizingMode, + flags | B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE), fDrawAsDefault(false) { // Resize to minimum height if needed @@ -36,7 +37,7 @@ BButton::BButton(const char* name, const char* label, BMessage *message, uint32 flags) : BControl(BRect(0, 0, -1, -1), name, label, message, B_FOLLOW_NONE, - flags | B_WILL_DRAW | B_SUPPORTS_LAYOUT), + flags | B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_SUPPORTS_LAYOUT), fDrawAsDefault(false) { // Resize to minimum height if needed @@ -50,7 +51,8 @@ BButton::BButton(const char* label, BMessage *message) : BControl(BRect(0, 0, -1, -1), NULL, label, message, B_FOLLOW_NONE, - B_WILL_DRAW | B_NAVIGABLE | B_SUPPORTS_LAYOUT), + B_WILL_DRAW | B_NAVIGABLE | B_FULL_UPDATE_ON_RESIZE + | B_SUPPORTS_LAYOUT), fDrawAsDefault(false) { // Resize to minimum height if needed From bonefish at mail.berlios.de Sat May 12 19:02:29 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 12 May 2007 19:02:29 +0200 Subject: [Haiku-commits] r21122 - haiku/trunk/src/tests/kits/interface/layout Message-ID: <200705121702.l4CH2T5S021085@sheep.berlios.de> Author: bonefish Date: 2007-05-12 19:02:28 +0200 (Sat, 12 May 2007) New Revision: 21122 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21122&view=rev Modified: haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp Log: Catch up with the recent API changes. Modified: haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp 2007-05-12 17:01:41 UTC (rev 21121) +++ haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp 2007-05-12 17:02:28 UTC (rev 21122) @@ -26,13 +26,6 @@ // missing operators in BPoint BPoint -operator-(const BPoint& p) -{ - return BPoint(-p.x, -p.y); -} - - -BPoint operator+(const BPoint& p, const BSize& size) { return BPoint(p.x + size.width, p.y + size.height); @@ -100,7 +93,7 @@ BSize Size() const { - return BSize(Frame()); + return Frame().Size(); } BPoint LocationInContainer() const @@ -798,8 +791,7 @@ // wrapper view fWrapperView = new WrapperView(BRect(10, 10, 100, 100), new BButton(BRect(0, 0, 9, 9), "test button", "Ooh, press me!", - (BMessage*)NULL, B_FOLLOW_NONE, - B_WILL_DRAW | B_NAVIGABLE | B_FULL_UPDATE_ON_RESIZE)); + (BMessage*)NULL, B_FOLLOW_NONE)); fWrapperView->GetView()->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); view->AddChild(fWrapperView); fWrapperView->SetSize(fWrapperView->PreferredSize()); @@ -973,7 +965,7 @@ _UpdateSizeViews(fPreferredWidthView, fPreferredHeightView, fWrapperView->GetView()->PreferredSize()); _UpdateSizeViews(fCurrentWidthView, fCurrentHeightView, - BRect(fWrapperView->GetView()->Frame())); + fWrapperView->GetView()->Frame().Size()); } private: From stefano.ceccherini at gmail.com Sat May 12 19:16:29 2007 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Sat, 12 May 2007 19:16:29 +0200 Subject: [Haiku-commits] r21112 - in haiku/trunk: headers/private/interface In-Reply-To: <20070512142915.1196.6@cs.tu-berlin.de> References: <200705120846.l4C8kvUn010349@sheep.berlios.de> <26378110.1178969295007.JavaMail.ngmail@webmail16> <20070512142915.1196.6@cs.tu-berlin.de> Message-ID: <894b9700705121016k862a0a4kccb578772958787c@mail.gmail.com> 2007/5/12, Ingo Weinhold : > > On 2007-05-12 at 13:28:15 [+0200], Marcus Overhagen > wrote: > > > > I don't think that throwing of a B_ERROR (int) can be caught with a catch > > (status_t) > > Yep. Best consequently use a macro like: > > #define THROW_ERROR(error) throw ((status_t)(error)) > Thank you, I'll do that. From mmu_man at mail.berlios.de Sat May 12 20:34:51 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Sat, 12 May 2007 20:34:51 +0200 Subject: [Haiku-commits] r21123 - haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam Message-ID: <200705121834.l4CIYpLQ025456@sheep.berlios.de> Author: mmu_man Date: 2007-05-12 20:34:50 +0200 (Sat, 12 May 2007) New Revision: 21123 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21123&view=rev Modified: haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/README.txt Log: update (c) years Modified: haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/README.txt =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/README.txt 2007-05-12 17:02:28 UTC (rev 21122) +++ haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/README.txt 2007-05-12 18:34:50 UTC (rev 21123) @@ -1,5 +1,5 @@ USB Webcam driver -(c) 2004,2005,2006 Fran?ois Revol. +(c) 2004-2007 Fran?ois Revol. Parts (c) Be,Inc. (ProducerNode sample code). Current version of my USB Webcam driver. WORK IN PROGRESS! From mmu_man at mail.berlios.de Sat May 12 20:38:23 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Sat, 12 May 2007 20:38:23 +0200 Subject: [Haiku-commits] r21124 - haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam Message-ID: <200705121838.l4CIcNPO025709@sheep.berlios.de> Author: mmu_man Date: 2007-05-12 20:38:22 +0200 (Sat, 12 May 2007) New Revision: 21124 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21124&view=rev Modified: haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamDebug.h Log: use __BASE_FILE__ to get shorter file paths. Modified: haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamDebug.h =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamDebug.h 2007-05-12 18:34:50 UTC (rev 21123) +++ haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamDebug.h 2007-05-12 18:38:22 UTC (rev 21124) @@ -9,6 +9,6 @@ #endif #define CH "\033[" CD_COL "mWebcam::%s::%s" -#define CT "\033[0m\n", __FILE__, __FUNCTION__ +#define CT "\033[0m\n", __BASE_FILE__, __FUNCTION__ #endif From mmu_man at mail.berlios.de Sat May 12 20:48:04 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Sat, 12 May 2007 20:48:04 +0200 Subject: [Haiku-commits] r21125 - haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam Message-ID: <200705121848.l4CIm46W026563@sheep.berlios.de> Author: mmu_man Date: 2007-05-12 20:48:04 +0200 (Sat, 12 May 2007) New Revision: 21125 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21125&view=rev Modified: haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamDevice.cpp haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/Producer.cpp Log: Better locking: CamDevice::Start/StopTransfer() should be called with lock held. Modified: haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamDevice.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamDevice.cpp 2007-05-12 18:38:22 UTC (rev 21124) +++ haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamDevice.cpp 2007-05-12 18:48:04 UTC (rev 21125) @@ -172,7 +172,12 @@ if (err < B_OK) return err; fTransferEnabled = false; + + // the thread itself might Lock() + fLocker.Unlock(); wait_for_thread(fPumpThread, &err); + fLocker.Lock(); + return B_OK; } Modified: haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/Producer.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/Producer.cpp 2007-05-12 18:38:22 UTC (rev 21124) +++ haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/Producer.cpp 2007-05-12 18:48:04 UTC (rev 21125) @@ -494,6 +494,12 @@ return; } +#if 0 + /* Some dumb apps don't stop nodes before disconnecting... */ + if (fRunning) + HandleStop(); +#endif + fEnabled = false; fOutput.destination = media_destination::null; @@ -616,7 +622,10 @@ resume_thread(fThread); - fCamDevice->StartTransfer(); + { + BAutolock lock(fCamDevice->Locker()); + fCamDevice->StartTransfer(); + } fRunning = true; return; @@ -640,6 +649,7 @@ delete_sem(fFrameSync); wait_for_thread(fThread, &fThread); + BAutolock lock(fCamDevice->Locker()); fCamDevice->StopTransfer(); fRunning = false; @@ -673,6 +683,7 @@ bigtime_t wait_until = system_time(); while (1) { + PRINTF(1, ("FrameGenerator: acquire_sem_etc() until %Ld?s (in %Ld?s)\n", wait_until, wait_until - system_time())); status_t err = acquire_sem_etc(fFrameSync, 1, B_ABSOLUTE_TIMEOUT, wait_until); @@ -697,6 +708,12 @@ if (wait_until < system_time()) continue; + PRINTF(1, ("FrameGenerator: wait until %Ld, %ctimed out, %crunning, %cenabled.\n", + wait_until, + (err == B_OK)?'!':' ', + (fRunning)?' ':'!', + (fEnabled)?' ':'!')); + /* If the semaphore was acquired successfully, it means something * changed the timing information (see VideoProducer::Connect()) and * so the thread should go back to sleep until the newly-calculated @@ -751,6 +768,9 @@ *(p++) = ((((x+y)^0^x)+fFrame) & 0xff) * (0x01010101 & fColor); #endif + //NO! must be called without lock! + //BAutolock lock(fCamDevice->Locker()); + //#ifdef UseFillFrameBuffer err = fCamDevice->FillFrameBuffer(buffer); if (err < B_OK) { @@ -765,6 +785,7 @@ } #endif + PRINTF(1, ("FrameGenerator: SendBuffer...\n")); /* Send the buffer on down to the consumer */ if (SendBuffer(buffer, fOutput.destination) < B_OK) { PRINTF(-1, ("FrameGenerator: Error sending buffer\n")); @@ -774,6 +795,7 @@ } } + PRINTF(1, ("FrameGenerator: thread existed.\n")); return B_OK; } From mmu_man at mail.berlios.de Sat May 12 20:56:02 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Sat, 12 May 2007 20:56:02 +0200 Subject: [Haiku-commits] r21126 - haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam Message-ID: <200705121856.l4CIu2EV027132@sheep.berlios.de> Author: mmu_man Date: 2007-05-12 20:56:01 +0200 (Sat, 12 May 2007) New Revision: 21126 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21126&view=rev Modified: haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamDevice.cpp haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamDevice.h Log: added CamdDevice::WaitFrame() which will be needed to rewrite teh producer frame generator thread Modified: haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamDevice.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamDevice.cpp 2007-05-12 18:48:04 UTC (rev 21125) +++ haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamDevice.cpp 2007-05-12 18:56:01 UTC (rev 21126) @@ -233,6 +233,15 @@ // ----------------------------------------------------------------------------- status_t +CamDevice::WaitFrame(bigtime_t timeout) +{ + if (fDeframer) + return WaitFrame(timeout); + return EINVAL; +} + +// ----------------------------------------------------------------------------- +status_t CamDevice::GetFrameBitmap(BBitmap **bm) { return EINVAL; Modified: haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamDevice.h =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamDevice.h 2007-05-12 18:48:04 UTC (rev 21125) +++ haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamDevice.h 2007-05-12 18:56:01 UTC (rev 21126) @@ -64,6 +64,7 @@ virtual bool ValidateEndOfFrameTag(const uint8 *tag, size_t taglen, size_t datalen); // several ways to get raw frames + virtual status_t WaitFrame(bigtime_t timeout); virtual status_t GetFrameBitmap(BBitmap **bm); virtual status_t FillFrameBuffer(BBuffer *buffer); From colacoder at mail.berlios.de Sun May 13 19:04:51 2007 From: colacoder at mail.berlios.de (colacoder at BerliOS) Date: Sun, 13 May 2007 19:04:51 +0200 Subject: [Haiku-commits] r21127 - in haiku/trunk/src/add-ons/kernel/drivers/audio: . hda Message-ID: <200705131704.l4DH4piA010912@sheep.berlios.de> Author: colacoder Date: 2007-05-13 19:04:45 +0200 (Sun, 13 May 2007) New Revision: 21127 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21127&view=rev Added: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/Jamfile haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.c haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec.c haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec_defs.h haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller_defs.h haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.c haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hooks.c Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/Jamfile Log: *** WARNING: UNSTABLE CODE AHEAD :P *** This is the first (sort-of) working incarnation of the High Definition Audio driver. This driver still has quite some way to go before coming to a point that we could call it stable and useful, so please use with care. It has been developed on R5, so it might even become useful for people still stuck on R5. This driver was inspired by both the BSD work on HDA support, as well as our own dr_evil's work on the ich_ac97 driver. Before you start bugging me about completing the driver, or adding features, please capture the serial debug output and mail it to ithamar AT unet DOT nl, including hardware details, and success/failure descriptions. As a last note, DasJott, if you're reading this, the first music it played was... 'Prodigy: Smack Your Bitch Up' :) Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/Jamfile 2007-05-12 18:56:01 UTC (rev 21126) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/Jamfile 2007-05-13 17:04:45 UTC (rev 21127) @@ -6,3 +6,5 @@ SubInclude HAIKU_TOP src add-ons kernel drivers audio module_driver ; SubInclude HAIKU_TOP src add-ons kernel drivers audio sis7018 ; SubInclude HAIKU_TOP src add-ons kernel drivers audio usb_audio ; +SubInclude HAIKU_TOP src add-ons kernel drivers audio hda ; + Added: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/Jamfile 2007-05-12 18:56:01 UTC (rev 21126) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/Jamfile 2007-05-13 17:04:45 UTC (rev 21127) @@ -0,0 +1,18 @@ +SubDir HAIKU_TOP src add-ons kernel drivers audio hda ; + +SetSubDirSupportedPlatformsBeOSCompatible ; + +UsePrivateHeaders media ; + +KernelAddon hda : + driver.c + hooks.c + hda_multi_audio.c + hda_controller.c + hda_codec.c +; + +Package haiku-hda-cvs : + hda : + boot home config add-ons kernel drivers bin ; +PackageDriverSymLink haiku-hda-cvs : audio multi hda ; Added: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.c 2007-05-12 18:56:01 UTC (rev 21126) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.c 2007-05-13 17:04:45 UTC (rev 21127) @@ -0,0 +1,102 @@ +#include "driver.h" + +hda_controller cards[MAXCARDS]; +uint32 num_cards; + +pci_module_info* pci; + +status_t +init_hardware(void) +{ + pci_info pcii; + status_t rc; + long i; + + if ((rc=get_module(B_PCI_MODULE_NAME, (module_info**)&pci)) == B_OK) { + for (i=0; pci->get_nth_pci_info(i,&pcii) == B_OK; i++) { + if (pcii.class_base == PCI_multimedia && pcii.class_sub == PCI_hd_audio) { + put_module(B_PCI_MODULE_NAME); + pci = NULL; + return B_OK; + } + } + } + + put_module(B_PCI_MODULE_NAME); + pci = NULL; + + return ENODEV; +} + +status_t +init_driver (void) +{ + char path[B_PATH_NAME_LENGTH]; + pci_info pcii; + status_t rc; + long i; + + num_cards = 0; + + if ((rc=get_module(B_PCI_MODULE_NAME, (module_info**)&pci)) == B_OK) { + for (i=0; pci->get_nth_pci_info(i,&pcii) == B_OK; i++) { + if (pcii.class_base == PCI_multimedia && pcii.class_sub == PCI_hd_audio) { + cards[num_cards].pcii = pcii; + cards[num_cards].opened = 0; + sprintf(path, DEVFS_PATH_FORMAT, num_cards); + cards[num_cards++].devfs_path = strdup(path); + + dprintf("HDA: Detected controller @ PCI:%d:%d:%d, IRQ:%d, type %04x/%04x\n", + pcii.bus, pcii.device, pcii.function, + pcii.u.h0.interrupt_line, + pcii.vendor_id, pcii.device_id); + } + } + } else { + return rc; + } + + if (num_cards == 0) { + put_module(B_PCI_MODULE_NAME); + pci = NULL; + + return ENODEV; + } + + return B_OK; +} + +void +uninit_driver (void) +{ + long i; + for (i=0; i < num_cards; i++) { + free((void*)cards[i].devfs_path); + cards[i].devfs_path = NULL; + } + + if (pci != NULL) { + put_module(B_PCI_MODULE_NAME); + pci = NULL; + } +} + +const char** +publish_devices() +{ + static const char* devs[MAXCARDS+1]; + long i; + + for (i=0; i < num_cards; i++) + devs[i] = cards[i].devfs_path; + + devs[i] = NULL; + + return devs; +} + +device_hooks* +find_device(const char* name) +{ + return &driver_hooks; +} Added: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2007-05-12 18:56:01 UTC (rev 21126) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2007-05-13 17:04:45 UTC (rev 21127) @@ -0,0 +1,163 @@ +#ifndef _HDA_H_ +#define _HDA_H_ + +#include +#include +#include + +#include +#include + +#include "multi_audio.h" +#include "hda_controller_defs.h" +#include "hda_codec_defs.h" + +#define MAXCARDS 4 + +/* values for the class_sub field for class_base = 0x04 (multimedia device) */ +#define PCI_hd_audio 3 + +#define DEVFS_PATH_FORMAT "audio/multi/hda/%lu" +#define MAXWORK 16 +#define HDA_MAXCODECS 15 +#define HDA_MAXSTREAMS 16 +#define MAX_CODEC_RESPONSES 10 +#define MAXINPUTS 32 + +typedef struct hda_controller_s hda_controller; + +#define STRMAXBUF 10 +#define STRMINBUF 2 + +enum { + STRM_PLAYBACK, + STRM_RECORD +}; + +typedef struct hda_stream_info_s { + uint32 id; /* HDA controller stream # */ + uint32 off; /* HDA I/O/B descriptor offset */ + bool running; /* Is this stream active? */ + + uint32 pin_wid; /* PIN Widget ID */ + uint32 io_wid; /* Input/Output Converter Widget ID */ + + uint32 samplerate; + uint32 sampleformat; + + uint32 num_buffers; + uint32 num_channels; + uint32 buffer_length; /* size of buffer in samples */ + uint32 sample_size; + void* buffers[STRMAXBUF]; /* Virtual addresses for buffer */ + uint32 buffers_pa[STRMAXBUF]; /* Physical addresses for buffer */ + sem_id buffer_ready_sem; + bigtime_t played_real_time; + uint32 played_frames_count; + + area_id buffer_area; + area_id bdl_area; + uint32 bdl_pa; /* BDL physical address */ +} hda_stream; + +typedef struct hda_codec_s { + uint16 vendor_id; + uint16 product_id; + uint8 hda_rev; + uint16 rev_stepping; + uint8 addr; + + sem_id response_sem; + uint32 responses[MAX_CODEC_RESPONSES]; + uint32 response_count; + + /* Multi Audio API data */ + hda_stream* playback_stream; + hda_stream* record_stream; + + /* Function Group Data */ + uint32 afg_nid; + uint32 afg_wid_start, afg_wid_count; + uint32 afg_deffmts; + uint32 afg_defrates; + uint32 afg_defpm; + + struct { + uint32 num_inputs; + uint32 active_input; + uint32 inputs[MAXINPUTS]; + uint32 flags; + + hda_widget_type type; + uint32 pm; + + union { + struct { + uint32 formats; + uint32 rates; + } output; + struct { + uint32 formats; + uint32 rates; + } input; + struct { + } mixer; + struct { + uint32 output : 1; + uint32 input : 1; + pin_dev_type device; + } pin; + } d; + } *afg_widgets; + + struct hda_controller_s* ctrlr; +} hda_codec; + +struct hda_controller_s { + pci_info pcii; + vuint32 opened; + const char* devfs_path; + + area_id regs_area; + vuint8* regs; + uint32 irq; + + uint16 codecsts; + uint32 num_input_streams; + uint32 num_output_streams; + uint32 num_bidir_streams; + + uint32 corblen; + uint32 rirblen; + uint32 rirbrp; + uint32 corbwp; + area_id rb_area; + corb_t* corb; + rirb_t* rirb; + + hda_codec* codecs[HDA_MAXCODECS]; + uint32 num_codecs; + + hda_stream* streams[HDA_MAXSTREAMS]; +}; + +extern device_hooks driver_hooks; + +extern pci_module_info* pci; + +extern hda_controller cards[MAXCARDS]; +extern uint32 num_cards; + +status_t hda_hw_init(hda_controller* ctrlr); +void hda_hw_stop(hda_controller* ctrlr); +void hda_hw_uninit(hda_controller* ctrlr); +hda_codec* hda_codec_new(hda_controller* ctrlr, uint32 cad); +status_t hda_send_verbs(hda_codec* codec, corb_t* verbs, uint32* responses, int count); +status_t multi_audio_control(void* cookie, uint32 op, void* arg, size_t len); +hda_stream* hda_stream_alloc(hda_controller* ctrlr, int type); +status_t hda_stream_setup_buffers(hda_codec* codec, hda_stream* s, const char* desc); +status_t hda_stream_start(hda_controller* ctrlr, hda_stream* s); +status_t hda_stream_stop(hda_controller* ctrlr, hda_stream* s); +status_t hda_stream_check_intr(hda_controller* ctrlr, hda_stream* s); + +#endif /* _HDA_H_ */ Added: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec.c 2007-05-12 18:56:01 UTC (rev 21126) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec.c 2007-05-13 17:04:45 UTC (rev 21127) @@ -0,0 +1,411 @@ +#include "driver.h" +#include "hda_codec_defs.h" + +const char* portcon[] = { + "Jack", "None", "Fixed", "Dual" +}; + +const char* defdev[] = { + "Line Out", "Speaker", "HP Out", "CD", "SPDIF out", "Digital Other Out", "Modem Line Side", + "Modem Hand Side", "Line In", "AUX", "Mic In", "Telephony", "SPDIF In", "Digital Other In", + "Reserved", "Other" +}; + +const char* conntype[] = { + "N/A", "1/8\"", "1/4\"", "ATAPI internal", "RCA", "Optical", "Other Digital", "Other Analog", + "Multichannel Analog (DIN)", "XLR/Professional", "RJ-11 (Modem)", "Combination", "-", "-", "-", "Other" +}; + +const char* jcolor[] = { + "N/A", "Black", "Grey", "Blue", "Green", "Red", "Orange", "Yellow", "Purple", "Pink", + "-", "-", "-", "-", "White", "Other" +}; + +static status_t +hda_widget_get_pm_support(hda_codec* codec, uint32 nid, uint32* pm) +{ + corb_t verb = MAKE_VERB(codec->addr,nid,VID_GET_PARAM,PID_POWERSTATE_SUPPORT); + status_t rc; + uint32 resp; + + if ((rc=hda_send_verbs(codec, &verb, &resp, 1)) == B_OK) { + *pm = 0; + + /* FIXME: Define constants for powermanagement modes */ + if (resp & (1 << 0)) ; + if (resp & (1 << 1)) ; + if (resp & (1 << 2)) ; + if (resp & (1 << 3)) ; + } + + return rc; +} + +static status_t +hda_widget_get_stream_support(hda_codec* codec, uint32 nid, uint32* fmts, uint32* rates) +{ + corb_t verbs[2]; + uint32 resp[2]; + status_t rc; + + verbs[0] = MAKE_VERB(codec->addr,nid,VID_GET_PARAM,PID_STREAM_SUPPORT); + verbs[1] = MAKE_VERB(codec->addr,nid,VID_GET_PARAM,PID_PCM_SUPPORT); + if ((rc=hda_send_verbs(codec, verbs, resp, 2)) == B_OK) { + *fmts = 0; *rates = 0; + + if (resp[2] & (1 << 0)) { + if (resp[1] & (1 << 0)) *rates |= B_SR_8000; + if (resp[1] & (1 << 1)) *rates |= B_SR_11025; + if (resp[1] & (1 << 2)) *rates |= B_SR_16000; + if (resp[1] & (1 << 3)) *rates |= B_SR_22050; + if (resp[1] & (1 << 4)) *rates |= B_SR_32000; + if (resp[1] & (1 << 5)) *rates |= B_SR_44100; + if (resp[1] & (1 << 6)) *rates |= B_SR_48000; + if (resp[1] & (1 << 7)) *rates |= B_SR_88200; + if (resp[1] & (1 << 8)) *rates |= B_SR_96000; + if (resp[1] & (1 << 9)) *rates |= B_SR_176400; + if (resp[1] & (1 << 10)) *rates |= B_SR_192000; + if (resp[1] & (1 << 11)) *rates |= B_SR_384000; + + if (resp[1] & (1<<16)) *fmts |= B_FMT_8BIT_S; + if (resp[1] & (1<<17)) *fmts |= B_FMT_16BIT; + if (resp[1] & (1<<18)) *fmts |= B_FMT_18BIT; + if (resp[1] & (1<<19)) *fmts |= B_FMT_24BIT; + if (resp[1] & (1<<20)) *fmts |= B_FMT_32BIT; + } + + if (resp[0] & (1 << 1)) *fmts |= B_FMT_FLOAT; + if (resp[0] & (1 << 2)) /* Sort out how to handle AC3 */; + } + + return rc; +} + +static status_t +hda_widget_get_amplifier_capabilities(hda_codec* codec, uint32 nid) +{ + status_t rc; + corb_t verb; + uint32 resp; + + verb = MAKE_VERB(codec->addr,nid,VID_GET_PARAM,PID_OUTPUT_AMP_CAP); + if ((rc=hda_send_verbs(codec, &verb, &resp, 1)) == B_OK && resp != 0) { + dprintf("\tAMP: Mute: %s, step size: %ld, # steps: %ld, offset: %ld\n", + (resp & (1 << 31)) ? "supported" : "N/A", + (resp >> 16) & 0x7F, + (resp >> 8) & 0x7F, + resp & 0x7F); + } + + return rc; +} + +static status_t +hda_codec_parse_afg(hda_codec* codec, uint32 afg_nid) +{ + corb_t verbs[6]; + uint32 resp[6]; + uint32 widx; + + hda_widget_get_stream_support(codec, afg_nid, &codec->afg_deffmts, &codec->afg_defrates); + hda_widget_get_pm_support(codec, afg_nid, &codec->afg_defpm); + + verbs[0] = MAKE_VERB(codec->addr,afg_nid,VID_GET_PARAM,PID_AUDIO_FG_CAP); + verbs[1] = MAKE_VERB(codec->addr,afg_nid,VID_GET_PARAM,PID_GPIO_COUNT); + verbs[2] = MAKE_VERB(codec->addr,afg_nid,VID_GET_PARAM,PID_SUBORD_NODE_COUNT); + + if (hda_send_verbs(codec, verbs, resp, 3) == B_OK) { + dprintf("%s: Output delay: %ld samples, Input delay: %ld samples, Beep Generator: %s\n", __func__, + resp[0] & 0xf, (resp[0] >> 8) & 0xf, (resp[0] & (1 << 16)) ? "yes" : "no"); + + dprintf("%s: #GPIO: %ld, #GPO: %ld, #GPI: %ld, unsol: %s, wake: %s\n", __func__, + resp[4] & 0xFF, (resp[1] >> 8) & 0xFF, (resp[1] >> 16) & 0xFF, + (resp[1] & (1 << 30)) ? "yes" : "no", + (resp[1] & (1 << 31)) ? "yes" : "no"); + + codec->afg_wid_start = resp[2] >> 16; + codec->afg_wid_count = resp[2] & 0xFF; + + codec->afg_widgets = calloc(sizeof(*codec->afg_widgets), codec->afg_wid_count); + if (codec->afg_widgets == NULL) { + dprintf("ERROR: Not enough memory!\n"); + return B_NO_MEMORY; + } + + /* Only now mark the AFG as found and used */ + codec->afg_nid = afg_nid; + + /* Iterate over all Widgets and collect info */ + for (widx=0; widx < codec->afg_wid_count; widx++) { + uint32 wid = codec->afg_wid_start + widx; + char buf[256]; + int off; + + verbs[0] = MAKE_VERB(codec->addr,wid,VID_GET_PARAM,PID_AUDIO_WIDGET_CAP); + verbs[1] = MAKE_VERB(codec->addr,wid,VID_GET_PARAM,PID_CONNLIST_LEN); + hda_send_verbs(codec, verbs, resp, 2); + + codec->afg_widgets[widx].type = resp[0] >> 20; + codec->afg_widgets[widx].num_inputs = resp[1] & 0x7F; + + off = 0; + if (resp[0] & (1 << 11)) off += sprintf(buf+off, "[L-R Swap] "); + if (resp[0] & (1 << 10)) off += sprintf(buf+off, "[Power] "); + if (resp[0] & (1 << 9)) off += sprintf(buf+off, "[Digital] "); + if (resp[0] & (1 << 7)) off += sprintf(buf+off, "[Unsol Capable] "); + if (resp[0] & (1 << 6)) off += sprintf(buf+off, "[Proc Widget] "); + if (resp[0] & (1 << 5)) off += sprintf(buf+off, "[Stripe] "); + if (resp[0] & (1 << 4)) off += sprintf(buf+off, "[Format Override] "); + if (resp[0] & (1 << 3)) off += sprintf(buf+off, "[Amp Param Override] "); + if (resp[0] & (1 << 2)) off += sprintf(buf+off, "[Out Amp] "); + if (resp[0] & (1 << 1)) off += sprintf(buf+off, "[In Amp] "); + if (resp[0] & (1 << 0)) off += sprintf(buf+off, "[Stereo] "); + + switch(codec->afg_widgets[widx].type) { + case WT_AUDIO_OUTPUT: + dprintf("%ld:\tAudio Output\n", wid); + hda_widget_get_stream_support(codec, wid, + &codec->afg_widgets[widx].d.input.formats, + &codec->afg_widgets[widx].d.input.rates); + hda_widget_get_amplifier_capabilities(codec, wid); + break; + case WT_AUDIO_INPUT: + dprintf("%ld:\tAudio Input\n", wid); + hda_widget_get_stream_support(codec, wid, + &codec->afg_widgets[widx].d.input.formats, + &codec->afg_widgets[widx].d.input.rates); + hda_widget_get_amplifier_capabilities(codec, wid); + break; + case WT_AUDIO_MIXER: + dprintf("%ld:\tAudio Mixer\n", wid); + hda_widget_get_amplifier_capabilities(codec, wid); + break; + case WT_AUDIO_SELECTOR: + dprintf("%ld:\tAudio Selector\n", wid); + hda_widget_get_amplifier_capabilities(codec, wid); + break; + case WT_PIN_COMPLEX: + dprintf("%ld:\tPin Complex\n", wid); + verbs[0] = MAKE_VERB(codec->addr,wid,VID_GET_PARAM,PID_PIN_CAP); + if (hda_send_verbs(codec, verbs, resp, 1) == B_OK) { + codec->afg_widgets[widx].d.pin.input = resp[0] & (1 << 5); + codec->afg_widgets[widx].d.pin.output = resp[0] & (1 << 4); + } + + verbs[0] = MAKE_VERB(codec->addr,wid,VID_GET_CFGDEFAULT,0); + if (hda_send_verbs(codec, verbs, resp, 1) == B_OK) { + codec->afg_widgets[widx].d.pin.device = (resp[0] >> 20) & 0xF; + dprintf("\t%s, %s, %s, %s\n", + portcon[resp[0] >> 30], + defdev[codec->afg_widgets[widx].d.pin.device], + conntype[(resp[0] >> 16) & 0xF], + jcolor[(resp[0] >> 12) & 0xF]); + } + + hda_widget_get_amplifier_capabilities(codec, wid); + break; + case WT_POWER: + dprintf("%ld:\tPower\n", wid); + break; + case WT_VOLUME_KNOB: + dprintf("%ld:\tVolume Knob\n", wid); + break; + case WT_BEEP_GENERATOR: + dprintf("%ld:\tBeep Generator\n", wid); + break; + case WT_VENDOR_DEFINED: + dprintf("%ld:\tVendor Defined\n", wid); + break; + default: /* Reserved */ + break; + } + + dprintf("\t%s\n", buf); + + hda_widget_get_pm_support(codec, wid, &codec->afg_widgets[widx].pm); + + if (codec->afg_widgets[widx].num_inputs) { + int idx; + + off = 0; + + if (codec->afg_widgets[widx].num_inputs > 1) { + verbs[0] = MAKE_VERB(codec->addr,wid,VID_GET_CONNSEL,0); + if (hda_send_verbs(codec, verbs, resp, 1) == B_OK) + codec->afg_widgets[widx].active_input = resp[0] & 0xFF; + else + codec->afg_widgets[widx].active_input = -1; + } else + codec->afg_widgets[widx].active_input = -1; + + for (idx=0; idx < codec->afg_widgets[widx].num_inputs; idx ++) { + if (!(idx % 4)) { + verbs[0] = MAKE_VERB(codec->addr,wid,VID_GET_CONNLENTRY,idx); + if (hda_send_verbs(codec, verbs, resp, 1) != B_OK) { + dprintf("%s: Error parsing inputs for widget %ld!\n", __func__, wid); + break; + } + } + + if (idx != codec->afg_widgets[widx].active_input) + off += sprintf(buf+off, "%ld ", (resp[0] >> (8*(idx%4))) & 0xFF); + else + off += sprintf(buf+off, "(%ld) ", (resp[0] >> (8*(idx%4))) & 0xFF); + + codec->afg_widgets[widx].inputs[idx] = (resp[0] >> (8*(idx%4))) & 0xFF; + } + + dprintf("\t[ %s]\n", buf); + } + } + } + + return B_OK; +} + +static uint32 +hda_codec_afg_find_dac_path(hda_codec* codec, uint32 wid, uint32 depth) +{ + int widx = wid - codec->afg_wid_start; + int idx; + + switch(codec->afg_widgets[widx].type) { + case WT_AUDIO_OUTPUT: + return wid; + + case WT_AUDIO_MIXER: + for (idx=0; idx < codec->afg_widgets[widx].num_inputs; idx++) { + if (hda_codec_afg_find_dac_path(codec, codec->afg_widgets[widx].inputs[idx], depth +1)) { + if (codec->afg_widgets[widx].active_input == -1) + codec->afg_widgets[widx].active_input = idx; + + return codec->afg_widgets[widx].inputs[idx]; + } + } + break; + + case WT_AUDIO_SELECTOR: + { + int idx = codec->afg_widgets[widx].active_input; + if (idx != -1) { + uint32 wid = codec->afg_widgets[widx].inputs[idx]; + if (hda_codec_afg_find_dac_path(codec, wid, depth +1)) { + return wid; + } + } + } + break; + + default: + break; + } + + return 0; +} + +static void +hda_codec_audiofg_new(hda_codec* codec, uint32 afg_nid) +{ + uint32 idx; + + /* FIXME: Bail if this isn't the first Audio Function Group we find... */ + if (codec->afg_nid != 0) { + dprintf("SORRY: This driver currently only supports a single Audio Function Group!\n"); + return; + } + + /* Parse all widgets in Audio Function Group */ + hda_codec_parse_afg(codec, afg_nid); + + /* Try to locate all output channels */ + for (idx=0; idx < codec->afg_wid_count; idx++) { + uint32 iidx, output_wid = 0; + + if (codec->afg_widgets[idx].type != WT_PIN_COMPLEX) + continue; + if (!codec->afg_widgets[idx].d.pin.output) + continue; + if (codec->afg_widgets[idx].d.pin.device != PIN_DEV_HP_OUT && + codec->afg_widgets[idx].d.pin.device != PIN_DEV_SPEAKER && + codec->afg_widgets[idx].d.pin.device != PIN_DEV_LINE_OUT) + continue; + + iidx = codec->afg_widgets[idx].active_input; + if (iidx != -1) { + output_wid = hda_codec_afg_find_dac_path(codec, codec->afg_widgets[idx].inputs[iidx], 0); + } else { + for (iidx=0; iidx < codec->afg_widgets[idx].num_inputs; iidx++) { + output_wid = hda_codec_afg_find_dac_path(codec, codec->afg_widgets[idx].inputs[iidx], 0); + if (output_wid) { + corb_t verb = MAKE_VERB(codec->addr,idx+codec->afg_wid_start,VID_SET_CONNSEL,iidx); + uint32 resp; + if (hda_send_verbs(codec, &verb, &resp, 1) == B_OK) + break; + } + } + } + + if (output_wid) { + corb_t verb; + uint32 resp; + + codec->playback_stream->pin_wid = idx + codec->afg_wid_start; + codec->playback_stream->io_wid = output_wid; + dprintf("%s: Found output PIN (%s) connected to output CONV wid:%ld\n", + __func__, defdev[codec->afg_widgets[idx].d.pin.device], output_wid); + + /* FIXME: Force Pin Widget to unmute */ + verb = MAKE_VERB(codec->addr, codec->playback_stream->pin_wid, + VID_SET_AMPGAINMUTE, (1 << 15) | (1 << 13) | (1 << 12)); + hda_send_verbs(codec, &verb, &resp, 1); + break; + } + } +} + +hda_codec* +hda_codec_new(hda_controller* ctrlr, uint32 cad) +{ + hda_codec* codec = calloc(sizeof(hda_codec),1); + if (codec) { + uint32 responses[3]; + corb_t verbs[3]; + status_t rc; + uint32 nid; + + codec->ctrlr = ctrlr; + codec->addr = cad; + codec->response_count = 0; + codec->response_sem = create_sem(0, "hda_codec_response_sem"); + codec->afg_nid = 0; + ctrlr->codecs[cad] = codec; + + /* Setup playback/record streams for Multi Audio API */ + codec->playback_stream = hda_stream_alloc(ctrlr, STRM_PLAYBACK); + codec->record_stream = hda_stream_alloc(ctrlr, STRM_RECORD); + + verbs[0] = MAKE_VERB(cad,0,VID_GET_PARAM,PID_VENDORID); + verbs[1] = MAKE_VERB(cad,0,VID_GET_PARAM,PID_REVISIONID); + verbs[2] = MAKE_VERB(cad,0,VID_GET_PARAM,PID_SUBORD_NODE_COUNT); + + if (hda_send_verbs(codec, verbs, responses, 3) == B_OK) { + dprintf("Codec %ld Vendor: %04lx Product: %04lx\n", + cad, responses[0] >> 16, responses[0] & 0xFFFF); + + for (nid=responses[2] >> 16; + nid < (responses[2] >> 16) + (responses[2] & 0xFF); + nid++) { + uint32 resp; + verbs[0] = MAKE_VERB(cad,nid,VID_GET_PARAM,PID_FUNCGRP_TYPE); + + if ((rc=hda_send_verbs(codec, verbs, &resp, 1)) == B_OK && (resp&0xFF) == 1) { + /* Found an Audio Function Group! */ + hda_codec_audiofg_new(codec, nid); + } else + dprintf("%s: FG %ld: %s\n", __func__, nid, strerror(rc)); + } + } + } + + return codec; +} Added: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec_defs.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec_defs.h 2007-05-12 18:56:01 UTC (rev 21126) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec_defs.h 2007-05-13 17:04:45 UTC (rev 21127) @@ -0,0 +1,130 @@ +#ifndef HDA_CODEC_H +#define HDA_CODEC_H + +typedef enum { + WT_AUDIO_OUTPUT = 0, + WT_AUDIO_INPUT = 1, + WT_AUDIO_MIXER = 2, + WT_AUDIO_SELECTOR = 3, + WT_PIN_COMPLEX = 4, + WT_POWER = 5, + WT_VOLUME_KNOB = 6, + WT_BEEP_GENERATOR = 7, + WT_VENDOR_DEFINED = 15 +} hda_widget_type; + + +typedef enum { + PIN_DEV_LINE_OUT = 0, + PIN_DEV_SPEAKER, + PIN_DEV_HP_OUT, + PIN_DEV_CD, + PIN_DEV_SPDIF_OUT, + PIN_DEV_DIGITAL_OTHER_OUT, + PIN_DEV_MODEM_LINE_SIDE, + PIN_DEV_MODEM_HAND_SIDE, + PIN_DEV_LINE_IN, + PIN_DEV_AUX, + PIN_DEV_MIC_IN, + PIN_DEV_TELEPHONY, + PIN_DEV_SPDIF_IN, + PIN_DEV_DIGITAL_OTHER_IN, + PIN_DEV_RESERVED, + PIN_DEV_OTHER +} pin_dev_type; + + +/* Verb Helper Macro */ +#define MAKE_VERB(cad,nid,vid,payl) (((cad)<<28)|((nid)<<20)|(vid)|(payl)) + +/* Verb IDs */ +#define VID_GET_PARAM 0xF0000 +#define VID_GET_CONNSEL 0xF0100 +#define VID_SET_CONNSEL 0x70100 +#define VID_GET_CONNLENTRY 0xF0200 +#define VID_GET_PROCSTATE 0xF0300 +#define VID_SET_PROCSTATE 0x70300 +#define VID_GET_COEFFIDX 0xD0000 +#define VID_SET_COEFFIDX 0x50000 +#define VID_GET_PROCCOEFF 0xC0000 +#define VID_SET_PROCCOEFF 0x40000 +#define VID_GET_AMPGAINMUTE 0xB0000 +#define VID_SET_AMPGAINMUTE 0x30000 +#define VID_GET_CONVFORMAT 0xA0000 +#define VID_SET_CONVFORMAT 0x20000 +#define VID_GET_DIGCVTCTRL 0xF0D00 +#define VID_SET_DIGCVTCTRL1 0x70D00 +#define VID_SET_DIGCVTCTRL2 0x70E00 +#define VID_GET_POWERSTATE 0xF0500 +#define VID_SET_POWERSTATE 0x70500 +#define VID_GET_CVTSTRCHN 0xF0600 +#define VID_SET_CVTSTRCHN 0x70600 +#define VID_GET_SDISELECT 0xF0400 +#define VID_SET_SDISELECT 0x70400 +#define VID_GET_PINWCTRL 0xF0700 +#define VID_SET_PINWCTRL 0x70700 +#define VID_GET_UNSOLRESP 0xF0800 +#define VID_SET_UNSOLRESP 0x70800 +#define VID_GET_PINSENSE 0xF0900 +#define VID_SET_PINSENSE 0x70900 +#define VID_GET_EAPDBTL_EN 0xF0C00 +#define VID_SET_EAPDBTL_EN 0x70C00 +#define VID_GET_GPIDATA 0xF1000 +#define VID_SET_GPIDATA 0x71000 +#define VID_GET_GPIWAKE_EN 0xF1100 +#define VID_SET_GPIWAKE_EN 0x71100 +#define VID_GET_GPIUNSOL 0xF1200 +#define VID_SET_GPIUNSOL 0x71200 +#define VID_GET_GPISTICKY 0xF1300 +#define VID_SET_GPISTICKY 0x71300 +#define VID_GET_GPODATA 0xF1400 +#define VID_SET_GPODATA 0x71400 +#define VID_GET_GPIODATA 0xF1500 +#define VID_SET_GPIODATA 0x71500 +#define VID_GET_GPIO_EN 0xF1600 +#define VID_SET_GPIO_EN 0x71600 +#define VID_GET_GPIO_DIR 0xF1700 +#define VID_SET_GPIO_DIR 0x71700 +#define VID_GET_GPIOWAKE_EN 0xF1800 +#define VID_SET_GPIOWAKE_EN 0x71800 +#define VID_GET_GPIOUNSOL_EN 0xF1900 +#define VID_SET_GPIOUNSOL_EN 0x71900 +#define VID_GET_GPIOSTICKY 0xF1A00 +#define VID_SET_GPIOSTICKY 0x71A00 +#define VID_GET_BEEPGEN 0xF0A00 +#define VID_SET_BEEPGEN 0x70A00 +#define VID_GET_VOLUMEKNOB 0xF0F00 +#define VID_SET_VOLUMEKNOB 0x70F00 +#define VID_GET_SUBSYSTEMID 0xF2000 +#define VID_SET_SUBSYSTEMID1 0x72000 +#define VID_SET_SUBSYSTEMID2 0x72100 +#define VID_SET_SUBSYSTEMID3 0x72200 +#define VID_SET_SUBSYSTEMID4 0x72300 +#define VID_GET_CFGDEFAULT 0xF1C00 +#define VID_SET_CFGDEFAULT1 0x71C00 +#define VID_SET_CFGDEFAULT2 0x71D00 +#define VID_SET_CFGDEFAULT3 0x71E00 +#define VID_SET_CFGDEFAULT4 0x71F00 +#define VID_GET_STRIPECTRL 0xF2400 +#define VID_SET_STRIPECTRL 0x72000 +#define VID_FUNCTION_RESET 0x7FF00 + +/* Parameter IDs */ +#define PID_VENDORID 0x00 +#define PID_REVISIONID 0x02 +#define PID_SUBORD_NODE_COUNT 0x04 +#define PID_FUNCGRP_TYPE 0x05 +#define PID_AUDIO_FG_CAP 0x08 +#define PID_AUDIO_WIDGET_CAP 0x09 +#define PID_PCM_SUPPORT 0x0A +#define PID_STREAM_SUPPORT 0x0B +#define PID_PIN_CAP 0x0C +#define PID_INPUT_AMP_CAP 0x0D +#define PID_CONNLIST_LEN 0x0E +#define PID_POWERSTATE_SUPPORT 0x0F +#define PID_PROCESSING_CAP 0x10 +#define PID_GPIO_COUNT 0x11 +#define PID_OUTPUT_AMP_CAP 0x12 +#define PID_VOLUMEKNOB_CAP 0x13 + +#endif /* HDA_CODEC_H */ Added: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c 2007-05-12 18:56:01 UTC (rev 21126) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c 2007-05-13 17:04:45 UTC (rev 21127) @@ -0,0 +1,537 @@ +#include "driver.h" +#include "hda_controller_defs.h" +#include "hda_codec_defs.h" + +#include "driver.h" + +hda_stream* +hda_stream_alloc(hda_controller* ctrlr, int type) +{ + hda_stream* s = calloc(1, sizeof(hda_stream)); + if (s != NULL) { + s->buffer_area = B_ERROR; + s->bdl_area = B_ERROR; + + switch(type) { + case STRM_PLAYBACK: + s->buffer_ready_sem = create_sem(0, "hda_playback_sem"); + s->id = 1; + s->off = (ctrlr->num_input_streams * HDAC_SDSIZE); + ctrlr->streams[ctrlr->num_input_streams] = s; + break; + + case STRM_RECORD: + s->buffer_area = B_ERROR; + s->bdl_area = B_ERROR; + s->buffer_ready_sem = create_sem(0, "hda_record_sem"); + s->id = 2; + s->off = 0; + ctrlr->streams[0] = s; + break; + + default: + dprintf("%s: Unknown stream type %d!\n", __func__, type); + free(s); + s = NULL; + break; + } + } + + return s; +} + +status_t +hda_stream_start(hda_controller* ctrlr, hda_stream* s) +{ + OREG8(ctrlr,s->off,CTL0) |= CTL0_RUN; + + while(!(OREG8(ctrlr,s->off,CTL0) & CTL0_RUN)) + snooze(1); + + s->running = true; + + return B_OK; +} + +status_t +hda_stream_check_intr(hda_controller* ctrlr, hda_stream* s) +{ + if (s->running) { + uint8 sts = OREG8(ctrlr,s->off,STS); + if (sts) { + OREG8(ctrlr,s->off,STS) = sts; + + s->played_real_time = system_time(); + s->played_frames_count += s->buffer_length; + release_sem_etc(s->buffer_ready_sem, 1, B_DO_NOT_RESCHEDULE); + } + } + + return B_OK; +} + +status_t +hda_stream_stop(hda_controller* ctrlr, hda_stream* s) +{ + OREG8(ctrlr,s->off,CTL0) &= ~CTL0_RUN; + + while(OREG8(ctrlr,s->off,CTL0) & CTL0_RUN) + snooze(1); + + s->running = false; + + return B_OK; +} + +status_t +hda_stream_setup_buffers(hda_codec* codec, hda_stream* s, const char* desc) +{ + uint32 buffer_size, buffer_pa, alloc; + uint32 response[2], idx; + physical_entry pe; + bdl_entry_t* bdl; + corb_t verb[2]; + uint8* buffer; + status_t rc; + uint16 wfmt; + + /* Clear previously allocated memory */ + if (s->buffer_area >= B_OK) { + delete_area(s->buffer_area); + s->buffer_area = B_ERROR; + } + + if (s->bdl_area >= B_OK) { + delete_area(s->bdl_area); + s->bdl_area = B_ERROR; + } + + /* Calculate size of buffer (aligned to 128 bytes) */ + buffer_size = s->sample_size * s->num_channels * s->buffer_length; + buffer_size = (buffer_size + 127) & (~127); + + /* Calculate total size of all buffers (aligned to size of B_PAGE_SIZE) */ + alloc = buffer_size * s->num_buffers; + alloc = (alloc + B_PAGE_SIZE - 1) & (~(B_PAGE_SIZE -1)); + + /* Allocate memory for buffers */ + s->buffer_area = create_area("hda_buffers", (void**)&buffer, B_ANY_KERNEL_ADDRESS, alloc, B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA); + if (s->buffer_area < B_OK) + return s->buffer_area; + + /* Get the physical address of memory */ + rc = get_memory_map(buffer, alloc, &pe, 1); + if (rc != B_OK) { + delete_area(s->buffer_area); + return rc; + } + + buffer_pa = (uint32)pe.address; + [... truncated: 916 lines follow ...] From korli at mail.berlios.de Sun May 13 19:47:24 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Sun, 13 May 2007 19:47:24 +0200 Subject: [Haiku-commits] r21128 - in haiku/trunk: headers/private/print src/apps/expander src/apps/soundrecorder src/servers/app Message-ID: <200705131747.l4DHlOYh022735@sheep.berlios.de> Author: korli Date: 2007-05-13 19:47:23 +0200 (Sun, 13 May 2007) New Revision: 21128 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21128&view=rev Modified: haiku/trunk/headers/private/print/FolderWatcher.h haiku/trunk/src/apps/expander/DirectoryFilePanel.h haiku/trunk/src/apps/expander/GenericThread.h haiku/trunk/src/apps/soundrecorder/DrawingTidbits.h haiku/trunk/src/servers/app/EventDispatcher.h haiku/trunk/src/servers/app/FontFamily.h haiku/trunk/src/servers/app/HashTable.h haiku/trunk/src/servers/app/ScreenManager.h Log: cleanup, fixed some warnings Modified: haiku/trunk/headers/private/print/FolderWatcher.h =================================================================== --- haiku/trunk/headers/private/print/FolderWatcher.h 2007-05-13 17:04:45 UTC (rev 21127) +++ haiku/trunk/headers/private/print/FolderWatcher.h 2007-05-13 17:47:23 UTC (rev 21128) @@ -42,6 +42,7 @@ class FolderListener { public: + virtual ~FolderListener() {}; // entry created or moved into folder virtual void EntryCreated(node_ref* node, entry_ref* entry) {}; // entry removed from folder (or moved to another folder) Modified: haiku/trunk/src/apps/expander/DirectoryFilePanel.h =================================================================== --- haiku/trunk/src/apps/expander/DirectoryFilePanel.h 2007-05-13 17:04:45 UTC (rev 21127) +++ haiku/trunk/src/apps/expander/DirectoryFilePanel.h 2007-05-13 17:47:23 UTC (rev 21128) @@ -49,6 +49,7 @@ uint32 node_flavors = 0, bool allow_multiple_selection = true, BMessage *message = 0, BRefFilter * = 0, bool modal = false, bool hide_when_done = true); + virtual ~DirectoryFilePanel() {}; virtual void SelectionChanged(void); virtual void Show(); Modified: haiku/trunk/src/apps/expander/GenericThread.h =================================================================== --- haiku/trunk/src/apps/expander/GenericThread.h 2007-05-13 17:04:45 UTC (rev 21127) +++ haiku/trunk/src/apps/expander/GenericThread.h 2007-05-13 17:47:23 UTC (rev 21128) @@ -24,7 +24,7 @@ status_t Kill(void); void ExitWithReturnValue(status_t a_return_value); - status_t SetExitCallback(void(* a_callback)(void *), void * a_data); + status_t SetExitCallback(void (* a_callback)(void *), void * a_data); status_t WaitForThread(status_t * a_exit_value); status_t Rename(char * a_name); Modified: haiku/trunk/src/apps/soundrecorder/DrawingTidbits.h =================================================================== --- haiku/trunk/src/apps/soundrecorder/DrawingTidbits.h 2007-05-13 17:04:45 UTC (rev 21127) +++ haiku/trunk/src/apps/soundrecorder/DrawingTidbits.h 2007-05-13 17:47:23 UTC (rev 21128) @@ -47,4 +47,5 @@ void ReplaceColor(BBitmap *bitmap, rgb_color from, rgb_color to); void ReplaceTransparentColor(BBitmap *bitmap, rgb_color with); -#endif \ No newline at end of file +#endif + Modified: haiku/trunk/src/servers/app/EventDispatcher.h =================================================================== --- haiku/trunk/src/servers/app/EventDispatcher.h 2007-05-13 17:04:45 UTC (rev 21127) +++ haiku/trunk/src/servers/app/EventDispatcher.h 2007-05-13 17:47:23 UTC (rev 21128) @@ -56,6 +56,7 @@ class EventFilter { public: + virtual ~EventFilter() {}; virtual filter_result Filter(BMessage* event, EventTarget** _target, int32* _viewToken = NULL, BMessage* latestMouseMoved = NULL) = 0; virtual void RemoveTarget(EventTarget* target); Modified: haiku/trunk/src/servers/app/FontFamily.h =================================================================== --- haiku/trunk/src/servers/app/FontFamily.h 2007-05-13 17:04:45 UTC (rev 21127) +++ haiku/trunk/src/servers/app/FontFamily.h 2007-05-13 17:47:23 UTC (rev 21128) @@ -49,6 +49,7 @@ : fHash(familyID | (styleID << 16UL)) { } + virtual ~FontKey() {}; virtual uint32 Hash() const { return fHash; } Modified: haiku/trunk/src/servers/app/HashTable.h =================================================================== --- haiku/trunk/src/servers/app/HashTable.h 2007-05-13 17:04:45 UTC (rev 21127) +++ haiku/trunk/src/servers/app/HashTable.h 2007-05-13 17:47:23 UTC (rev 21128) @@ -14,6 +14,7 @@ class Hashable { public: + virtual ~Hashable() {}; virtual uint32 Hash() const = 0; virtual bool CompareTo(Hashable& hashable) const = 0; }; Modified: haiku/trunk/src/servers/app/ScreenManager.h =================================================================== --- haiku/trunk/src/servers/app/ScreenManager.h 2007-05-13 17:04:45 UTC (rev 21127) +++ haiku/trunk/src/servers/app/ScreenManager.h 2007-05-13 17:47:23 UTC (rev 21128) @@ -24,6 +24,7 @@ class ScreenOwner { public: + virtual ~ScreenOwner() {}; virtual void ScreenRemoved(Screen* screen) = 0; virtual void ScreenAdded(Screen* screen) = 0; From korli at mail.berlios.de Sun May 13 21:17:09 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Sun, 13 May 2007 21:17:09 +0200 Subject: [Haiku-commits] r21129 - haiku/trunk/src/add-ons/kernel/drivers/audio Message-ID: <200705131917.l4DJH9qS028014@sheep.berlios.de> Author: korli Date: 2007-05-13 21:17:08 +0200 (Sun, 13 May 2007) New Revision: 21129 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21129&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/Jamfile Log: sorted correctly hda :) Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/Jamfile 2007-05-13 17:47:23 UTC (rev 21128) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/Jamfile 2007-05-13 19:17:08 UTC (rev 21129) @@ -3,8 +3,8 @@ SubInclude HAIKU_TOP src add-ons kernel drivers audio ac97 ; SubInclude HAIKU_TOP src add-ons kernel drivers audio echo ; SubInclude HAIKU_TOP src add-ons kernel drivers audio emuxki ; +SubInclude HAIKU_TOP src add-ons kernel drivers audio hda ; SubInclude HAIKU_TOP src add-ons kernel drivers audio module_driver ; SubInclude HAIKU_TOP src add-ons kernel drivers audio sis7018 ; SubInclude HAIKU_TOP src add-ons kernel drivers audio usb_audio ; -SubInclude HAIKU_TOP src add-ons kernel drivers audio hda ; From axeld at mail.berlios.de Sun May 13 21:33:43 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 13 May 2007 21:33:43 +0200 Subject: [Haiku-commits] r21130 - in haiku/trunk/src/preferences: keyboard keymap mouse virtualmemory Message-ID: <200705131933.l4DJXhwn029239@sheep.berlios.de> Author: axeld Date: 2007-05-13 21:33:43 +0200 (Sun, 13 May 2007) New Revision: 21130 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21130&view=rev Modified: haiku/trunk/src/preferences/keyboard/Keyboard.rdef haiku/trunk/src/preferences/keymap/Keymap.rdef haiku/trunk/src/preferences/mouse/Mouse.rdef haiku/trunk/src/preferences/virtualmemory/VirtualMemory.rdef Log: * Committed zuMi's icons as they already have a place on the image. * I'm not sure, but neither Joysticks nor PowerStatus is rendered within Haiku (FlatIconImporter::_ParseSections() - error parsing shapes: Out of memory), therefore, I didn't commit those yet. * Also, Joysticks already seem to have a vector icon, but that shows the same error - stippi? :-) Modified: haiku/trunk/src/preferences/keyboard/Keyboard.rdef =================================================================== --- haiku/trunk/src/preferences/keyboard/Keyboard.rdef 2007-05-13 19:17:08 UTC (rev 21129) +++ haiku/trunk/src/preferences/keyboard/Keyboard.rdef 2007-05-13 19:33:43 UTC (rev 21130) @@ -15,9 +15,29 @@ internal = 0, short_info = "Keyboard", - long_info = "Keyboard ?2004-2006 Haiku" + long_info = "Keyboard ?2004-2007 Haiku" }; +#ifdef HAIKU_TARGET_PLATFORM_HAIKU + +resource vector_icon { + $"6E63696605020016023910813A2974BB43733A501C4A60D94AC7F400E9FFB902" + $"001602B8513BB55C0A38B9DABBC2B74A98024B8D270066FF9002011603BC39E2" + $"364286B516B5BB0AE64ACEF94A7E0500FF56E5FFC1050004006D0A0202392E36" + $"2C3C303D2A402C3A2808023C2D3E3008054B3148354C344C37513408032F3D35" + $"3A333F0802323C343D0004414441444045454544464644434242434441474348" + $"4246440A04445E4ECAE758C6EB504B0A0434543849444E445C0A04445C444E4E" + $"4550500A043849444E4E454240160A030309080730180801178322040A000107" + $"2018080A0101082018080A0201092018080A030200011001178100040A040106" + $"2028100A030309080730281001178322040A0001072028100A0101082028100A" + $"0201092028100A0301021001178122040A030309080730101801178422040A00" + $"01072010180A0101082010180A0201092010180A030203041001178100040A04" + $"0106000A03030908071001178322040A000107000A010108000A020109000A03" + $"0105100117810004" +}; + +#else // HAIKU_TARGET_PLATFORM_HAIKU + resource large_icon { $"FFFFFFFFFFFFFFFFFFFFFFFFFFFF000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" $"FFFFFFFFFFFFFFFFFFFFFFFFFF001B1C1B0000FFFFFFFFFFFFFFFFFFFFFFFFFF" @@ -72,7 +92,7 @@ $"FFFFFF00000E0F0FFFFFFFFFFFFFFFFF" }; -resource file_types message; +#endif // HAIKU_TARGET_PLATFORM_HAIKU resource(601, "key_bmap") #'bits' array { $"424D14050000000000003A000000280000001100000012000000010018000000" Modified: haiku/trunk/src/preferences/keymap/Keymap.rdef =================================================================== --- haiku/trunk/src/preferences/keymap/Keymap.rdef 2007-05-13 19:17:08 UTC (rev 21129) +++ haiku/trunk/src/preferences/keymap/Keymap.rdef 2007-05-13 19:33:43 UTC (rev 21130) @@ -22,6 +22,33 @@ "types" = "application/x-vnd.Be-kmap" }; +#ifdef HAIKU_TARGET_PLATFORM_HAIKU + +resource vector_icon { + $"6E63696605020016023910813A2974BB43733A501C4B20D94AA7F400E9FFB902" + $"001602B82588B66C3639EE80BB7BCD4B41FC4B6A3B0066FF9002011603BC39E2" + $"364286B516B5BB0AE64B8EF94A7E0500FF56E5FFC1050004006D0E0A04525E5C" + $"CAE766C6EB5E4B0A0442544648524E525C0A04525C524E5C445E500A04464852" + $"4E5C44503E0A02B8DABA5FB913BA320A02BA25B92DB942BA0F0803B70BBCFDB8" + $"C7BB84B7BBBB82000CC151BD52C151BD52C151BD52C0B0BDBEC0B0BDBEC105BD" + $"83C0EEBD21C116BD40C0C6BD01C00CBD38C022BD28BFCCBD68BFEBBDBDBFCBBD" + $"A7C016BDDBC08ABDBEC08ABDBEC072BDD0C080BE0CC065BDF9C0ADBE2CC19CBD" + $"CEC15EBE0BC20ABD6244BCC9C1A4BCF5C0ABBC64BF88BD14BFD6BCC6BEE4BDB8" + $"BFE6BE44BFB33CC052BE81C100BE6EC0E2BE7AC100BE6E0406FA0FBD8FC04CBC" + $"96BFB3BD553FBCDC3FBDCE3FBE873FBE3BBF8DBED4BF27BE94BE7ABEDABEB4BE" + $"4EBE41BDB5BE94BDCFBE7ABDB5BE940802C63340C74DC0670802C5C6C01FC6D8" + $"C0CB0802C791BFECC5F9C0E50802C58DC0A5C712BFA00007C361C29EC361C29E" + $"C33FC2BBC39AC332C35FC30EC3D5C357C496C30FC468C33EC4C4C2E1C463C25D" + $"C4D4C29EC4D4C29EC537C245C515C26DC558C21DC50AC1AA4EC1DDC4C1C177C4" + $"4945C461C1A9C449450E0A030303020130001001178322040A0001012000100A" + $"0101022000100A0201032000100A030303020130101801178322040A00010120" + $"10180A0101022010180A0201032010180A040100000A03030302011001178322" + $"040A000101000A010102000A020103000A030A0D090A0B0C0807060504100117" + $"812204" +}; + +#else // HAIKU_TARGET_PLATFORM_HAIKU + resource large_icon { $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00FFFFFFFFFFFFFFFFFFFFFFFFFFFF" $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF003F0000FFFFFFFFFFFFFFFFFFFFFFFF" @@ -76,6 +103,8 @@ $"FFFFFFFFFF00000F0FFFFFFFFFFFFFFF" }; +#endif // HAIKU_TARGET_PLATFORM_HAIKU + resource(0, "BEOS:L:application/x-vnd.be-kmap") #'ICON' array { $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00FFFFFFFFFFFFFFFFFFFFFF" Modified: haiku/trunk/src/preferences/mouse/Mouse.rdef =================================================================== --- haiku/trunk/src/preferences/mouse/Mouse.rdef 2007-05-13 19:17:08 UTC (rev 21129) +++ haiku/trunk/src/preferences/mouse/Mouse.rdef 2007-05-13 19:33:43 UTC (rev 21130) @@ -1,8 +1,6 @@ resource app_signature "application/x-vnd.Haiku-Mouse"; -resource file_types message; - resource app_flags B_SINGLE_LAUNCH; resource app_version { @@ -17,9 +15,31 @@ internal = 0, short_info = "Mouse", - long_info = "Mouse ?2002-2006 Haiku" + long_info = "Mouse ?2002-2007 Haiku" }; +#ifdef HAIKU_TARGET_PLATFORM_HAIKU + +resource vector_icon { + $"6E636966080301000002000202AC6DA33A810CBCBF0CAEA9C248C4E546BB2A00" + $"01000000FF010000FF020016023D2328BA287D3B40A23E5D334837CE48FA2500" + $"69FF01020116023E40000000000000003E400048000048000000FBFFC0020106" + $"02B832FBBACA8D3ACA8DB832FB48D3BB493902FFBEBEBE0001000005BE05FC01" + $"0100007D0604033E2C3C2436263E222E2E282E342E2802082C4CB5EDC39ABA27" + $"C5B7BFBFC883BD60C754C19AC9715052C4C9C842C722C5E9544EC6B5C656C90E" + $"C3FDC7B7C08BC992C179C558BF5C4038C21FBDBFBDE5BBA232BD5BBB83BC04B9" + $"2ABE5DB6FB42B7FDBF8AB5A4C1E30208475443544B54C6EB50C660C6ABC777C5" + $"9456C487C803C508C9DBC33056405842543E42334E3536312C3A3036283EB628" + $"C223B628C2232A4A344AB80EC27CBE0FC50F0604EE2E383838323638383B3635" + $"333B332F3304032F3049304930433A36BA1DBE14413141330606FE0B4659C487" + $"59C36B59C5605954C8E9C6D7C95AC91CC837CBD7C4FBCB67C614CC30C41DCAE7" + $"C289CBC8C2FAC983C1D75443080A070105000A0101001001178400040A000302" + $"01031001178422040A020101000A030102000A0001041001178100040A060104" + $"123FE3AA0000000000003FDFFC41DB9540107701178100040A04010300" +}; + +#else // HAIKU_TARGET_PLATFORM_HAIKU + resource large_icon { $"FFFFFFFFFFFF000000000000000000000EFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" $"FFFFFFFF00000E0F0F0F0F0F0F0F0E0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" @@ -74,6 +94,8 @@ $"FFFF00000E0F0F0F0FFFFFFFFFFFFFFF" }; +#endif // HAIKU_TARGET_PLATFORM_HAIKU + resource(601, "double_click_bmap") #'bits' array { $"424D06070000000000003A000000280000000E0000001E000000010018000000" $"0000CC060000130B0000130B00000000000000000000FFFFFFFFD8D8D8000000" Modified: haiku/trunk/src/preferences/virtualmemory/VirtualMemory.rdef =================================================================== --- haiku/trunk/src/preferences/virtualmemory/VirtualMemory.rdef 2007-05-13 19:17:08 UTC (rev 21129) +++ haiku/trunk/src/preferences/virtualmemory/VirtualMemory.rdef 2007-05-13 19:33:43 UTC (rev 21130) @@ -1,8 +1,48 @@ -resource file_types message; +resource app_signature "application/x-vnd.Haiku-VirtualMemory"; -resource large_icon -{ +resource app_version { + major = 1, + middle = 0, + minor = 0, + + /* 0 = development 1 = alpha 2 = beta + 3 = gamma 4 = golden master 5 = final */ + variety = 2, + + internal = 0, + + short_info = "VirtualMemory", + long_info = "VirtualMemory ?2005-2007 Haiku" +}; + +resource app_flags B_SINGLE_LAUNCH; + +#ifdef HAIKU_TARGET_PLATFORM_HAIKU + +resource vector_icon { + $"6E6369660603010000010100006A0533020006023A5D2C39F8B1B9DBF13A4C0F" + $"48AEEA4AC09100747474FF3E3D3D0200160238221B3B1173BC5EB5394BAA4A47" + $"F149C21D00B0FF830200160336EDE936B949BA0AF63A326F4A79EF4B03E7005A" + $"38DCFF7E050A043C5A5A3C5A363C520A04244E3C5A3C5224480607AA3F422E24" + $"483C525A365133513350344B334D3449324930483149300608FAFA42503E5440" + $"553FC7EB41C85142C94F42C8DA42CA41C0F15D45CA8146C7B746C8A946C74244" + $"5145C6B943C6530A073C5C405C425E485E4A5C465A454B100A010104023FCA1A" + $"0000000000004000004906BCC880000A010104023FCA1A000000000000400000" + $"481435C780000A010104023FCA1A00000000000040000046435EC500000A0101" + $"04023FCA1A00000000000040000040F2860000000A0003020100100117842204" + $"0A020100000A030101000A040102000A000103123FC7130000000000003F9C00" + $"490728C7E05901178422040A050103023FC7130000000000003F9C00490728C7" + $"E0590A000103123FC7130000000000003F9C00481563C6125801178422040A05" + $"0103023FC7130000000000003F9C00481563C612580A000103123FC713000000" + $"0000003F9C0046473DC022C301178422040A050103023FC7130000000000003F" + $"9C0046473DC022C30A000103123FC7130000000000003F9C00411D9945135001" + $"178422040A050103023FC7130000000000003F9C00411D99451350" +}; + +#else // HAIKU_TARGET_PLATFORM_HAIKU + +resource large_icon { $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00FFFFFFFFFFFFFFFFFFFFFFFF" $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00FF00150000FFFFFFFFFFFFFFFFFFFF" $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF003F00153F15150000FFFFFFFFFFFFFFFF" @@ -37,8 +77,7 @@ $"FFFFFFFF0000000E0F0F0F0F0F0F0F0F0F0FFFFFFFFFFFFFFFFFFFFFFFFFFFFF" }; -resource mini_icon -{ +resource mini_icon { $"FFFFFFFFFFFFFF00000000FFFFFFFFFF" $"FFFFFFFFFFFFFF00003F150000FFFFFF" $"FFFFFFFFFF0000003F151515160000FF" @@ -57,13 +96,4 @@ $"FFFF00000E0F0F0F0FFFFFFFFFFFFFFF" }; -resource app_signature "application/x-vnd.Haiku-VirtualMemory"; - -resource app_version -{ - short_info = "Haiku-VirtualMemory", - long_info = "Haiku version of VirtualMemory" -}; - -resource app_flags B_SINGLE_LAUNCH; - +#endif // HAIKU_TARGET_PLATFORM_HAIKU From colacoder at mail.berlios.de Sun May 13 22:19:54 2007 From: colacoder at mail.berlios.de (colacoder at BerliOS) Date: Sun, 13 May 2007 22:19:54 +0200 Subject: [Haiku-commits] r21131 - haiku/trunk/src/add-ons/kernel/drivers/audio/hda Message-ID: <200705132019.l4DKJsW0000931@sheep.berlios.de> Author: colacoder Date: 2007-05-13 22:19:54 +0200 (Sun, 13 May 2007) New Revision: 21131 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21131&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec.c haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c Log: * Make response argument to hda_send_verbs able to handle NULL, in case we don't care for the response * Minor tweaking to buffer handling, which seems to fix the "distorted audio" probs I was having :) Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec.c 2007-05-13 19:33:43 UTC (rev 21130) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec.c 2007-05-13 20:19:54 UTC (rev 21131) @@ -323,7 +323,7 @@ if (codec->afg_widgets[idx].type != WT_PIN_COMPLEX) continue; - if (!codec->afg_widgets[idx].d.pin.output) + if (codec->afg_widgets[idx].d.pin.output) continue; if (codec->afg_widgets[idx].d.pin.device != PIN_DEV_HP_OUT && codec->afg_widgets[idx].d.pin.device != PIN_DEV_SPEAKER && @@ -338,26 +338,26 @@ output_wid = hda_codec_afg_find_dac_path(codec, codec->afg_widgets[idx].inputs[iidx], 0); if (output_wid) { corb_t verb = MAKE_VERB(codec->addr,idx+codec->afg_wid_start,VID_SET_CONNSEL,iidx); - uint32 resp; - if (hda_send_verbs(codec, &verb, &resp, 1) == B_OK) - break; + if (hda_send_verbs(codec, &verb, NULL, 1) != B_OK) + dprintf("%s: Setting output selector failed!\n", __func__); + break; } } } if (output_wid) { corb_t verb; - uint32 resp; codec->playback_stream->pin_wid = idx + codec->afg_wid_start; codec->playback_stream->io_wid = output_wid; + dprintf("%s: Found output PIN (%s) connected to output CONV wid:%ld\n", __func__, defdev[codec->afg_widgets[idx].d.pin.device], output_wid); /* FIXME: Force Pin Widget to unmute */ verb = MAKE_VERB(codec->addr, codec->playback_stream->pin_wid, VID_SET_AMPGAINMUTE, (1 << 15) | (1 << 13) | (1 << 12)); - hda_send_verbs(codec, &verb, &resp, 1); + hda_send_verbs(codec, &verb, NULL, 1); break; } } Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c 2007-05-13 19:33:43 UTC (rev 21130) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c 2007-05-13 20:19:54 UTC (rev 21131) @@ -59,11 +59,16 @@ if (s->running) { uint8 sts = OREG8(ctrlr,s->off,STS); if (sts) { + int32 count; + OREG8(ctrlr,s->off,STS) = sts; s->played_real_time = system_time(); s->played_frames_count += s->buffer_length; - release_sem_etc(s->buffer_ready_sem, 1, B_DO_NOT_RESCHEDULE); + + get_sem_count(s->buffer_ready_sem, &count); + if (count <= 0) + release_sem_etc(s->buffer_ready_sem, 1, B_DO_NOT_RESCHEDULE); } } @@ -219,7 +224,7 @@ REG16(codec->ctrlr,CORBWP) = (codec->ctrlr->corbwp += count); rc = acquire_sem_etc(codec->response_sem, count, B_CAN_INTERRUPT | B_RELATIVE_TIMEOUT, 1000ULL * 50); - if (rc == B_OK) + if (rc == B_OK && responses != NULL) memcpy(responses, codec->responses, count*sizeof(uint32)); return rc; From colacoder at mail.berlios.de Sun May 13 22:24:38 2007 From: colacoder at mail.berlios.de (colacoder at BerliOS) Date: Sun, 13 May 2007 22:24:38 +0200 Subject: [Haiku-commits] r21132 - haiku/trunk/build/jam Message-ID: <200705132024.l4DKOcxk001280@sheep.berlios.de> Author: colacoder Date: 2007-05-13 22:24:38 +0200 (Sun, 13 May 2007) New Revision: 21132 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21132&view=rev Modified: haiku/trunk/build/jam/HaikuImage Log: * Add hda audio driver to image for public testing Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2007-05-13 20:19:54 UTC (rev 21131) +++ haiku/trunk/build/jam/HaikuImage 2007-05-13 20:24:38 UTC (rev 21132) @@ -103,7 +103,7 @@ Print\ To\ File Serial\ Port USB\ Port ; BEOS_ADD_ONS_SCREENSAVERS = Haiku IFS ; -BEOS_ADD_ONS_DRIVERS_AUDIO = auich auvia emuxki ; +BEOS_ADD_ONS_DRIVERS_AUDIO = auich auvia emuxki hda ; BEOS_ADD_ONS_DRIVERS_GRAPHICS = $(X86_ONLY)radeon $(X86_ONLY)nvidia $(X86_ONLY)neomagic $(X86_ONLY)matrox $(X86_ONLY)intel_extreme vesa #$(X86_ONLY)vmware From jackburton at mail.berlios.de Sun May 13 22:26:32 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Sun, 13 May 2007 22:26:32 +0200 Subject: [Haiku-commits] r21133 - haiku/trunk/src/kits/interface Message-ID: <200705132026.l4DKQW8U001435@sheep.berlios.de> Author: jackburton Date: 2007-05-13 22:26:31 +0200 (Sun, 13 May 2007) New Revision: 21133 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21133&view=rev Modified: haiku/trunk/src/kits/interface/PictureDataWriter.cpp Log: Cast errors to status_t before throwing, otherwise the catch operator won't catch them (as ints). Thanks to Ingo and Marcus for pointing out the problem and suggesting a solution. Modified: haiku/trunk/src/kits/interface/PictureDataWriter.cpp =================================================================== --- haiku/trunk/src/kits/interface/PictureDataWriter.cpp 2007-05-13 20:24:38 UTC (rev 21132) +++ haiku/trunk/src/kits/interface/PictureDataWriter.cpp 2007-05-13 20:26:31 UTC (rev 21133) @@ -15,6 +15,8 @@ #include +#define THROW_ERROR(error) throw (status_t)(error) + PictureDataWriter::PictureDataWriter() : fData(NULL) @@ -450,7 +452,7 @@ PictureDataWriter::BeginOp(const int16 &op) { if (fData == NULL) - throw B_NO_INIT; + THROW_ERROR(B_NO_INIT); fStack.push(fData->Position()); fData->Write(&op, sizeof(op)); @@ -465,7 +467,7 @@ PictureDataWriter::EndOp() { if (fData == NULL) - throw B_NO_INIT; + THROW_ERROR(B_NO_INIT); off_t curPos = fData->Position(); off_t stackPos = fStack.top(); @@ -489,7 +491,7 @@ { ssize_t result = fData->Write(data, size); if (result < 0) - throw (status_t)result; + THROW_ERROR(result); if (result != size) - throw B_IO_ERROR; + THROW_ERROR(B_IO_ERROR); } From colacoder at mail.berlios.de Mon May 14 00:41:04 2007 From: colacoder at mail.berlios.de (colacoder at BerliOS) Date: Mon, 14 May 2007 00:41:04 +0200 Subject: [Haiku-commits] r21134 - haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme Message-ID: <200705132241.l4DMf4er001744@sheep.berlios.de> Author: colacoder Date: 2007-05-14 00:41:03 +0200 (Mon, 14 May 2007) New Revision: 21134 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21134&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/intel_extreme.cpp Log: * Set clock values based on card type. Modified: haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/intel_extreme.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/intel_extreme.cpp 2007-05-13 20:26:31 UTC (rev 21133) +++ haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/intel_extreme.cpp 2007-05-13 22:41:03 UTC (rev 21134) @@ -417,9 +417,17 @@ info.shared_info->graphics_memory_size = totalSize; info.shared_info->frame_buffer_offset = 0; info.shared_info->dpms_mode = B_DPMS_ON; - info.shared_info->pll_info.reference_frequency = 48000; // 48 kHz - info.shared_info->pll_info.min_frequency = 25000; // 25 MHz (not tested) - info.shared_info->pll_info.max_frequency = 350000; // 350 MHz RAM DAC speed + + if (info.device_type == INTEL_TYPE_9xx) { + info.shared_info->pll_info.reference_frequency = 96000; // 96 kHz + info.shared_info->pll_info.max_frequency = 400000; // 400 MHz RAM DAC speed + info.shared_info->pll_info.min_frequency = 20000; // 20 MHz (not tested) + } else { + info.shared_info->pll_info.reference_frequency = 48000; // 48 kHz + info.shared_info->pll_info.max_frequency = 350000; // 350 MHz RAM DAC speed + info.shared_info->pll_info.min_frequency = 25000; // 25 MHz (not tested) + } + info.shared_info->pll_info.divisor_register = INTEL_DISPLAY_A_PLL_DIVISOR_0; info.shared_info->device_type = info.device_type; From colacoder at mail.berlios.de Mon May 14 03:23:38 2007 From: colacoder at mail.berlios.de (colacoder at BerliOS) Date: Mon, 14 May 2007 03:23:38 +0200 Subject: [Haiku-commits] r21135 - haiku/trunk/src/add-ons/kernel/drivers/audio/hda Message-ID: <200705140123.l4E1Ncrm007936@sheep.berlios.de> Author: colacoder Date: 2007-05-14 03:23:36 +0200 (Mon, 14 May 2007) New Revision: 21135 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21135&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.c haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.c Log: * More buffer (cycle) handling * Locking of stream info. * Add compile-time support for Haiku/BeOS multi_audio API. TODO: Need to check out why we have multiple (different) multi_audio.h files floating around in the source tree.... Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.c 2007-05-13 22:41:03 UTC (rev 21134) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.c 2007-05-14 01:23:36 UTC (rev 21135) @@ -5,6 +5,9 @@ pci_module_info* pci; +const char** publish_devices(void); /* Just to silence compiler */ + + status_t init_hardware(void) { @@ -82,7 +85,7 @@ } const char** -publish_devices() +publish_devices(void) { static const char* devs[MAXCARDS+1]; long i; Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2007-05-13 22:41:03 UTC (rev 21134) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2007-05-14 01:23:36 UTC (rev 21135) @@ -5,10 +5,17 @@ #include #include +#include + #include #include -#include "multi_audio.h" +#ifdef COMPILED_FOR_R5 + #define DEVFS_PATH_FORMAT "audio/multi/hda/%lu" +#else + #define DEVFS_PATH_FORMAT "audio/hmulti/hda/%lu" +#endif + #include "hda_controller_defs.h" #include "hda_codec_defs.h" @@ -17,7 +24,6 @@ /* values for the class_sub field for class_base = 0x04 (multimedia device) */ #define PCI_hd_audio 3 -#define DEVFS_PATH_FORMAT "audio/multi/hda/%lu" #define MAXWORK 16 #define HDA_MAXCODECS 15 #define HDA_MAXSTREAMS 16 @@ -38,7 +44,8 @@ uint32 id; /* HDA controller stream # */ uint32 off; /* HDA I/O/B descriptor offset */ bool running; /* Is this stream active? */ - + spinlock lock; /* Write lock */ + uint32 pin_wid; /* PIN Widget ID */ uint32 io_wid; /* Input/Output Converter Widget ID */ @@ -52,8 +59,9 @@ void* buffers[STRMAXBUF]; /* Virtual addresses for buffer */ uint32 buffers_pa[STRMAXBUF]; /* Physical addresses for buffer */ sem_id buffer_ready_sem; - bigtime_t played_real_time; - uint32 played_frames_count; + bigtime_t real_time; + uint32 frames_count; + uint32 buffer_cycle; area_id buffer_area; area_id bdl_area; Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c 2007-05-13 22:41:03 UTC (rev 21134) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c 2007-05-14 01:23:36 UTC (rev 21135) @@ -59,13 +59,21 @@ if (s->running) { uint8 sts = OREG8(ctrlr,s->off,STS); if (sts) { + cpu_status status; int32 count; OREG8(ctrlr,s->off,STS) = sts; - s->played_real_time = system_time(); - s->played_frames_count += s->buffer_length; + status = disable_interrupts(); + acquire_spinlock(&s->lock); + s->real_time = system_time(); + s->frames_count += s->buffer_length; + s->buffer_cycle = (s->buffer_cycle +1) % s->num_buffers; + + release_spinlock(&s->lock); + restore_interrupts(status); + get_sem_count(s->buffer_ready_sem, &count); if (count <= 0) release_sem_etc(s->buffer_ready_sem, 1, B_DO_NOT_RESCHEDULE); Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.c 2007-05-13 22:41:03 UTC (rev 21134) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.c 2007-05-14 01:23:36 UTC (rev 21135) @@ -209,25 +209,29 @@ buffer_exchange(hda_codec* codec, multi_buffer_info* data) { static int debug_buffers_exchanged = 0; + cpu_status status; status_t rc; if (!codec->playback_stream->running) hda_stream_start(codec->ctrlr, codec->playback_stream); -// if (!codec->record_stream->running) -// hda_stream_start(codec->ctrlr, codec->record_stream); - /* do playback */ - rc=acquire_sem(codec->playback_stream->buffer_ready_sem); - if (rc != B_OK) return rc; + rc=acquire_sem_etc(codec->playback_stream->buffer_ready_sem, 1, B_RELATIVE_TIMEOUT | B_CAN_INTERRUPT, 50000); + if (rc != B_OK) { + dprintf("%s: Timeout waiting for playback buffer to finish!\n", __func__); + return rc; + } - data->played_real_time = codec->playback_stream->played_real_time; - data->played_frames_count = codec->playback_stream->played_frames_count; + status = disable_interrupts(); + acquire_spinlock(&codec->playback_stream->lock); - /* do record */ - data->record_buffer_cycle = 0; - data->recorded_frames_count = 0; + data->playback_buffer_cycle = codec->playback_stream->buffer_cycle; + data->played_real_time = codec->playback_stream->real_time; + data->played_frames_count = codec->playback_stream->frames_count; + release_spinlock(&codec->playback_stream->lock); + restore_interrupts(status); + debug_buffers_exchanged++; if (((debug_buffers_exchanged % 100) == 1) && (debug_buffers_exchanged < 1111)) { dprintf("%s: %d buffers processed\n", __func__, debug_buffers_exchanged); From colacoder at mail.berlios.de Mon May 14 04:37:16 2007 From: colacoder at mail.berlios.de (colacoder at BerliOS) Date: Mon, 14 May 2007 04:37:16 +0200 Subject: [Haiku-commits] r21136 - in haiku/trunk: headers/private/media src/add-ons/kernel/drivers/audio/ac97/auich src/add-ons/kernel/drivers/audio/ac97/auvia src/add-ons/kernel/drivers/audio/echo src/add-ons/kernel/drivers/audio/echo/24 src/add-ons/kernel/drivers/audio/echo/3g src/add-ons/kernel/drivers/audio/echo/gals src/add-ons/kernel/drivers/audio/echo/indigo src/add-ons/kernel/drivers/audio/emuxki src/add-ons/kernel/drivers/audio/hda src/add-ons/media/media-add-ons/multi_audio Message-ID: <200705140237.l4E2bG9k012142@sheep.berlios.de> Author: colacoder Date: 2007-05-14 04:37:14 +0200 (Mon, 14 May 2007) New Revision: 21136 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21136&view=rev Added: haiku/trunk/headers/private/media/hmulti_audio.h Removed: haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/multi_audio.h haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auvia/multi_audio.h haiku/trunk/src/add-ons/kernel/drivers/audio/echo/multi_audio.h haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/multi_audio.h haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/multi_audio.h Modified: haiku/trunk/headers/private/media/multi_audio.h haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/Jamfile haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/auich.h haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/multi.c haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auvia/Jamfile haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auvia/auvia.h haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auvia/multi.c haiku/trunk/src/add-ons/kernel/drivers/audio/echo/24/Jamfile haiku/trunk/src/add-ons/kernel/drivers/audio/echo/3g/Jamfile haiku/trunk/src/add-ons/kernel/drivers/audio/echo/echo.h haiku/trunk/src/add-ons/kernel/drivers/audio/echo/gals/Jamfile haiku/trunk/src/add-ons/kernel/drivers/audio/echo/indigo/Jamfile haiku/trunk/src/add-ons/kernel/drivers/audio/echo/multi.cpp haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/Jamfile haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/emuxki.h haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/multi.c haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/Jamfile haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioDevice.h haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.h haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/driver_io.h Log: * Delete all local copies of multi_audio from source tree. * Change name of header for Haiku specific multi_audio to hmulti_audio (in line with the rename of the media addon itself) Copied: haiku/trunk/headers/private/media/hmulti_audio.h (from rev 21134, haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/multi_audio.h) Modified: haiku/trunk/headers/private/media/multi_audio.h =================================================================== --- haiku/trunk/headers/private/media/multi_audio.h 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/headers/private/media/multi_audio.h 2007-05-14 02:37:14 UTC (rev 21136) @@ -13,7 +13,10 @@ #define _MULTI_AUDIO_H #include + +#ifndef ASSERT #include +#endif #define B_MULTI_DRIVER_BASE (B_AUDIO_DRIVER_BASE+20) Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/Jamfile 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/Jamfile 2007-05-14 02:37:14 UTC (rev 21136) @@ -2,6 +2,8 @@ SetSubDirSupportedPlatformsBeOSCompatible ; +UsePrivateHeaders media ; + KernelAddon auich : ac97.c debug.c Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/auich.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/auich.h 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/auich.h 2007-05-14 02:37:14 UTC (rev 21136) @@ -42,7 +42,7 @@ #include "auichreg.h" #include "config.h" #include "queue.h" -#include "multi_audio.h" +#include "hmulti_audio.h" #include "multi.h" #define INTEL_VENDOR_ID 0x8086 /* Intel */ Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/multi.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/multi.c 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/multi.c 2007-05-14 02:37:14 UTC (rev 21136) @@ -32,7 +32,7 @@ #include #include #include -#include "multi_audio.h" +#include "hmulti_audio.h" #include "multi.h" #include "ac97.h" Deleted: haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/multi_audio.h Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auvia/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auvia/Jamfile 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auvia/Jamfile 2007-05-14 02:37:14 UTC (rev 21136) @@ -2,6 +2,8 @@ SetSubDirSupportedPlatformsBeOSCompatible ; +UsePrivateHeaders media ; + KernelAddon auvia : ac97.c debug.c Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auvia/auvia.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auvia/auvia.h 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auvia/auvia.h 2007-05-14 02:37:14 UTC (rev 21136) @@ -45,7 +45,7 @@ #include "auviareg.h" #include "config.h" #include "queue.h" -#include "multi_audio.h" +#include "hmulti_audio.h" #include "multi.h" #define VIATECH_VENDOR_ID 0x1106 /* Via Technologies */ Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auvia/multi.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auvia/multi.c 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auvia/multi.c 2007-05-14 02:37:14 UTC (rev 21136) @@ -32,7 +32,7 @@ #include #include #include -#include "multi_audio.h" +#include "hmulti_audio.h" #include "multi.h" #include "ac97.h" Deleted: haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auvia/multi_audio.h Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/echo/24/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/echo/24/Jamfile 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/echo/24/Jamfile 2007-05-14 02:37:14 UTC (rev 21136) @@ -12,7 +12,8 @@ SubDirHdrs $(HAIKU_TOP) src add-ons kernel drivers audio echo generic DSP ; SubDirHdrs $(HAIKU_TOP) src add-ons kernel drivers audio echo generic ASIC ; -UsePrivateHeaders [ FDirName kernel ] ; # For kernel_cpp.cpp +UsePrivateHeaders [ FDirName kernel ] # For kernel_cpp.cpp + media ; # set some additional defines SubDirCcFlags -DECHO_BEOS -DECHO24_FAMILY ; Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/echo/3g/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/echo/3g/Jamfile 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/echo/3g/Jamfile 2007-05-14 02:37:14 UTC (rev 21136) @@ -12,7 +12,8 @@ SubDirHdrs $(HAIKU_TOP) src add-ons kernel drivers audio echo generic DSP ; SubDirHdrs $(HAIKU_TOP) src add-ons kernel drivers audio echo generic ASIC ; -UsePrivateHeaders [ FDirName kernel ] ; # For kernel_cpp.cpp +UsePrivateHeaders [ FDirName kernel ] # For kernel_cpp.cpp + media ; # set some additional defines SubDirCcFlags -DECHO_BEOS -DECHO3G_FAMILY ; Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/echo/echo.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/echo/echo.h 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/echo/echo.h 2007-05-14 02:37:14 UTC (rev 21136) @@ -31,7 +31,7 @@ #endif #include "OsSupportBeOS.h" #include "CEchoGals.h" -#include "multi_audio.h" +#include "hmulti_audio.h" #include "multi.h" #include "queue.h" Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/echo/gals/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/echo/gals/Jamfile 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/echo/gals/Jamfile 2007-05-14 02:37:14 UTC (rev 21136) @@ -12,7 +12,8 @@ SubDirHdrs $(HAIKU_TOP) src add-ons kernel drivers audio echo generic DSP ; SubDirHdrs $(HAIKU_TOP) src add-ons kernel drivers audio echo generic ASIC ; -UsePrivateHeaders [ FDirName kernel ] ; # For kernel_cpp.cpp +UsePrivateHeaders [ FDirName kernel ] # For kernel_cpp.cpp + media ; # set some additional defines SubDirCcFlags -DECHO_BEOS -DECHOGALS_FAMILY ; Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/echo/indigo/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/echo/indigo/Jamfile 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/echo/indigo/Jamfile 2007-05-14 02:37:14 UTC (rev 21136) @@ -12,7 +12,8 @@ SubDirHdrs $(HAIKU_TOP) src add-ons kernel drivers audio echo generic DSP ; SubDirHdrs $(HAIKU_TOP) src add-ons kernel drivers audio echo generic ASIC ; -UsePrivateHeaders [ FDirName kernel ] ; # For kernel_cpp.cpp +UsePrivateHeaders [ FDirName kernel ] # For kernel_cpp.cpp + media ; # set some additional defines SubDirCcFlags -DECHO_BEOS -DINDIGO_FAMILY -DCARDBUS ; Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/echo/multi.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/echo/multi.cpp 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/echo/multi.cpp 2007-05-14 02:37:14 UTC (rev 21136) @@ -32,7 +32,7 @@ #include #include #include "debug.h" -#include "multi_audio.h" +#include "hmulti_audio.h" #include "multi.h" //#define DEBUG 1 Deleted: haiku/trunk/src/add-ons/kernel/drivers/audio/echo/multi_audio.h Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/Jamfile 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/Jamfile 2007-05-14 02:37:14 UTC (rev 21136) @@ -2,6 +2,8 @@ SetSubDirSupportedPlatformsBeOSCompatible ; +UsePrivateHeaders media ; + KernelAddon emuxki : ac97.c debug.c Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/emuxki.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/emuxki.h 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/emuxki.h 2007-05-14 02:37:14 UTC (rev 21136) @@ -46,7 +46,7 @@ #include "emuxkireg.h" #include "config.h" #include "queue.h" -#include "multi_audio.h" +#include "hmulti_audio.h" #include "multi.h" Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/multi.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/multi.c 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/multi.c 2007-05-14 02:37:14 UTC (rev 21136) @@ -32,7 +32,7 @@ #include #include #include -#include "multi_audio.h" +#include "hmulti_audio.h" #include "multi.h" #include "ac97.h" #include "debug.h" Deleted: haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/multi_audio.h Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2007-05-14 02:37:14 UTC (rev 21136) @@ -5,15 +5,15 @@ #include #include -#include - #include #include #ifdef COMPILED_FOR_R5 #define DEVFS_PATH_FORMAT "audio/multi/hda/%lu" + #include #else #define DEVFS_PATH_FORMAT "audio/hmulti/hda/%lu" + #include #endif #include "hda_controller_defs.h" Modified: haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/Jamfile =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/Jamfile 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/Jamfile 2007-05-14 02:37:14 UTC (rev 21136) @@ -2,6 +2,8 @@ SetSubDirSupportedPlatformsBeOSCompatible ; +UsePrivateHeaders media ; + if $(TARGET_PLATFORM) != haiku { SubDirC++Flags -fmultiple-symbol-spaces ; } Modified: haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioDevice.h =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioDevice.h 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioDevice.h 2007-05-14 02:37:14 UTC (rev 21136) @@ -6,7 +6,7 @@ #ifndef _MULTIAUDIODEVICE_H #define _MULTIAUDIODEVICE_H -#include "multi_audio.h" +#include "hmulti_audio.h" #define MAX_CONTROLS 128 #define MAX_CHANNELS 32 Modified: haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.h =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.h 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.h 2007-05-14 02:37:14 UTC (rev 21136) @@ -40,7 +40,7 @@ #include #include #include -#include "multi_audio.h" +#include "hmulti_audio.h" #include "MultiAudioDevice.h" /*bool format_is_acceptible( Modified: haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/driver_io.h =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/driver_io.h 2007-05-14 01:23:36 UTC (rev 21135) +++ haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/driver_io.h 2007-05-14 02:37:14 UTC (rev 21136) @@ -31,7 +31,7 @@ #include #include #include -#include "multi_audio.h" +#include "hmulti_audio.h" #define DRIVER_GET_DESCRIPTION(x...) ioctl( fd, B_MULTI_GET_DESCRIPTION, x ) #define DRIVER_GET_ENABLED_CHANNELS(x...) ioctl( fd, B_MULTI_GET_ENABLED_CHANNELS, x ) Deleted: haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/multi_audio.h From axeld at pinc-software.de Mon May 14 08:55:42 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Mon, 14 May 2007 08:55:42 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r21134_-_haiku/trunk/src/add-ons/?= =?iso-8859-15?q?kernel/drivers/graphics/intel=5Fextreme?= In-Reply-To: <200705132241.l4DMf4er001744@sheep.berlios.de> Message-ID: <326052366-BeMail@zon> colacoder at BerliOS wrote: > + if (info.device_type == INTEL_TYPE_9xx) { Thanks! I don't know if the newer ones (945, 965) add any special things, but it would be better to check the type like this: > + if ((info.device_type & INTEL_TYPE_9xx) != 0) { Bye, Axel. From wkornewald at haiku-os.org Mon May 14 09:34:04 2007 From: wkornewald at haiku-os.org (Waldemar Kornewald) Date: Mon, 14 May 2007 09:34:04 +0200 Subject: [Haiku-commits] r21127 - in haiku/trunk/src/add-ons/kernel/drivers/audio: . hda In-Reply-To: <200705131704.l4DH4piA010912@sheep.berlios.de> References: <200705131704.l4DH4piA010912@sheep.berlios.de> Message-ID: On 5/13/07, colacoder at BerliOS wrote: > As a last note, DasJott, if you're reading this, the first music it played was... > 'Prodigy: Smack Your Bitch Up' :) The song is called "Smack *My* ...", anyway, thanks a lot for working on the HDA driver! :) Bye, Waldemar Kornewald From korli at users.berlios.de Mon May 14 11:03:16 2007 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Mon, 14 May 2007 11:03:16 +0200 Subject: [Haiku-commits] r21136 - in haiku/trunk: headers/private/media src/add-ons/kernel/drivers/audio/ac97/auich src/add-ons/kernel/drivers/audio/ac97/auvia src/add-ons/kernel/drivers/audio/echo src/add-ons/kernel/drivers/audio/echo/24 src/add-ons/kern Message-ID: Hi Ithamar, 2007/5/14, colacoder at BerliOS : > Log: > * Delete all local copies of multi_audio from source tree. > * Change name of header for Haiku specific multi_audio to hmulti_audio (in line with the rename of the media addon itself) Thanks for this :) To better explain the differences on both versions of the header, it was about the mixer API, I couldn't describe well controls for interfacing the BParameterWeb. It adds some kind of hierarchy (see parent identifier) and enables the use of a type identifier for names. Bye, J?r?me From superstippi at gmx.de Mon May 14 12:25:55 2007 From: superstippi at gmx.de (Stephan Assmus) Date: Mon, 14 May 2007 12:25:55 +0200 Subject: [Haiku-commits] r21130 - in haiku/trunk/src/preferences: keyboard keymap mouse virtualmemory Message-ID: <20070514102555.91750@gmx.net> Hi Axel, > Author: axeld > Date: 2007-05-13 21:33:43 +0200 (Sun, 13 May 2007) > New Revision: 21130 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21130&view=rev > > Modified: > haiku/trunk/src/preferences/keyboard/Keyboard.rdef > haiku/trunk/src/preferences/keymap/Keymap.rdef > haiku/trunk/src/preferences/mouse/Mouse.rdef > haiku/trunk/src/preferences/virtualmemory/VirtualMemory.rdef > Log: > * Committed zuMi's icons as they already have a place on the image. Thanks! > * I'm not sure, but neither Joysticks nor PowerStatus is rendered within Haiku > (FlatIconImporter::_ParseSections() - error parsing shapes: Out of memory), > therefore, I didn't commit those yet. > * Also, Joysticks already seem to have a vector icon, but that shows the same > error - stippi? :-) I looked at these icons at home, and they all opened fine. I also did some little tweaks here and there, which I will commit as soon as I have internet again. I don't know about any vector Joysticks icon. Best regards, -Stephan -------------- next part -------------- An HTML attachment was scrubbed... URL: From axeld at pinc-software.de Mon May 14 13:01:28 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Mon, 14 May 2007 13:01:28 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r21130_-_in_haiku/trunk/src/prefe?= =?iso-8859-15?q?rences=3A_keyboard_keymap_mouse_virtualmemory?= In-Reply-To: <20070514102555.91750@gmx.net> Message-ID: <15072296296-BeMail@zon> "Stephan Assmus" wrote: > I looked at these icons at home, and they all opened fine. I also did > some > little tweaks here and there, which I will commit as soon as I have > internet > again. I don't know about any vector Joysticks icon. Me neither, but there is one in the tree - maybe it's just some other icon. Anyway, I could open all icons with Icon-O-Matic, but I got those errors when Haiku tried to render them in Tracker. Bye, Axel. From axeld at mail.berlios.de Mon May 14 16:15:36 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 14 May 2007 16:15:36 +0200 Subject: [Haiku-commits] r21137 - in haiku/trunk/src/apps/cortex: . DiagramView MediaRoutingView RouteApp ValControl Message-ID: <200705141415.l4EEFaQf002373@sheep.berlios.de> Author: axeld Date: 2007-05-14 16:15:34 +0200 (Mon, 14 May 2007) New Revision: 21137 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21137&view=rev Modified: haiku/trunk/src/apps/cortex/DiagramView/DiagramBox.cpp haiku/trunk/src/apps/cortex/DiagramView/DiagramBox.h haiku/trunk/src/apps/cortex/DiagramView/DiagramItemGroup.cpp haiku/trunk/src/apps/cortex/DiagramView/DiagramItemGroup.h haiku/trunk/src/apps/cortex/DiagramView/DiagramView.cpp haiku/trunk/src/apps/cortex/DiagramView/DiagramView.h haiku/trunk/src/apps/cortex/DiagramView/DiagramWire.cpp haiku/trunk/src/apps/cortex/MediaRoutingView/MediaNodePanel.cpp haiku/trunk/src/apps/cortex/MediaRoutingView/MediaRoutingView.cpp haiku/trunk/src/apps/cortex/RouteApp/RouteApp.cpp haiku/trunk/src/apps/cortex/ValControl/NumericValControl.cpp haiku/trunk/src/apps/cortex/ValControl/ValControl.cpp haiku/trunk/src/apps/cortex/ValControl/ValControl.h haiku/trunk/src/apps/cortex/ValControl/ValControlSegment.cpp haiku/trunk/src/apps/cortex/ValControl/ValControlSegment.h haiku/trunk/src/apps/cortex/cortex_defs.h Log: Next row of Cortex style updates, courtesy of Vasilis Kaoutsis - thanks! Modified: haiku/trunk/src/apps/cortex/DiagramView/DiagramBox.cpp =================================================================== --- haiku/trunk/src/apps/cortex/DiagramView/DiagramBox.cpp 2007-05-14 02:37:14 UTC (rev 21136) +++ haiku/trunk/src/apps/cortex/DiagramView/DiagramBox.cpp 2007-05-14 14:15:34 UTC (rev 21137) @@ -39,11 +39,11 @@ // derived from DiagramItemGroup (public) bool -DiagramBox::addItem(DiagramItem *item) +DiagramBox::AddItem(DiagramItem *item) { - D_METHOD(("DiagramBox::addItem()\n")); + D_METHOD(("DiagramBox::AddItem()\n")); if (item) { - if (DiagramItemGroup::addItem(item)) { + if (DiagramItemGroup::AddItem(item)) { if (m_view) { item->_setOwner(m_view); item->attachedToDiagram(); @@ -56,12 +56,12 @@ bool -DiagramBox::removeItem(DiagramItem *item) +DiagramBox::RemoveItem(DiagramItem *item) { - D_METHOD(("DiagramBox::removeItem()\n")); + D_METHOD(("DiagramBox::RemoveItem()\n")); if (item) { item->detachedFromDiagram(); - if (DiagramItemGroup::removeItem(item)) { + if (DiagramItemGroup::RemoveItem(item)) { item->_setOwner(0); return true; } @@ -81,22 +81,22 @@ if (m_flags & M_DRAW_UNDER_ENDPOINTS) { BRegion region, clipping; region.Include(frame()); - if (group()->getClippingAbove(this, &clipping)) + if (group()->GetClippingAbove(this, &clipping)) region.Exclude(&clipping); view()->ConstrainClippingRegion(®ion); drawBox(); - for (uint32 i = 0; i < countItems(); i++) { - DiagramItem *item = itemAt(i); + for (uint32 i = 0; i < CountItems(); i++) { + DiagramItem *item = ItemAt(i); if (region.Intersects(item->frame())) item->draw(item->frame()); } } else { BRegion region, clipping; region.Include(frame()); - if (view()->getClippingAbove(this, &clipping)) + if (view()->GetClippingAbove(this, &clipping)) region.Exclude(&clipping); - for (uint32 i = 0; i < countItems(); i++) { - DiagramItem *item = itemAt(i); + for (uint32 i = 0; i < CountItems(); i++) { + DiagramItem *item = ItemAt(i); BRect r; if (region.Intersects(r = item->frame())) { item->draw(r); @@ -116,7 +116,7 @@ DiagramBox::mouseDown(BPoint point, uint32 buttons, uint32 clicks) { D_MOUSE(("DiagramBox::mouseDown()\n")); - DiagramItem *item = itemUnder(point); + DiagramItem *item = ItemUnder(point); if (item) item->mouseDown(point, buttons, clicks); else if (clicks == 1) { @@ -144,12 +144,12 @@ DiagramBox::mouseOver(BPoint point, uint32 transit) { D_MOUSE(("DiagramBox::mouseOver()\n")); - DiagramItem *last = lastItemUnder(); + DiagramItem *last = _LastItemUnder(); if (last && (transit == B_EXITED_VIEW)) { last->mouseOver(point, B_EXITED_VIEW); - resetItemUnder(); + _ResetItemUnder(); } else { - DiagramItem *item = itemUnder(point); + DiagramItem *item = ItemUnder(point); if (item) { if (item != last) { if (last) @@ -168,12 +168,12 @@ DiagramBox::messageDragged(BPoint point, uint32 transit, const BMessage *message) { D_MOUSE(("DiagramBox::messageDragged()\n")); - DiagramItem *last = lastItemUnder(); + DiagramItem *last = _LastItemUnder(); if (last && (transit == B_EXITED_VIEW)) { last->messageDragged(point, B_EXITED_VIEW, message); - resetItemUnder(); + _ResetItemUnder(); } else { - DiagramItem *item = itemUnder(point); + DiagramItem *item = ItemUnder(point); if (item) { if (item != last) { if (last) @@ -194,7 +194,7 @@ DiagramBox::messageDropped(BPoint point, BMessage *message) { D_METHOD(("DiagramBox::messageDropped()\n")); - DiagramItem *item = itemUnder(point); + DiagramItem *item = ItemUnder(point); if (item) { item->messageDropped(point, message); return; @@ -210,8 +210,8 @@ if (view()) { view()->PushState(); { - for (uint32 i = 0; i < countItems(); i++) { - DiagramEndPoint *endPoint = dynamic_cast(itemAt(i)); + for (uint32 i = 0; i < CountItems(); i++) { + DiagramEndPoint *endPoint = dynamic_cast(ItemAt(i)); if (endPoint) endPoint->moveBy(x, y, wireRegion); } @@ -243,8 +243,8 @@ { D_METHOD(("DiagramBox::_setOwner()\n")); m_view = owner; - for (uint32 i = 0; i < countItems(DiagramItem::M_ENDPOINT); i++) { - DiagramItem *item = itemAt(i); + for (uint32 i = 0; i < CountItems(DiagramItem::M_ENDPOINT); i++) { + DiagramItem *item = ItemAt(i); item->_setOwner(m_view); if (m_view) item->attachedToDiagram(); Modified: haiku/trunk/src/apps/cortex/DiagramView/DiagramBox.h =================================================================== --- haiku/trunk/src/apps/cortex/DiagramView/DiagramBox.h 2007-05-14 02:37:14 UTC (rev 21136) +++ haiku/trunk/src/apps/cortex/DiagramView/DiagramBox.h 2007-05-14 14:15:34 UTC (rev 21137) @@ -42,11 +42,11 @@ // extends the DiagramItemGroup implementation by setting // the items owner and calling the attachedToDiagram() hook // on it - virtual bool addItem(DiagramItem *item); + virtual bool AddItem(DiagramItem *item); // extends the DiagramItemGroup implementation by calling // the detachedToDiagram() hook on the item - virtual bool removeItem(DiagramItem *item); + virtual bool RemoveItem(DiagramItem *item); public: // derived from DiagramItem Modified: haiku/trunk/src/apps/cortex/DiagramView/DiagramItemGroup.cpp =================================================================== --- haiku/trunk/src/apps/cortex/DiagramView/DiagramItemGroup.cpp 2007-05-14 02:37:14 UTC (rev 21136) +++ haiku/trunk/src/apps/cortex/DiagramView/DiagramItemGroup.cpp 2007-05-14 14:15:34 UTC (rev 21137) @@ -1,5 +1,13 @@ // DiagramItemGroup.cpp +/*! \class DiagramItemGroup. + \brief Basic class for managing and accessing DiagramItem objects. + + Objects of this class can manage one or more of the DiagramItem + type M_BOX, M_WIRE and M_ENDPOINT. Many methods let you specify + which type of item you want to deal with. +*/ + #include "DiagramItemGroup.h" #include "DiagramItem.h" @@ -10,397 +18,341 @@ #include #define D_METHOD(x) //PRINT (x) -// -------------------------------------------------------- // -// *** ctor/dtor -// -------------------------------------------------------- // -DiagramItemGroup::DiagramItemGroup( - uint32 acceptedTypes, - bool multiSelection) - : m_boxes(0), - m_wires(0), - m_endPoints(0), - m_selection(0), - m_types(acceptedTypes), - m_itemAlignment(1.0, 1.0), - m_multiSelection(multiSelection), - m_lastItemUnder(0) +DiagramItemGroup::DiagramItemGroup(uint32 acceptedTypes, bool multiSelection) + : fBoxes(0), + fWires(0), + fEndPoints(0), + fSelection(0), + fTypes(acceptedTypes), + fItemAlignment(1.0, 1.0), + fMultiSelection(multiSelection), + fLastItemUnder(0) { D_METHOD(("DiagramItemGroup::DiagramItemGroup()\n")); - m_selection = new BList(1); + fSelection = new BList(1); } + DiagramItemGroup::~DiagramItemGroup() { D_METHOD(("DiagramItemGroup::~DiagramItemGroup()\n")); - if (m_selection) - { - m_selection->MakeEmpty(); - delete m_selection; + if (fSelection) { + fSelection->MakeEmpty(); + delete fSelection; } - if (m_boxes && (m_types & DiagramItem::M_BOX)) - { - while (countItems(DiagramItem::M_BOX) > 0) - { - DiagramItem *item = itemAt(0, DiagramItem::M_BOX); - if (removeItem(item)) + + if (fBoxes && (fTypes & DiagramItem::M_BOX)) { + while (CountItems(DiagramItem::M_BOX) > 0) { + DiagramItem *item = ItemAt(0, DiagramItem::M_BOX); + if (RemoveItem(item)) delete item; } - delete m_boxes; + delete fBoxes; } - if (m_wires && (m_types & DiagramItem::M_WIRE)) - { - while (countItems(DiagramItem::M_WIRE) > 0) - { - DiagramItem *item = itemAt(0, DiagramItem::M_WIRE); - if (removeItem(item)) + + if (fWires && (fTypes & DiagramItem::M_WIRE)) { + while (CountItems(DiagramItem::M_WIRE) > 0) { + DiagramItem *item = ItemAt(0, DiagramItem::M_WIRE); + if (RemoveItem(item)) delete item; } - delete m_wires; + delete fWires; } - if (m_endPoints && (m_types & DiagramItem::M_ENDPOINT)) - { - while (countItems(DiagramItem::M_ENDPOINT) > 0) - { - DiagramItem *item = itemAt(0, DiagramItem::M_ENDPOINT); - if (removeItem(item)) + + if (fEndPoints && (fTypes & DiagramItem::M_ENDPOINT)) { + while (CountItems(DiagramItem::M_ENDPOINT) > 0) { + DiagramItem *item = ItemAt(0, DiagramItem::M_ENDPOINT); + if (RemoveItem(item)) delete item; } - delete m_endPoints; + delete fEndPoints; } } -// -------------------------------------------------------- // -// *** item accessors -// -------------------------------------------------------- // -uint32 DiagramItemGroup::countItems( - uint32 whichType) const +// #pragma mark - item accessors + + +//! Returns the number of items in the group (optionally only those +// of the given type \param whichType) +uint32 +DiagramItemGroup::CountItems(uint32 whichType) const { - D_METHOD(("DiagramItemGroup::countItems()\n")); + D_METHOD(("DiagramItemGroup::CountItems()\n")); uint32 count = 0; - if (whichType & m_types) - { - if (whichType & DiagramItem::M_BOX) - { - if (m_boxes) - { - count += m_boxes->CountItems(); - } + if (whichType & fTypes) { + if (whichType & DiagramItem::M_BOX) { + if (fBoxes) + count += fBoxes->CountItems(); + } - if (whichType & DiagramItem::M_WIRE) - { - if (m_wires) - { - count += m_wires->CountItems(); - } + + if (whichType & DiagramItem::M_WIRE) { + if (fWires) + count += fWires->CountItems(); } - if (whichType & DiagramItem::M_ENDPOINT) - { - if (m_endPoints) - { - count += m_endPoints->CountItems(); - } + + if (whichType & DiagramItem::M_ENDPOINT) { + if (fEndPoints) + count += fEndPoints->CountItems(); } } + return count; } -DiagramItem *DiagramItemGroup::itemAt( - uint32 index, - uint32 whichType) const + +/*! Returns a pointer to the item in the lists which is + at the given index; if none is found, this function + returns 0 +*/ +DiagramItem* +DiagramItemGroup::ItemAt(uint32 index, uint32 whichType) const { - D_METHOD(("DiagramItemGroup::itemAt()\n")); - if (m_types & whichType) - { - if (whichType & DiagramItem::M_BOX) - { - if (m_boxes && (index < countItems(DiagramItem::M_BOX))) - { - return static_cast(m_boxes->ItemAt(index)); - } + D_METHOD(("DiagramItemGroup::ItemAt()\n")); + if (fTypes & whichType) { + if (whichType & DiagramItem::M_BOX) { + if (fBoxes && (index < CountItems(DiagramItem::M_BOX))) + return static_cast(fBoxes->ItemAt(index)); else - { - index -= countItems(DiagramItem::M_BOX); - } + index -= CountItems(DiagramItem::M_BOX); } - if (whichType & DiagramItem::M_WIRE) - { - if (m_wires && (index < countItems(DiagramItem::M_WIRE))) - { - return static_cast(m_wires->ItemAt(index)); - } + + if (whichType & DiagramItem::M_WIRE) { + if (fWires && (index < CountItems(DiagramItem::M_WIRE))) + return static_cast(fWires->ItemAt(index)); else - { - index -= countItems(DiagramItem::M_WIRE); - } + index -= CountItems(DiagramItem::M_WIRE); } - if (whichType & DiagramItem::M_ENDPOINT) - { - if (m_endPoints && (index < countItems(DiagramItem::M_ENDPOINT))) - { - return static_cast(m_endPoints->ItemAt(index)); - } + + if (whichType & DiagramItem::M_ENDPOINT) { + if (fEndPoints && (index < CountItems(DiagramItem::M_ENDPOINT))) + return static_cast(fEndPoints->ItemAt(index)); } } + return 0; } -// This function returns the first box or endpoint found that -// contains the given point. For connections it looks at all -// wires that 'might' contain the point and calls their method -// howCloseTo() to find the one closest to the point. -// The lists should be sorted by selection time for proper results! -DiagramItem *DiagramItemGroup::itemUnder( - BPoint point) + +/*! This function returns the first box or endpoint found that + contains the given \param point. For connections it looks at all + wires that 'might' contain the point and calls their method + howCloseTo() to find the one closest to the point. + The lists should be sorted by selection time for proper results! +*/ +DiagramItem* +DiagramItemGroup::ItemUnder(BPoint point) { - D_METHOD(("DiagramItemGroup::itemUnder()\n")); - if (m_types & DiagramItem::M_BOX) - { - for (uint32 i = 0; i < countItems(DiagramItem::M_BOX); i++) - { - DiagramItem *item = itemAt(i, DiagramItem::M_BOX); - if (item->frame().Contains(point) && (item->howCloseTo(point) == 1.0)) - { -// DiagramItemGroup *group = dynamic_cast(item); - return (m_lastItemUnder = item); + D_METHOD(("DiagramItemGroup::ItemUnder()\n")); + if (fTypes & DiagramItem::M_BOX) { + for (uint32 i = 0; i < CountItems(DiagramItem::M_BOX); i++) { + DiagramItem *item = ItemAt(i, DiagramItem::M_BOX); + if (item->frame().Contains(point) && (item->howCloseTo(point) == 1.0)) { + // DiagramItemGroup *group = dynamic_cast(item); + return (fLastItemUnder = item); } } } - if (m_types & DiagramItem::M_WIRE) - { + + if (fTypes & DiagramItem::M_WIRE) { float closest = 0.0; DiagramItem *closestItem = 0; - for (uint32 i = 0; i < countItems(DiagramItem::M_WIRE); i++) - { - DiagramItem *item = itemAt(i, DiagramItem::M_WIRE); - if (item->frame().Contains(point)) - { + for (uint32 i = 0; i < CountItems(DiagramItem::M_WIRE); i++) { + DiagramItem *item = ItemAt(i, DiagramItem::M_WIRE); + if (item->frame().Contains(point)) { float howClose = item->howCloseTo(point); - if (howClose > closest) - { + if (howClose > closest) { closestItem = item; if (howClose == 1.0) - return (m_lastItemUnder = item); + return (fLastItemUnder = item); closest = howClose; } } } + if (closest > 0.5) - { - return (m_lastItemUnder = closestItem); - } + return (fLastItemUnder = closestItem); } - if (m_types & DiagramItem::M_ENDPOINT) - { - for (uint32 i = 0; i < countItems(DiagramItem::M_ENDPOINT); i++) - { - DiagramItem *item = itemAt(i, DiagramItem::M_ENDPOINT); + + if (fTypes & DiagramItem::M_ENDPOINT) { + for (uint32 i = 0; i < CountItems(DiagramItem::M_ENDPOINT); i++) { + DiagramItem *item = ItemAt(i, DiagramItem::M_ENDPOINT); if (item->frame().Contains(point) && (item->howCloseTo(point) == 1.0)) - { - return (m_lastItemUnder = item); - } + return (fLastItemUnder = item); } } - return (m_lastItemUnder = 0); // no item was found! + + return (fLastItemUnder = 0); // no item was found! } -// -------------------------------------------------------- // -// *** item operations -// -------------------------------------------------------- // -bool DiagramItemGroup::addItem( - DiagramItem *item) +// #pragma mark - item operations + + +//! Adds an \param item to the group; returns true on success. +bool +DiagramItemGroup::AddItem(DiagramItem *item) { - D_METHOD(("DiagramItemGroup::addItem()\n")); - if (item && (m_types & item->type())) - { - switch (item->type()) - { + D_METHOD(("DiagramItemGroup::AddItem()\n")); + if (item && (fTypes & item->type())) { + switch (item->type()) { case DiagramItem::M_BOX: - { - if (!m_boxes) - { - m_boxes = new BList(); - } + if (!fBoxes) + fBoxes = new BList(); item->m_group = this; - return m_boxes->AddItem(static_cast(item)); - } + return fBoxes->AddItem(static_cast(item)); + case DiagramItem::M_WIRE: - { - if (!m_wires) - { - m_wires = new BList(); - } + if (!fWires) + fWires = new BList(); item->m_group = this; - return m_wires->AddItem(static_cast(item)); - } + return fWires->AddItem(static_cast(item)); + case DiagramItem::M_ENDPOINT: - { - if (!m_endPoints) - { - m_endPoints = new BList(); - } + if (!fEndPoints) + fEndPoints = new BList(); item->m_group = this; - return m_endPoints->AddItem(static_cast(item)); - } + return fEndPoints->AddItem(static_cast(item)); } } + return false; } -bool DiagramItemGroup::removeItem( - DiagramItem *item) + +//! Removes an \param item from the group; returns true on success. +bool +DiagramItemGroup::RemoveItem(DiagramItem* item) { - D_METHOD(("DiagramItemGroup::removeItem()\n")); - if (item && (m_types & item->type())) - { + D_METHOD(("DiagramItemGroup::RemoveItem()\n")); + if (item && (fTypes & item->type())) { // reset the lastItemUnder-pointer if it pointed to this item - if (m_lastItemUnder == item) - { - m_lastItemUnder = 0; - } + if (fLastItemUnder == item) + fLastItemUnder = 0; + // remove it from the selection list if it was selected if (item->isSelected()) - { - m_selection->RemoveItem(static_cast(item)); - } + fSelection->RemoveItem(static_cast(item)); + // try to remove the item from its list - switch (item->type()) - { + switch (item->type()) { case DiagramItem::M_BOX: - { - if (m_boxes) - { + if (fBoxes) { item->m_group = 0; - return m_boxes->RemoveItem(static_cast(item)); + return fBoxes->RemoveItem(static_cast(item)); } - } + break; + case DiagramItem::M_WIRE: - { - if (m_wires) - { + if (fWires) { item->m_group = 0; - return m_wires->RemoveItem(static_cast(item)); + return fWires->RemoveItem(static_cast(item)); } - } + break; + case DiagramItem::M_ENDPOINT: - { - if (m_endPoints) - { + if (fEndPoints) { item->m_group = 0; - return m_endPoints->RemoveItem(static_cast(item)); + return fEndPoints->RemoveItem(static_cast(item)); } - } } } + return false; } -void DiagramItemGroup::sortItems( - uint32 whichType, + +/*! Performs a quicksort on a list of items with the provided + compare function (one is already defined in the DiagramItem + implementation); can't handle more than one item type at a + time! +*/ +void +DiagramItemGroup::SortItems(uint32 whichType, int (*compareFunc)(const void *, const void *)) { - D_METHOD(("DiagramItemGroup::sortItems()\n")); - if ((whichType != DiagramItem::M_ANY) && (m_types & whichType)) - { - switch (whichType) - { + D_METHOD(("DiagramItemGroup::SortItems()\n")); + if ((whichType != DiagramItem::M_ANY) && (fTypes & whichType)) { + switch (whichType) { case DiagramItem::M_BOX: - { - if (m_boxes) - { - m_boxes->SortItems(compareFunc); - } + if (fBoxes) + fBoxes->SortItems(compareFunc); break; - } + case DiagramItem::M_WIRE: - { - if (m_wires) - { - m_wires->SortItems(compareFunc); - } + if (fWires) + fWires->SortItems(compareFunc); break; - } + case DiagramItem::M_ENDPOINT: - { - if (m_endPoints) - { - m_endPoints->SortItems(compareFunc); - } + if (fEndPoints) + fEndPoints->SortItems(compareFunc); break; - } } } } -// items are drawn in reverse order; they should be sorted by -// selection time before this function gets called, so that -// the more recently selected item are drawn above others -void DiagramItemGroup::drawItems( - BRect updateRect, - uint32 whichType, - BRegion *updateRegion) + +/*! Fires a draw() command at all items of a specific type that + intersect with the \param updateRect; + items are drawn in reverse order; they should be sorted by + selection time before this function gets called, so that + the more recently selected item are drawn above others. +*/ +void +DiagramItemGroup::DrawItems(BRect updateRect, uint32 whichType, BRegion* updateRegion) { - D_METHOD(("DiagramItemGroup::drawItems()\n")); - if (whichType & DiagramItem::M_WIRE) - { - for (int32 i = countItems(DiagramItem::M_WIRE) - 1; i >= 0; i--) - { - DiagramItem *item = itemAt(i, DiagramItem::M_WIRE); + D_METHOD(("DiagramItemGroup::DrawItems()\n")); + if (whichType & DiagramItem::M_WIRE) { + for (int32 i = CountItems(DiagramItem::M_WIRE) - 1; i >= 0; i--) { + DiagramItem *item = ItemAt(i, DiagramItem::M_WIRE); if (item->frame().Intersects(updateRect)) - { item->draw(updateRect); - } } } - if (whichType & DiagramItem::M_BOX) - { - for (int32 i = countItems(DiagramItem::M_BOX) - 1; i >= 0; i--) - { - DiagramItem *item = itemAt(i, DiagramItem::M_BOX); - if (item && item->frame().Intersects(updateRect)) - { + + if (whichType & DiagramItem::M_BOX) { + for (int32 i = CountItems(DiagramItem::M_BOX) - 1; i >= 0; i--) { + DiagramItem *item = ItemAt(i, DiagramItem::M_BOX); + if (item && item->frame().Intersects(updateRect)) { item->draw(updateRect); if (updateRegion) updateRegion->Exclude(item->frame()); } } } - if (whichType & DiagramItem::M_ENDPOINT) - { - for (int32 i = countItems(DiagramItem::M_ENDPOINT) - 1; i >= 0; i--) - { - DiagramItem *item = itemAt(i, DiagramItem::M_ENDPOINT); + + if (whichType & DiagramItem::M_ENDPOINT) { + for (int32 i = CountItems(DiagramItem::M_ENDPOINT) - 1; i >= 0; i--) { + DiagramItem *item = ItemAt(i, DiagramItem::M_ENDPOINT); if (item && item->frame().Intersects(updateRect)) - { item->draw(updateRect); - } } } } -bool DiagramItemGroup::getClippingAbove( - DiagramItem *which, - BRegion *region) + +/*! Returns in outRegion the \param region of items that lay "over" the given + DiagramItem in \param which; returns false if no items are above or the item + doesn't exist. +*/ +bool +DiagramItemGroup::GetClippingAbove(DiagramItem *which, BRegion *region) { - D_METHOD(("DiagramItemGroup::getClippingAbove()\n")); + D_METHOD(("DiagramItemGroup::GetClippingAbove()\n")); bool found = false; - if (which && region) - { - switch (which->type()) - { + if (which && region) { + switch (which->type()) { case DiagramItem::M_BOX: { - int32 index = m_boxes->IndexOf(which); - if (index >= 0) // the item was found - { + int32 index = fBoxes->IndexOf(which); + if (index >= 0) { // the item was found BRect r = which->frame(); - for (int32 i = 0; i < index; i++) - { - DiagramItem *item = itemAt(i, DiagramItem::M_BOX); - if (item && item->frame().Intersects(r)) - { + for (int32 i = 0; i < index; i++) { + DiagramItem *item = ItemAt(i, DiagramItem::M_BOX); + if (item && item->frame().Intersects(r)) { region->Include(item->frame() & r); found = true; } @@ -408,14 +360,13 @@ } break; } + case DiagramItem::M_WIRE: { BRect r = which->frame(); - for (uint32 i = 0; i < countItems(DiagramItem::M_BOX); i++) - { - DiagramItem *item = itemAt(i, DiagramItem::M_BOX); - if (item && item->frame().Intersects(r)) - { + for (uint32 i = 0; i < CountItems(DiagramItem::M_BOX); i++) { + DiagramItem *item = ItemAt(i, DiagramItem::M_BOX); + if (item && item->frame().Intersects(r)) { region->Include(item->frame() & r); found = true; } @@ -424,219 +375,227 @@ } } } + return found; } -// -------------------------------------------------------- // -// *** selection accessors -// -------------------------------------------------------- // -uint32 DiagramItemGroup::selectedType() const +// #pragma mark - selection accessors + + +/*! Returns the type of DiagramItems in the current selection + (currently only one type at a time is supported!) +*/ +uint32 +DiagramItemGroup::SelectedType() const { - D_METHOD(("DiagramItemGroup::selectedType()\n")); - if (countSelectedItems() > 0) - { - return selectedItemAt(0)->type(); - } + D_METHOD(("DiagramItemGroup::SelectedType()\n")); + if (CountSelectedItems() > 0) + return SelectedItemAt(0)->type(); + return 0; } -uint32 DiagramItemGroup::countSelectedItems() const + +//! Returns the number of items in the current selection +uint32 +DiagramItemGroup::CountSelectedItems() const { - D_METHOD(("DiagramItemGroup::countSelectedItems()\n")); - if (m_selection) - { - return m_selection->CountItems(); - } + D_METHOD(("DiagramItemGroup::CountSelectedItems()\n")); + if (fSelection) + return fSelection->CountItems(); + return 0; } -DiagramItem *DiagramItemGroup::selectedItemAt( - uint32 index) const + +/*! Returns a pointer to the item in the list which is + at the given \param index; if none is found, this function + returns 0 +*/ +DiagramItem* +DiagramItemGroup::SelectedItemAt(uint32 index) const { - D_METHOD(("DiagramItemGroup::selectedItemAt()\n")); - if (m_selection) - { - return static_cast(m_selection->ItemAt(index)); - } + D_METHOD(("DiagramItemGroup::SelectedItemAt()\n")); + if (fSelection) + return static_cast(fSelection->ItemAt(index)); + return 0; } -// -------------------------------------------------------- // -// *** selection related operations -// -------------------------------------------------------- // -// selects an item, optionally replacing the complete former -// selection. If the type of the item to be selected differs -// from the type of items currently selected, this methods -// automatically replaces the former selection -bool DiagramItemGroup::selectItem( - DiagramItem *which, - bool deselectOthers) +// #pragma mark - selection related operations + + +/*! Selects an item, optionally replacing the complete former + selection. If the type of the item to be selected differs + from the type of items currently selected, this methods + automatically replaces the former selection +*/ +bool +DiagramItemGroup::SelectItem(DiagramItem* which, bool deselectOthers) { - D_METHOD(("DiagramItemGroup::selectItem()\n")); + D_METHOD(("DiagramItemGroup::SelectItem()\n")); bool selectionChanged = false; - if (which && !which->isSelected() && which->isSelectable()) - { + if (which && !which->isSelected() && which->isSelectable()) { // check if the item's type is the same as of the other // selected items - if (m_multiSelection) - { - if (which->type() != selectedType()) - { + if (fMultiSelection) { + if (which->type() != SelectedType()) deselectOthers = true; - } } // check if the former selection has to be deselected - if (deselectOthers || !m_multiSelection) - { - while (countSelectedItems() > 0) - { - deselectItem(selectedItemAt(0)); - } + if (deselectOthers || !fMultiSelection) { + while (CountSelectedItems() > 0) + DeselectItem(SelectedItemAt(0)); } // select the item - if (deselectOthers || countSelectedItems() == 0) - { + if (deselectOthers || CountSelectedItems() == 0) which->select(); - } else - { which->selectAdding(); - } - m_selection->AddItem(which); + + fSelection->AddItem(which); selectionChanged = true; } // resort the lists if necessary - if (selectionChanged) - { - sortItems(which->type(), compareSelectionTime); - sortSelectedItems(compareSelectionTime); + if (selectionChanged) { + SortItems(which->type(), compareSelectionTime); + SortSelectedItems(compareSelectionTime); return true; } + return false; } -bool DiagramItemGroup::deselectItem( - DiagramItem *which) + +//! Simply deselects one item +bool +DiagramItemGroup::DeselectItem(DiagramItem* which) { - D_METHOD(("DiagramItemGroup::deselectItem()\n")); - if (which && which->isSelected()) - { - m_selection->RemoveItem(which); + D_METHOD(("DiagramItemGroup::DeselectItem()\n")); + if (which && which->isSelected()) { + fSelection->RemoveItem(which); which->deselect(); - sortItems(which->type(), compareSelectionTime); - sortSelectedItems(compareSelectionTime); + SortItems(which->type(), compareSelectionTime); + SortSelectedItems(compareSelectionTime); return true; } + return false; } -bool DiagramItemGroup::selectAll( - uint32 itemType) + +//! Selects all items of the given \param itemType +bool +DiagramItemGroup::SelectAll(uint32 itemType) { - D_METHOD(("DiagramItemGroup::selectAll()\n")); + D_METHOD(("DiagramItemGroup::SelectAll()\n")); bool selectionChanged = false; - if (m_types & itemType) - { - for (int32 i = 0; i < countItems(itemType); i++) - { - if (selectItem(itemAt(i, itemType), false)) + if (fTypes & itemType) { + for (uint32 i = 0; i < CountItems(itemType); i++) { + if (SelectItem(ItemAt(i, itemType), false)) selectionChanged = true; [... truncated: 3663 lines follow ...] From leavengood at gmail.com Mon May 14 16:43:00 2007 From: leavengood at gmail.com (Ryan Leavengood) Date: Mon, 14 May 2007 10:43:00 -0400 Subject: [Haiku-commits] r21130 - in haiku/trunk/src/preferences: keyboard keymap mouse virtualmemory In-Reply-To: <15072296296-BeMail@zon> References: <20070514102555.91750@gmx.net> <15072296296-BeMail@zon> Message-ID: On 5/14/07, Axel D?rfler wrote: > "Stephan Assmus" wrote: > > I looked at these icons at home, and they all opened fine. I also did > > some > > little tweaks here and there, which I will commit as soon as I have > > internet > > again. I don't know about any vector Joysticks icon. > > Me neither, but there is one in the tree - maybe it's just some other > icon. > Anyway, I could open all icons with Icon-O-Matic, but I got those > errors when Haiku tried to render them in Tracker. The Joysticks vector icon is just a copy of the Fonts vector icon, added as temporary filler until a proper one could be made. Ryan From axeld at mail.berlios.de Mon May 14 17:56:39 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 14 May 2007 17:56:39 +0200 Subject: [Haiku-commits] r21138 - in haiku/trunk/src: apps/powerstatus preferences/joysticks Message-ID: <200705141556.l4EFudXX015005@sheep.berlios.de> Author: axeld Date: 2007-05-14 17:56:39 +0200 (Mon, 14 May 2007) New Revision: 21138 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21138&view=rev Modified: haiku/trunk/src/apps/powerstatus/PowerStatus.rdef haiku/trunk/src/preferences/joysticks/Joysticks.rdef Log: Added two more of zuMi's icons - turns out it was my fault that the icons couldn't be rendered before... Thanks zuMi! Now, only the floppy icon doesn't have a home yet. Modified: haiku/trunk/src/apps/powerstatus/PowerStatus.rdef =================================================================== --- haiku/trunk/src/apps/powerstatus/PowerStatus.rdef 2007-05-14 14:15:34 UTC (rev 21137) +++ haiku/trunk/src/apps/powerstatus/PowerStatus.rdef 2007-05-14 15:56:39 UTC (rev 21138) @@ -12,6 +12,36 @@ internal = 0, short_info = "PowerStatus", - long_info = "PowerStatus ?2006 Haiku" + long_info = "PowerStatus ?2006-2007 Haiku" }; +#ifdef HAIKU_TARGET_PLATFORM_HAIKU + +resource vector_icon { + $"6E6369660A01000100FC0100010073020006033C00000000000000003C000049" + $"40004B0000003399333F66CC66FF339933020016033C00000000000000003C00" + $"004940004B000000B83FEEFFB8020006033C00000000000000003C0000494000" + $"4B000000FF99003FFFCC00FFFF9900020006023A9D433BA9A6BCD9483C088A4A" + $"42A9428A8A0099FF99FF60D160020116023D00000000000000003D0000494000" + $"484000FF010066020016033A00000000000000003A000049400048C00000993F" + $"CCFF8602001602374FE739A41DBBA41D394FE74A0A044642FE00F3FFC2020016" + $"02383B6C3951BCBB51BC3A3B6C4A4680464DDA00FFFF9E0802062A442A44B6FE" + $"C3FB3A50B9D450C0DF504A44C3B9C3FB4A444A304A304AB6BC3A24C0E124B9D6" + $"242A302AB6BC2A300206C3B9C156C3B9C1564AC3F93A50C0DF50B9D4502AC156" + $"B6F9C3F92AC1562A502A50B6FEC8C33A5CB9D45CC0DF5C4A50C3B9C8C34A5002" + $"042A302ABC032AB6BC3A24B9D624C0E1244A304AB6BC4ABC033A3CC0E13CB9D6" + $"3C0204483048B72C48BB933A3AC0703ABA473A2C302CBB932CB72C3A26BA4726" + $"C070260206322C322C32B6763A26BB9926BF1E26422C42B676422C4230423042" + $"BAB13A36BF1E36BB9936323032BAB132300204322C32B91932B6763A26BB9926" + $"BF1E26422C42B67642B9193A32BF1E32BB9932020E40C03140C031BF3FC0593C" + $"C081BEB6C0733CC0813CBEE93CBEE9BDE5BEEF3A3EBDA13EBD163E38BEE9BCD2" + $"BEEF38BEE938C08138C081BC01C07334C031BB78C05834C03134C1CA34C1CABB" + $"78C1F138C219BC01C20B38C21938C3B138C3B1BCD3C3B73A4ABD164ABDA14A3C" + $"C3B1BDE5C3B73CC3B13CC2193CC219BEB6C20B40C1CABF3FC1F140C1CA0604FE" + $"3A5E4C5E4C5E545E5A505A5A5A4A4A4856484A480B0A010107000A0002000110" + $"01178422040A020100000A040101000A050102000A060103000A000204051001" + $"178422040A070104000A080105000A090105123F878F0000000000003F878F43" + $"C38740D2A501178200040A03010600" +}; + +#endif // HAIKU_TARGET_PLATFORM_HAIKU Modified: haiku/trunk/src/preferences/joysticks/Joysticks.rdef =================================================================== --- haiku/trunk/src/preferences/joysticks/Joysticks.rdef 2007-05-14 14:15:34 UTC (rev 21137) +++ haiku/trunk/src/preferences/joysticks/Joysticks.rdef 2007-05-14 15:56:39 UTC (rev 21138) @@ -21,19 +21,30 @@ #ifdef HAIKU_TARGET_PLATFORM_HAIKU resource vector_icon { - $"6E63696608050004005F020006023D5F39368F62B905F93FFB6B4ACB36BEDE32" - $"00032288FF1944E7020006023AAFCC3BFAA8BF50A93E3D044B460F48AEEC0002" - $"0258FF1919E7020006023BA7EB3CD6E4BF5D013E2A4C4B0DDA478DDF0097C3FF" - $"FF376AFF02000602380D3A384399BEF6CA3EAF9C4B2833C6F2DC00E3ECFFFFAC" - $"C7FF02000602371F7FB98A813FA8F13D3A58C4B8AC48909300CEDEFFFF3778FF" - $"02000602371F7FB98A813FA8F13D3A58C60C5648909300BADAFFFF032E850B0A" - $"0432482C503E543C4B0A0550485452485E565A60500A0A47273D24322A244A2C" - $"4E34C2B0BE5BC408BFBFC94F485C52520A0447273C2D485C52520A08BE5AC40E" - $"4058485CBE3D2D322A244A2C4EB935C20F0A03BC12BB843BC1D3B9EBC0700A03" - $"BC12BB84BCC2BE1AB9EBC0700A03BD75C0B13BC1D3B9EBC0700A03BCC2BE1ABD" - $"75C0B1B9EBC0700A032C4E34C2B0B939C20A0A043D24322A3C2D4727090A0102" - $"0001000A0001021001178400040A020103000A030109000A030106000A060107" - $"000A070108000A04020405000A05010A00" + $"6E6369661102001602AE1F623AC0B4BC7FF4AFDAE84B61574B01BF0099FE8002" + $"0016023A72333A634ABACB4D3ADCBF49B5514AA84A00CCFDB402001602389476" + $"3AB560BCB5603A94764AE4104A26C500E5FFD5020116023C0000000000000000" + $"3C000048FC0049AC000099FF33056602011602BC6AE033DF93B1CA89BA5DBE4A" + $"838A4A71F20099FF3305330200160236000000000000000036000049C00049F0" + $"000099FF33020106033B4F850000000000003B4F85495FFB467FF700FFFFFF7F" + $"FF3300FFCC0000020006023800000000000000003800004B00004A900000FF33" + $"33FFCC00000566020106023793E43593E4B593E43793E44AF1B04A351100FFAC" + $"ACFFF56A6A03010000010100007B056105A50537100A044456445C584858440A" + $"044456445C244C24480A042448445658443A3602044A454ABFC24AC3B83E4EC1" + $"974EBC504E324532C3B832BFC23E3CBC503CC1973C020447C12547BFD347C276" + $"3EC389C0EFC389BCF8C38935C12535C27635BFD33EBEC1BCF8BEC1C0EFBEC102" + $"04424542C11542C2663E48BFD548BE12483A453AC2663AC1153E42BE1242BFD5" + $"4206051F033E48BEA948BF3E4840C2C5BF83C2DF40C2C5333C3CC2C53CC2C5BE" + $"64C2DF0204472D47B63347BA283E36C0EE36BCF936352D35BA2835B6333E24BC" + $"F924C0EE240204544554C11554C2665048C70148C53E484C454CC2664CC11550" + $"42C53E42C701420204534453C0E753C1C85046C6C846C577464D444DC1C84DC0" + $"E75042C57742C6C8420804445E4A5E60485A450A043E494449474542450A0444" + $"49444D484947450A04444D4E4D524949490A054E4D4E4D4E52524E524906031F" + $"3C363C363C3840393E39403936140A0D010A000A0D01072039460A0C04000102" + $"071001178422040A000100000A010101000A020102000A030103000A04010310" + $"01178000040A050104000A060105000A070106000A10010F000A080107000A09" + $"0108000A0A01081001178000040A0B0109000A10010B000A0C010C000A0F010D" + $"000A0E010E00" }; #else // HAIKU_TARGET_PLATFORM_HAIKU From axeld at pinc-software.de Mon May 14 17:57:44 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Mon, 14 May 2007 17:57:44 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r21130_-_in_haiku/trunk/src/prefe?= =?iso-8859-15?q?rences=3A_keyboard_keymap_mouse_virtualmemory?= In-Reply-To: Message-ID: <32848427500-BeMail@zon> "Ryan Leavengood" wrote: > On 5/14/07, Axel D?rfler wrote: > > "Stephan Assmus" wrote: > > > I looked at these icons at home, and they all opened fine. I also > > > did > > > some > > > little tweaks here and there, which I will commit as soon as I > > > have > > > internet > > > again. I don't know about any vector Joysticks icon. > > Me neither, but there is one in the tree - maybe it's just some > > other > > icon. > > Anyway, I could open all icons with Icon-O-Matic, but I got those > > errors when Haiku tried to render them in Tracker. > The Joysticks vector icon is just a copy of the Fonts vector icon, > added as temporary filler until a proper one could be made. Thanks! I've now added zuMi's icons to the repository - I copied the files with copy_to_bfs_image (which cannot be built anymore since Ingo changed the build system a long time ago), and that one is broken with regards to copying attributes... :-) Bye, Axel. From axeld at mail.berlios.de Tue May 15 02:51:37 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 15 May 2007 02:51:37 +0200 Subject: [Haiku-commits] r21139 - in haiku/trunk/src: add-ons/kernel/file_systems/cdda tests/add-ons/kernel/file_systems tests/add-ons/kernel/file_systems/cdda Message-ID: <200705150051.l4F0pbNI024254@sheep.berlios.de> Author: axeld Date: 2007-05-15 02:51:35 +0200 (Tue, 15 May 2007) New Revision: 21139 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21139&view=rev Added: haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.h haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/ haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/Jamfile haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/cdda_text.cpp Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/Jamfile haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp haiku/trunk/src/tests/add-ons/kernel/file_systems/Jamfile Log: * Moved cdda_text test application to the test directory, and separated it from cdda.cpp. * Implemented most of the directory retrieval functions of the file system; even renaming titles should work now. Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/Jamfile 2007-05-14 15:56:39 UTC (rev 21138) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/Jamfile 2007-05-15 00:51:35 UTC (rev 21139) @@ -6,8 +6,5 @@ KernelAddon cdda : kernel_interface.cpp - ; - -SimpleTest cdda_text : cdda.cpp - : be ; + ; Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp 2007-05-14 15:56:39 UTC (rev 21138) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp 2007-05-15 00:51:35 UTC (rev 21139) @@ -4,17 +4,15 @@ */ -#include +#include "cdda.h" + +#include #include #include -#include #include #include -#include -#define kFramesPerSecond 75 -#define kFramesPerMinute (kFramesPerSecond * 60) struct cdtext_pack_data { uint8 id; @@ -27,35 +25,37 @@ uint8 crc[2]; } _PACKED; - -static const uint8 kMaxTracks = 0x63; enum { kTrackID = 0x80, kArtistID = 0x81, kMessageID = 0x85, }; -struct cdtext { - char *artist; - char *album; - char *titles[kMaxTracks]; - char *artists[kMaxTracks]; - uint8 track_count; - char *genre; -}; +static const uint32 kBufferSize = 16384; +static const uint32 kSenseSize = 1024; // #pragma mark - string functions -bool +static char * +copy_string(const char *string) +{ + if (string == NULL || !string[0]) + return NULL; + + return strdup(string); +} + + +static bool is_garbage(char c) { return isspace(c) || c == '-' || c == '/' || c == '\\'; } -void +static void sanitize_string(char *string) { if (string == NULL) @@ -106,7 +106,7 @@ } -void +static void cut_string(char *string, char *cut) { if (string == NULL || cut == NULL) @@ -121,7 +121,7 @@ } -void +static void sanitize_album(cdtext &text) { cut_string(text.album, text.artist); @@ -133,7 +133,7 @@ if (space != NULL) { space[0] = '\0'; text.artist = text.album; - text.album = strdup(space + 2); + text.album = copy_string(space + 2); sanitize_string(text.artist); sanitize_string(text.album); @@ -142,26 +142,28 @@ } -void +static void sanitize_titles(cdtext &text) { for (uint8 i = 0; i < text.track_count; i++) { cut_string(text.titles[i], "(Album Version)"); sanitize_string(text.titles[i]); sanitize_string(text.artists[i]); - if (!strcasecmp(text.artists[i], text.artist)) { + + if (text.artists[i] != NULL && text.artist != NULL + && !strcasecmp(text.artists[i], text.artist)) { // if the title artist is the same as the main artist, remove it free(text.artists[i]); text.artists[i] = NULL; } if (text.titles[i] != NULL && text.titles[i][0] == '\t' && i > 0) - text.titles[i] = strdup(text.titles[i - 1]); + text.titles[i] = copy_string(text.titles[i - 1]); } } -bool +static bool single_case(const char *string, bool &upper, bool &first) { if (string == NULL) @@ -185,7 +187,7 @@ } -void +static void capitalize_string(char *string) { if (string == NULL) @@ -207,7 +209,7 @@ } -void +static void correct_case(cdtext &text) { // check if all titles share a single case @@ -238,14 +240,39 @@ // #pragma mark - CD-Text -bool +cdtext::cdtext() + : + artist(NULL), + album(NULL), + genre(NULL), + track_count(0) +{ + memset(titles, 0, sizeof(titles)); + memset(artists, 0, sizeof(artists)); +} + + +cdtext::~cdtext() +{ + free(album); + free(artist); + free(genre); + + for (uint8 i = 0; i < track_count; i++) { + free(titles[i]); + free(artists[i]); + } +} + + +static bool is_string_id(uint8 id) { return id >= kTrackID && id <= kMessageID; } -bool +static bool parse_pack_data(cdtext_pack_data *&pack, uint32 &packLeft, cdtext_pack_data *&lastPack, uint8 &id, uint8 &track, uint8 &state, char *buffer, size_t &length) @@ -280,13 +307,13 @@ while (id == pack->id && track == pack->track) { #if 1 - printf("%u.%u.%u, %u.%u.%u, ", pack->id, pack->track, pack->number, + dprintf("%u.%u.%u, %u.%u.%u, ", pack->id, pack->track, pack->number, pack->double_byte, pack->block_number, pack->character_position); for (int32 i = 0; i < 12; i++) { if (isprint(pack->text[i])) - putchar(pack->text[i]); + dprintf("%c", pack->text[i]); } - putchar('\n'); + dprintf("\n"); #endif if (is_string_id(id)) { // TODO: support double byte characters @@ -330,72 +357,22 @@ } -void -dump_cdtext(cdtext_pack_data *pack, size_t packLength) +static void +dump_cdtext(cdtext &text) { - cdtext_pack_data *lastPack = NULL; - char buffer[256]; - uint8 state = 0; - cdtext text; - - memset(&text, 0, sizeof(cdtext)); - - while (true) { - size_t length = sizeof(buffer); - uint8 id, track; - - if (!parse_pack_data(pack, packLength, lastPack, id, track, - state, buffer, length)) - break; - - switch (id) { - case kTrackID: - if (track == 0) { - if (text.album == NULL) - text.album = strdup(buffer); - } else if (track <= kMaxTracks) { - if (text.titles[track - 1] == NULL) - text.titles[track - 1] = strdup(buffer); - if (track > text.track_count) - text.track_count = track; - } - break; - - case kArtistID: - if (track == 0) { - if (text.artist == NULL) - text.artist = strdup(buffer); - } else if (track <= kMaxTracks) { - if (text.artists[track - 1] == NULL) - text.artists[track - 1] = strdup(buffer); - } - break; - - default: - if (is_string_id(id)) - printf("UNKNOWN %u: \"%s\"\n", id, buffer); - break; - } - } - - sanitize_string(text.artist); - sanitize_album(text); - sanitize_titles(text); - correct_case(text); - if (text.album) - printf("Album: \"%s\"\n", text.album); + dprintf("Album: \"%s\"\n", text.album); if (text.artist) - printf("Artist: \"%s\"\n", text.artist); + dprintf("Artist: \"%s\"\n", text.artist); for (uint8 i = 0; i < text.track_count; i++) { - printf("Track %02u: \"%s\"%s%s%s\n", i + 1, text.titles[i], + dprintf("Track %02u: \"%s\"%s%s%s\n", i + 1, text.titles[i], text.artists[i] ? " (" : "", text.artists[i] ? text.artists[i] : "", text.artists[i] ? ")" : ""); } } -void +static void dump_toc(scsi_toc_toc *toc) { int32 numTracks = toc->last_track + 1 - toc->first_track; @@ -415,22 +392,24 @@ length.second = (diff % kFramesPerMinute) / kFramesPerSecond; length.frame = diff % kFramesPerSecond; - printf("%02u. %02u:%02u.%02u (length %02u:%02u.%02u)\n", + dprintf("%02u. %02u:%02u.%02u (length %02u:%02u.%02u)\n", track.track_number, start.minute, start.second, start.frame, length.minute, length.second, length.frame); } } -status_t +static status_t read_table_of_contents(int fd, uint32 track, uint8 format, uint8 *buffer, size_t bufferSize) { raw_device_command raw; - uint8 senseData[1024]; + uint8 *senseData = (uint8 *)malloc(kSenseSize); + if (senseData == NULL) + return B_NO_MEMORY; memset(&raw, 0, sizeof(raw_device_command)); - memset(senseData, 0, sizeof(senseData)); + memset(senseData, 0, kSenseSize); memset(buffer, 0, bufferSize); scsi_cmd_read_toc &toc = *(scsi_cmd_read_toc*)&raw.command; @@ -449,84 +428,106 @@ raw.data_length = bufferSize; raw.timeout = 10000000LL; // 10 secs raw.sense_data = senseData; - raw.sense_data_length = sizeof(senseData); + raw.sense_data_length = sizeof(kSenseSize); - if (ioctl(fd, B_RAW_DEVICE_COMMAND, &raw) == 0) { - if (raw.scsi_status == 0 && raw.cam_status == 1) { - puts("success!\n"); - } else { - puts("failure!\n"); - } + if (ioctl(fd, B_RAW_DEVICE_COMMAND, &raw) == 0 + && raw.scsi_status == 0 && raw.cam_status == 1) { + free(senseData); + return B_OK; } - return 0; + free(senseData); + return B_ERROR; } -void -dump_block(const uint8 *buffer, int size, const char *prefix) +// #pragma mark - exported functions + + +status_t +read_cdtext(int fd, struct cdtext &cdtext) { - int i; - - for (i = 0; i < size;) - { - int start = i; + uint8 *buffer = (uint8 *)malloc(kBufferSize); + if (buffer == NULL) + return B_NO_MEMORY; - printf(prefix); - for (; i < start+16; i++) - { - if (!(i % 4)) - printf(" "); + // do it twice, just in case... + // (at least my CD-ROM sometimes returned broken data on first try) + read_table_of_contents(fd, 1, SCSI_TOC_FORMAT_CD_TEXT, buffer, + kBufferSize); + if (read_table_of_contents(fd, 1, SCSI_TOC_FORMAT_CD_TEXT, buffer, + kBufferSize) < B_OK) { + free(buffer); + return B_ERROR; + } - if (i >= size) - printf(" "); - else - printf("%02x", *(unsigned char *)(buffer + i)); - } - printf(" "); + scsi_toc_general *header = (scsi_toc_general *)buffer; - for (i = start; i < start + 16; i++) - { - if (i < size) - { - char c = buffer[i]; + size_t packLength = B_BENDIAN_TO_HOST_INT16(header->data_length) - 2; + cdtext_pack_data *pack = (cdtext_pack_data *)(header + 1); + cdtext_pack_data *lastPack = NULL; + uint8 state = 0; + char text[256]; - if (c < 30) - printf("."); - else - printf("%c", c); - } - else + while (true) { + size_t length = sizeof(text); + uint8 id, track; + + if (!parse_pack_data(pack, packLength, lastPack, id, track, + state, text, length)) + break; + + switch (id) { + case kTrackID: + if (track == 0) { + if (cdtext.album == NULL) + cdtext.album = copy_string(text); + } else if (track <= kMaxTracks) { + if (cdtext.titles[track - 1] == NULL) + cdtext.titles[track - 1] = copy_string(text); + if (track > cdtext.track_count) + cdtext.track_count = track; + } break; + + case kArtistID: + if (track == 0) { + if (cdtext.artist == NULL) + cdtext.artist = copy_string(text); + } else if (track <= kMaxTracks) { + if (cdtext.artists[track - 1] == NULL) + cdtext.artists[track - 1] = copy_string(text); + } + break; + + default: + if (is_string_id(id)) + dprintf("UNKNOWN %u: \"%s\"\n", id, text); + break; } - printf("\n"); } -} + free(buffer); -int -main(int argc, char** argv) -{ - int fd = open(argv[1], O_RDONLY); - if (fd < 0) - return -1; + sanitize_string(cdtext.artist); + sanitize_album(cdtext); + sanitize_titles(cdtext); + correct_case(cdtext); - uint8 buffer[1024]; - scsi_toc_general *header = (scsi_toc_general *)buffer; + dump_cdtext(cdtext); + return B_OK; +} - read_table_of_contents(fd, 1, SCSI_TOC_FORMAT_TOC, buffer, sizeof(buffer)); - header->data_length = B_BENDIAN_TO_HOST_INT16(header->data_length); - printf("TOC header %u, %d, %d\n", header->data_length, header->first, header->last); - //dump_block(buffer, header->data_length + 2, "TOC"); - dump_toc((scsi_toc_toc *)buffer); - read_table_of_contents(fd, 1, SCSI_TOC_FORMAT_CD_TEXT, buffer, sizeof(buffer)); - read_table_of_contents(fd, 1, SCSI_TOC_FORMAT_CD_TEXT, buffer, sizeof(buffer)); - header->data_length = B_BENDIAN_TO_HOST_INT16(header->data_length); - printf("TEXT header %u, %d, %d\n", header->data_length, header->first, header->last); - //dump_block(buffer, header->data_length + 2, "TEXT"); +status_t +read_table_of_contents(int fd, scsi_toc_toc *toc, size_t length) +{ + status_t status = read_table_of_contents(fd, 1, SCSI_TOC_FORMAT_TOC, + (uint8*)toc, length); + if (status < B_OK) + return status; - dump_cdtext((cdtext_pack_data *)(buffer + 4), header->data_length - 2); + dump_toc(toc); + return B_OK; +} - close(fd); -} Added: haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.h 2007-05-14 15:56:39 UTC (rev 21138) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.h 2007-05-15 00:51:35 UTC (rev 21139) @@ -0,0 +1,34 @@ +/* + * Copyright 2007, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + */ +#ifndef CDDA_H +#define CDDA_H + + +#include + + +static const uint32 kFramesPerSecond = 75; +static const uint32 kFramesPerMinute = kFramesPerSecond * 60; +static const uint32 kFrameSize = 2352; +static const uint8 kMaxTracks = 0x63; + +struct cdtext { + cdtext(); + ~cdtext(); + + char *artist; + char *album; + char *genre; + + char *titles[kMaxTracks]; + char *artists[kMaxTracks]; + uint8 track_count; +}; + + +status_t read_cdtext(int fd, cdtext &text); +status_t read_table_of_contents(int fd, scsi_toc_toc *toc, size_t length); + +#endif // CDDA_H Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp 2007-05-14 15:56:39 UTC (rev 21138) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp 2007-05-15 00:51:35 UTC (rev 21139) @@ -4,6 +4,7 @@ */ +#include "cdda.h" #include "Lock.h" #include @@ -57,7 +58,8 @@ off_t NumBlocks() const { return fNumBlocks; } private: - Inode *_CreateNode(Inode *parent, const char *name, int32 type); + Inode *_CreateNode(Inode *parent, const char *name, + off_t start, off_t frames, int32 type); Semaphore fLock; int fDevice; @@ -74,7 +76,8 @@ class Inode { public: - Inode(Volume *volume, Inode *parent, const char *name, int32 type); + Inode(Volume *volume, Inode *parent, const char *name, off_t start, + off_t frames, int32 type); ~Inode(); status_t InitCheck(); @@ -93,8 +96,12 @@ { return fCreationTime; } time_t ModificationTime() const { return fModificationTime; } + off_t StartFrame() const + { return fStartFrame; } + off_t FrameCount() const + { return fFrameCount; } off_t Size() const - { return fSize; } + { return fFrameCount * kFrameSize /* + WAV header */; } Inode *Next() const { return fNext; } void SetNext(Inode *inode) { fNext = inode; } @@ -103,12 +110,13 @@ Inode *fNext; vnode_id fID; int32 fType; - const char *fName; + char *fName; gid_t fGroupID; uid_t fUserID; time_t fCreationTime; time_t fModificationTime; - off_t fSize; + off_t fStartFrame; + off_t fFrameCount; }; @@ -142,7 +150,7 @@ fFirstEntry(NULL) { // create the root vnode - fRootNode = _CreateNode(NULL, "", S_IFDIR | 0777); + fRootNode = _CreateNode(NULL, "", 0, 0, S_IFDIR | 0777); } @@ -160,6 +168,8 @@ next = inode->Next(); delete inode; } + + free(fName); } @@ -181,6 +191,64 @@ if (fDevice < 0) return errno; + scsi_toc_toc *toc = (scsi_toc_toc *)malloc(1024); + if (toc == NULL) + return B_NO_MEMORY; + + status_t status = read_table_of_contents(fDevice, toc, 1024); + if (status < B_OK) { + free(toc); + return status; + } + + cdtext text; + if (read_cdtext(fDevice, text) < B_OK) + dprintf("CDDA: no CD-Text found.\n"); + + int32 trackCount = toc->last_track + 1 - toc->first_track; + char title[256]; + + for (int32 i = 0; i < trackCount; i++) { + scsi_cd_msf& next = toc->tracks[i + 1].start.time; + // the last track is always lead-out + scsi_cd_msf& start = toc->tracks[i].start.time; + + off_t startFrame = start.minute * kFramesPerMinute + + start.second * kFramesPerSecond + start.frame; + off_t frames = next.minute * kFramesPerMinute + + next.second * kFramesPerSecond + next.frame + - startFrame; + + if (text.titles[i] != NULL && text.titles[i]) { + if (text.artists[i] != NULL && text.artists[i]) { + snprintf(title, sizeof(title), "%02ld. %s - %s.wav", i + 1, + text.artists[i], text.titles[i]); + } else { + snprintf(title, sizeof(title), "%02ld. %s.wav", i + 1, + text.titles[i]); + } + } else + snprintf(title, sizeof(title), "%02ld.wav", i + 1); + + _CreateNode(fRootNode, title, startFrame, frames, S_IFREG | 0444); + } + + free(toc); + + // determine volume title + + if (text.artist != NULL && text.album != NULL) + snprintf(title, sizeof(title), "%s - %s", text.artist, text.album); + else if (text.artist != NULL || text.album != NULL) { + snprintf(title, sizeof(title), "%s", text.artist != NULL + ? text.artist : text.album); + } else + strcpy(title, "Audio CD"); + + fName = strdup(title); + if (fName == NULL) + return B_NO_MEMORY; + return B_OK; } @@ -193,9 +261,10 @@ Inode * -Volume::_CreateNode(Inode *parent, const char *name, int32 type) +Volume::_CreateNode(Inode *parent, const char *name, off_t start, off_t frames, + int32 type) { - Inode *inode = new Inode(this, parent, name, type); + Inode *inode = new Inode(this, parent, name, start, frames, type); if (inode == NULL) return NULL; @@ -245,14 +314,24 @@ status_t Volume::SetName(const char *name) { - return B_ERROR; + if (name == NULL || !name[0]) + return B_BAD_VALUE; + + name = strdup(name); + if (name == NULL) + return B_NO_MEMORY; + + free(fName); + fName = (char *)name; + return B_OK; } // #pragma mark - -Inode::Inode(Volume *volume, Inode *parent, const char *name, int32 type) +Inode::Inode(Volume *volume, Inode *parent, const char *name, off_t start, + off_t frames, int32 type) : fNext(NULL) { @@ -262,6 +341,8 @@ fID = volume->GetNextNodeID(); fType = type; + fStartFrame = start; + fFrameCount = frames; fUserID = geteuid(); fGroupID = parent ? parent->GroupID() : getegid(); @@ -289,7 +370,16 @@ status_t Inode::SetName(const char* name) { - return B_ERROR; + if (name == NULL || !name[0]) + return B_BAD_VALUE; + + name = strdup(name); + if (name == NULL) + return B_NO_MEMORY; + + free(fName); + fName = (char *)name; + return B_OK; } @@ -578,7 +668,19 @@ || strchr(newName, '/') != NULL) return B_BAD_VALUE; - return B_ERROR; + // we only have a single directory which simplifies things a bit :-) + + Volume *volume = (Volume *)_volume; + Locker _(volume->Lock()); + + Inode *inode = volume->Find(oldName); + if (inode == NULL) + return B_ENTRY_NOT_FOUND; + + if (volume->Find(newName) != NULL) + return B_NAME_IN_USE; + + return inode->SetName(newName); } Modified: haiku/trunk/src/tests/add-ons/kernel/file_systems/Jamfile =================================================================== --- haiku/trunk/src/tests/add-ons/kernel/file_systems/Jamfile 2007-05-14 15:56:39 UTC (rev 21138) +++ haiku/trunk/src/tests/add-ons/kernel/file_systems/Jamfile 2007-05-15 00:51:35 UTC (rev 21139) @@ -1,6 +1,7 @@ SubDir HAIKU_TOP src tests add-ons kernel file_systems ; SubInclude HAIKU_TOP src tests add-ons kernel file_systems bfs ; +SubInclude HAIKU_TOP src tests add-ons kernel file_systems cdda ; SubInclude HAIKU_TOP src tests add-ons kernel file_systems fs_shell ; #SubInclude HAIKU_TOP src tests add-ons kernel file_systems iso9660 ; SubInclude HAIKU_TOP src tests add-ons kernel file_systems udf ; Added: haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/Jamfile =================================================================== --- haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/Jamfile 2007-05-14 15:56:39 UTC (rev 21138) +++ haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/Jamfile 2007-05-15 00:51:35 UTC (rev 21139) @@ -0,0 +1,9 @@ +SubDir HAIKU_TOP src tests add-ons kernel file_systems cdda ; + +SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src add-ons kernel file_systems cdda ] ; + +SimpleTest cdda_text + : + cdda_text.cpp + cdda.cpp +; Added: haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/cdda_text.cpp =================================================================== --- haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/cdda_text.cpp 2007-05-14 15:56:39 UTC (rev 21138) +++ haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/cdda_text.cpp 2007-05-15 00:51:35 UTC (rev 21139) @@ -0,0 +1,48 @@ +/* + * Copyright 2007, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + */ + + +#include "cdda.h" + +#include +#include +#include +#include + + +extern const char* __progname; + + +extern "C" void +dprintf(const char* format, ...) +{ + va_list args; + va_start(args, format); + vprintf(format, args); + fflush(stdout); + va_end(args); +} + + +int +main(int argc, char** argv) +{ + if (argc < 2) + return -1; + int fd = open(argv[1], O_RDONLY); + if (fd < 0) + return -1; + + uint8 buffer[1024]; + if (read_table_of_contents(fd, (scsi_toc_toc*)buffer, sizeof(buffer)) < 0) { + fprintf(stderr, "%s: Retrieving TOC failed", __progname); + return -1; + } + + cdtext text; + read_cdtext(fd, text); + + close(fd); +} From bonefish at mail.berlios.de Tue May 15 17:37:49 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Tue, 15 May 2007 17:37:49 +0200 Subject: [Haiku-commits] r21140 - haiku/trunk/headers/os/interface Message-ID: <200705151537.l4FFbn3F023277@sheep.berlios.de> Author: bonefish Date: 2007-05-15 17:37:48 +0200 (Tue, 15 May 2007) New Revision: 21140 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21140&view=rev Modified: haiku/trunk/headers/os/interface/Window.h Log: Fixed indentation of the layout related methods. Modified: haiku/trunk/headers/os/interface/Window.h =================================================================== --- haiku/trunk/headers/os/interface/Window.h 2007-05-15 00:51:35 UTC (rev 21139) +++ haiku/trunk/headers/os/interface/Window.h 2007-05-15 15:37:48 UTC (rev 21140) @@ -258,10 +258,10 @@ virtual bool QuitRequested(); virtual thread_id Run(); - virtual void SetLayout(BLayout* layout); - BLayout* GetLayout() const; + virtual void SetLayout(BLayout* layout); + BLayout* GetLayout() const; - void InvalidateLayout(bool descendants = false); + void InvalidateLayout(bool descendants = false); private: typedef BLooper inherited; From bonefish at mail.berlios.de Tue May 15 17:38:26 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Tue, 15 May 2007 17:38:26 +0200 Subject: [Haiku-commits] r21141 - in haiku/trunk: headers/os/interface src/kits/interface Message-ID: <200705151538.l4FFcQgO023371@sheep.berlios.de> Author: bonefish Date: 2007-05-15 17:38:26 +0200 (Tue, 15 May 2007) New Revision: 21141 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21141&view=rev Modified: haiku/trunk/headers/os/interface/View.h haiku/trunk/src/kits/interface/View.cpp Log: Added IsLayoutValid(). Modified: haiku/trunk/headers/os/interface/View.h =================================================================== --- haiku/trunk/headers/os/interface/View.h 2007-05-15 15:37:48 UTC (rev 21140) +++ haiku/trunk/headers/os/interface/View.h 2007-05-15 15:38:26 UTC (rev 21141) @@ -536,6 +536,7 @@ void InvalidateLayout(bool descendants = false); void EnableLayoutInvalidation(); void DisableLayoutInvalidation(); + bool IsLayoutValid() const; BLayoutContext* LayoutContext() const; Modified: haiku/trunk/src/kits/interface/View.cpp =================================================================== --- haiku/trunk/src/kits/interface/View.cpp 2007-05-15 15:37:48 UTC (rev 21140) +++ haiku/trunk/src/kits/interface/View.cpp 2007-05-15 15:38:26 UTC (rev 21141) @@ -4066,6 +4066,13 @@ } +bool +BView::IsLayoutValid() const +{ + return fLayoutData->fLayoutValid; +} + + BLayoutContext* BView::LayoutContext() const { From bonefish at mail.berlios.de Tue May 15 17:41:30 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Tue, 15 May 2007 17:41:30 +0200 Subject: [Haiku-commits] r21142 - haiku/trunk/src/tests/kits/interface/layout Message-ID: <200705151541.l4FFfU1v023710@sheep.berlios.de> Author: bonefish Date: 2007-05-15 17:41:27 +0200 (Tue, 15 May 2007) New Revision: 21142 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21142&view=rev Modified: haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp Log: Added a bit of layout management to the test views framework. The maximum size of the view tested can now be overridden explicitly. Modified: haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp 2007-05-15 15:38:26 UTC (rev 21141) +++ haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp 2007-05-15 15:41:27 UTC (rev 21142) @@ -19,7 +19,9 @@ // internal messages enum { - MSG_2D_SLIDER_VALUE_CHANGED = '2dsv', + MSG_LAYOUT_CONTAINER = 'layc', + MSG_2D_SLIDER_VALUE_CHANGED = '2dsv', + MSG_UNLIMITED_MAX_SIZE_CHANGED = 'usch', }; @@ -35,12 +37,23 @@ // View class View { public: + View() + : fFrame(0, 0, 0, 0), + fContainer(NULL), + fParent(NULL), + fChildren(), + fViewColor(B_TRANSPARENT_32_BIT), + fLayoutValid(false) + { + } + View(BRect frame) : fFrame(frame), fContainer(NULL), fParent(NULL), fChildren(), - fViewColor(B_TRANSPARENT_32_BIT) + fViewColor(B_TRANSPARENT_32_BIT), + fLayoutValid(false) { } @@ -61,6 +74,12 @@ FrameChanged(oldFrame, frame); } + + // relayout if necessary + if (!fLayoutValid) { + Layout(); + fLayoutValid = true; + } } BRect Frame() const @@ -96,6 +115,26 @@ return Frame().Size(); } + virtual BSize MinSize() + { + return BSize(-1, -1); + } + + virtual BSize MaxSize() + { + return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED); + } + + virtual BSize PreferredSize() + { + return MinSize(); + } + + virtual BAlignment Alignment() + { + return BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER); + } + BPoint LocationInContainer() const { BPoint location = fFrame.LeftTop(); @@ -155,6 +194,7 @@ child->_AddedToParent(this); child->Invalidate(); + InvalidateLayout(); return true; } @@ -177,6 +217,8 @@ child->_RemovingFromParent(); fChildren.RemoveItem(index); + InvalidateLayout(); + return child; } @@ -240,6 +282,20 @@ Invalidate(Bounds()); } + virtual void InvalidateLayout() + { + if (fLayoutValid) { + fLayoutValid = false; + if (fParent) + fParent->InvalidateLayout(); + } + } + + bool IsLayoutValid() const + { + return fLayoutValid; + } + void SetViewColor(rgb_color color) { fViewColor = color; @@ -273,6 +329,13 @@ { } + virtual void Layout() + { + // simply trigger relayouting the children + for (int32 i = 0; View* child = ChildAt(i); i++) + child->SetFrame(child->Frame()); + } + protected: virtual void _AddedToParent(View* parent) { @@ -314,9 +377,6 @@ void _Draw(BView* container, BRect updateRect) { -//printf("%p->View::_Draw(): ", this); -//updateRect.PrintToStream(); - // compute the clipping region BRegion region(Bounds()); for (int32 i = 0; View* child = ChildAt(i); i++) @@ -367,6 +427,7 @@ View* fParent; BList fChildren; rgb_color fViewColor; + bool fLayoutValid; }; @@ -382,6 +443,34 @@ _AddedToContainer(this); } + virtual void InvalidateLayout() + { + if (View::IsLayoutValid()) { + View::InvalidateLayout(); + + // trigger asynchronous re-layout + if (Window()) + Window()->PostMessage(MSG_LAYOUT_CONTAINER, this); + } + } + + virtual void MessageReceived(BMessage* message) + { + switch (message->what) { + case MSG_LAYOUT_CONTAINER: + View::Layout(); + break; + default: + BView::MessageReceived(message); + break; + } + } + + virtual void AllAttached() + { + Window()->PostMessage(MSG_LAYOUT_CONTAINER, this); + } + virtual void Draw(BRect updateRect) { View::_Draw(this, updateRect); @@ -587,8 +676,8 @@ // WrapperView class WrapperView : public View { public: - WrapperView(BRect frame, BView* view) - : View(frame), + WrapperView(BView* view) + : View(), fView(view), fInsets(1, 1, 1, 1) { @@ -600,17 +689,17 @@ return fView; } - BSize MinSize() const + virtual BSize MinSize() { return _FromViewSize(fView->MinSize()); } - BSize MaxSize() const + virtual BSize MaxSize() { return _FromViewSize(fView->MaxSize()); } - BSize PreferredSize() const + virtual BSize PreferredSize() { return _FromViewSize(fView->PreferredSize()); } @@ -673,13 +762,14 @@ // StringView class StringView : public View { public: - StringView(BRect frame, const char* string) - : View(frame), + StringView(const char* string) + : View(), fString(string), fAlignment(B_ALIGN_LEFT), fStringAscent(0), fStringDescent(0), - fStringWidth(0) + fStringWidth(0), + fExplicitMinSize(B_SIZE_UNSET, B_SIZE_UNSET) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fTextColor = (rgb_color){ 0, 0, 0, 255 }; @@ -691,6 +781,7 @@ _UpdateStringMetrics(); Invalidate(); + InvalidateLayout(); } void SetAlignment(alignment align) @@ -707,11 +798,21 @@ Invalidate(); } - BSize PreferredSize() const + virtual BSize MinSize() { - return BSize(fStringWidth - 1, fStringAscent + fStringDescent - 1); + BSize size(fExplicitMinSize); + if (!size.IsWidthSet()) + size.width = fStringWidth - 1; + if (!size.IsHeightSet()) + size.height = fStringAscent + fStringDescent - 1; + return size; } + void SetExplicitMinSize(BSize size) + { + fExplicitMinSize = size; + } + virtual void AddedToContainer() { _UpdateStringMetrics(); @@ -767,9 +868,514 @@ float fStringAscent; float fStringDescent; float fStringWidth; + BSize fExplicitMinSize; }; +// CheckBox +class CheckBox : public View, public BInvoker { +public: + CheckBox(BMessage* message = NULL, BMessenger target = BMessenger()) + : View(BRect(0, 0, 12, 12)), + BInvoker(message, target), + fSelected(false), + fPressed(false) + { + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + } + + void SetSelected(bool selected) + { + if (selected != fSelected) { + fSelected = selected; + Invalidate(); + + // send the message + if (Message()) { + BMessage message(*Message()); + message.AddBool("selected", IsSelected()); + InvokeNotify(&message); + } + } + } + + bool IsSelected() const + { + return fSelected; + } + + virtual BSize MinSize() + { + return BSize(12, 12); + } + + virtual BSize MaxSize() + { + return MinSize(); + } + + virtual void Draw(BView* container, BRect updateRect) + { + BRect rect(Bounds()); + + if (fPressed) + container->SetHighColor((rgb_color){ 120, 0, 0, 255 }); + else + container->SetHighColor((rgb_color){ 0, 0, 0, 255 }); + + container->StrokeRect(rect); + + if (fPressed ? fPressedSelected : fSelected) { + rect.InsetBy(2, 2); + container->StrokeLine(rect.LeftTop(), rect.RightBottom()); + container->StrokeLine(rect.RightTop(), rect.LeftBottom()); + } + } + + virtual void MouseDown(BPoint where, uint32 buttons, int32 modifiers) + { + if (fPressed) + return; + + fPressed = true; + fPressedSelected = fSelected; + _PressedUpdate(where); + } + + virtual void MouseUp(BPoint where, uint32 buttons, int32 modifiers) + { + if (!fPressed || (buttons & B_PRIMARY_MOUSE_BUTTON)) + return; + + _PressedUpdate(where); + fPressed = false; + SetSelected(fPressedSelected); + Invalidate(); + } + + virtual void MouseMoved(BPoint where, uint32 buttons, int32 modifiers) + { + if (!fPressed) + return; + + _PressedUpdate(where); + } + +private: + void _PressedUpdate(BPoint where) + { + bool pressedSelected = Bounds().Contains(where) ^ fSelected; + if (pressedSelected != fPressedSelected) { + fPressedSelected = pressedSelected; + Invalidate(); + } + } + +private: + bool fSelected; + bool fPressed; + bool fPressedSelected; +}; + + +// GroupView +class GroupView : public View { +public: + GroupView(enum orientation orientation, int32 lineCount = 1) + : View(BRect(0, 0, 0, 0)), + fOrientation(orientation), + fLineCount(lineCount), + fColumnSpacing(0), + fRowSpacing(0), + fInsets(0, 0, 0, 0), + fMinMaxValid(false), + fColumnInfos(NULL), + fRowInfos(NULL) + { + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + if (fLineCount < 1) + fLineCount = 1; + } + + virtual ~GroupView() + { + delete fColumnInfos; + delete fRowInfos; + } + + void SetSpacing(float horizontal, float vertical) + { + if (horizontal != fColumnSpacing || vertical != fRowSpacing) { + fColumnSpacing = horizontal; + fRowSpacing = vertical; + + InvalidateLayout(); + } + } + + void SetInsets(float left, float top, float right, float bottom) + { + BRect newInsets(left, top, right, bottom); + if (newInsets != fInsets) { + fInsets = newInsets; + InvalidateLayout(); + } + } + + virtual BSize MinSize() + { + _ValidateMinMax(); + return _AddInsetsAndSpacing(BSize(fMinWidth - 1, fMinHeight - 1)); + } + + virtual BSize MaxSize() + { + _ValidateMinMax(); + return _AddInsetsAndSpacing(BSize(fMaxWidth - 1, fMaxHeight - 1)); + } + + virtual BSize PreferredSize() + { + _ValidateMinMax(); + return _AddInsetsAndSpacing(BSize(fPreferredWidth - 1, + fPreferredHeight - 1)); + } + + virtual BAlignment Alignment() + { + return BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT); + } + + + virtual void Layout() + { + _ValidateMinMax(); + // actually a little late already + + BSize size = _SubtractInsetsAndSpacing(Size()); + _LayoutLine(size.IntegerWidth() + 1, fColumnInfos, fColumnCount); + _LayoutLine(size.IntegerHeight() + 1, fRowInfos, fRowCount); + + // layout children + BPoint location = fInsets.LeftTop(); + for (int32 column = 0; column < fColumnCount; column++) { + LayoutInfo& columnInfo = fColumnInfos[column]; + location.y = fInsets.top; + for (int32 row = 0; row < fRowCount; row++) { + View* child = _ChildAt(column, row); + if (!child) + continue; + + // get the grid cell frame + BRect cellFrame(location, + BSize(columnInfo.size - 1, fRowInfos[row].size - 1)); + + // align the child frame in the grid cell + BRect childFrame = BLayoutUtils::AlignInFrame(cellFrame, + child->MaxSize(), child->Alignment()); + + // layout child + child->SetFrame(childFrame); + + location.y += fRowInfos[row].size + fRowSpacing; + } + + location.x += columnInfo.size + fColumnSpacing; + } + } + +private: + struct LayoutInfo { + int32 min; + int32 max; + int32 preferred; + int32 size; + + LayoutInfo() + : min(0), + max(B_SIZE_UNLIMITED), + preferred(0) + { + } + + void AddConstraints(float addMin, float addMax, float addPreferred) + { + if (addMin >= min) + min = (int32)addMin + 1; + if (addMax <= max) + max = (int32)addMax + 1; + if (addPreferred >= preferred) + preferred = (int32)addPreferred + 1; + } + + void Normalize() + { + if (max > min) + max = min; + if (preferred < min) + preferred = min; + if (preferred > max) + preferred = max; + } + }; + +private: + void _ValidateMinMax() + { + if (fMinMaxValid) + return; + + delete fColumnInfos; + delete fRowInfos; + + fColumnCount = _ColumnCount(); + fRowCount = _RowCount(); + + fColumnInfos = new LayoutInfo[fColumnCount]; + fRowInfos = new LayoutInfo[fRowCount]; + + // collect the children's min/max constraints + for (int32 column = 0; column < fColumnCount; column++) { + for (int32 row = 0; row < fRowCount; row++) { + View* child = _ChildAt(column, row); + if (!child) + continue; + + BSize min = child->MinSize(); + BSize max = child->MaxSize(); + BSize preferred = child->PreferredSize(); + + // apply constraints to column/row info + fColumnInfos[column].AddConstraints(min.width, max.width, + preferred.width); + fRowInfos[row].AddConstraints(min.height, max.height, + preferred.height); + } + } + + // normalize the column/row constraints and compute sum min/max + fMinWidth = 0; + fMinHeight = 0; + fMaxWidth = 0; + fMaxHeight = 0; + fPreferredWidth = 0; + fPreferredHeight = 0; + + for (int32 column = 0; column < fColumnCount; column++) { + fColumnInfos[column].Normalize(); + fMinWidth = BLayoutUtils::AddSizesInt32(fMinWidth, + fColumnInfos[column].min); + fMaxWidth = BLayoutUtils::AddSizesInt32(fMaxWidth, + fColumnInfos[column].max); + fPreferredWidth = BLayoutUtils::AddSizesInt32(fPreferredWidth, + fColumnInfos[column].preferred); + } + + for (int32 row = 0; row < fRowCount; row++) { + fRowInfos[row].Normalize(); + fMinHeight = BLayoutUtils::AddSizesInt32(fMinHeight, + fRowInfos[row].min); + fMaxHeight = BLayoutUtils::AddSizesInt32(fMaxHeight, + fRowInfos[row].max); + fPreferredHeight = BLayoutUtils::AddSizesInt32(fPreferredHeight, + fRowInfos[row].preferred); + } + + fMinMaxValid = true; + } + + void _LayoutLine(int32 size, LayoutInfo* infos, int32 infoCount) + { + BList infosToLayout; + for (int32 i = 0; i < infoCount; i++) { + infos[i].size = 0; + infosToLayout.AddItem(infos + i); + } + + // Distribute the available space over the infos. Each iteration we + // try to distribute the remaining space evenly. We respect min and + // max constraints, though, add up the space we failed to assign + // due to the constraints, and use the sum as remaining space for the + // next iteration (can be negative). Then we ignore infos that can't + // shrink or grow anymore (depending on what would be needed). + while (!infosToLayout.IsEmpty()) { + BList canShrinkInfos; + BList canGrowInfos; + + int32 sizeDiff = 0; + int32 infosToLayoutCount = infosToLayout.CountItems(); + for (int32 i = 0; i < infosToLayoutCount; i++) { + LayoutInfo* info = (LayoutInfo*)infosToLayout.ItemAt(i); + info->size += (i + 1) * size / infosToLayoutCount + - i * size / infosToLayoutCount; + if (info->size < info->min) { + sizeDiff -= info->min - info->size; + info->size = info->min; + } else if (info->size > info->max) { + sizeDiff += info->size - info->max; + info->size = info->max; + } + + if (info->size > info->min) + canShrinkInfos.AddItem(info); + if (info->size < info->max) + canGrowInfos.AddItem(info); + } + + size = sizeDiff; + if (size == 0) + break; + + if (size > 0) + infosToLayout = canGrowInfos; + else + infosToLayout = canShrinkInfos; + } + + // If unassigned space is remaining, that means, that the group has + // been resized beyond its max size. We distribute the excess space + // evenly. + if (size > 0) { + for (int32 i = 0; i < infoCount; i++) { + infos[i].size += (i + 1) * size / infoCount + - i * size / infoCount; + } + } + } + + virtual BSize _AddInsetsAndSpacing(BSize size) + { + size.width = BLayoutUtils::AddDistances(size.width, + fInsets.left + fInsets.right - 1 + + (fColumnCount - 1) * fColumnSpacing); + size.height = BLayoutUtils::AddDistances(size.height, + fInsets.top + fInsets.bottom - 1 + + (fRowCount - 1) * fRowSpacing); + return size; + } + + virtual BSize _SubtractInsetsAndSpacing(BSize size) + { + size.width = BLayoutUtils::SubtractDistances(size.width, + fInsets.left + fInsets.right - 1 + + (fColumnCount - 1) * fColumnSpacing); + size.height = BLayoutUtils::SubtractDistances(size.height, + fInsets.top + fInsets.bottom - 1 + + (fRowCount - 1) * fRowSpacing); + return size; + } + + int32 _RowCount() const + { + int32 childCount = CountChildren(); + int32 count; + if (fOrientation == B_HORIZONTAL) + count = min_c(fLineCount, childCount); + else + count = (childCount + fLineCount - 1) / fLineCount; + + return max_c(count, 1); + } + + int32 _ColumnCount() const + { + int32 childCount = CountChildren(); + int32 count; + if (fOrientation == B_HORIZONTAL) + count = (childCount + fLineCount - 1) / fLineCount; + else + count = min_c(fLineCount, childCount); + + return max_c(count, 1); + } + + View* _ChildAt(int32 column, int32 row) const + { + if (fOrientation == B_HORIZONTAL) + return ChildAt(column * fLineCount + row); + else + return ChildAt(row * fLineCount + column); + } + +private: + enum orientation fOrientation; + int32 fLineCount; + float fColumnSpacing; + float fRowSpacing; + BRect fInsets; + bool fMinMaxValid; + int32 fMinWidth; + int32 fMinHeight; + int32 fMaxWidth; + int32 fMaxHeight; + int32 fPreferredWidth; + int32 fPreferredHeight; + LayoutInfo* fColumnInfos; + LayoutInfo* fRowInfos; + int32 fColumnCount; + int32 fRowCount; +}; + + +// Glue +class Glue : public View { +public: + Glue() + : View() + { + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + } +}; + + +// Strut +class Strut : public View { +public: + Strut(float pixelWidth, float pixelHeight) + : View(), + fSize(pixelWidth >= 0 ? pixelWidth - 1 : B_SIZE_UNSET, + pixelHeight >= 0 ? pixelHeight - 1 : B_SIZE_UNSET) + { + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + } + + virtual BSize MinSize() + { + return BLayoutUtils::ComposeSize(fSize, BSize(-1, -1)); + } + + virtual BSize MaxSize() + { + return BLayoutUtils::ComposeSize(fSize, + BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); + } + +private: + BSize fSize; +}; + + +// HStrut +class HStrut : public Strut { +public: + HStrut(float width) + : Strut(width, -1) + { + } +}; + + +// VStrut +class VStrut : public Strut { +public: + VStrut(float height) + : Strut(-1, height) + { + } +}; + + // TestWindow class TestWindow : public BWindow { public: @@ -789,10 +1395,10 @@ view->SetViewColor((rgb_color){200, 200, 240, 255}); // wrapper view - fWrapperView = new WrapperView(BRect(10, 10, 100, 100), + fWrapperView = new WrapperView( new BButton(BRect(0, 0, 9, 9), "test button", "Ooh, press me!", (BMessage*)NULL, B_FOLLOW_NONE)); -fWrapperView->GetView()->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); + fWrapperView->SetLocation(BPoint(10, 10)); view->AddChild(fWrapperView); fWrapperView->SetSize(fWrapperView->PreferredSize()); @@ -804,78 +1410,58 @@ _UpdateSliderConstraints(); - // size labels - - // min label - rect.top = rect.bottom + 10; - rect.bottom = rect.top + 10; - StringView* minLabel = new StringView(rect, "min: "); - minLabel->SetAlignment(B_ALIGN_RIGHT); - fViewContainer->View::AddChild(minLabel); - minLabel->SetSize(minLabel->PreferredSize()); - BRect minFrame(minLabel->Frame()); - - // max label - rect = minFrame.OffsetToCopy(minFrame.LeftBottom() + BPoint(0, 8)); - StringView* maxLabel = new StringView(rect, "max: "); - maxLabel->SetAlignment(B_ALIGN_RIGHT); - fViewContainer->View::AddChild(maxLabel); - maxLabel->SetSize(maxLabel->PreferredSize()); - BRect maxFrame(maxLabel->Frame()); - - // preferred label - rect = maxFrame.OffsetToCopy(maxFrame.LeftBottom() + BPoint(0, 8)); - StringView* preferredLabel = new StringView(rect, "preferred: "); - preferredLabel->SetAlignment(B_ALIGN_RIGHT); - fViewContainer->View::AddChild(preferredLabel); - preferredLabel->SetSize(preferredLabel->PreferredSize()); - BRect preferredFrame(preferredLabel->Frame()); - - // preferred label - rect = preferredFrame.OffsetToCopy(preferredFrame.LeftBottom() - + BPoint(0, 8)); - StringView* currentLabel = new StringView(rect, "current: "); - currentLabel->SetAlignment(B_ALIGN_RIGHT); - fViewContainer->View::AddChild(currentLabel); - currentLabel->SetSize(currentLabel->PreferredSize()); - BRect currentFrame(currentLabel->Frame()); - - float labelWidth = max_c(minFrame.Width(), maxFrame.Width()); - labelWidth = max_c(labelWidth, preferredFrame.Width()); - labelWidth = max_c(labelWidth, currentFrame.Width()); - BSize labelSize(labelWidth, minLabel->Size().height); - minLabel->SetSize(labelSize); - maxLabel->SetSize(labelSize); - preferredLabel->SetSize(labelSize); - currentLabel->SetSize(labelSize); - // size views + GroupView* sizeViewsGroup = new GroupView(B_VERTICAL, 6); + sizeViewsGroup->SetSpacing(0, 8); + fViewContainer->View::AddChild(sizeViewsGroup); // min - _CreateSizeViews(minFrame.LeftTop() + BPoint(labelWidth + 1, 0), - fMinWidthView, fMinHeightView); + _CreateSizeViews(sizeViewsGroup, "min: ", fMinWidthView, + fMinHeightView); - // max - _CreateSizeViews(maxFrame.LeftTop() + BPoint(labelWidth + 1, 0), - fMaxWidthView, fMaxHeightView); + // max (with checkbox) + GroupView* unlimitedMaxGroup = new GroupView(B_HORIZONTAL); + fUnlimitedMaxSizeCheckBox = new CheckBox( + new BMessage(MSG_UNLIMITED_MAX_SIZE_CHANGED), this); + unlimitedMaxGroup->AddChild(fUnlimitedMaxSizeCheckBox); + unlimitedMaxGroup->AddChild(new StringView(" override")); + _CreateSizeViews(sizeViewsGroup, "max: ", fMaxWidthView, + fMaxHeightView, unlimitedMaxGroup); + // preferred - _CreateSizeViews(preferredFrame.LeftTop() + BPoint(labelWidth + 1, 0), - fPreferredWidthView, fPreferredHeightView); + _CreateSizeViews(sizeViewsGroup, "preferred: ", fPreferredWidthView, + fPreferredHeightView); // current - _CreateSizeViews(currentFrame.LeftTop() + BPoint(labelWidth + 1, 0), - fCurrentWidthView, fCurrentHeightView); + _CreateSizeViews(sizeViewsGroup, "current: ", fCurrentWidthView, + fCurrentHeightView); + sizeViewsGroup->SetFrame(BRect(BPoint(rect.left, rect.bottom + 10), + sizeViewsGroup->PreferredSize())); + _UpdateSizeViews(); } + virtual void DispatchMessage(BMessage* message, BHandler* handler) + { + switch (message->what) { + case B_LAYOUT_WINDOW: + if (!fWrapperView->GetView()->IsLayoutValid()) { + _UpdateSliderConstraints(); + _UpdateSizeViews(); + } + break; + } + + BWindow::DispatchMessage(message, handler); + } + virtual void MessageReceived(BMessage* message) { switch (message->what) { case MSG_2D_SLIDER_VALUE_CHANGED: { -// message->PrintToStream(); BPoint sliderLocation(fSliderView->Location()); BPoint wrapperLocation(fWrapperView->Location()); BSize size(sliderLocation.x - wrapperLocation.x - 1, @@ -885,6 +1471,16 @@ break; } + case MSG_UNLIMITED_MAX_SIZE_CHANGED: + if (fUnlimitedMaxSizeCheckBox->IsSelected()) { + fWrapperView->GetView()->SetExplicitMaxSize( + BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); + } else { + fWrapperView->GetView()->SetExplicitMaxSize( + BSize(B_SIZE_UNSET, B_SIZE_UNSET)); + } + break; + default: BWindow::MessageReceived(message); break; @@ -913,30 +1509,39 @@ fSliderView->SetLocationRange(minSliderLocation, maxSliderLocation); } - void _CreateSizeViews(BPoint location, StringView*& widthView, - StringView*& heightView) + void _CreateSizeViews(View* group, const char* labelText, + StringView*& widthView, StringView*& heightView, + View* additionalView = NULL) { + // label + StringView* label = new StringView(labelText); + label->SetAlignment(B_ALIGN_RIGHT); + group->AddChild(label); + // width view - BRect rect(location, location + BPoint(10, 10)); - widthView = new StringView(rect, "9999999999.9"); + widthView = new StringView("9999999999.9"); widthView->SetAlignment(B_ALIGN_RIGHT); - fViewContainer->View::AddChild(widthView); - widthView->SetSize(widthView->PreferredSize()); + group->AddChild(widthView); + widthView->SetExplicitMinSize(widthView->PreferredSize()); // "," label - rect = widthView->Frame(); - rect.OffsetTo(rect.RightTop() + BPoint(1, 0)); - StringView* labelView = new StringView(rect, ", "); - fViewContainer->View::AddChild(labelView); - labelView->SetSize(labelView->PreferredSize()); + StringView* labelView = new StringView(", "); + group->AddChild(labelView); // height view - rect = labelView->Frame(); - rect.OffsetTo(rect.RightTop() + BPoint(1, 0)); - heightView = new StringView(rect, "9999999999.9"); + heightView = new StringView("9999999999.9"); heightView->SetAlignment(B_ALIGN_RIGHT); - fViewContainer->View::AddChild(heightView); - heightView->SetSize(heightView->PreferredSize()); + group->AddChild(heightView); + heightView->SetExplicitMinSize(heightView->PreferredSize()); + + // spacing + group->AddChild(new HStrut(20)); + + // glue or unlimited max size check box + if (additionalView) + group->AddChild(additionalView); + else + group->AddChild(new Glue()); } void _UpdateSizeView(StringView* view, float size) @@ -980,6 +1585,7 @@ StringView* fPreferredHeightView; StringView* fCurrentWidthView; StringView* fCurrentHeightView; + CheckBox* fUnlimitedMaxSizeCheckBox; }; From bonefish at mail.berlios.de Tue May 15 17:47:03 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Tue, 15 May 2007 17:47:03 +0200 Subject: [Haiku-commits] r21143 - in haiku/trunk/src/tests/kits/interface/layout: . widget_layout_test Message-ID: <200705151547.l4FFl3bi024298@sheep.berlios.de> Author: bonefish Date: 2007-05-15 17:47:02 +0200 (Tue, 15 May 2007) New Revision: 21143 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21143&view=rev Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp Removed: haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp Modified: haiku/trunk/src/tests/kits/interface/layout/Jamfile Log: Moved the WidgetLayoutTest into a subdirectory. The source file has grown big and I'm going to split it up. Modified: haiku/trunk/src/tests/kits/interface/layout/Jamfile =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/Jamfile 2007-05-15 15:41:27 UTC (rev 21142) +++ haiku/trunk/src/tests/kits/interface/layout/Jamfile 2007-05-15 15:47:02 UTC (rev 21143) @@ -8,15 +8,10 @@ be ; -SimpleTest WidgetLayoutTest : - WidgetLayoutTest.cpp - : - be -; - - if $(TARGET_PLATFORM) = libbe_test { HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) - : LayoutTest1 WidgetLayoutTest + : LayoutTest1 : tests!apps ; } + +HaikuSubInclude widget_layout_test ; Deleted: haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp Copied: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile (from rev 21142, haiku/trunk/src/tests/kits/interface/layout/Jamfile) =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/Jamfile 2007-05-15 15:41:27 UTC (rev 21142) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile 2007-05-15 15:47:02 UTC (rev 21143) @@ -0,0 +1,15 @@ +SubDir HAIKU_TOP src tests kits interface layout widget_layout_test ; + +SetSubDirSupportedPlatforms haiku libbe_test ; + +SimpleTest WidgetLayoutTest : + WidgetLayoutTest.cpp + : + be +; + +if $(TARGET_PLATFORM) = libbe_test { + HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) + : WidgetLayoutTest + : tests!apps ; +} Copied: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp (from rev 21142, haiku/trunk/src/tests/kits/interface/layout/WidgetLayoutTest.cpp) From axeld at mail.berlios.de Tue May 15 19:33:06 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 15 May 2007 19:33:06 +0200 Subject: [Haiku-commits] r21144 - in haiku/trunk/src: add-ons/kernel/file_systems/cdda tests/add-ons/kernel/file_systems/cdda Message-ID: <200705151733.l4FHX6Xh012311@sheep.berlios.de> Author: axeld Date: 2007-05-15 19:33:05 +0200 (Tue, 15 May 2007) New Revision: 21144 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21144&view=rev Added: haiku/trunk/src/add-ons/kernel/file_systems/cdda/cddb.cpp haiku/trunk/src/add-ons/kernel/file_systems/cdda/cddb.h Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/Jamfile haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/Jamfile haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/cdda_text.cpp Log: * Implemented attribute handling - you can change them, but they are not stored yet. * Implemented CDDB ID computation (that's what BeOS's cdda-fs is using). * Some other minor changes. Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/Jamfile 2007-05-15 15:47:02 UTC (rev 21143) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/Jamfile 2007-05-15 17:33:05 UTC (rev 21144) @@ -7,4 +7,5 @@ KernelAddon cdda : kernel_interface.cpp cdda.cpp + cddb.cpp ; Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp 2007-05-15 15:47:02 UTC (rev 21143) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp 2007-05-15 17:33:05 UTC (rev 21144) @@ -56,7 +56,7 @@ static void -sanitize_string(char *string) +sanitize_string(char *&string) { if (string == NULL) return; @@ -78,6 +78,12 @@ while (length > 1 && isspace(string[length - 1])) { string[--length] = '\0'; } + + if (!string[0]) { + // free string if it's empty + free(string); + string = NULL; + } } @@ -127,7 +133,13 @@ cut_string(text.album, text.artist); sanitize_string(text.album); - if ((text.artist == NULL || !text.artist[0]) && text.album != NULL) { + if (text.album != NULL && !strcasecmp(text.album, "My CD")) { + // don't laugh, people really do that! + free(text.album); + text.album = NULL; + } + + if ((text.artist == NULL || text.artist[0] == NULL) && text.album != NULL) { // try to extract artist from album char *space = strstr(text.album, " "); if (space != NULL) { Added: haiku/trunk/src/add-ons/kernel/file_systems/cdda/cddb.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/cddb.cpp 2007-05-15 15:47:02 UTC (rev 21143) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/cddb.cpp 2007-05-15 17:33:05 UTC (rev 21144) @@ -0,0 +1,47 @@ +/* + * Copyright 2007, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + */ + + +#include "cddb.h" + + +static int32 +cddb_sum(int32 n) +{ + int32 result = 0; + + while (n > 0) { + result = result + (n % 10); + n = n / 10; + } + + return result; +} + + +// #pragma mark - exported functions + + +/*! + Computes the CD Disc ID as specified in the FreeDB how-to (code taken from there). +*/ +uint32 +compute_cddb_disc_id(scsi_toc_toc &toc) +{ + int32 numTracks = toc.last_track + 1 - toc.first_track; + uint32 n = 0; + + for (int32 i = 0; i < numTracks; i++) { + n = n + cddb_sum((toc.tracks[i].start.time.minute * 60) + + toc.tracks[i].start.time.second); + } + + int32 t = ((toc.tracks[numTracks].start.time.minute * 60) + + toc.tracks[numTracks].start.time.second) + - ((toc.tracks[0].start.time.minute * 60) + + toc.tracks[0].start.time.second); + + return (n % 0xff) << 24 | t << 8 | numTracks; +} Added: haiku/trunk/src/add-ons/kernel/file_systems/cdda/cddb.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/cddb.h 2007-05-15 15:47:02 UTC (rev 21143) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/cddb.h 2007-05-15 17:33:05 UTC (rev 21144) @@ -0,0 +1,14 @@ +/* + * Copyright 2007, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + */ +#ifndef CDDB_H +#define CDDB_H + + +#include + + +uint32 compute_cddb_disc_id(scsi_toc_toc &toc); + +#endif // CDDB_H Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp 2007-05-15 15:47:02 UTC (rev 21143) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp 2007-05-15 17:33:05 UTC (rev 21144) @@ -10,8 +10,11 @@ #include #include #include +#include +#include #include +#include #include #include @@ -29,10 +32,14 @@ #endif -class Volume; +class Attribute; class Inode; +struct attr_cookie; struct dir_cookie; +typedef DoublyLinkedList AttributeList; +typedef DoublyLinkedList AttrCookieList; + class Volume { public: Volume(mount_id id); @@ -73,7 +80,30 @@ Inode *fFirstEntry; }; +class Attribute : public DoublyLinkedListLinkImpl { + public: + Attribute(const char *name, type_code type); + ~Attribute(); + status_t InitCheck() const { return fName != NULL ? B_OK : B_NO_MEMORY; } + status_t SetTo(const char *name, type_code type); + void SetType(type_code type) { fType = type; } + + status_t ReadAt(off_t offset, uint8 *buffer, size_t *_length); + status_t WriteAt(off_t offset, const uint8 *buffer, size_t *_length); + void Truncate(); + + const char *Name() const { return fName; } + size_t Size() const { return fSize; } + type_code Type() const { return fType; } + + private: + char *fName; + type_code fType; + uint8 *fData; + size_t fSize; +}; + class Inode { public: Inode(Volume *volume, Inode *parent, const char *name, off_t start, @@ -103,6 +133,18 @@ off_t Size() const { return fFrameCount * kFrameSize /* + WAV header */; } + Attribute *FindAttribute(const char *name) const; + status_t AddAttribute(const char *name, type_code type, + const uint8 *data = 0, size_t length = 0); + status_t AddAttribute(const char *name, type_code type, + const char *string); + status_t AddAttribute(const char *name, int32 value); + status_t RemoveAttribute(const char *name); + + void AddAttrCookie(attr_cookie *cookie); + void RemoveAttrCookie(attr_cookie *cookie); + void RewindAttrCookie(attr_cookie *cookie); + Inode *Next() const { return fNext; } void SetNext(Inode *inode) { fNext = inode; } @@ -117,12 +159,13 @@ time_t fModificationTime; off_t fStartFrame; off_t fFrameCount; + AttributeList fAttributes; + AttrCookieList fAttrCookies; }; - struct dir_cookie { - Inode *current; - int state; // iteration state + Inode *current; + int state; // iteration state }; // directory iteration states @@ -133,8 +176,12 @@ ITERATION_STATE_BEGIN = ITERATION_STATE_DOT, }; +struct attr_cookie : DoublyLinkedListLinkImpl { + Attribute *current; +}; + struct file_cookie { - int open_mode; + int open_mode; }; @@ -212,6 +259,7 @@ scsi_cd_msf& next = toc->tracks[i + 1].start.time; // the last track is always lead-out scsi_cd_msf& start = toc->tracks[i].start.time; + int32 track = i + 1; off_t startFrame = start.minute * kFramesPerMinute + start.second * kFramesPerSecond + start.frame; @@ -219,18 +267,43 @@ + next.second * kFramesPerSecond + next.frame - startFrame; - if (text.titles[i] != NULL && text.titles[i]) { - if (text.artists[i] != NULL && text.artists[i]) { - snprintf(title, sizeof(title), "%02ld. %s - %s.wav", i + 1, + const char *artist = text.artists[i] != NULL + ? text.artists[i] : text.artist; + + if (text.titles[i] != NULL) { + if (artist != NULL) { + snprintf(title, sizeof(title), "%02ld. %s - %s.wav", track, text.artists[i], text.titles[i]); } else { - snprintf(title, sizeof(title), "%02ld. %s.wav", i + 1, + snprintf(title, sizeof(title), "%02ld. %s.wav", track, text.titles[i]); } } else - snprintf(title, sizeof(title), "%02ld.wav", i + 1); + snprintf(title, sizeof(title), "%02ld.wav", track); - _CreateNode(fRootNode, title, startFrame, frames, S_IFREG | 0444); + // remove '/' from title + for (int32 j = 0; title[j]; j++) { + if (title[j] == '/') + title[j] = '-'; + } + + Inode *inode = _CreateNode(fRootNode, title, startFrame, frames, + S_IFREG | 0444); + if (inode == NULL) + continue; + + // add attributes + + inode->AddAttribute("Audio:Artist", B_STRING_TYPE, artist); + inode->AddAttribute("Audio:Title", B_STRING_TYPE, text.titles[i]); + inode->AddAttribute("Audio:Genre", B_STRING_TYPE, text.genre); + inode->AddAttribute("Audio:Track", track); + + snprintf(title, sizeof(title), "%02lu:%02lu", + uint32(inode->FrameCount() / kFramesPerMinute), + uint32((inode->FrameCount() % kFramesPerMinute) / kFramesPerSecond)); + inode->AddAttribute("Audio:Length", B_STRING_TYPE, title); + inode->AddAttribute("BEOS:TYPE", B_MIME_STRING_TYPE, "audio/x-wav"); } free(toc); @@ -330,6 +403,116 @@ // #pragma mark - +Attribute::Attribute(const char *name, type_code type) + : + fName(NULL), + fType(0), + fData(NULL), + fSize(0) +{ + SetTo(name, type); +} + + +Attribute::~Attribute() +{ + free(fName); + free(fData); +} + + +status_t +Attribute::SetTo(const char *name, type_code type) +{ + if (name == NULL || !name[0]) + return B_BAD_VALUE; + + name = strdup(name); + if (name == NULL) + return B_NO_MEMORY; + + free(fName); + + fName = (char *)name; + fType = type; + return B_OK; +} + + +status_t +Attribute::ReadAt(off_t offset, uint8 *buffer, size_t *_length) +{ + size_t length = *_length; + + if (offset < 0) + return B_BAD_VALUE; + if (offset >= length) { + *_length = 0; + return B_OK; + } + if (offset + length > fSize) + length = fSize - offset; + + if (user_memcpy(buffer, fData + offset, length) < B_OK) + return B_BAD_ADDRESS; + + *_length = length; + return B_OK; +} + + +status_t +Attribute::WriteAt(off_t offset, const uint8 *buffer, size_t *_length) +{ + size_t length = *_length; + + if (offset < 0) + return B_BAD_VALUE; + + // we limit the attribute size to something reasonable + off_t end = offset + length; + if (end > 65536) { + end = 65536; + length = end - offset; + } + if (offset > end) { + *_length = 0; + return E2BIG; + } + + if (end > fSize) { + // make room in the data stream + uint8 *data = (uint8 *)realloc(fData, end); + if (data == NULL) + return B_NO_MEMORY; + + if (fSize < offset) + memset(data + fSize, 0, offset - fSize); + + fData = data; + fSize = end; + } + + if (user_memcpy(fData + offset, buffer, length) < B_OK) + return B_BAD_ADDRESS; + + *_length = length; + return B_OK; +} + + +void +Attribute::Truncate() +{ + free(fData); + fData = NULL; + fSize = 0; +} + + +// #pragma mark - + + Inode::Inode(Volume *volume, Inode *parent, const char *name, off_t start, off_t frames, int32 type) : @@ -383,6 +566,150 @@ } +Attribute * +Inode::FindAttribute(const char *name) const +{ + if (name == NULL || !name[0]) + return NULL; + + AttributeList::ConstIterator iterator = fAttributes.GetIterator(); + + while (iterator.HasNext()) { + Attribute *attribute = iterator.Next(); + if (!strcmp(attribute->Name(), name)) + return attribute; + } + + return NULL; +} + + +status_t +Inode::AddAttribute(const char *name, type_code type, + const uint8 *data, size_t length) +{ + if (FindAttribute(name) != NULL) + return B_NAME_IN_USE; + + Attribute *attribute = new Attribute(name, type); + status_t status = attribute != NULL ? B_OK : B_NO_MEMORY; + if (status == B_OK) + status = attribute->InitCheck(); + if (status == B_OK && data != NULL && length != 0) + status = attribute->WriteAt(0, data, &length); + if (status < B_OK) { + delete attribute; + return status; + } + + fAttributes.Add(attribute); + return B_OK; +} + + +status_t +Inode::AddAttribute(const char *name, type_code type, + const char *string) +{ + if (string == NULL) + return NULL; + + return AddAttribute(name, type, (const uint8 *)string, + strlen(string)); +} + + +status_t +Inode::AddAttribute(const char *name, int32 value) +{ + return AddAttribute(name, B_INT32_TYPE, (const uint8 *)&value, + sizeof(int32)); +} + + +status_t +Inode::RemoveAttribute(const char *name) +{ + if (name == NULL || !name[0]) + return B_ENTRY_NOT_FOUND; + + AttributeList::Iterator iterator = fAttributes.GetIterator(); + + while (iterator.HasNext()) { + Attribute *attribute = iterator.Next(); + if (!strcmp(attribute->Name(), name)) { + // look for attribute in cookies + AttrCookieList::Iterator i = fAttrCookies.GetIterator(); + while (i.HasNext()) { + attr_cookie *cookie = i.Next(); + if (cookie->current == attribute) + cookie->current = attribute->GetDoublyLinkedListLink()->next; + } + + iterator.Remove(); + delete attribute; + return B_OK; + } + } + + return B_ENTRY_NOT_FOUND; +} + + +void +Inode::AddAttrCookie(attr_cookie *cookie) +{ + fAttrCookies.Add(cookie); + RewindAttrCookie(cookie); +} + + +void +Inode::RemoveAttrCookie(attr_cookie *cookie) +{ + fAttrCookies.Remove(cookie); +} + + +void +Inode::RewindAttrCookie(attr_cookie *cookie) +{ + cookie->current = fAttributes.First(); +} + + +// #pragma mark - + + +void +fill_stat_buffer(Volume *volume, Inode *inode, Attribute *attribute, + struct stat &stat) +{ + stat.st_dev = volume->ID(); + stat.st_ino = inode->ID(); + + if (attribute != NULL) { + stat.st_size = attribute->Size(); + stat.st_mode = S_ATTR | 0666; + stat.st_type = attribute->Type(); + } else { + stat.st_size = inode->Size(); + stat.st_mode = inode->Type(); + stat.st_type = 0; + } + + stat.st_nlink = 1; + stat.st_blksize = 2048; + + stat.st_uid = inode->UserID(); + stat.st_gid = inode->GroupID(); + + stat.st_atime = time(NULL); + stat.st_mtime = stat.st_ctime = inode->ModificationTime(); + stat.st_crtime = inode->CreationTime(); +} + + // #pragma mark - module API @@ -636,22 +963,8 @@ TRACE(("cdda_read_stat: vnode %p (0x%Lx), stat %p\n", inode, inode->ID(), stat)); - stat->st_dev = volume->ID(); - stat->st_ino = inode->ID(); + fill_stat_buffer(volume, inode, NULL, *stat); - stat->st_size = inode->Size(); - stat->st_mode = inode->Type(); - - stat->st_nlink = 1; - stat->st_blksize = 2048; - - stat->st_uid = inode->UserID(); - stat->st_gid = inode->GroupID(); - - stat->st_atime = time(NULL); - stat->st_mtime = stat->st_ctime = inode->ModificationTime(); - stat->st_crtime = inode->CreationTime(); - return B_OK; } @@ -813,7 +1126,229 @@ } +// #pragma mark - attribute functions + + static status_t +cdda_open_attr_dir(fs_volume _volume, fs_vnode _vnode, fs_cookie *_cookie) +{ + Volume *volume = (Volume *)_volume; + Inode *inode = (Inode *)_vnode; + + attr_cookie *cookie = new attr_cookie; + if (cookie == NULL) + return B_NO_MEMORY; + + Locker _(volume->Lock()); + + inode->AddAttrCookie(cookie); + *_cookie = cookie; + return B_OK; +} + + +static status_t +cdda_close_attr_dir(fs_volume _volume, fs_vnode _vnode, fs_cookie _cookie) +{ + return B_OK; +} + + +static status_t +cdda_free_attr_dir_cookie(fs_volume _volume, fs_vnode _vnode, fs_cookie _cookie) +{ + Volume *volume = (Volume *)_volume; + Inode *inode = (Inode *)_vnode; + attr_cookie *cookie = (attr_cookie *)_cookie; + + Locker _(volume->Lock()); + + inode->RemoveAttrCookie(cookie); + delete cookie; + return B_OK; +} + + +static status_t +cdda_rewind_attr_dir(fs_volume _volume, fs_vnode _vnode, fs_cookie _cookie) +{ + Volume *volume = (Volume *)_volume; + Inode *inode = (Inode *)_vnode; + attr_cookie *cookie = (attr_cookie *)_cookie; + + Locker _(volume->Lock()); + + inode->RewindAttrCookie(cookie); + return B_OK; +} + + +static status_t +cdda_read_attr_dir(fs_volume _volume, fs_vnode _vnode, fs_cookie _cookie, + struct dirent *dirent, size_t bufferSize, uint32 *_num) +{ + Volume *volume = (Volume *)_volume; + Inode *inode = (Inode *)_vnode; + attr_cookie *cookie = (attr_cookie *)_cookie; + + Locker _(volume->Lock()); + Attribute *attribute = cookie->current; + + if (attribute == NULL) { + *_num = 0; + return B_OK; + } + + size_t length = strlcpy(dirent->d_name, attribute->Name(), bufferSize); + dirent->d_dev = volume->ID(); + dirent->d_ino = inode->ID(); + dirent->d_reclen = sizeof(struct dirent) + length; + + cookie->current = attribute->GetDoublyLinkedListLink()->next; + *_num = 1; + return B_OK; +} + + +static status_t +cdda_create_attr(fs_volume _volume, fs_vnode _node, const char *name, + uint32 type, int openMode, fs_cookie *_cookie) +{ + Volume *volume = (Volume *)_volume; + Inode *inode = (Inode *)_node; + + Locker _(volume->Lock()); + + Attribute *attribute = inode->FindAttribute(name); + if (attribute == NULL) { + status_t status = inode->AddAttribute(name, type); + if (status < B_OK) + return status; + } else if ((openMode & O_EXCL) == 0) { + attribute->SetType(type); + } else + return B_FILE_EXISTS; + + *_cookie = strdup(name); + if (*_cookie == NULL) + return B_NO_MEMORY; + + return B_OK; +} + + +static status_t +cdda_open_attr(fs_volume _volume, fs_vnode _node, const char *name, + int openMode, fs_cookie *_cookie) +{ + Volume *volume = (Volume *)_volume; + Inode *inode = (Inode *)_node; + + Locker _(volume->Lock()); + + Attribute *attribute = inode->FindAttribute(name); + if (attribute == NULL) + return B_ENTRY_NOT_FOUND; + + *_cookie = strdup(name); + if (*_cookie == NULL) + return B_NO_MEMORY; + + return B_OK; +} + + +static status_t +cdda_close_attr(fs_volume _fs, fs_vnode _file, fs_cookie cookie) +{ + return B_OK; +} + + +static status_t +cdda_free_attr_cookie(fs_volume _fs, fs_vnode _file, fs_cookie cookie) +{ + free(cookie); + return B_OK; +} + + +static status_t +cdda_read_attr(fs_volume _volume, fs_vnode _node, fs_cookie _cookie, + off_t offset, void *buffer, size_t *_length) +{ + Volume *volume = (Volume *)_volume; + Inode *inode = (Inode *)_node; + + Locker _(volume->Lock()); + + Attribute *attribute = inode->FindAttribute((const char *)_cookie); + if (attribute == NULL) + return B_ENTRY_NOT_FOUND; + + return attribute->ReadAt(offset, (uint8 *)buffer, _length); +} + + +static status_t +cdda_write_attr(fs_volume _volume, fs_vnode _file, fs_cookie _cookie, + off_t offset, const void *buffer, size_t *_length) +{ + Volume *volume = (Volume *)_volume; + Inode *inode = (Inode *)_file; + + Locker _(volume->Lock()); + + Attribute *attribute = inode->FindAttribute((const char *)_cookie); + if (attribute == NULL) + return B_ENTRY_NOT_FOUND; + + return attribute->WriteAt(offset, (uint8 *)buffer, _length); +} + + +static status_t +cdda_read_attr_stat(fs_volume _volume, fs_vnode _file, fs_cookie _cookie, + struct stat *stat) +{ + Volume *volume = (Volume *)_volume; + Inode *inode = (Inode *)_file; + + Locker _(volume->Lock()); + + Attribute *attribute = inode->FindAttribute((const char *)_cookie); + if (attribute == NULL) + return B_ENTRY_NOT_FOUND; + + fill_stat_buffer(volume, inode, attribute, *stat); + return B_OK; +} + + +static status_t +cdda_write_attr_stat(fs_volume _volume, fs_vnode file, fs_cookie cookie, + const struct stat *stat, int statMask) +{ + return EOPNOTSUPP; +} + + +static status_t +cdda_remove_attr(fs_volume _volume, fs_vnode _node, const char *name) +{ + if (name == NULL) + return B_BAD_VALUE; + + Volume *volume = (Volume *)_volume; + Inode *inode = (Inode *)_node; + + Locker _(volume->Lock()); + + return inode->RemoveAttribute(name); +} + + +static status_t cdda_std_ops(int32 op, ...) { switch (op) { @@ -873,7 +1408,7 @@ NULL, // fs_symlink() NULL, // fs_link() NULL, // fs_unlink() - NULL, // fs_rename() + &cdda_rename, NULL, // fs_access() &cdda_read_stat, @@ -896,7 +1431,6 @@ &cdda_read_dir, &cdda_rewind_dir, -#if 0 // attribute directory operations &cdda_open_attr_dir, &cdda_close_attr_dir, @@ -914,9 +1448,8 @@ &cdda_read_attr_stat, &cdda_write_attr_stat, - &cdda_rename_attr, + NULL, // fs_rename_attr() &cdda_remove_attr, -#endif // the other operations are not yet supported (indices, queries) NULL, Modified: haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/Jamfile =================================================================== --- haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/Jamfile 2007-05-15 15:47:02 UTC (rev 21143) +++ haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/Jamfile 2007-05-15 17:33:05 UTC (rev 21144) @@ -6,4 +6,5 @@ : cdda_text.cpp cdda.cpp + cddb.cpp ; Modified: haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/cdda_text.cpp =================================================================== --- haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/cdda_text.cpp 2007-05-15 15:47:02 UTC (rev 21143) +++ haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/cdda_text.cpp 2007-05-15 17:33:05 UTC (rev 21144) @@ -5,6 +5,7 @@ #include "cdda.h" +#include "cddb.h" #include #include @@ -36,7 +37,8 @@ return -1; uint8 buffer[1024]; - if (read_table_of_contents(fd, (scsi_toc_toc*)buffer, sizeof(buffer)) < 0) { + scsi_toc_toc *toc = (scsi_toc_toc *)buffer; + if (read_table_of_contents(fd, toc, sizeof(buffer)) < 0) { fprintf(stderr, "%s: Retrieving TOC failed", __progname); return -1; } @@ -44,5 +46,8 @@ cdtext text; read_cdtext(fd, text); + uint32 id = compute_cddb_disc_id(*toc); + printf("CDDB disc ID: %lx\n", id); + close(fd); } From bonefish at mail.berlios.de Tue May 15 19:54:11 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Tue, 15 May 2007 19:54:11 +0200 Subject: [Haiku-commits] r21145 - haiku/trunk/src/tests/kits/interface/layout/widget_layout_test Message-ID: <200705151754.l4FHsARo014039@sheep.berlios.de> Author: bonefish Date: 2007-05-15 19:54:08 +0200 (Tue, 15 May 2007) New Revision: 21145 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21145&view=rev Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/CheckBox.cpp haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/CheckBox.h haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/GroupView.cpp haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/GroupView.h haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/StringView.cpp haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/StringView.h haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/TwoDimensionalSliderView.cpp haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/TwoDimensionalSliderView.h haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/View.cpp haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/View.h haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/ViewContainer.cpp haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/ViewContainer.h haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/WrapperView.cpp haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/WrapperView.h Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp Log: Refactoring. Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/CheckBox.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/CheckBox.cpp 2007-05-15 17:33:05 UTC (rev 21144) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/CheckBox.cpp 2007-05-15 17:54:08 UTC (rev 21145) @@ -0,0 +1,122 @@ +/* + * Copyright 2007, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "CheckBox.h" + +#include + + +CheckBox::CheckBox(BMessage* message, BMessenger target) + : View(BRect(0, 0, 12, 12)), + BInvoker(message, target), + fSelected(false), + fPressed(false) +{ + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); +} + + +void +CheckBox::SetSelected(bool selected) +{ + if (selected != fSelected) { + fSelected = selected; + Invalidate(); + + // send the message + if (Message()) { + BMessage message(*Message()); + message.AddBool("selected", IsSelected()); + InvokeNotify(&message); + } + } +} + + +bool +CheckBox::IsSelected() const +{ + return fSelected; +} + + +BSize +CheckBox::MinSize() +{ + return BSize(12, 12); +} + + +BSize +CheckBox::MaxSize() +{ + return MinSize(); +} + + +void +CheckBox::Draw(BView* container, BRect updateRect) +{ + BRect rect(Bounds()); + + if (fPressed) + container->SetHighColor((rgb_color){ 120, 0, 0, 255 }); + else + container->SetHighColor((rgb_color){ 0, 0, 0, 255 }); + + container->StrokeRect(rect); + + if (fPressed ? fPressedSelected : fSelected) { + rect.InsetBy(2, 2); + container->StrokeLine(rect.LeftTop(), rect.RightBottom()); + container->StrokeLine(rect.RightTop(), rect.LeftBottom()); + } +} + + +void +CheckBox::MouseDown(BPoint where, uint32 buttons, int32 modifiers) +{ + if (fPressed) + return; + + fPressed = true; + fPressedSelected = fSelected; + _PressedUpdate(where); +} + + +void +CheckBox::MouseUp(BPoint where, uint32 buttons, int32 modifiers) +{ + if (!fPressed || (buttons & B_PRIMARY_MOUSE_BUTTON)) + return; + + _PressedUpdate(where); + fPressed = false; + SetSelected(fPressedSelected); + Invalidate(); +} + + +void +CheckBox::MouseMoved(BPoint where, uint32 buttons, int32 modifiers) +{ + if (!fPressed) + return; + + _PressedUpdate(where); +} + + +void +CheckBox::_PressedUpdate(BPoint where) +{ + bool pressedSelected = Bounds().Contains(where) ^ fSelected; + if (pressedSelected != fPressedSelected) { + fPressedSelected = pressedSelected; + Invalidate(); + } +} Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/CheckBox.h =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/CheckBox.h 2007-05-15 17:33:05 UTC (rev 21144) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/CheckBox.h 2007-05-15 17:54:08 UTC (rev 21145) @@ -0,0 +1,44 @@ +/* + * Copyright 2007, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef WIDGET_LAYOUT_TEST_CHECK_BOX_H +#define WIDGET_LAYOUT_TEST_CHECK_BOX_H + + +#include + +#include "View.h" + + +class CheckBox : public View, public BInvoker { +public: + CheckBox(BMessage* message = NULL, + BMessenger target = BMessenger()); + + void SetSelected(bool selected); + bool IsSelected() const; + + virtual BSize MinSize(); + virtual BSize MaxSize(); + + virtual void Draw(BView* container, BRect updateRect); + + virtual void MouseDown(BPoint where, uint32 buttons, + int32 modifiers); + virtual void MouseUp(BPoint where, uint32 buttons, + int32 modifiers); + virtual void MouseMoved(BPoint where, uint32 buttons, + int32 modifiers); + +private: + void _PressedUpdate(BPoint where); + +private: + bool fSelected; + bool fPressed; + bool fPressedSelected; +}; + + +#endif // WIDGET_LAYOUT_TEST_CHECK_BOX_H Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/GroupView.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/GroupView.cpp 2007-05-15 17:33:05 UTC (rev 21144) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/GroupView.cpp 2007-05-15 17:54:08 UTC (rev 21145) @@ -0,0 +1,410 @@ +/* + * Copyright 2007, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "GroupView.h" + +#include + + +// #pragma mark - GroupView + + +struct GroupView::LayoutInfo { + int32 min; + int32 max; + int32 preferred; + int32 size; + + LayoutInfo() + : min(0), + max(B_SIZE_UNLIMITED), + preferred(0) + { + } + + void AddConstraints(float addMin, float addMax, float addPreferred) + { + if (addMin >= min) + min = (int32)addMin + 1; + if (addMax <= max) + max = (int32)addMax + 1; + if (addPreferred >= preferred) + preferred = (int32)addPreferred + 1; + } + + void Normalize() + { + if (max > min) + max = min; + if (preferred < min) + preferred = min; + if (preferred > max) + preferred = max; + } +}; + + +GroupView::GroupView(enum orientation orientation, int32 lineCount) + : View(BRect(0, 0, 0, 0)), + fOrientation(orientation), + fLineCount(lineCount), + fColumnSpacing(0), + fRowSpacing(0), + fInsets(0, 0, 0, 0), + fMinMaxValid(false), + fColumnInfos(NULL), + fRowInfos(NULL) +{ + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + if (fLineCount < 1) + fLineCount = 1; +} + + +GroupView::~GroupView() +{ + delete fColumnInfos; + delete fRowInfos; +} + + +void +GroupView::SetSpacing(float horizontal, float vertical) +{ + if (horizontal != fColumnSpacing || vertical != fRowSpacing) { + fColumnSpacing = horizontal; + fRowSpacing = vertical; + + InvalidateLayout(); + } +} + + +void +GroupView::SetInsets(float left, float top, float right, float bottom) +{ + BRect newInsets(left, top, right, bottom); + if (newInsets != fInsets) { + fInsets = newInsets; + InvalidateLayout(); + } +} + + +BSize +GroupView::MinSize() +{ + _ValidateMinMax(); + return _AddInsetsAndSpacing(BSize(fMinWidth - 1, fMinHeight - 1)); +} + + +BSize +GroupView::MaxSize() +{ + _ValidateMinMax(); + return _AddInsetsAndSpacing(BSize(fMaxWidth - 1, fMaxHeight - 1)); +} + + +BSize +GroupView::PreferredSize() +{ + _ValidateMinMax(); + return _AddInsetsAndSpacing(BSize(fPreferredWidth - 1, + fPreferredHeight - 1)); +} + + +BAlignment +GroupView::Alignment() +{ + return BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT); +} + + +void +GroupView::Layout() +{ + _ValidateMinMax(); + // actually a little late already + + BSize size = _SubtractInsetsAndSpacing(Size()); + _LayoutLine(size.IntegerWidth() + 1, fColumnInfos, fColumnCount); + _LayoutLine(size.IntegerHeight() + 1, fRowInfos, fRowCount); + + // layout children + BPoint location = fInsets.LeftTop(); + for (int32 column = 0; column < fColumnCount; column++) { + LayoutInfo& columnInfo = fColumnInfos[column]; + location.y = fInsets.top; + for (int32 row = 0; row < fRowCount; row++) { + View* child = _ChildAt(column, row); + if (!child) + continue; + + // get the grid cell frame + BRect cellFrame(location, + BSize(columnInfo.size - 1, fRowInfos[row].size - 1)); + + // align the child frame in the grid cell + BRect childFrame = BLayoutUtils::AlignInFrame(cellFrame, + child->MaxSize(), child->Alignment()); + + // layout child + child->SetFrame(childFrame); + + location.y += fRowInfos[row].size + fRowSpacing; + } + + location.x += columnInfo.size + fColumnSpacing; + } +} + + +void +GroupView::_ValidateMinMax() +{ + if (fMinMaxValid) + return; + + delete fColumnInfos; + delete fRowInfos; + + fColumnCount = _ColumnCount(); + fRowCount = _RowCount(); + + fColumnInfos = new LayoutInfo[fColumnCount]; + fRowInfos = new LayoutInfo[fRowCount]; + + // collect the children's min/max constraints + for (int32 column = 0; column < fColumnCount; column++) { + for (int32 row = 0; row < fRowCount; row++) { + View* child = _ChildAt(column, row); + if (!child) + continue; + + BSize min = child->MinSize(); + BSize max = child->MaxSize(); + BSize preferred = child->PreferredSize(); + + // apply constraints to column/row info + fColumnInfos[column].AddConstraints(min.width, max.width, + preferred.width); + fRowInfos[row].AddConstraints(min.height, max.height, + preferred.height); + } + } + + // normalize the column/row constraints and compute sum min/max + fMinWidth = 0; + fMinHeight = 0; + fMaxWidth = 0; + fMaxHeight = 0; + fPreferredWidth = 0; + fPreferredHeight = 0; + + for (int32 column = 0; column < fColumnCount; column++) { + fColumnInfos[column].Normalize(); + fMinWidth = BLayoutUtils::AddSizesInt32(fMinWidth, + fColumnInfos[column].min); + fMaxWidth = BLayoutUtils::AddSizesInt32(fMaxWidth, + fColumnInfos[column].max); + fPreferredWidth = BLayoutUtils::AddSizesInt32(fPreferredWidth, + fColumnInfos[column].preferred); + } + + for (int32 row = 0; row < fRowCount; row++) { + fRowInfos[row].Normalize(); + fMinHeight = BLayoutUtils::AddSizesInt32(fMinHeight, + fRowInfos[row].min); + fMaxHeight = BLayoutUtils::AddSizesInt32(fMaxHeight, + fRowInfos[row].max); + fPreferredHeight = BLayoutUtils::AddSizesInt32(fPreferredHeight, + fRowInfos[row].preferred); + } + + fMinMaxValid = true; +} + + +void +GroupView::_LayoutLine(int32 size, LayoutInfo* infos, int32 infoCount) +{ + BList infosToLayout; + for (int32 i = 0; i < infoCount; i++) { + infos[i].size = 0; + infosToLayout.AddItem(infos + i); + } + + // Distribute the available space over the infos. Each iteration we + // try to distribute the remaining space evenly. We respect min and + // max constraints, though, add up the space we failed to assign + // due to the constraints, and use the sum as remaining space for the + // next iteration (can be negative). Then we ignore infos that can't + // shrink or grow anymore (depending on what would be needed). + while (!infosToLayout.IsEmpty()) { + BList canShrinkInfos; + BList canGrowInfos; + + int32 sizeDiff = 0; + int32 infosToLayoutCount = infosToLayout.CountItems(); + for (int32 i = 0; i < infosToLayoutCount; i++) { + LayoutInfo* info = (LayoutInfo*)infosToLayout.ItemAt(i); + info->size += (i + 1) * size / infosToLayoutCount + - i * size / infosToLayoutCount; + if (info->size < info->min) { + sizeDiff -= info->min - info->size; + info->size = info->min; + } else if (info->size > info->max) { + sizeDiff += info->size - info->max; + info->size = info->max; + } + + if (info->size > info->min) + canShrinkInfos.AddItem(info); + if (info->size < info->max) + canGrowInfos.AddItem(info); + } + + size = sizeDiff; + if (size == 0) + break; + + if (size > 0) + infosToLayout = canGrowInfos; + else + infosToLayout = canShrinkInfos; + } + + // If unassigned space is remaining, that means, that the group has + // been resized beyond its max size. We distribute the excess space + // evenly. + if (size > 0) { + for (int32 i = 0; i < infoCount; i++) { + infos[i].size += (i + 1) * size / infoCount + - i * size / infoCount; + } + } +} + + +BSize +GroupView::_AddInsetsAndSpacing(BSize size) +{ + size.width = BLayoutUtils::AddDistances(size.width, + fInsets.left + fInsets.right - 1 + + (fColumnCount - 1) * fColumnSpacing); + size.height = BLayoutUtils::AddDistances(size.height, + fInsets.top + fInsets.bottom - 1 + + (fRowCount - 1) * fRowSpacing); + return size; +} + + +BSize +GroupView::_SubtractInsetsAndSpacing(BSize size) +{ + size.width = BLayoutUtils::SubtractDistances(size.width, + fInsets.left + fInsets.right - 1 + + (fColumnCount - 1) * fColumnSpacing); + size.height = BLayoutUtils::SubtractDistances(size.height, + fInsets.top + fInsets.bottom - 1 + + (fRowCount - 1) * fRowSpacing); + return size; +} + +int32 +GroupView::_RowCount() const +{ + int32 childCount = CountChildren(); + int32 count; + if (fOrientation == B_HORIZONTAL) + count = min_c(fLineCount, childCount); + else + count = (childCount + fLineCount - 1) / fLineCount; + + return max_c(count, 1); +} + + +int32 +GroupView::_ColumnCount() const +{ + int32 childCount = CountChildren(); + int32 count; + if (fOrientation == B_HORIZONTAL) + count = (childCount + fLineCount - 1) / fLineCount; + else + count = min_c(fLineCount, childCount); + + return max_c(count, 1); +} + + +View* +GroupView::_ChildAt(int32 column, int32 row) const +{ + if (fOrientation == B_HORIZONTAL) + return ChildAt(column * fLineCount + row); + else + return ChildAt(row * fLineCount + column); +} + + +// #pragma mark - Glue + + +Glue::Glue() + : View() +{ + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); +} + + +// #pragma mark - Strut + + +Strut::Strut(float pixelWidth, float pixelHeight) + : View(), + fSize(pixelWidth >= 0 ? pixelWidth - 1 : B_SIZE_UNSET, + pixelHeight >= 0 ? pixelHeight - 1 : B_SIZE_UNSET) +{ + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); +} + + +BSize +Strut::MinSize() +{ + return BLayoutUtils::ComposeSize(fSize, BSize(-1, -1)); +} + + +BSize +Strut::MaxSize() +{ + return BLayoutUtils::ComposeSize(fSize, + BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); +} + + +// #pragma mark - HStrut + + +HStrut::HStrut(float width) + : Strut(width, -1) +{ +} + + +// #pragma mark - VStrut + + +VStrut::VStrut(float height) + : Strut(-1, height) +{ +} Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/GroupView.h =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/GroupView.h 2007-05-15 17:33:05 UTC (rev 21144) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/GroupView.h 2007-05-15 17:54:08 UTC (rev 21145) @@ -0,0 +1,99 @@ +/* + * Copyright 2007, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef WIDGET_LAYOUT_TEST_GROUP_VIEW_H +#define WIDGET_LAYOUT_TEST_GROUP_VIEW_H + + +#include "View.h" + + +// GroupView +class GroupView : public View { +public: + GroupView(enum orientation orientation, + int32 lineCount = 1); + virtual ~GroupView(); + + void SetSpacing(float horizontal, float vertical); + void SetInsets(float left, float top, float right, + float bottom); + + virtual BSize MinSize(); + virtual BSize MaxSize(); + virtual BSize PreferredSize(); + virtual BAlignment Alignment(); + + virtual void Layout(); + +private: + struct LayoutInfo; + +private: + void _ValidateMinMax(); + void _LayoutLine(int32 size, LayoutInfo* infos, + int32 infoCount); + + BSize _AddInsetsAndSpacing(BSize size); + BSize _SubtractInsetsAndSpacing(BSize size); + + int32 _RowCount() const; + int32 _ColumnCount() const; + View* _ChildAt(int32 column, int32 row) const; + +private: + enum orientation fOrientation; + int32 fLineCount; + float fColumnSpacing; + float fRowSpacing; + BRect fInsets; + bool fMinMaxValid; + int32 fMinWidth; + int32 fMinHeight; + int32 fMaxWidth; + int32 fMaxHeight; + int32 fPreferredWidth; + int32 fPreferredHeight; + LayoutInfo* fColumnInfos; + LayoutInfo* fRowInfos; + int32 fColumnCount; + int32 fRowCount; +}; + + +// Glue +class Glue : public View { +public: + Glue(); +}; + + +// Strut +class Strut : public View { +public: + Strut(float pixelWidth, float pixelHeight); + + virtual BSize MinSize(); + virtual BSize MaxSize(); + +private: + BSize fSize; +}; + + +// HStrut +class HStrut : public Strut { +public: + HStrut(float width); +}; + + +// VStrut +class VStrut : public Strut { +public: + VStrut(float height); +}; + + +#endif // WIDGET_LAYOUT_TEST_GROUP_VIEW_H Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile 2007-05-15 17:33:05 UTC (rev 21144) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile 2007-05-15 17:54:08 UTC (rev 21145) @@ -4,6 +4,14 @@ SimpleTest WidgetLayoutTest : WidgetLayoutTest.cpp + + CheckBox.cpp + GroupView.cpp + StringView.cpp + TwoDimensionalSliderView.cpp + View.cpp + ViewContainer.cpp + WrapperView.cpp : be ; Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/StringView.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/StringView.cpp 2007-05-15 17:33:05 UTC (rev 21144) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/StringView.cpp 2007-05-15 17:54:08 UTC (rev 21145) @@ -0,0 +1,125 @@ +/* + * Copyright 2007, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "StringView.h" + +#include + +#include + + +StringView::StringView(const char* string) + : View(), + fString(string), + fAlignment(B_ALIGN_LEFT), + fStringAscent(0), + fStringDescent(0), + fStringWidth(0), + fExplicitMinSize(B_SIZE_UNSET, B_SIZE_UNSET) +{ + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + fTextColor = (rgb_color){ 0, 0, 0, 255 }; +} + + +void +StringView::SetString(const char* string) +{ + fString = string; + + _UpdateStringMetrics(); + Invalidate(); + InvalidateLayout(); +} + + +void +StringView::SetAlignment(alignment align) +{ + if (align != fAlignment) { + fAlignment = align; + Invalidate(); + } +} + + +void +StringView::SetTextColor(rgb_color color) +{ + fTextColor = color; + Invalidate(); +} + + +BSize +StringView::MinSize() +{ + BSize size(fExplicitMinSize); + if (!size.IsWidthSet()) + size.width = fStringWidth - 1; + if (!size.IsHeightSet()) + size.height = fStringAscent + fStringDescent - 1; + return size; +} + + +void +StringView::SetExplicitMinSize(BSize size) +{ + fExplicitMinSize = size; +} + + +void +StringView::AddedToContainer() +{ + _UpdateStringMetrics(); +} + + +void +StringView::Draw(BView* container, BRect updateRect) +{ + BSize size(Size()); + int widthDiff = (int)size.width + 1 - (int)fStringWidth; + int heightDiff = (int)size.height + 1 + - (int)(fStringAscent + (int)fStringDescent); + BPoint base; + + // horizontal alignment + switch (fAlignment) { + case B_ALIGN_RIGHT: + base.x = widthDiff; + break; + case B_ALIGN_LEFT: + default: + base.x = 0; + break; + } + + base.y = heightDiff / 2 + fStringAscent; + + container->SetHighColor(fTextColor); + container->DrawString(fString.String(), base); +} + + +void +StringView::_UpdateStringMetrics() +{ + BView* container = Container(); + if (!container) + return; + + BFont font; + container->GetFont(&font); + + font_height fh; + font.GetHeight(&fh); + + fStringAscent = ceilf(fh.ascent); + fStringDescent = ceilf(fh.descent); + fStringWidth = font.StringWidth(fString.String()); +} Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/StringView.h =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/StringView.h 2007-05-15 17:33:05 UTC (rev 21144) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/StringView.h 2007-05-15 17:54:08 UTC (rev 21145) @@ -0,0 +1,44 @@ +/* + * Copyright 2007, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef WIDGET_LAYOUT_TEST_STRING_VIEW_H +#define WIDGET_LAYOUT_TEST_STRING_VIEW_H + + +#include + +#include "View.h" + + +class StringView : public View { +public: + StringView(const char* string); + + void SetString(const char* string); + void SetAlignment(alignment align); + void SetTextColor(rgb_color color); + + virtual BSize MinSize(); + + void SetExplicitMinSize(BSize size); + + virtual void AddedToContainer(); + + virtual void Draw(BView* container, BRect updateRect); + +private: + void _UpdateStringMetrics(); + +private: + BString fString; + alignment fAlignment; + rgb_color fTextColor; + float fStringAscent; + float fStringDescent; + float fStringWidth; + BSize fExplicitMinSize; +}; + + +#endif // WIDGET_LAYOUT_TEST_STRING_VIEW_H Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/TwoDimensionalSliderView.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/TwoDimensionalSliderView.cpp 2007-05-15 17:33:05 UTC (rev 21144) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/TwoDimensionalSliderView.cpp 2007-05-15 17:54:08 UTC (rev 21145) @@ -0,0 +1,119 @@ +/* + * Copyright 2007, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "TwoDimensionalSliderView.h" + +#include + + +TwoDimensionalSliderView::TwoDimensionalSliderView(BMessage* message, + BMessenger target) + : View(BRect(0, 0, 4, 4)), + BInvoker(message, target), + fMinLocation(0, 0), + fMaxLocation(0, 0), + fDragging(false) +{ + SetViewColor((rgb_color){0, 120, 0, 255}); +} + + +void +TwoDimensionalSliderView::SetLocationRange(BPoint minLocation, + BPoint maxLocation) +{ + if (maxLocation.x < minLocation.x) + maxLocation.x = minLocation.x; + if (maxLocation.y < minLocation.y) + maxLocation.y = minLocation.y; + + fMinLocation = minLocation; + fMaxLocation = maxLocation; + + // force valid value + SetValue(Value()); +} + + +BPoint +TwoDimensionalSliderView::MinLocation() const +{ + return fMinLocation; +} + + +BPoint +TwoDimensionalSliderView::MaxLocation() const +{ + return fMaxLocation; +} + + +BPoint +TwoDimensionalSliderView::Value() const +{ + return Location() - fMinLocation; +} + + +void +TwoDimensionalSliderView::SetValue(BPoint value) +{ + BPoint location = fMinLocation + value; + if (location.x < fMinLocation.x) + location.x = fMinLocation.x; + if (location.y < fMinLocation.y) + location.y = fMinLocation.y; + if (location.x > fMaxLocation.x) + location.x = fMaxLocation.x; + if (location.y > fMaxLocation.y) + location.y = fMaxLocation.y; + + if (location != Location()) { + SetFrame(Frame().OffsetToCopy(location)); + + // send the message + if (Message()) { + BMessage message(*Message()); + message.AddPoint("value", Value()); + InvokeNotify(&message); + } + } +} + + +void +TwoDimensionalSliderView::MouseDown(BPoint where, uint32 buttons, + int32 modifiers) +{ + if (fDragging) + return; + + fOriginalLocation = Frame().LeftTop(); + fOriginalPoint = ConvertToContainer(where); [... truncated: 2466 lines follow ...] From mmu_man at mail.berlios.de Tue May 15 19:56:02 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Tue, 15 May 2007 19:56:02 +0200 Subject: [Haiku-commits] r21146 - haiku/trunk/src/bin Message-ID: <200705151756.l4FHu2OF014192@sheep.berlios.de> Author: mmu_man Date: 2007-05-15 19:56:02 +0200 (Tue, 15 May 2007) New Revision: 21146 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21146&view=rev Added: haiku/trunk/src/bin/setdecor.cpp Log: Zeta-like setdecor command to list/set decorator addon. Just for the sake of it. Added: haiku/trunk/src/bin/setdecor.cpp =================================================================== --- haiku/trunk/src/bin/setdecor.cpp 2007-05-15 17:54:08 UTC (rev 21145) +++ haiku/trunk/src/bin/setdecor.cpp 2007-05-15 17:56:02 UTC (rev 21146) @@ -0,0 +1,91 @@ +/* + * Copyright 2007, Fran?ois Revol, revol at free.fr. + * + * Distributed under the terms of the MIT license. + */ + + +#include +#include +#include +#include + +// this isn't public yet ? +namespace BPrivate { +int32 count_decorators(void); +int32 get_decorator(void); +status_t get_decorator_name(const int32 &index, BString &name); +status_t get_decorator_preview(const int32 &index, BBitmap *bitmap); +status_t set_decorator(const int32 &index); +} + +using namespace BPrivate; + +int main(int argc, char **argv) +{ + status_t err; + if (argc < 2) { + printf("usage: %s [-l|-c|decorname]\n", argv[0]); + printf("\t-l: list available decors\n"); + printf("\t-c: give current decor name\n"); + return 1; + } + BApplication app("application/x-vnd.Haiku-setdecor"); + // we want the list + if (!strcmp(argv[1], "-l")) { + int32 i, count; + count = count_decorators(); + if (count < 0) { + fprintf(stderr, "error counting decorators: %s\n", strerror(count)); + return 1; + } + for (i = 0; i < count; i++) { + BString name; + err = get_decorator_name(i, name); + if (err < 0) + continue; + printf("%s\n", name.String()); + } + return 0; + } + // we want the current one + if (!strcmp(argv[1], "-c")) { + int32 i; + BString name; + i = get_decorator(); + if (i < 0) { + fprintf(stderr, "error getting current decorator: %s\n", strerror(i)); + return 1; + } + err = get_decorator_name(i, name); + if (err < 0) { + fprintf(stderr, "error getting name of decorator: %s\n", strerror(err)); + return 1; + } + printf("%s\n", name.String()); + } + // we want to change it + int32 i, count; + count = count_decorators(); + if (count < 0) { + fprintf(stderr, "error counting decorators: %s\n", strerror(count)); + return 1; + } + for (i = 0; i < count; i++) { + BString name; + err = get_decorator_name(i, name); + if (err < 0) + continue; + if (name == argv[1]) { + err = set_decorator(i); + if (err < 0) { + fprintf(stderr, "error setting decorator: %s\n", strerror(err)); + return 1; + } + return 0; + } + } + fprintf(stderr, "can't find decorator \"%s\"\n", argv[1]); + return 1; +} + From mmu_man at mail.berlios.de Tue May 15 19:56:54 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Tue, 15 May 2007 19:56:54 +0200 Subject: [Haiku-commits] r21147 - haiku/trunk/src/bin Message-ID: <200705151756.l4FHus3C014260@sheep.berlios.de> Author: mmu_man Date: 2007-05-15 19:56:54 +0200 (Tue, 15 May 2007) New Revision: 21147 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21147&view=rev Modified: haiku/trunk/src/bin/Jamfile Log: Add setdecor. Modified: haiku/trunk/src/bin/Jamfile =================================================================== --- haiku/trunk/src/bin/Jamfile 2007-05-15 17:56:02 UTC (rev 21146) +++ haiku/trunk/src/bin/Jamfile 2007-05-15 17:56:54 UTC (rev 21147) @@ -95,6 +95,7 @@ query.cpp quit.cpp roster.cpp + setdecor.cpp settype.cpp setversion.cpp urlwrapper.cpp From mmu_man at mail.berlios.de Tue May 15 19:58:12 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Tue, 15 May 2007 19:58:12 +0200 Subject: [Haiku-commits] r21148 - haiku/trunk/build/jam Message-ID: <200705151758.l4FHwCJF014349@sheep.berlios.de> Author: mmu_man Date: 2007-05-15 19:58:12 +0200 (Tue, 15 May 2007) New Revision: 21148 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21148&view=rev Modified: haiku/trunk/build/jam/HaikuImage Log: Add nbd and setdecor to the image. Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2007-05-15 17:56:54 UTC (rev 21147) +++ haiku/trunk/build/jam/HaikuImage 2007-05-15 17:58:12 UTC (rev 21148) @@ -34,7 +34,7 @@ mount_nfs mountvolume mv nc netstat nl od open pack_cis paste patch pathchk pc ping play playfile playsound playwav pr prio printenv printf ps ptx pwd query quit release renice rescan rlog rm rmattr rmindex rmdir roster route - safemode screen_blanker sed settype setversion setvolume seq sh shar + safemode screen_blanker sed setdecor settype setversion setvolume seq sh shar shutdown sleep sort split strace stty su sum sync sysinfo tac tail tar tcpdump tcptester tee telnet telnetd test top touch tput tr traceroute translate true tsort tty uname unchop unexpand unmount uniq unrar unshar @@ -149,6 +149,7 @@ AddDriversToHaikuImage midi : $(BEOS_ADD_ONS_DRIVERS_MIDI) ; AddDriversToHaikuImage bus : usb_raw ; AddDriversToHaikuImage disk scsi : scsi_cd scsi_dsk ; +AddDriversToHaikuImage disk virtual : nbd ; AddDriversToHaikuImage dvb : cx23882 ; AddDriversToHaikuImage graphics : $(BEOS_ADD_ONS_DRIVERS_GRAPHICS) ; AddDriversToHaikuImage input : ps2_hid usb_hid ; From mmu_man at mail.berlios.de Tue May 15 20:15:27 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Tue, 15 May 2007 20:15:27 +0200 Subject: [Haiku-commits] r21149 - haiku/trunk/src/bin Message-ID: <200705151815.l4FIFRk3015800@sheep.berlios.de> Author: mmu_man Date: 2007-05-15 20:15:26 +0200 (Tue, 15 May 2007) New Revision: 21149 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21149&view=rev Modified: haiku/trunk/src/bin/setdecor.cpp Log: forgot a return there... Modified: haiku/trunk/src/bin/setdecor.cpp =================================================================== --- haiku/trunk/src/bin/setdecor.cpp 2007-05-15 17:58:12 UTC (rev 21148) +++ haiku/trunk/src/bin/setdecor.cpp 2007-05-15 18:15:26 UTC (rev 21149) @@ -63,6 +63,7 @@ return 1; } printf("%s\n", name.String()); + return 0; } // we want to change it int32 i, count; From axeld at mail.berlios.de Tue May 15 23:21:04 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 15 May 2007 23:21:04 +0200 Subject: [Haiku-commits] r21150 - haiku/trunk/src/add-ons/kernel/file_systems/cdda Message-ID: <200705152121.l4FLL4Qc030349@sheep.berlios.de> Author: axeld Date: 2007-05-15 23:21:01 +0200 (Tue, 15 May 2007) New Revision: 21150 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21150&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp Log: * Made the code that reads the table of contents of the CD a bit more failsafe. * Implemented disk scanner to automatically identify the volume. Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp 2007-05-15 18:15:26 UTC (rev 21149) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp 2007-05-15 21:21:01 UTC (rev 21150) @@ -539,6 +539,22 @@ if (status < B_OK) return status; + int32 lastTrack = toc->last_track + 1 - toc->first_track; + size_t dataLength = B_BENDIAN_TO_HOST_INT16(toc->data_length) + 2; + if (dataLength < sizeof(scsi_toc_toc) + || lastTrack <= 0) + return B_BAD_DATA; + + // make sure the values in the TOC make sense + + if (length > dataLength) + length = dataLength; + + length -= sizeof(scsi_toc_general); + + if (lastTrack * sizeof(scsi_toc_track) > length) + toc->last_track = length / sizeof(scsi_toc_track) + toc->first_track; + dump_toc(toc); return B_OK; } Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp 2007-05-15 18:15:26 UTC (rev 21149) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp 2007-05-15 21:21:01 UTC (rev 21150) @@ -64,6 +64,8 @@ Inode *FirstEntry() const { return fFirstEntry; } off_t NumBlocks() const { return fNumBlocks; } + static void DetermineName(cdtext &text, char *name, size_t length); + private: Inode *_CreateNode(Inode *parent, const char *name, off_t start, off_t frames, int32 type); @@ -231,6 +233,19 @@ } +/*static*/ void +Volume::DetermineName(cdtext &text, char *name, size_t length) +{ + if (text.artist != NULL && text.album != NULL) + snprintf(name, length, "%s - %s", text.artist, text.album); + else if (text.artist != NULL || text.album != NULL) { + snprintf(name, length, "%s", text.artist != NULL + ? text.artist : text.album); + } else + strlcpy(name, "Audio CD", length); +} + + status_t Volume::Mount(const char* device) { @@ -309,15 +324,8 @@ free(toc); // determine volume title + DetermineName(text, title, sizeof(title)); - if (text.artist != NULL && text.album != NULL) - snprintf(title, sizeof(title), "%s - %s", text.artist, text.album); - else if (text.artist != NULL || text.album != NULL) { - snprintf(title, sizeof(title), "%s", text.artist != NULL - ? text.artist : text.album); - } else - strcpy(title, "Audio CD"); - fName = strdup(title); if (fName == NULL) return B_NO_MEMORY; @@ -710,10 +718,67 @@ } -// #pragma mark - module API +// #pragma mark - Module API +static float +cdda_identify_partition(int fd, partition_data *partition, void **_cookie) +{ + scsi_toc_toc *toc = (scsi_toc_toc *)malloc(1024); + if (toc == NULL) + return B_NO_MEMORY; + + status_t status = read_table_of_contents(fd, toc, 1024); + if (status < B_OK) { + free(toc); + return status; + } + + *_cookie = toc; + return 0.8f; +} + + static status_t +cdda_scan_partition(int fd, partition_data *partition, void *_cookie) +{ + scsi_toc_toc *toc = (scsi_toc_toc *)_cookie; + + partition->status = B_PARTITION_VALID; + partition->flags |= B_PARTITION_FILE_SYSTEM; + + // compute length + + uint32 lastTrack = toc->last_track + 1 - toc->first_track; + scsi_cd_msf& end = toc->tracks[lastTrack].start.time; + + partition->content_size = off_t(end.minute * kFramesPerMinute + + end.second * kFramesPerSecond + end.frame) * kFrameSize; + partition->block_size = kFrameSize; + + // determine volume title + + cdtext text; + read_cdtext(fd, text); + + char name[256]; + Volume::DetermineName(text, name, sizeof(name)); + partition->content_name = strdup(name); + if (partition->content_name == NULL) + return B_NO_MEMORY; + + return B_OK; +} + + +static void +cdda_free_identify_partition_cookie(partition_data *partition, void *_cookie) +{ + free(_cookie); +} + + +static status_t cdda_mount(mount_id id, const char *device, uint32 flags, const char *args, fs_volume *_volume, vnode_id *_rootVnodeID) { @@ -1373,27 +1438,27 @@ "CDDA File System", - NULL, // identify_partition() - NULL, // scan_partition() - NULL, // free_identify_partition_cookie() + cdda_identify_partition, + cdda_scan_partition, + cdda_free_identify_partition_cookie, NULL, // free_partition_content_cookie() - &cdda_mount, - &cdda_unmount, - &cdda_read_fs_stat, - &cdda_write_fs_stat, - &cdda_sync, + cdda_mount, + cdda_unmount, + cdda_read_fs_stat, + cdda_write_fs_stat, + cdda_sync, - &cdda_lookup, - &cdda_get_vnode_name, + cdda_lookup, + cdda_get_vnode_name, - &cdda_get_vnode, - &cdda_put_vnode, + cdda_get_vnode, + cdda_put_vnode, NULL, // fs_remove_vnode() - &cdda_can_page, - &cdda_read_pages, - &cdda_write_pages, + cdda_can_page, + cdda_read_pages, + cdda_write_pages, NULL, // get_file_map() @@ -1402,54 +1467,54 @@ NULL, // fs_set_flags() NULL, // fs_select() NULL, // fs_deselect() - &cdda_fsync, + cdda_fsync, NULL, // fs_read_link() NULL, // fs_symlink() NULL, // fs_link() NULL, // fs_unlink() - &cdda_rename, + cdda_rename, NULL, // fs_access() - &cdda_read_stat, + cdda_read_stat, NULL, // fs_write_stat() // file NULL, // fs_create() - &cdda_open, - &cdda_close, - &cdda_free_cookie, - &cdda_read, + cdda_open, + cdda_close, + cdda_free_cookie, + cdda_read, NULL, // fs_write() // directory NULL, // fs_create_dir() NULL, // fs_remove_dir() - &cdda_open_dir, - &cdda_close_dir, - &cdda_free_dir_cookie, - &cdda_read_dir, - &cdda_rewind_dir, + cdda_open_dir, + cdda_close_dir, + cdda_free_dir_cookie, + cdda_read_dir, + cdda_rewind_dir, // attribute directory operations - &cdda_open_attr_dir, - &cdda_close_attr_dir, - &cdda_free_attr_dir_cookie, - &cdda_read_attr_dir, - &cdda_rewind_attr_dir, + cdda_open_attr_dir, + cdda_close_attr_dir, + cdda_free_attr_dir_cookie, + cdda_read_attr_dir, + cdda_rewind_attr_dir, // attribute operations - &cdda_create_attr, - &cdda_open_attr, - &cdda_close_attr, - &cdda_free_attr_cookie, - &cdda_read_attr, - &cdda_write_attr, + cdda_create_attr, + cdda_open_attr, + cdda_close_attr, + cdda_free_attr_cookie, + cdda_read_attr, + cdda_write_attr, - &cdda_read_attr_stat, - &cdda_write_attr_stat, + cdda_read_attr_stat, + cdda_write_attr_stat, NULL, // fs_rename_attr() - &cdda_remove_attr, + cdda_remove_attr, // the other operations are not yet supported (indices, queries) NULL, From axeld at mail.berlios.de Wed May 16 11:19:42 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 16 May 2007 11:19:42 +0200 Subject: [Haiku-commits] r21151 - in haiku/trunk/src: add-ons/kernel/file_systems/cdda tests/add-ons/kernel/file_systems/cdda Message-ID: <200705160919.l4G9Jgg7009694@sheep.berlios.de> Author: axeld Date: 2007-05-16 11:19:42 +0200 (Wed, 16 May 2007) New Revision: 21151 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21151&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.h haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/cdda_text.cpp Log: Implemented reading from CD and prepending a fake WAV header - not yet tested, though. Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp 2007-05-15 21:21:01 UTC (rev 21150) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp 2007-05-16 09:19:42 UTC (rev 21151) @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -412,6 +413,46 @@ static status_t +read_frames(int fd, off_t frame, uint8 *buffer, size_t count) +{ + size_t framesLeft = count; + + while (framesLeft > 0) { + scsi_read_cd read; + read.start_m = frame / kFramesPerMinute; + read.start_s = (frame / kFramesPerSecond) % 60; + read.start_f = frame % kFramesPerSecond; + + read.length_m = count / kFramesPerMinute; + read.length_s = (count / kFramesPerSecond) % 60; + read.length_f = count % kFramesPerSecond; + + read.buffer_length = count * kFrameSize; + read.buffer = (char *)buffer; + read.play = false; + + if (ioctl(fd, B_SCSI_READ_CD, &read) < 0) { + // drive couldn't read data - try again to read with a smaller block size + if (count == 1) + return errno; + + if (count >= 32) + count = 8; + else + count = 1; + continue; + } + + buffer += count * kFrameSize; + framesLeft -= count; + frame += count; + } + + return B_OK; +} + + +static status_t read_table_of_contents(int fd, uint32 track, uint8 format, uint8 *buffer, size_t bufferSize) { @@ -559,3 +600,35 @@ return B_OK; } + +status_t +read_cdda_data(int fd, off_t offset, void *data, size_t length, + off_t bufferOffset, void *buffer, size_t bufferSize) +{ + if (bufferOffset >= 0 && bufferOffset <= offset + length + && bufferOffset + bufferSize > offset) { + // TODO: fill request from buffer + } + + while (length > 0) { + off_t frame = offset / kFrameSize; + uint32 count = bufferSize / kFrameSize; + + status_t status = read_frames(fd, frame, (uint8 *)buffer, count); + if (status < B_OK) + return status; + + off_t dataOffset = offset - frame * kFrameSize; + size_t bytes = bufferSize - dataOffset; + if (bytes > length) + bytes = length; + + if (user_memcpy(data, (uint8 *)buffer + dataOffset, bytes) < B_OK) + return B_BAD_ADDRESS; + + length -= bytes; + offset += bytes; + } + + return B_OK; +} Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.h 2007-05-15 21:21:01 UTC (rev 21150) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.h 2007-05-16 09:19:42 UTC (rev 21151) @@ -30,5 +30,7 @@ status_t read_cdtext(int fd, cdtext &text); status_t read_table_of_contents(int fd, scsi_toc_toc *toc, size_t length); +status_t read_cdda_data(int fd, off_t offset, void *data, size_t length, + off_t bufferOffset, void *buffer, size_t bufferSize); #endif // CDDA_H Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp 2007-05-15 21:21:01 UTC (rev 21150) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp 2007-05-16 09:19:42 UTC (rev 21151) @@ -40,6 +40,32 @@ typedef DoublyLinkedList AttributeList; typedef DoublyLinkedList AttrCookieList; +struct riff_header { + uint32 magic; + uint32 length; + uint32 id; +} _PACKED; + +struct riff_chunk { + uint32 fourcc; + uint32 length; +} _PACEKD; + +struct wav_format_chunk : riff_chunk { + uint16 format_tag; + uint16 channels; + uint32 samples_per_second; + uint32 average_bytes_per_second; + uint16 block_align; + uint16 bits_per_sample; +} _PACKED; + +struct wav_header { + riff_header header; + wav_format_chunk format; + riff_chunk data; +} _PACKED; + class Volume { public: Volume(mount_id id); @@ -62,7 +88,10 @@ Inode *Find(const char *name); Inode *FirstEntry() const { return fFirstEntry; } + off_t NumBlocks() const { return fNumBlocks; } + size_t BufferSize() const { return 32 * kFrameSize; } + // TODO: for now static void DetermineName(cdtext &text, char *name, size_t length); @@ -147,6 +176,8 @@ void RemoveAttrCookie(attr_cookie *cookie); void RewindAttrCookie(attr_cookie *cookie); + const wav_header *WAVHeader() const { return &fWAVHeader; } + Inode *Next() const { return fNext; } void SetNext(Inode *inode) { fNext = inode; } @@ -163,6 +194,7 @@ off_t fFrameCount; AttributeList fAttributes; AttrCookieList fAttrCookies; + wav_header fWAVHeader; }; struct dir_cookie { @@ -184,6 +216,8 @@ struct file_cookie { int open_mode; + off_t buffer_offset; + void *buffer; }; @@ -268,6 +302,7 @@ dprintf("CDDA: no CD-Text found.\n"); int32 trackCount = toc->last_track + 1 - toc->first_track; + off_t totalFrames = 0; char title[256]; for (int32 i = 0; i < trackCount; i++) { @@ -302,6 +337,8 @@ title[j] = '-'; } + totalFrames += frames; + Inode *inode = _CreateNode(fRootNode, title, startFrame, frames, S_IFREG | 0444); if (inode == NULL) @@ -330,6 +367,7 @@ if (fName == NULL) return B_NO_MEMORY; + fNumBlocks = totalFrames; return B_OK; } @@ -539,6 +577,32 @@ fGroupID = parent ? parent->GroupID() : getegid(); fCreationTime = fModificationTime = time(NULL); + + if (frames) { + // initialize WAV header + + // RIFF header + fWAVHeader.header.magic = B_HOST_TO_LENDIAN_INT32('RIFF'); + fWAVHeader.header.length = B_HOST_TO_LENDIAN_INT32(Size() + + sizeof(wav_header) - sizeof(riff_chunk)); + fWAVHeader.header.id = B_HOST_TO_LENDIAN_INT32('WAVE'); + + // 'fmt ' format chunk + fWAVHeader.format.fourcc = B_HOST_TO_LENDIAN_INT32('fmt '); + fWAVHeader.format.length = B_HOST_TO_LENDIAN_INT32( + sizeof(wav_format_chunk) - sizeof(riff_chunk)); + fWAVHeader.format.format_tag = B_HOST_TO_LENDIAN_INT16(1); + fWAVHeader.format.channels = B_HOST_TO_LENDIAN_INT16(2); + fWAVHeader.format.samples_per_second = B_HOST_TO_LENDIAN_INT32(44100); + fWAVHeader.format.average_bytes_per_second = B_HOST_TO_LENDIAN_INT32( + 44100 * sizeof(uint16) * 2); + fWAVHeader.format.block_align = B_HOST_TO_LENDIAN_INT16(4); + fWAVHeader.format.bits_per_sample = B_HOST_TO_LENDIAN_INT16(16); + + // 'data' chunk + fWAVHeader.data.fourcc = B_HOST_TO_LENDIAN_INT32('data'); + fWAVHeader.data.length = B_HOST_TO_LENDIAN_INT32(Size()); + } } @@ -943,6 +1007,7 @@ TRACE((" open cookie = %p\n", cookie)); cookie->open_mode = openMode; + cookie->buffer = NULL; *_cookie = (void *)cookie; @@ -981,6 +1046,7 @@ void *buffer, size_t *_length) { file_cookie *cookie = (file_cookie *)_cookie; + Volume *volume = (Volume *)_volume; Inode *inode = (Inode *)_node; TRACE(("cdda_read(vnode = %p, offset %Ld, length = %lu, mode = %d)\n", @@ -990,10 +1056,52 @@ return B_IS_A_DIRECTORY; if ((cookie->open_mode & O_RWMASK) != O_RDONLY) return B_NOT_ALLOWED; + if (offset < 0) + return B_BAD_VALUE; - // TODO: read! - *_length = 0; - return B_OK; + off_t maxSize = inode->Size() + sizeof(wav_header); + if (offset >= maxSize) { + *_length = 0; + return B_OK; + } + + if (cookie->buffer == NULL) { + // TODO: move that to open() to make sure reading can't fail for this reason? + cookie->buffer = malloc(volume->BufferSize()); + if (cookie->buffer == NULL) + return B_NO_MEMORY; + + cookie->buffer_offset = -1; + } + + size_t length = *_length; + if (offset + length > maxSize) + length = maxSize - offset; + + status_t status = B_OK; + + if (offset < sizeof(wav_header)) { + // read fake WAV header + size_t size = sizeof(wav_header) - offset; + size = min_c(size, length); + + if (user_memcpy(buffer, (uint8 *)inode->WAVHeader() + offset, size) < B_OK) + return B_BAD_ADDRESS; + + length -= size; + } + + if (length > 0) { + // read actual CD data + offset -= sizeof(wav_header); + + status = read_cdda_data(volume->Device(), offset, buffer, length, + cookie->buffer_offset, cookie->buffer, volume->BufferSize()); + } + if (status == B_OK) + *_length = length; + + return status; } Modified: haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/cdda_text.cpp =================================================================== --- haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/cdda_text.cpp 2007-05-15 21:21:01 UTC (rev 21150) +++ haiku/trunk/src/tests/add-ons/kernel/file_systems/cdda/cdda_text.cpp 2007-05-16 09:19:42 UTC (rev 21151) @@ -16,6 +16,14 @@ extern const char* __progname; +extern "C" status_t +user_memcpy(void *dest, const void *source, size_t length) +{ + memcpy(dest, source, length); + return B_OK; +} + + extern "C" void dprintf(const char* format, ...) { From axeld at mail.berlios.de Wed May 16 12:07:22 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 16 May 2007 12:07:22 +0200 Subject: [Haiku-commits] r21152 - haiku/trunk/src/kits/storage/mime Message-ID: <200705161007.l4GA7MEk014089@sheep.berlios.de> Author: axeld Date: 2007-05-16 12:07:21 +0200 (Wed, 16 May 2007) New Revision: 21152 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21152&view=rev Modified: haiku/trunk/src/kits/storage/mime/database_access.cpp Log: * All functions returning a message will now return an empty message in case there is none yet, instead of returning an error. * Cleanup. Modified: haiku/trunk/src/kits/storage/mime/database_access.cpp =================================================================== --- haiku/trunk/src/kits/storage/mime/database_access.cpp 2007-05-16 09:19:42 UTC (rev 21151) +++ haiku/trunk/src/kits/storage/mime/database_access.cpp 2007-05-16 10:07:21 UTC (rev 21152) @@ -1,7 +1,12 @@ -//---------------------------------------------------------------------- -// This software is part of the OpenBeOS distribution and is covered -// by the OpenBeOS license. -//--------------------------------------------------------------------- +/* + * Copyright 2002-2007, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Tyler Dauwalder + */ + + /*! \file database_access.cpp Mime database atomic read functions @@ -35,13 +40,10 @@ namespace Storage { namespace Mime { -//------------------------------------------------------------------------------ -// Functions -//------------------------------------------------------------------------------ -// get_app_hint -//! Fetches the application hint for the given MIME type. -/*! The entry_ref pointed to by \c ref must be pre-allocated. +/*! \brief Fetches the application hint for the given MIME type. + + The entry_ref pointed to by \c ref must be pre-allocated. \param type The MIME type of interest \param ref Pointer to a pre-allocated \c entry_ref struct into @@ -71,7 +73,7 @@ return status; } -// get_attr_info + /*! \brief Fetches from the MIME database a BMessage describing the attributes typically associated with files of the given MIME type @@ -90,19 +92,26 @@ get_attr_info(const char *type, BMessage *info) { status_t err = read_mime_attr_message(type, kAttrInfoAttr, info); - if (!err) { - info->what = 233; // Don't know why, but that's what R5 does. + if (err == B_ENTRY_NOT_FOUND) { + // return an empty message + info->MakeEmpty(); + err = B_OK; + } + if (err == B_OK) { + info->what = 233; + // Don't know why, but that's what R5 does. err = info->AddString("type", type); } return err; } -// get_short_description -//! Fetches the short description for the given MIME type. -/*! The string pointed to by \c description must be long enough to + +/*! \brief Fetches the short description for the given MIME type. + + The string pointed to by \c description must be long enough to hold the short description; a length of \c B_MIME_TYPE_LENGTH is recommended. - + \param type The MIME type of interest \param description Pointer to a pre-allocated string into which the short description is copied. If the function fails, the contents @@ -117,7 +126,8 @@ get_short_description(const char *type, char *description) { /// DBG(OUT("Mime::Database::get_short_description()\n")); - ssize_t err = read_mime_attr(type, kShortDescriptionAttr, description, B_MIME_TYPE_LENGTH, kShortDescriptionType); + ssize_t err = read_mime_attr(type, kShortDescriptionAttr, description, + B_MIME_TYPE_LENGTH, kShortDescriptionType); return err >= 0 ? B_OK : err ; } @@ -141,17 +151,20 @@ get_long_description(const char *type, char *description) { // DBG(OUT("Mime::Database::get_long_description()\n")); - ssize_t err = read_mime_attr(type, kLongDescriptionAttr, description, B_MIME_TYPE_LENGTH, kLongDescriptionType); + ssize_t err = read_mime_attr(type, kLongDescriptionAttr, description, + B_MIME_TYPE_LENGTH, kLongDescriptionType); return err >= 0 ? B_OK : err ; } -// get_file_extensions -//! Fetches a BMessage describing the MIME type's associated filename extensions -/*! The list of extensions is returned in a pre-allocated BMessage pointed to by - the \c extensions parameter (note that the any prior contents of the message - will be destroyed). Please see BMimeType::GetFileExtensions() for a description - of the message format. - + +/*! \brief Fetches a BMessage describing the MIME type's associated filename + extensions + + The list of extensions is returned in a pre-allocated BMessage pointed to + by the \c extensions parameter (note that the any prior contents of the + message will be destroyed). Please see BMimeType::GetFileExtensions() for + a description of the message format. + \param extensions Pointer to a pre-allocated BMessage into which the MIME type's associated file extensions will be stored. \return @@ -162,16 +175,22 @@ get_file_extensions(const char *type, BMessage *extensions) { status_t err = read_mime_attr_message(type, kFileExtensionsAttr, extensions); - if (!err) { + if (err == B_ENTRY_NOT_FOUND) { + // return an empty message + extensions->MakeEmpty(); + err = B_OK; + } + if (err == B_OK) { extensions->what = 234; // Don't know why, but that's what R5 does. err = extensions->AddString("type", type); } return err; } -// get_icon -//! Fetches the icon of given size associated with the given MIME type -/*! The bitmap pointed to by \c icon must be of the proper size (\c 32x32 + +/*! \brief Fetches the icon of given size associated with the given MIME type + + The bitmap pointed to by \c icon must be of the proper size (\c 32x32 for \c B_LARGE_ICON, \c 16x16 for \c B_MINI_ICON) and color depth (\c B_CMAP8). @@ -224,7 +243,7 @@ */ status_t get_icon_for_type(const char* type, const char* fileType, BBitmap* icon, - icon_size which) + icon_size which) { if (!type || !icon) return B_BAD_VALUE; @@ -412,18 +431,20 @@ return err; } -// get_preferred_app -//! Fetches signature of the MIME type's preferred application for the given action. -/*! The string pointed to by \c signature must be long enough to + +/*! \brief Fetches signature of the MIME type's preferred application for the + given action. + + The string pointed to by \c signature must be long enough to hold the short description; a length of \c B_MIME_TYPE_LENGTH is recommended. Currently, the only supported app verb is \c B_OPEN. \param type The MIME type of interest - \param description Pointer to a pre-allocated string into which the preferred - application's signature is copied. If the function fails, the - contents of the string are undefined. + \param description Pointer to a pre-allocated string into which the + preferred application's signature is copied. If the function fails, + the contents of the string are undefined. \param verb \c The action of interest \return @@ -435,11 +456,12 @@ get_preferred_app(const char *type, char *signature, app_verb verb = B_OPEN) { // Since B_OPEN is the currently the only app_verb, it is essentially ignored - ssize_t err = read_mime_attr(type, kPreferredAppAttr, signature, B_MIME_TYPE_LENGTH, kPreferredAppType); + ssize_t err = read_mime_attr(type, kPreferredAppAttr, signature, + B_MIME_TYPE_LENGTH, kPreferredAppType); return err >= 0 ? B_OK : err ; } -// get_sniffer_rule + /*! \brief Fetches the sniffer rule for the given MIME type. \param type The MIME type of interest \param result Pointer to a pre-allocated BString into which the type's @@ -455,19 +477,24 @@ return read_mime_attr_string(type, kSnifferRuleAttr, result); } -// get_supported_types + status_t get_supported_types(const char *type, BMessage *types) { status_t err = read_mime_attr_message(type, kSupportedTypesAttr, types); - if (!err) { + if (err == B_ENTRY_NOT_FOUND) { + // return an empty message + types->MakeEmpty(); + err = B_OK; + } + if (err == B_OK) { types->what = 0; err = types->AddString("type", type); } return err; } -// is_installed + //! Checks if the given MIME type is present in the database bool is_installed(const char *type) @@ -476,22 +503,25 @@ return open_type(type, &node) == B_OK; } -// get_icon_data -/*! \brief Returns properly formatted raw bitmap data, ready to be shipped off to the hacked - up 4-parameter version of Database::SetIcon() - - This function exists as something of a hack until an OBOS::BBitmap implementation is - available. It takes the given bitmap, converts it to the B_CMAP8 color space if necessary - and able, and returns said bitmap data in a newly allocated array pointed to by the - pointer that's pointed to by \c data. The length of the array is stored in the integer - pointed to by \c dataSize. The array is allocated with \c new[], and it's your responsibility - to \c delete[] it when you're finished. - + +/*! \brief Returns properly formatted raw bitmap data, ready to be shipped off + to the hacked up 4-parameter version of Database::SetIcon() + + This function exists as something of a hack until an OBOS::BBitmap + implementation is available. It takes the given bitmap, converts it to the + B_CMAP8 color space if necessary and able, and returns said bitmap data in + a newly allocated array pointed to by the pointer that's pointed to by + \c data. The length of the array is stored in the integer pointed to by + \c dataSize. The array is allocated with \c new[], and it's your + responsibility to \c delete[] it when you're finished. */ status_t -get_icon_data(const BBitmap *icon, icon_size which, void **data, int32 *dataSize) +get_icon_data(const BBitmap *icon, icon_size which, void **data, + int32 *dataSize) { - ssize_t err = (icon && data && dataSize && icon->InitCheck() == B_OK) ? B_OK : B_BAD_VALUE; + if (icon == NULL || data == NULL || dataSize == 0 + || icon->InitCheck() != B_OK) + return B_BAD_VALUE; BRect bounds; BBitmap *icon8 = NULL; @@ -499,22 +529,20 @@ bool otherColorSpace = false; // Figure out what kind of data we *should* have - if (!err) { - switch (which) { - case B_MINI_ICON: - bounds.Set(0, 0, 15, 15); - break; - case B_LARGE_ICON: - bounds.Set(0, 0, 31, 31); - break; - default: - err = B_BAD_VALUE; - break; - } + switch (which) { + case B_MINI_ICON: + bounds.Set(0, 0, 15, 15); + break; + case B_LARGE_ICON: + bounds.Set(0, 0, 31, 31); + break; + default: + return B_BAD_VALUE; } + // Check the icon - if (!err) - err = (icon->Bounds() == bounds) ? B_OK : B_BAD_VALUE; + status_t err = icon->Bounds() == bounds ? B_OK : B_BAD_VALUE; + // Convert to B_CMAP8 if necessary if (!err) { otherColorSpace = (icon->ColorSpace() != B_CMAP8); @@ -534,12 +562,14 @@ *dataSize = icon->BitsLength(); } } + // Alloc a new data buffer if (!err) { *data = new(std::nothrow) char[*dataSize]; if (!*data) err = B_NO_MEMORY; } + // Copy the data into it. if (!err) memcpy(*data, srcData, *dataSize); From stefano.ceccherini at gmail.com Wed May 16 12:10:57 2007 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Wed, 16 May 2007 12:10:57 +0200 Subject: [Haiku-commits] r21152 - haiku/trunk/src/kits/storage/mime In-Reply-To: <200705161007.l4GA7MEk014089@sheep.berlios.de> References: <200705161007.l4GA7MEk014089@sheep.berlios.de> Message-ID: <894b9700705160310p2870dee0jed29f043ea05a6a7@mail.gmail.com> 2007/5/16, axeld at BerliOS : > > + This function exists as something of a hack until an OBOS::BBitmap > + implementation is available. I think we DO have this implementation in place now, no ? :) From axeld at pinc-software.de Wed May 16 12:50:07 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Wed, 16 May 2007 12:50:07 +0200 CEST Subject: [Haiku-commits] r21152 - haiku/trunk/src/kits/storage/mime In-Reply-To: <894b9700705160310p2870dee0jed29f043ea05a6a7@mail.gmail.com> Message-ID: <12605076661-BeMail@zon> "Stefano Ceccherini" wrote: > 2007/5/16, axeld at BerliOS : > > + This function exists as something of a hack until an > > OBOS::BBitmap > > + implementation is available. > I think we DO have this implementation in place now, no ? :) AFAICT it's already using it, even :-) Still, I just reformatted it, I didn't even read it when I made the changes :) Anyway, I'm not sure this function is needed as is or not, maybe someone may want to have a look at it some day. Bye, Axel. From axeld at mail.berlios.de Wed May 16 17:09:46 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 16 May 2007 17:09:46 +0200 Subject: [Haiku-commits] r21153 - haiku/trunk/src/add-ons/kernel/file_systems/cdda Message-ID: <200705161509.l4GF9kkZ019274@sheep.berlios.de> Author: axeld Date: 2007-05-16 17:09:45 +0200 (Wed, 16 May 2007) New Revision: 21153 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21153&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp Log: * The WAV header is now created correctly (mixed up endian of the fourcc members) * More or less fixed reading - it now works nicely when you copy the file to the hard drive first, but MediaPlayer cannot handle the files directly from CD for some reason yet to investigate. Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp 2007-05-16 10:07:21 UTC (rev 21152) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/cdda.cpp 2007-05-16 15:09:45 UTC (rev 21153) @@ -413,15 +413,15 @@ static status_t -read_frames(int fd, off_t frame, uint8 *buffer, size_t count) +read_frames(int fd, off_t firstFrame, uint8 *buffer, size_t count) { size_t framesLeft = count; while (framesLeft > 0) { scsi_read_cd read; - read.start_m = frame / kFramesPerMinute; - read.start_s = (frame / kFramesPerSecond) % 60; - read.start_f = frame % kFramesPerSecond; + read.start_m = firstFrame / kFramesPerMinute; + read.start_s = (firstFrame / kFramesPerSecond) % 60; + read.start_f = firstFrame % kFramesPerSecond; read.length_m = count / kFramesPerMinute; read.length_s = (count / kFramesPerSecond) % 60; @@ -445,7 +445,7 @@ buffer += count * kFrameSize; framesLeft -= count; - frame += count; + firstFrame += count; } return B_OK; @@ -618,7 +618,7 @@ if (status < B_OK) return status; - off_t dataOffset = offset - frame * kFrameSize; + off_t dataOffset = offset % kFrameSize; size_t bytes = bufferSize - dataOffset; if (bytes > length) bytes = length; @@ -626,6 +626,7 @@ if (user_memcpy(data, (uint8 *)buffer + dataOffset, bytes) < B_OK) return B_BAD_ADDRESS; + data = (void *)((uint8 *)data + bytes); length -= bytes; offset += bytes; } Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp 2007-05-16 10:07:21 UTC (rev 21152) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp 2007-05-16 15:09:45 UTC (rev 21153) @@ -317,11 +317,8 @@ + next.second * kFramesPerSecond + next.frame - startFrame; - const char *artist = text.artists[i] != NULL - ? text.artists[i] : text.artist; - if (text.titles[i] != NULL) { - if (artist != NULL) { + if (text.artists[i] != NULL) { snprintf(title, sizeof(title), "%02ld. %s - %s.wav", track, text.artists[i], text.titles[i]); } else { @@ -346,7 +343,8 @@ // add attributes - inode->AddAttribute("Audio:Artist", B_STRING_TYPE, artist); + inode->AddAttribute("Audio:Artist", B_STRING_TYPE, + text.artists[i] != NULL ? text.artists[i] : text.artist); inode->AddAttribute("Audio:Title", B_STRING_TYPE, text.titles[i]); inode->AddAttribute("Audio:Genre", B_STRING_TYPE, text.genre); inode->AddAttribute("Audio:Track", track); @@ -582,13 +580,13 @@ // initialize WAV header // RIFF header - fWAVHeader.header.magic = B_HOST_TO_LENDIAN_INT32('RIFF'); + fWAVHeader.header.magic = B_HOST_TO_BENDIAN_INT32('RIFF'); fWAVHeader.header.length = B_HOST_TO_LENDIAN_INT32(Size() + sizeof(wav_header) - sizeof(riff_chunk)); - fWAVHeader.header.id = B_HOST_TO_LENDIAN_INT32('WAVE'); + fWAVHeader.header.id = B_HOST_TO_BENDIAN_INT32('WAVE'); // 'fmt ' format chunk - fWAVHeader.format.fourcc = B_HOST_TO_LENDIAN_INT32('fmt '); + fWAVHeader.format.fourcc = B_HOST_TO_BENDIAN_INT32('fmt '); fWAVHeader.format.length = B_HOST_TO_LENDIAN_INT32( sizeof(wav_format_chunk) - sizeof(riff_chunk)); fWAVHeader.format.format_tag = B_HOST_TO_LENDIAN_INT16(1); @@ -600,7 +598,7 @@ fWAVHeader.format.bits_per_sample = B_HOST_TO_LENDIAN_INT16(16); // 'data' chunk - fWAVHeader.data.fourcc = B_HOST_TO_LENDIAN_INT32('data'); + fWAVHeader.data.fourcc = B_HOST_TO_BENDIAN_INT32('data'); fWAVHeader.data.length = B_HOST_TO_LENDIAN_INT32(Size()); } } @@ -1054,8 +1052,6 @@ if (S_ISDIR(inode->Type())) return B_IS_A_DIRECTORY; - if ((cookie->open_mode & O_RWMASK) != O_RDONLY) - return B_NOT_ALLOWED; if (offset < 0) return B_BAD_VALUE; @@ -1088,12 +1084,15 @@ if (user_memcpy(buffer, (uint8 *)inode->WAVHeader() + offset, size) < B_OK) return B_BAD_ADDRESS; + buffer = (void *)((uint8 *)buffer + size); length -= size; - } + offset = 0; + } else + offset -= sizeof(wav_header); if (length > 0) { // read actual CD data - offset -= sizeof(wav_header); + offset += inode->StartFrame() * kFrameSize; status = read_cdda_data(volume->Device(), offset, buffer, length, cookie->buffer_offset, cookie->buffer, volume->BufferSize()); From axeld at mail.berlios.de Wed May 16 17:22:24 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 16 May 2007 17:22:24 +0200 Subject: [Haiku-commits] r21154 - in haiku/trunk: headers/private/kernel/arch/x86 src/apps/powerstatus src/system/kernel/arch/x86 Message-ID: <200705161522.l4GFMOhF021317@sheep.berlios.de> Author: axeld Date: 2007-05-16 17:22:23 +0200 (Wed, 16 May 2007) New Revision: 21154 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21154&view=rev Modified: haiku/trunk/headers/private/kernel/arch/x86/apm.h haiku/trunk/src/apps/powerstatus/Jamfile haiku/trunk/src/apps/powerstatus/PowerStatusView.cpp haiku/trunk/src/system/kernel/arch/x86/apm.cpp Log: * Implemented APM generic syscall API to query the current power status. * PowerStatus is now using this API when compiled for Haiku. * Note, I'm not sure why yet, but running PowerStatus in the background crashes at least my laptop after some time. Modified: haiku/trunk/headers/private/kernel/arch/x86/apm.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/x86/apm.h 2007-05-16 15:09:45 UTC (rev 21153) +++ haiku/trunk/headers/private/kernel/arch/x86/apm.h 2007-05-16 15:22:23 UTC (rev 21154) @@ -47,6 +47,17 @@ } apm_info; +// temporary generic syscall interface +#define APM_SYSCALLS "apm" +#define APM_GET_BATTERY_INFO 1 + +struct battery_info { + bool online; + int32 percent; + time_t time_left; +}; + + #ifndef _BOOT_MODE #ifdef __cplusplus extern "C" { Modified: haiku/trunk/src/apps/powerstatus/Jamfile =================================================================== --- haiku/trunk/src/apps/powerstatus/Jamfile 2007-05-16 15:09:45 UTC (rev 21153) +++ haiku/trunk/src/apps/powerstatus/Jamfile 2007-05-16 15:22:23 UTC (rev 21154) @@ -3,6 +3,7 @@ SetSubDirSupportedPlatformsBeOSCompatible ; UsePrivateHeaders shared ; +UseHeaders $(TARGET_PRIVATE_KERNEL_HEADERS) : true ; Application PowerStatus : PowerStatusWindow.cpp Modified: haiku/trunk/src/apps/powerstatus/PowerStatusView.cpp =================================================================== --- haiku/trunk/src/apps/powerstatus/PowerStatusView.cpp 2007-05-16 15:09:45 UTC (rev 21153) +++ haiku/trunk/src/apps/powerstatus/PowerStatusView.cpp 2007-05-16 15:22:23 UTC (rev 21154) @@ -10,6 +10,11 @@ #include "PowerStatusView.h" #include "PowerStatus.h" +#include +#include +#include + // temporary, as long as there is no real power state API + #include #include #include @@ -110,7 +115,19 @@ fTimeLeft = 0; #ifdef HAIKU_TARGET_PLATFORM_HAIKU - // TODO: implement me + uint32 version = 0; + status_t status = _kern_generic_syscall(APM_SYSCALLS, B_SYSCALL_INFO, + &version, sizeof(version)); + if (status == B_OK) { + battery_info info; + status = _kern_generic_syscall(APM_SYSCALLS, APM_GET_BATTERY_INFO, &info, + sizeof(battery_info)); + } + + if (status != B_OK) { + fprintf(stderr, "No power interface found.\n"); + _Quit(); + } #else fDevice = open("/dev/misc/apm", O_RDONLY); if (fDevice < 0) { @@ -422,9 +439,14 @@ #ifdef HAIKU_TARGET_PLATFORM_HAIKU // TODO: retrieve data from APM/ACPI kernel interface - fPercent = 42; - fTimeLeft = 1500; - fOnline = true; + battery_info info; + status_t status = _kern_generic_syscall(APM_SYSCALLS, APM_GET_BATTERY_INFO, &info, + sizeof(battery_info)); + if (status == B_OK) { + fPercent = info.percent; + fTimeLeft = info.time_left; + fOnline = info.online; + } #else if (fDevice < 0) return; Modified: haiku/trunk/src/system/kernel/arch/x86/apm.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/apm.cpp 2007-05-16 15:09:45 UTC (rev 21153) +++ haiku/trunk/src/system/kernel/arch/x86/apm.cpp 2007-05-16 15:22:23 UTC (rev 21154) @@ -1,5 +1,5 @@ /* - * Copyright 2006, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Copyright 2006-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -196,6 +197,56 @@ } +static status_t +get_battery_info(battery_info *info) +{ + bios_regs regs; + regs.eax = BIOS_APM_GET_POWER_STATUS; + regs.ebx = APM_ALL_DEVICES; + regs.ecx = 0; + + status_t status = call_apm_bios(®s); + if (status != B_OK) + return status; + + uint16 lineStatus = (regs.ebx >> 8) & 0xff; + if (lineStatus == 0xff) + return B_NOT_SUPPORTED; + + info->online = lineStatus != 0 && lineStatus != 2; + info->percent = regs.ecx & 0xff; + if (info->percent > 100 || info->percent < 0) + info->percent = -1; + + info->time_left = info->percent >= 0 ? (int32)(regs.edx & 0xffff) : -1; + if (info->time_left & 0x8000) + info->time_left = (info->time_left & 0x7fff) * 60; + + return B_OK; +} + + +static status_t +apm_control(const char *subsystem, uint32 function, + void *buffer, size_t bufferSize) +{ + struct battery_info info; + if (bufferSize != sizeof(struct battery_info)) + return B_BAD_VALUE; + + switch (function) { + case APM_GET_BATTERY_INFO: + status_t status = get_battery_info(&info); + if (status < B_OK) + return status; + + return user_memcpy(buffer, &info, sizeof(struct battery_info)); + } + + return B_BAD_VALUE; +} + + // #pragma mark - @@ -304,6 +355,7 @@ register_kernel_daemon(apm_daemon, NULL, 10); // run the daemon once every second + register_generic_syscall(APM_SYSCALLS, apm_control, 1, 0); sAPMEnabled = true; return B_OK; } From axeld at mail.berlios.de Wed May 16 17:50:04 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 16 May 2007 17:50:04 +0200 Subject: [Haiku-commits] r21155 - haiku/trunk/src/kits/interface Message-ID: <200705161550.l4GFo4mh024303@sheep.berlios.de> Author: axeld Date: 2007-05-16 17:50:04 +0200 (Wed, 16 May 2007) New Revision: 21155 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21155&view=rev Modified: haiku/trunk/src/kits/interface/CheckBox.cpp Log: Minor cleanup. Modified: haiku/trunk/src/kits/interface/CheckBox.cpp =================================================================== --- haiku/trunk/src/kits/interface/CheckBox.cpp 2007-05-16 15:22:23 UTC (rev 21154) +++ haiku/trunk/src/kits/interface/CheckBox.cpp 2007-05-16 15:50:04 UTC (rev 21155) @@ -1,5 +1,5 @@ /* - * Copyright 2001-2006, Haiku Inc. + * Copyright 2001-2007, Haiku Inc. * Distributed under the terms of the MIT License. * * Authors: @@ -14,14 +14,15 @@ BCheckBox::BCheckBox(BRect frame, const char *name, const char *label, - BMessage *message, uint32 resizingMode, uint32 flags) + BMessage *message, uint32 resizingMode, uint32 flags) : BControl(frame, name, label, message, resizingMode, flags), fOutlined(false) { // Resize to minimum height if needed font_height fontHeight; GetFontHeight(&fontHeight); - float minHeight = (float)ceil(6.0f + fontHeight.ascent + fontHeight.descent); + float minHeight = (float)ceil(6.0f + fontHeight.ascent + + fontHeight.descent); if (Bounds().Height() < minHeight) ResizeTo(Bounds().Width(), minHeight); } @@ -52,7 +53,7 @@ status_t BCheckBox::Archive(BMessage *archive, bool deep) const { - return BControl::Archive(archive,deep); + return BControl::Archive(archive, deep); } @@ -73,24 +74,23 @@ SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); StrokeLine(BPoint(x, y), BPoint(x + StringWidth(Label()), y)); - return; } - rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR), - lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT), - lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT), - darken1 = tint_color(no_tint, B_DARKEN_1_TINT), - darken2 = tint_color(no_tint, B_DARKEN_2_TINT), - darken3 = tint_color(no_tint, B_DARKEN_3_TINT), - darken4 = tint_color(no_tint, B_DARKEN_4_TINT), - darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); + rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR); + rgb_color lighten1 = tint_color(noTint, B_LIGHTEN_1_TINT); + rgb_color lightenMax = tint_color(noTint, B_LIGHTEN_MAX_TINT); + rgb_color darken1 = tint_color(noTint, B_DARKEN_1_TINT); + rgb_color darken2 = tint_color(noTint, B_DARKEN_2_TINT); + rgb_color darken3 = tint_color(noTint, B_DARKEN_3_TINT); + rgb_color darken4 = tint_color(noTint, B_DARKEN_4_TINT); + rgb_color darkenmax = tint_color(noTint, B_DARKEN_MAX_TINT); BRect rect = _CheckBoxFrame(); if (IsEnabled()) { // Filling - SetHighColor(lightenmax); + SetHighColor(lightenMax); FillRect(rect); // Box @@ -98,7 +98,7 @@ SetHighColor(darken3); StrokeRect(rect); - rect.InsetBy(1,1); + rect.InsetBy(1, 1); BeginLineArray(6); @@ -119,33 +119,33 @@ BPoint(rect.left, rect.top), darken1); AddLine(BPoint(rect.left, rect.top), BPoint(rect.right, rect.top), darken1); - rect.InsetBy(1,1); + rect.InsetBy(1, 1); AddLine(BPoint(rect.left, rect.bottom), BPoint(rect.left, rect.top), darken4); AddLine(BPoint(rect.left, rect.top), BPoint(rect.right, rect.top), darken4); AddLine(BPoint(rect.left + 1.0f, rect.bottom), - BPoint(rect.right, rect.bottom), no_tint); + BPoint(rect.right, rect.bottom), noTint); AddLine(BPoint(rect.right, rect.bottom), - BPoint(rect.right, rect.top + 1.0f), no_tint); + BPoint(rect.right, rect.top + 1.0f), noTint); EndLineArray(); } // Checkmark if (Value() == B_CONTROL_ON) { - rect.InsetBy(2,2); + rect.InsetBy(2, 2); SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); SetPenSize(2); -// Yes, Haiku is differnt because of the anti-aliasing -SetDrawingMode(B_OP_OVER); + SetDrawingMode(B_OP_OVER); + // needed because of anti-aliasing StrokeLine(BPoint(rect.left, rect.top), BPoint(rect.right, rect.bottom)); StrokeLine(BPoint(rect.left, rect.bottom), BPoint(rect.right, rect.top)); SetPenSize(1); -SetDrawingMode(B_OP_COPY); + SetDrawingMode(B_OP_COPY); } // Label @@ -170,10 +170,10 @@ BeginLineArray(6); AddLine(BPoint(rect.left, rect.bottom), - BPoint(rect.left, rect.top), no_tint); + BPoint(rect.left, rect.top), noTint); AddLine(BPoint(rect.left, rect.top), - BPoint(rect.right, rect.top), no_tint); - rect.InsetBy(1,1); + BPoint(rect.right, rect.top), noTint); + rect.InsetBy(1, 1); AddLine(BPoint(rect.left, rect.bottom), BPoint(rect.left, rect.top), darken2); AddLine(BPoint(rect.left, rect.top), @@ -192,18 +192,18 @@ SetHighColor(tint_color(ui_color(B_KEYBOARD_NAVIGATION_COLOR), B_DISABLED_MARK_TINT)); SetPenSize(2); -// Yes, Haiku is differnt because of the anti-aliasing -SetDrawingMode(B_OP_OVER); + SetDrawingMode(B_OP_OVER); + // needed because of anti-aliasing StrokeLine(BPoint(rect.left, rect.top), BPoint(rect.right, rect.bottom)); StrokeLine(BPoint(rect.left, rect.bottom), BPoint(rect.right, rect.top)); SetPenSize(1); -SetDrawingMode(B_OP_COPY); + SetDrawingMode(B_OP_COPY); } // Label - SetHighColor(tint_color(no_tint, B_DISABLED_LABEL_TINT)); + SetHighColor(tint_color(noTint, B_DISABLED_LABEL_TINT)); DrawString(Label(), BPoint((float)ceil(10.0f + fontHeight.ascent), 3.0f + (float)ceil(fontHeight.ascent))); } @@ -242,7 +242,6 @@ GetMouse(&point, &buttons, true); bool inside = bounds.Contains(point); - if (fOutlined != inside) { fOutlined = inside; Invalidate(); @@ -309,8 +308,7 @@ void -BCheckBox::MouseMoved(BPoint point, uint32 transit, - const BMessage *message) +BCheckBox::MouseMoved(BPoint point, uint32 transit, const BMessage *message) { if (!IsTracking()) return; @@ -396,7 +394,8 @@ BCheckBox::ResolveSpecifier(BMessage *message, int32 index, BMessage *specifier, int32 what, const char *property) { - return BControl::ResolveSpecifier(message, index, specifier, what, property); + return BControl::ResolveSpecifier(message, index, specifier, what, + property); } @@ -446,12 +445,13 @@ return *this; } -// _CheckBoxFrame + BRect BCheckBox::_CheckBoxFrame() const { - font_height fh; - GetFontHeight(&fh); + font_height fontHeight; + GetFontHeight(&fontHeight); - return BRect(1.0f, 3.0f, ceilf(3.0f + fh.ascent), ceilf(5.0f + fh.ascent)); + return BRect(1.0f, 3.0f, ceilf(3.0f + fontHeight.ascent), + ceilf(5.0f + fontHeight.ascent)); } From axeld at mail.berlios.de Wed May 16 18:34:16 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 16 May 2007 18:34:16 +0200 Subject: [Haiku-commits] r21156 - in haiku/trunk/src: add-ons/print/drivers/shared/libprint apps/cortex/RouteApp apps/deskbar apps/deskcalc apps/expander apps/mail apps/mediaplayer apps/networkstatus apps/people apps/poorman apps/processcontroller apps/pulse apps/stylededit apps/terminal apps/terminal/andrew apps/tv kits/interface preferences/datatranslations preferences/devices preferences/dun preferences/menu preferences/network Message-ID: <200705161634.l4GGYGcG001885@sheep.berlios.de> Author: axeld Date: 2007-05-16 18:34:09 +0200 (Wed, 16 May 2007) New Revision: 21156 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21156&view=rev Modified: haiku/trunk/src/add-ons/print/drivers/shared/libprint/JobSetupDlg.cpp haiku/trunk/src/apps/cortex/RouteApp/RouteWindow.cpp haiku/trunk/src/apps/deskbar/BeMenu.cpp haiku/trunk/src/apps/deskbar/StatusView.cpp haiku/trunk/src/apps/deskcalc/CalcView.cpp haiku/trunk/src/apps/expander/ExpanderWindow.cpp haiku/trunk/src/apps/mail/Mail.cpp haiku/trunk/src/apps/mediaplayer/MainWin.cpp haiku/trunk/src/apps/networkstatus/NetworkStatusView.cpp haiku/trunk/src/apps/people/PeopleWindow.cpp haiku/trunk/src/apps/poorman/constants.cpp haiku/trunk/src/apps/processcontroller/ProcessController.cpp haiku/trunk/src/apps/pulse/PulseView.cpp haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp haiku/trunk/src/apps/terminal/PrefWindow.cpp haiku/trunk/src/apps/terminal/TermWindow.cpp haiku/trunk/src/apps/terminal/andrew/TerminalWindow.cpp haiku/trunk/src/apps/tv/MainWin.cpp haiku/trunk/src/kits/interface/Dragger.cpp haiku/trunk/src/preferences/datatranslations/DataTranslationsWindow.cpp haiku/trunk/src/preferences/devices/DevicesWindow.cpp haiku/trunk/src/preferences/dun/DUNWindow.cpp haiku/trunk/src/preferences/dun/DetailsView.cpp haiku/trunk/src/preferences/dun/ModemWindow.cpp haiku/trunk/src/preferences/dun/SettingsWindow.cpp haiku/trunk/src/preferences/menu/MenuBar.cpp haiku/trunk/src/preferences/network/NetworkWindow.cpp Log: * Applied patch by Jonas Sundstrom: fixed the usage of B_UTF8_ELLIPSIS hopefully everywhere in the tree. * Added the ellipsis to "About Haiku" in Deskbar as well. * Minor cleanup of Deskbar's StatusView.cpp Modified: haiku/trunk/src/add-ons/print/drivers/shared/libprint/JobSetupDlg.cpp =================================================================== --- haiku/trunk/src/add-ons/print/drivers/shared/libprint/JobSetupDlg.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/add-ons/print/drivers/shared/libprint/JobSetupDlg.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -718,7 +718,7 @@ /* preview */ - button = new BButton(preview_rect, "preview", "Preview ...", new BMessage(kMsgPreview)); + button = new BButton(preview_rect, "preview", "Preview" B_UTF8_ELLIPSIS, new BMessage(kMsgPreview)); AddChild(button); Modified: haiku/trunk/src/apps/cortex/RouteApp/RouteWindow.cpp =================================================================== --- haiku/trunk/src/apps/cortex/RouteApp/RouteWindow.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/apps/cortex/RouteApp/RouteWindow.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -74,20 +74,20 @@ BMenuBar* pMenuBar = new BMenuBar(b, "menuBar"); BMenu* pFileMenu = new BMenu("File"); BMenuItem* item = new BMenuItem( - "Open...", + "Open" B_UTF8_ELLIPSIS, new BMessage(RouteApp::M_SHOW_OPEN_PANEL), 'O'); item->SetTarget(be_app); pFileMenu->AddItem(item); pFileMenu->AddItem(new BSeparatorItem()); item = new BMenuItem( - "Save Nodes...", + "Save Nodes" B_UTF8_ELLIPSIS, new BMessage(RouteApp::M_SHOW_SAVE_PANEL), 'S'); item->SetTarget(be_app); pFileMenu->AddItem(item); pFileMenu->AddItem(new BSeparatorItem()); - pFileMenu->AddItem(new BMenuItem("About Cortex/Route...", + pFileMenu->AddItem(new BMenuItem("About Cortex/Route" B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED))); pFileMenu->AddItem(new BSeparatorItem()); pFileMenu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED))); Modified: haiku/trunk/src/apps/deskbar/BeMenu.cpp =================================================================== --- haiku/trunk/src/apps/deskbar/BeMenu.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/apps/deskbar/BeMenu.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -232,11 +232,13 @@ if (fBarView) dragging = fBarView->Dragging(); + BMenuItem* item = new BMenuItem( #ifdef __HAIKU__ - BMenuItem* item = new BMenuItem("About Haiku", new BMessage(kShowSplash)); + "About Haiku" #else - BMenuItem* item = new BMenuItem("About BeOS", new BMessage(kShowSplash)); + "About BeOS" #endif + B_UTF8_ELLIPSIS, new BMessage(kShowSplash)); item->SetEnabled(!dragging); AddItem(item); Modified: haiku/trunk/src/apps/deskbar/StatusView.cpp =================================================================== --- haiku/trunk/src/apps/deskbar/StatusView.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/apps/deskbar/StatusView.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -88,7 +88,8 @@ DumpItem(DeskbarItemInfo *item) { printf("is addon: %i, id: %li\n", item->isAddOn, item->id); - printf("entry_ref: %ld, %Ld, %s\n", item->entryRef.device, item->entryRef.directory, item->entryRef.name); + printf("entry_ref: %ld, %Ld, %s\n", item->entryRef.device, + item->entryRef.directory, item->entryRef.name); printf("node_ref: %ld, %Ld\n", item->nodeRef.device, item->nodeRef.node); } @@ -115,7 +116,7 @@ // don't change the name of this view to anything other than "Status"! TReplicantTray::TReplicantTray(TBarView *parent, bool vertical) - : BView(BRect(0, 0, 1, 1), "Status", B_FOLLOW_LEFT | B_FOLLOW_TOP, + : BView(BRect(0, 0, 1, 1), "Status", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_FRAME_EVENTS), fClock(NULL), fBarView(parent), @@ -137,8 +138,10 @@ { BView::AttachedToWindow(); - SetViewColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT)); + SetViewColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_DARKEN_1_TINT)); SetDrawingMode(B_OP_COPY); + Window()->SetPulseRate(1000000); DealWithClock(fBarView->ShowingClock()); @@ -233,8 +236,9 @@ if (!fClock) { desk_settings *settings = ((TBarApp *)be_app)->Settings(); - fClock = new TTimeView(settings->timeShowSeconds, settings->timeShowMil, - settings->timeFullDate, settings->timeShowEuro, false); + fClock = new TTimeView(settings->timeShowSeconds, + settings->timeShowMil, settings->timeFullDate, + settings->timeShowEuro, false); AddChild(fClock); fClock->MoveTo(Bounds().right - fClock->Bounds().Width() - 1, 2); @@ -252,12 +256,12 @@ } -/** width is set to a minimum of kMinimumReplicantCount by kMaxReplicantWidth - * if not in multirowmode and greater than kMinimumReplicantCount - * the width should be calculated based on the actual - * replicant widths - */ - +/*! + Width is set to a minimum of kMinimumReplicantCount by kMaxReplicantWidth + if not in multirowmode and greater than kMinimumReplicantCount + the width should be calculated based on the actual + replicant widths +*/ void TReplicantTray::GetPreferredSize(float *preferredWidth, float *preferredHeight) { @@ -281,7 +285,8 @@ if (fShelf->CountReplicants() > 0) { if (fBarView->ShowingClock() && fRightBottomReplicant.right + 6 >= fClock->Frame().left) { - width = fRightBottomReplicant.right + 6 + fClock->Frame().Width(); + width = fRightBottomReplicant.right + 6 + + fClock->Frame().Width(); } else width = fRightBottomReplicant.right + 3; } @@ -384,7 +389,7 @@ // If the clock is visible, show the extended menu // otheriwse, show "Show Time". - + if (fBarView->ShowingClock()) fClock->ShowClockOptions(ConvertToScreen(point)); else { @@ -462,7 +467,8 @@ // two computers would have to have exactly matching clocks, and launch // Deskbar at the exact same time into the bootsequence in order for their // security-ID to be identical - fDeskbarSecurityCode = ((real&0xffffffffULL)<<32)|(boot&0xffffffffULL); + fDeskbarSecurityCode = ((real & 0xffffffffULL) << 32) + | (boot & 0xffffffffULL); if (find_directory (B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) { path.Append(kDeskbarSecurityCodeFile); @@ -513,7 +519,8 @@ // newly mounted devices only - the Deskbar will automatically // create an index for every device mounted at startup). index_info info; - if (!volume->KnowsQuery() || fs_stat_index(volume->Device(),kStatusPredicate,&info) != 0) + if (!volume->KnowsQuery() + || fs_stat_index(volume->Device(), kStatusPredicate, &info) != 0) return; // run a new query on a specific volume @@ -540,7 +547,8 @@ BFile file(&ref, B_READ_ONLY); char status[64]; - ssize_t size = file.ReadAttr(kStatusPredicate, B_STRING_TYPE, 0, &status, 64); + ssize_t size = file.ReadAttr(kStatusPredicate, B_STRING_TYPE, 0, &status, + sizeof(status)); return size > 0; } @@ -549,7 +557,7 @@ TReplicantTray::DeskbarItemFor(node_ref &nodeRef) { for (int32 i = fItemList->CountItems(); i-- > 0 ;) { - DeskbarItemInfo *item = static_cast(fItemList->ItemAt(i)); + DeskbarItemInfo *item = (DeskbarItemInfo *)fItemList->ItemAt(i); if (item == NULL) continue; @@ -565,7 +573,7 @@ TReplicantTray::DeskbarItemFor(int32 id) { for (int32 i = fItemList->CountItems(); i-- > 0 ;) { - DeskbarItemInfo *item = static_cast(fItemList->ItemAt(i)); + DeskbarItemInfo *item = (DeskbarItemInfo *)fItemList->ItemAt(i); if (item == NULL) continue; @@ -584,10 +592,9 @@ } -/** This handles B_NODE_MONITOR & B_QUERY_UPDATE messages received - * for the registered add-ons. - */ - +/*! This handles B_NODE_MONITOR & B_QUERY_UPDATE messages received + for the registered add-ons. +*/ void TReplicantTray::HandleEntryUpdate(BMessage *message) { @@ -598,82 +605,82 @@ BPath path; switch (opcode) { case B_ENTRY_CREATED: + { // entry was just listed, matches live query - { - const char *name; - ino_t directory; - dev_t device; - // received when an app adds a ref to the - // Deskbar add-ons folder - if (message->FindString("name", &name) == B_OK - && message->FindInt64("directory", &directory) == B_OK - && message->FindInt32("device", &device) == B_OK) { - entry_ref ref(device, directory, name); - // see if this item has the attribute - // that we expect - if (IsAddOn(ref)) { - int32 id; - BEntry entry(&ref); - LoadAddOn(&entry, &id); - } + const char *name; + ino_t directory; + dev_t device; + // received when an app adds a ref to the + // Deskbar add-ons folder + if (message->FindString("name", &name) == B_OK + && message->FindInt64("directory", &directory) == B_OK + && message->FindInt32("device", &device) == B_OK) { + entry_ref ref(device, directory, name); + // see if this item has the attribute + // that we expect + if (IsAddOn(ref)) { + int32 id; + BEntry entry(&ref); + LoadAddOn(&entry, &id); } } break; + } case B_ATTR_CHANGED: + { // from node watch on individual items // (node_watch added in LoadAddOn) - { - node_ref nodeRef; - if (message->FindInt32("device", &(nodeRef.device)) == B_OK - && message->FindInt64("node", &(nodeRef.node)) == B_OK) { - // get the add-on this is for - DeskbarItemInfo *item = DeskbarItemFor(nodeRef); - if (item == NULL) - break; + node_ref nodeRef; + if (message->FindInt32("device", &(nodeRef.device)) == B_OK + && message->FindInt64("node", &(nodeRef.node)) == B_OK) { + // get the add-on this is for + DeskbarItemInfo *item = DeskbarItemFor(nodeRef); + if (item == NULL) + break; - BFile file(&item->entryRef, B_READ_ONLY); + BFile file(&item->entryRef, B_READ_ONLY); - char status[255]; - ssize_t size = file.ReadAttr(kStatusPredicate, - B_STRING_TYPE, 0, status, sizeof(status) - 1); - status[sizeof(status) - 1] = '\0'; + char status[255]; + ssize_t size = file.ReadAttr(kStatusPredicate, + B_STRING_TYPE, 0, status, sizeof(status) - 1); + status[sizeof(status) - 1] = '\0'; - // attribute was removed - if (size == B_ENTRY_NOT_FOUND) { - // cleans up and removes node_watch - UnloadAddOn(&nodeRef, NULL, true, false); - } else if (!strcmp(status, "enable")) { - int32 id; - BEntry entry(&item->entryRef, true); - LoadAddOn(&entry, &id); - } + // attribute was removed + if (size == B_ENTRY_NOT_FOUND) { + // cleans up and removes node_watch + UnloadAddOn(&nodeRef, NULL, true, false); + } else if (!strcmp(status, "enable")) { + int32 id; + BEntry entry(&item->entryRef, true); + LoadAddOn(&entry, &id); } } break; + } case B_ENTRY_MOVED: - { - entry_ref ref; - ino_t todirectory; - ino_t node; - const char *name; - if (message->FindString("name", &name) == B_OK - && message->FindInt64("from directory", &(ref.directory)) == B_OK - && message->FindInt64("to directory", &todirectory) == B_OK - && message->FindInt32("device", &(ref.device)) == B_OK - && message->FindInt64("node", &node) == B_OK ) { + { + entry_ref ref; + ino_t todirectory; + ino_t node; + const char *name; + if (message->FindString("name", &name) == B_OK + && message->FindInt64("from directory", &(ref.directory)) == B_OK + && message->FindInt64("to directory", &todirectory) == B_OK + && message->FindInt32("device", &(ref.device)) == B_OK + && message->FindInt64("node", &node) == B_OK ) { - if (!name) - break; + if (!name) + break; - ref.set_name(name); - // change the directory reference to - // the new directory - MoveItem(&ref, todirectory); - } + ref.set_name(name); + // change the directory reference to + // the new directory + MoveItem(&ref, todirectory); } break; + } case B_ENTRY_REMOVED: { @@ -692,41 +699,42 @@ UnloadAddOn(&nodeRef, NULL, true, false); } + break; } - break; case B_DEVICE_MOUNTED: - { - // run a new query on the new device - dev_t device; - if (message->FindInt32("new device", &device) != B_OK) - break; + { + // run a new query on the new device + dev_t device; + if (message->FindInt32("new device", &device) != B_OK) + break; - RunAddOnQuery(new BVolume(device), kEnabledPredicate); - } + RunAddOnQuery(new BVolume(device), kEnabledPredicate); break; + } + case B_DEVICE_UNMOUNTED: - { - // remove all items associated with the device - // unmounted - // contrary to what the BeBook says, the item is called "device", - // not "new device" like it is for B_DEVICE_MOUNTED - dev_t device; - if (message->FindInt32("device", &device) != B_OK) - break; + { + // remove all items associated with the device + // unmounted + // contrary to what the BeBook says, the item is called "device", + // not "new device" like it is for B_DEVICE_MOUNTED + dev_t device; + if (message->FindInt32("device", &device) != B_OK) + break; - UnloadAddOn(NULL, &device, false, true); - } + UnloadAddOn(NULL, &device, false, true); break; + } } } -/** The add-ons must support the exported C function API - * if they do, they will be loaded and added to deskbar - * primary function is the Instantiate function - */ - +/*! + The add-ons must support the exported C function API + if they do, they will be loaded and added to deskbar + primary function is the Instantiate function +*/ status_t TReplicantTray::LoadAddOn(BEntry *entry, int32 *id, bool force) { @@ -746,21 +754,24 @@ return error; uint64 deskbarID; - ssize_t size = node.ReadAttr(kDeskbarSecurityCodeAttr, B_UINT64_TYPE, 0, - &deskbarID, sizeof(fDeskbarSecurityCode)); - if (size != sizeof(fDeskbarSecurityCode) || deskbarID != fDeskbarSecurityCode) { + ssize_t size = node.ReadAttr(kDeskbarSecurityCodeAttr, B_UINT64_TYPE, + 0, &deskbarID, sizeof(fDeskbarSecurityCode)); + if (size != sizeof(fDeskbarSecurityCode) + || deskbarID != fDeskbarSecurityCode) { // no code or code doesn't match return B_ERROR; } } BPath path; - entry->GetPath(&path); + status_t status = entry->GetPath(&path); + if (status < B_OK) + return status; // load the add-on image_id image = load_add_on(path.Path()); - if (image < 0) - return (status_t)image; + if (image < B_OK) + return image; // get the view loading function symbol // we first look for a symbol that takes an image_id @@ -774,19 +785,17 @@ entry->GetRef(&ref); if (get_image_symbol(image, kInstantiateEntryCFunctionName, - B_SYMBOL_TYPE_TEXT, (void **)&entryFunction) >= 0) { - + B_SYMBOL_TYPE_TEXT, (void **)&entryFunction) >= B_OK) { view = (*entryFunction)(image, &ref); } else if (get_image_symbol(image, kInstantiateItemCFunctionName, - B_SYMBOL_TYPE_TEXT, (void **)&itemFunction) >= 0) { - + B_SYMBOL_TYPE_TEXT, (void **)&itemFunction) >= B_OK) { view = (*itemFunction)(); } else { unload_add_on(image); return B_ERROR; } - if (!view || IconExists(view->Name())) { + if (view == NULL || IconExists(view->Name())) { delete view; unload_add_on(image); return B_ERROR; Modified: haiku/trunk/src/apps/deskcalc/CalcView.cpp =================================================================== --- haiku/trunk/src/apps/deskcalc/CalcView.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/apps/deskcalc/CalcView.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -995,9 +995,9 @@ CalcView::_CreatePopUpMenu() { // construct items - fAboutItem = new BMenuItem("About Calculator...", + fAboutItem = new BMenuItem("About Calculator" B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED)); - fOptionsItem = new BMenuItem("Options...", + fOptionsItem = new BMenuItem("Options" B_UTF8_ELLIPSIS, new BMessage(K_OPTIONS_REQUESTED)); // construct menu Modified: haiku/trunk/src/apps/expander/ExpanderWindow.cpp =================================================================== --- haiku/trunk/src/apps/expander/ExpanderWindow.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/apps/expander/ExpanderWindow.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -52,11 +52,11 @@ fBar = new BMenuBar(BRect(0, 0, Bounds().right, 20), "menu_bar"); BMenu *menu = new BMenu("File"); BMenuItem *item; - menu->AddItem(item = new BMenuItem("About Expander...", new BMessage(B_ABOUT_REQUESTED))); + menu->AddItem(item = new BMenuItem("About Expander" B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED))); item->SetTarget(be_app_messenger); menu->AddSeparatorItem(); - menu->AddItem(fSourceItem = new BMenuItem("Set Source...", new BMessage(MSG_SOURCE), 'O')); - menu->AddItem(fDestItem = new BMenuItem("Set Destination...", new BMessage(MSG_DEST), 'D')); + menu->AddItem(fSourceItem = new BMenuItem("Set Source" B_UTF8_ELLIPSIS, new BMessage(MSG_SOURCE), 'O')); + menu->AddItem(fDestItem = new BMenuItem("Set Destination" B_UTF8_ELLIPSIS, new BMessage(MSG_DEST), 'D')); menu->AddSeparatorItem(); menu->AddItem(fExpandItem = new BMenuItem("Expand", new BMessage(MSG_EXPAND), 'E')); fExpandItem->SetEnabled(false); @@ -70,7 +70,7 @@ fBar->AddItem(menu); menu = new BMenu("Edit"); - menu->AddItem(fPreferencesItem = new BMenuItem("Preferences...", + menu->AddItem(fPreferencesItem = new BMenuItem("Preferences" B_UTF8_ELLIPSIS, new BMessage(MSG_PREFERENCES), 'P')); fBar->AddItem(menu); AddChild(fBar); Modified: haiku/trunk/src/apps/mail/Mail.cpp =================================================================== --- haiku/trunk/src/apps/mail/Mail.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/apps/mail/Mail.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -1378,7 +1378,7 @@ menu->AddSeparatorItem(); menu->AddItem(item = new BMenuItem( - MDR_DIALECT_CHOICE ("About", "A) Mail????") B_UTF8_ELLIPSIS, + MDR_DIALECT_CHOICE ("About Mail", "A) Mail????") B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED))); item->SetTarget(be_app); Modified: haiku/trunk/src/apps/mediaplayer/MainWin.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/MainWin.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/apps/mediaplayer/MainWin.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -274,7 +274,7 @@ fFileMenu->AddItem(new BMenuItem("Open File"B_UTF8_ELLIPSIS, new BMessage(M_FILE_OPEN), 'O', B_COMMAND_KEY)); fFileMenu->AddItem(new BMenuItem("File Info"B_UTF8_ELLIPSIS, new BMessage(M_FILE_INFO), 'I', B_COMMAND_KEY)); fFileMenu->AddSeparatorItem(); - fFileMenu->AddItem(new BMenuItem("About", new BMessage(M_FILE_ABOUT), 'A', B_COMMAND_KEY)); + fFileMenu->AddItem(new BMenuItem("About" NAME B_UTF8_ELLIPSIS, new BMessage(M_FILE_ABOUT))); fFileMenu->AddSeparatorItem(); fFileMenu->AddItem(new BMenuItem("Close", new BMessage(M_FILE_CLOSE), 'W', B_COMMAND_KEY)); fFileMenu->AddItem(new BMenuItem("Quit", new BMessage(M_FILE_QUIT), 'Q', B_COMMAND_KEY)); @@ -480,7 +480,7 @@ menu->AddItem(item = new BMenuItem("Keep Aspect Ratio", new BMessage(M_TOGGLE_KEEP_ASPECT_RATIO), 'K', B_COMMAND_KEY)); item->SetMarked(fKeepAspectRatio); menu->AddSeparatorItem(); - menu->AddItem(new BMenuItem("About", new BMessage(M_FILE_ABOUT), 'A', B_COMMAND_KEY)); + menu->AddItem(new BMenuItem("About" NAME B_UTF8_ELLIPSIS, new BMessage(M_FILE_ABOUT))); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem("Quit", new BMessage(M_FILE_QUIT), 'Q', B_COMMAND_KEY)); Modified: haiku/trunk/src/apps/networkstatus/NetworkStatusView.cpp =================================================================== --- haiku/trunk/src/apps/networkstatus/NetworkStatusView.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/apps/networkstatus/NetworkStatusView.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -352,7 +352,7 @@ } menu->AddSeparatorItem(); - menu->AddItem(new BMenuItem("About" B_UTF8_ELLIPSIS, + menu->AddItem(new BMenuItem("About NetworkStatus" B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED))); if (fInDeskbar) menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED))); @@ -472,6 +472,7 @@ extern "C" _EXPORT BView * instantiate_deskbar_item(void) { - return new NetworkStatusView(BRect(0, 0, 15, 15), B_FOLLOW_NONE, true); + return new NetworkStatusView(BRect(0, 0, 15, 15), + B_FOLLOW_LEFT | B_FOLLOW_TOP, true); } Modified: haiku/trunk/src/apps/people/PeopleWindow.cpp =================================================================== --- haiku/trunk/src/apps/people/PeopleWindow.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/apps/people/PeopleWindow.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -38,7 +38,7 @@ BRect rect(0, 0, 32767, 15); BMenuBar* menuBar = new BMenuBar(rect, ""); menu = new BMenu("File"); - menu->AddItem(item = new BMenuItem("New Person", new BMessage(M_NEW), 'N')); + menu->AddItem(item = new BMenuItem("New Person" B_UTF8_ELLIPSIS, new BMessage(M_NEW), 'N')); item->SetTarget(NULL, be_app); menu->AddItem(new BMenuItem("Close", new BMessage(B_CLOSE_REQUESTED), 'W')); menu->AddSeparatorItem(); Modified: haiku/trunk/src/apps/poorman/constants.cpp =================================================================== --- haiku/trunk/src/apps/poorman/constants.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/apps/poorman/constants.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -18,11 +18,11 @@ extern const char* STR_MNU_FILE = "File"; extern const char* STR_MNU_FILE_SAVE_AS - = "Save Console As..."; + = "Save Console As" B_UTF8_ELLIPSIS; extern const char* STR_MNU_FILE_SAVE_SELECTION - = "Save Console Selections As..."; + = "Save Console Selections As" B_UTF8_ELLIPSIS; extern const char* STR_MNU_FILE_ABOUT - = "About PoorMan"; + = "About PoorMan" B_UTF8_ELLIPSIS; extern const char* STR_MNU_FILE_QUIT = "Quit"; extern const char* STR_MNU_EDIT @@ -32,7 +32,7 @@ extern const char* STR_MNU_EDIT_SELECT_ALL = "Select All"; extern const char* STR_MNU_EDIT_PREF - = "Preferences..."; + = "Preferences" B_UTF8_ELLIPSIS; extern const char* STR_MNU_CTRL = "Controls"; extern const char* STR_MNU_CTRL_RUN_SERVER Modified: haiku/trunk/src/apps/processcontroller/ProcessController.cpp =================================================================== --- haiku/trunk/src/apps/processcontroller/ProcessController.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/apps/processcontroller/ProcessController.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -773,7 +773,7 @@ addtopbottom(new BSeparatorItem ()); - item = new IconMenuItem(gPCView->fProcessControllerIcon, "About ProcessController", + item = new IconMenuItem(gPCView->fProcessControllerIcon, "About ProcessController" B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED)); item->SetTarget(gPCView); addtopbottom(item); Modified: haiku/trunk/src/apps/pulse/PulseView.cpp =================================================================== --- haiku/trunk/src/apps/pulse/PulseView.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/apps/pulse/PulseView.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -44,8 +44,8 @@ popupmenu->SetFont(be_plain_font); mode1 = new BMenuItem("", NULL, 0, 0); mode2 = new BMenuItem("", NULL, 0, 0); - preferences = new BMenuItem("Preferences...", new BMessage(PV_PREFERENCES), 0, 0); - about = new BMenuItem("About...", new BMessage(PV_ABOUT), 0, 0); + preferences = new BMenuItem("Preferences" B_UTF8_ELLIPSIS, new BMessage(PV_PREFERENCES), 0, 0); + about = new BMenuItem("About Pulse" B_UTF8_ELLIPSIS, new BMessage(PV_ABOUT), 0, 0); popupmenu->AddItem(mode1); popupmenu->AddItem(mode2); Modified: haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp =================================================================== --- haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -129,7 +129,7 @@ menu->AddItem(menuItem = new BMenuItem("New", new BMessage(MENU_NEW), 'N')); menuItem->SetTarget(be_app); - menu->AddItem(menuItem = new BMenuItem(fRecentMenu = new BMenu("Open..."), + menu->AddItem(menuItem = new BMenuItem(fRecentMenu = new BMenu("Open" B_UTF8_ELLIPSIS), new BMessage(MENU_OPEN))); menuItem->SetShortcut('O', 0); menuItem->SetTarget(be_app); @@ -137,18 +137,18 @@ menu->AddItem(fSaveItem = new BMenuItem("Save", new BMessage(MENU_SAVE), 'S')); fSaveItem->SetEnabled(false); - menu->AddItem(menuItem = new BMenuItem("Save As...", new BMessage(MENU_SAVEAS))); + menu->AddItem(menuItem = new BMenuItem("Save As" B_UTF8_ELLIPSIS, new BMessage(MENU_SAVEAS))); menuItem->SetShortcut('S',B_SHIFT_KEY); menuItem->SetEnabled(true); - menu->AddItem(fRevertItem = new BMenuItem("Revert to Saved...", + menu->AddItem(fRevertItem = new BMenuItem("Revert to Saved" B_UTF8_ELLIPSIS, new BMessage(MENU_REVERT))); fRevertItem->SetEnabled(false); menu->AddItem(menuItem = new BMenuItem("Close", new BMessage(MENU_CLOSE), 'W')); menu->AddSeparatorItem(); - menu->AddItem(menuItem = new BMenuItem("Page Setup...", new BMessage(MENU_PAGESETUP))); - menu->AddItem(menuItem = new BMenuItem("Print...", new BMessage(MENU_PRINT), 'P')); + menu->AddItem(menuItem = new BMenuItem("Page Setup" B_UTF8_ELLIPSIS, new BMessage(MENU_PAGESETUP))); + menu->AddItem(menuItem = new BMenuItem("Print" B_UTF8_ELLIPSIS, new BMessage(MENU_PRINT), 'P')); menu->AddSeparatorItem(); menu->AddItem(menuItem = new BMenuItem("Quit", new BMessage(MENU_QUIT), 'Q')); @@ -180,12 +180,12 @@ menuItem->SetTarget(fTextView); menu->AddSeparatorItem(); - menu->AddItem(menuItem = new BMenuItem("Find...", new BMessage(MENU_FIND),'F')); + menu->AddItem(menuItem = new BMenuItem("Find" B_UTF8_ELLIPSIS, new BMessage(MENU_FIND),'F')); menu->AddItem(fFindAgainItem= new BMenuItem("Find Again",new BMessage(MENU_FIND_AGAIN),'G')); fFindAgainItem->SetEnabled(false); menu->AddItem(menuItem = new BMenuItem("Find Selection", new BMessage(MENU_FIND_SELECTION),'H')); - menu->AddItem(menuItem = new BMenuItem("Replace...", new BMessage(MENU_REPLACE),'R')); + menu->AddItem(menuItem = new BMenuItem("Replace" B_UTF8_ELLIPSIS, new BMessage(MENU_REPLACE),'R')); menu->AddItem(fReplaceSameItem = new BMenuItem("Replace Same", new BMessage(MENU_REPLACE_SAME),'T')); fReplaceSameItem->SetEnabled(false); Modified: haiku/trunk/src/apps/terminal/PrefWindow.cpp =================================================================== --- haiku/trunk/src/apps/terminal/PrefWindow.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/apps/terminal/PrefWindow.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -48,7 +48,7 @@ fPrefDlgMessenger); top->AddChild(prefView); - fSaveAsFileButton = new BButton(BRect(0, 0, 1, 1), "savebutton", "Save to File", + fSaveAsFileButton = new BButton(BRect(0, 0, 1, 1), "savebutton", "Save to File" B_UTF8_ELLIPSIS, new BMessage(MSG_SAVEAS_PRESSED), B_FOLLOW_TOP, B_WILL_DRAW); fSaveAsFileButton->ResizeToPreferred(); fSaveAsFileButton->MoveTo(5, top->Bounds().Height() - 5 - Modified: haiku/trunk/src/apps/terminal/TermWindow.cpp =================================================================== --- haiku/trunk/src/apps/terminal/TermWindow.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/apps/terminal/TermWindow.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -221,12 +221,12 @@ // Make File Menu. fFilemenu = new BMenu("Terminal"); fFilemenu->AddItem(new BMenuItem("Switch Terminals", new BMessage(MENU_SWITCH_TERM),'G')); - fFilemenu->AddItem(new BMenuItem("Start New Terminal", new BMessage(MENU_NEW_TERM), 'N')); + fFilemenu->AddItem(new BMenuItem("New Terminal" B_UTF8_ELLIPSIS, new BMessage(MENU_NEW_TERM), 'N')); fFilemenu->AddSeparatorItem(); fFilemenu->AddItem(new BMenuItem("Page Setup...", new BMessage(MENU_PAGE_SETUP))); fFilemenu->AddItem(new BMenuItem("Print", new BMessage(MENU_PRINT),'P')); fFilemenu->AddSeparatorItem(); - fFilemenu->AddItem(new BMenuItem("About Terminal...", new BMessage(B_ABOUT_REQUESTED))); + fFilemenu->AddItem(new BMenuItem("About Terminal" B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED))); fFilemenu->AddSeparatorItem(); fFilemenu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q')); fMenubar->AddItem(fFilemenu); @@ -239,7 +239,7 @@ fEditmenu->AddItem (new BMenuItem ("Select All", new BMessage (B_SELECT_ALL), 'A')); fEditmenu->AddItem (new BMenuItem ("Clear All", new BMessage (MENU_CLEAR_ALL), 'L')); fEditmenu->AddSeparatorItem (); - fEditmenu->AddItem (new BMenuItem ("Find", new BMessage (MENU_FIND_STRING),'F')); + fEditmenu->AddItem (new BMenuItem ("Find" B_UTF8_ELLIPSIS, new BMessage (MENU_FIND_STRING),'F')); fFindBackwardMenuItem = new BMenuItem ("Find Backward", new BMessage (MENU_FIND_BACKWARD), '['); fEditmenu->AddItem (fFindBackwardMenuItem); fFindBackwardMenuItem->SetEnabled(false); @@ -282,7 +282,7 @@ fHelpmenu->AddItem(fEncodingmenu); // fHelpmenu->AddItem(fNewFontMenu); fHelpmenu->AddSeparatorItem(); - fHelpmenu->AddItem(new BMenuItem("Preferences", new BMessage(MENU_PREF_OPEN))); + fHelpmenu->AddItem(new BMenuItem("Preferences" B_UTF8_ELLIPSIS, new BMessage(MENU_PREF_OPEN))); fHelpmenu->AddSeparatorItem(); fHelpmenu->AddItem(new BMenuItem("Save as default", new BMessage(SAVE_AS_DEFAULT))); fMenubar->AddItem(fHelpmenu); Modified: haiku/trunk/src/apps/terminal/andrew/TerminalWindow.cpp =================================================================== --- haiku/trunk/src/apps/terminal/andrew/TerminalWindow.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/apps/terminal/andrew/TerminalWindow.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -126,10 +126,10 @@ fTerminal->AddItem(fSwitchTerminals); fSwitchTerminals->SetTrigger('T'); - fStartNewTerminal = new BMenuItem("Start New Terminal", new BMessage(TERMINAL_START_NEW_TERMINAL), 'N'); + fStartNewTerminal = new BMenuItem("New Terminal" B_UTF8_ELLIPSIS, new BMessage(TERMINAL_START_NEW_TERMINAL), 'N'); fTerminal->AddItem(fStartNewTerminal); - fLogToFile = new BMenuItem("Log to File...", new BMessage(TERMINAL_LOG_TO_FILE)); + fLogToFile = new BMenuItem("Log to File" B_UTF8_ELLIPSIS, new BMessage(TERMINAL_LOG_TO_FILE)); fTerminal->AddItem(fLogToFile); // Edit menu @@ -148,7 +148,7 @@ fSelectAll = new BMenuItem("Select All", new BMessage(B_SELECT_ALL), 'A'); fEdit->AddItem(fSelectAll); - fWriteSelection = new BMenuItem("Write Selection...", new BMessage(EDIT_WRITE_SELECTION)); + fWriteSelection = new BMenuItem("Write Selection" B_UTF8_ELLIPSIS, new BMessage(EDIT_WRITE_SELECTION)); fEdit->AddItem(fWriteSelection); fClearAll = new BMenuItem("Clear All", new BMessage(EDIT_CLEAR_ALL), 'L'); @@ -156,7 +156,7 @@ fEdit->AddSeparatorItem(); - fFind = new BMenuItem("Find...", new BMessage(EDIT_FIND),'F'); + fFind = new BMenuItem("Find" B_UTF8_ELLIPSIS, new BMessage(EDIT_FIND),'F'); fEdit->AddItem(fFind); fFindBackward = new BMenuItem("Find Backward",new BMessage(EDIT_FIND_BACKWARD),'['); Modified: haiku/trunk/src/apps/tv/MainWin.cpp =================================================================== --- haiku/trunk/src/apps/tv/MainWin.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/apps/tv/MainWin.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -158,7 +158,7 @@ fMenuBar->AddItem(fSettingsMenu); fMenuBar->AddItem(fDebugMenu); - fFileMenu->AddItem(new BMenuItem("About", new BMessage(M_FILE_ABOUT), 'A', B_COMMAND_KEY)); + fFileMenu->AddItem(new BMenuItem("About " NAME B_UTF8_ELLIPSIS, new BMessage(M_FILE_ABOUT))); fFileMenu->AddSeparatorItem(); fFileMenu->AddItem(new BMenuItem("Quit", new BMessage(M_FILE_QUIT), 'Q', B_COMMAND_KEY)); @@ -488,7 +488,7 @@ menu->AddItem(item = new BMenuItem("Keep Aspect Ratio", new BMessage(M_TOGGLE_KEEP_ASPECT_RATIO), 'K', B_COMMAND_KEY)); item->SetMarked(fKeepAspectRatio); menu->AddSeparatorItem(); - menu->AddItem(new BMenuItem("About", new BMessage(M_FILE_ABOUT), 'A', B_COMMAND_KEY)); + menu->AddItem(new BMenuItem("About " NAME B_UTF8_ELLIPSIS, new BMessage(M_FILE_ABOUT))); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem("Quit", new BMessage(M_FILE_QUIT), 'Q', B_COMMAND_KEY)); Modified: haiku/trunk/src/kits/interface/Dragger.cpp =================================================================== --- haiku/trunk/src/kits/interface/Dragger.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/kits/interface/Dragger.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -593,7 +593,7 @@ msg->AddString("target", name); char about[B_OS_NAME_LENGTH]; - snprintf(about, B_OS_NAME_LENGTH, "About %s", name); + snprintf(about, B_OS_NAME_LENGTH, "About %s" B_UTF8_ELLIPSIS, name); fPopUp->AddItem(new BMenuItem(about, msg)); fPopUp->AddSeparatorItem(); Modified: haiku/trunk/src/preferences/datatranslations/DataTranslationsWindow.cpp =================================================================== --- haiku/trunk/src/preferences/datatranslations/DataTranslationsWindow.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/preferences/datatranslations/DataTranslationsWindow.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -211,7 +211,7 @@ // Add the translator info button BRect infoRect(0, 0, 80, 20); - BButton *button = new BButton(infoRect, "STD", "Info...", + BButton *button = new BButton(infoRect, "STD", "Info" B_UTF8_ELLIPSIS, new BMessage(kMsgTranslatorInfo), B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); button->ResizeToPreferred(); Modified: haiku/trunk/src/preferences/devices/DevicesWindow.cpp =================================================================== --- haiku/trunk/src/preferences/devices/DevicesWindow.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/preferences/devices/DevicesWindow.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -153,8 +153,8 @@ menubar->AddItem(menu); BMenu *jumperedDevicesMenu = new BMenu("New Jumpered Device"); - jumperedDevicesMenu->AddItem(new BMenuItem("Custom ...", new BMessage(MENU_DEVICES_NEW_JUMPERED_DEVICE_CUSTOM), 0)); - jumperedDevicesMenu->AddItem(new BMenuItem("Modem ...", new BMessage(MENU_DEVICES_NEW_JUMPERED_DEVICE_MODEM), 0)); + jumperedDevicesMenu->AddItem(new BMenuItem("Custom" B_UTF8_ELLIPSIS, new BMessage(MENU_DEVICES_NEW_JUMPERED_DEVICE_CUSTOM), 0)); + jumperedDevicesMenu->AddItem(new BMenuItem("Modem" B_UTF8_ELLIPSIS, new BMessage(MENU_DEVICES_NEW_JUMPERED_DEVICE_MODEM), 0)); //DevicesMenu->AddItem(new BMenuItem("New Jumpered Device", new BMessage(MENU_DEVICES_NEW_JUMPERED_DEVICE), NULL)); menu->AddItem(jumperedDevicesMenu); Modified: haiku/trunk/src/preferences/dun/DUNWindow.cpp =================================================================== --- haiku/trunk/src/preferences/dun/DUNWindow.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/preferences/dun/DUNWindow.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -58,7 +58,7 @@ float ButtonWidth = 24; BRect btn1(10,ButtonTop,83,ButtonTop+ButtonWidth); - modembutton = new BButton(btn1,"Modem","Modem...", new BMessage(BTN_MODEM), B_FOLLOW_BOTTOM, B_WILL_DRAW | B_NAVIGABLE); + modembutton = new BButton(btn1,"Modem","Modem" B_UTF8_ELLIPSIS, new BMessage(BTN_MODEM), B_FOLLOW_BOTTOM, B_WILL_DRAW | B_NAVIGABLE); BRect btn2(143,ButtonTop,218,ButtonTop+ButtonWidth); disconnectbutton = new BButton(btn2,"Disconnect","Disconnect", new BMessage(BTN_DISCONNECT), B_FOLLOW_BOTTOM, B_WILL_DRAW | B_NAVIGABLE); BRect btn3(230,ButtonTop,302,ButtonTop+ButtonWidth); @@ -82,7 +82,7 @@ conmenufield = new BMenu("Click to add"); //conmenufield = new BPopUpMenu("Click to add"); conmenufield->AddSeparatorItem(); - conmenufield->AddItem(menuconnew = new BMenuItem("New...", new BMessage(MENU_CON_NEW))); + conmenufield->AddItem(menuconnew = new BMenuItem("New" B_UTF8_ELLIPSIS, new BMessage(MENU_CON_NEW))); //menuconnew->SetTarget(be_app); conmenufield->AddItem(menucondelete = new BMenuItem("Delete Current", new BMessage(MENU_CON_DELETE_CURRENT))); menucondelete->SetEnabled(false); @@ -114,7 +114,7 @@ //menulocwork->SetTarget(be_app); locmenufield->AddSeparatorItem(); - locmenufield->AddItem(menulocnew = new BMenuItem("New...", new BMessage(MENU_LOC_NEW))); + locmenufield->AddItem(menulocnew = new BMenuItem("New" B_UTF8_ELLIPSIS, new BMessage(MENU_LOC_NEW))); //menulocnew->SetTarget(be_app); locmenufield->AddItem(menulocdelete = new BMenuItem("Delete Current", new BMessage(MENU_LOC_DELETE_CURRENT))); Modified: haiku/trunk/src/preferences/dun/DetailsView.cpp =================================================================== --- haiku/trunk/src/preferences/dun/DetailsView.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/preferences/dun/DetailsView.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -55,7 +55,7 @@ btnr.top = btnr.bottom - 24; btnr.left = btnr.right - 70; - settingsbtn = new BButton(btnr,"Settings...","Settings...", new BMessage(BTN_SETTINGS), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); + settingsbtn = new BButton(btnr,"Settings","Settings" B_UTF8_ELLIPSIS", new BMessage(BTN_SETTINGS), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); AddChild(settingsbtn); } void DetailsView::MessageReceived(BMessage* msg) Modified: haiku/trunk/src/preferences/dun/ModemWindow.cpp =================================================================== --- haiku/trunk/src/preferences/dun/ModemWindow.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/preferences/dun/ModemWindow.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -50,7 +50,7 @@ BRect btn1(10,r.bottom - 34,83,r.bottom - 16); BRect btn2(108,r.bottom - 34,184,r.bottom - 16); BRect btn3(196,r.bottom - 34,271,r.bottom - 16); - btnModemWindowCustom = new BButton(btn1,"Custom"," Custom ... ", new BMessage(BTN_MODEM_WINDOW_CUSTOM), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); + btnModemWindowCustom = new BButton(btn1,"Custom"," Custom" B_UTF8_ELLIPSIS " ", new BMessage(BTN_MODEM_WINDOW_CUSTOM), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); btnModemWindowCancel = new BButton(btn2,"Cancel"," Cancel ", new BMessage(BTN_MODEM_WINDOW_CANCEL), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); btnModemWindowDone = new BButton(btn3,"Done"," Done ", new BMessage(BTN_MODEM_WINDOW_DONE), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); @@ -59,7 +59,7 @@ BMenuItem *menu[100]; YourModemIsMenu = new BMenu(" "); YourModemIsMenu->AddSeparatorItem(); - YourModemIsMenu->AddItem(menu[1] = new BMenuItem("New...", new BMessage(MENU))); + YourModemIsMenu->AddItem(menu[1] = new BMenuItem("New" B_UTF8_ELLIPSIS, new BMessage(MENU))); menu[1]->SetTarget(be_app); YourModemIsMenuField = new BMenuField(mfld1,"yourmodem_menufield","Your modem is:",YourModemIsMenu,B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); YourModemIsMenuField->SetDivider(76); Modified: haiku/trunk/src/preferences/dun/SettingsWindow.cpp =================================================================== --- haiku/trunk/src/preferences/dun/SettingsWindow.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/preferences/dun/SettingsWindow.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -144,7 +144,7 @@ BMenuItem* item1 = new BMenuItem("Standard PPP",NULL); //n.b bmessage left out, add later YourServerTypeIsMenu->AddItem(item1); - BMenuItem* item2 = new BMenuItem("etc,etc...",NULL); + BMenuItem* item2 = new BMenuItem("Etc" B_UTF8_ELLIPSIS,NULL); YourServerTypeIsMenu->AddItem(item2); Modified: haiku/trunk/src/preferences/menu/MenuBar.cpp =================================================================== --- haiku/trunk/src/preferences/menu/MenuBar.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/preferences/menu/MenuBar.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -58,7 +58,7 @@ new BMessage(ALT_MARKED_MSG), BTranslationUtils::GetBitmap(B_RAW_TYPE, "ALT")); // color menu - BMenuItem* colorSchemeItem = new BMenuItem("Color Scheme...", + BMenuItem* colorSchemeItem = new BMenuItem("Color Scheme" B_UTF8_ELLIPSIS, new BMessage(COLOR_SCHEME_OPEN_MSG), 0, 0); // Add items to menubar Modified: haiku/trunk/src/preferences/network/NetworkWindow.cpp =================================================================== --- haiku/trunk/src/preferences/network/NetworkWindow.cpp 2007-05-16 15:50:04 UTC (rev 21155) +++ haiku/trunk/src/preferences/network/NetworkWindow.cpp 2007-05-16 16:34:09 UTC (rev 21156) @@ -206,7 +206,7 @@ fIdentityView->AddChild(fInterfaces); workrect = fInterfaces->Bounds().InsetByCopy(5,5); - fSettings = new BButton(BRect(0,0,1,1),"Settings","Settings...", + fSettings = new BButton(BRect(0,0,1,1),"Settings","Settings" B_UTF8_ELLIPSIS, new BMessage(kSettings_M), B_FOLLOW_TOP | B_FOLLOW_RIGHT); fSettings->ResizeToPreferred(); @@ -221,7 +221,7 @@ fInterfaces->AddChild(fClear); workrect.OffsetBy(0,workrect.Height()+15); - fCustom = new BButton(workrect,"Custom","Custom...",new BMessage(kCustom_M), + fCustom = new BButton(workrect,"Custom","Custom" B_UTF8_ELLIPSIS,new BMessage(kCustom_M), B_FOLLOW_TOP | B_FOLLOW_RIGHT); fInterfaces->AddChild(fCustom); @@ -257,7 +257,7 @@ fTelnetServer->MoveTo(10,height + 15); fServicesView->AddChild(fTelnetServer); - fLoginInfo = new BButton(workrect,"Login_Info","Login Info...", + fLoginInfo = new BButton(workrect,"Login_Info","Login Info" B_UTF8_ELLIPSIS, new BMessage(kLogin_Info_M)); fLoginInfo->ResizeToPreferred(); fLoginInfo->MoveTo(10,(height * 2) + 25); From axeld at mail.berlios.de Wed May 16 18:41:50 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 16 May 2007 18:41:50 +0200 Subject: [Haiku-commits] r21157 - haiku/trunk/src/apps/deskbar Message-ID: <200705161641.l4GGfo7C015588@sheep.berlios.de> Author: axeld Date: 2007-05-16 18:41:37 +0200 (Wed, 16 May 2007) New Revision: 21157 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21157&view=rev Modified: haiku/trunk/src/apps/deskbar/BeMenu.cpp Log: Added another patch by Jonas: this one adds the ellipsis to Shutdown/Restart in the Deskbar (see ticket #1181). Thanks! Modified: haiku/trunk/src/apps/deskbar/BeMenu.cpp =================================================================== --- haiku/trunk/src/apps/deskbar/BeMenu.cpp 2007-05-16 16:34:09 UTC (rev 21156) +++ haiku/trunk/src/apps/deskbar/BeMenu.cpp 2007-05-16 16:41:37 UTC (rev 21157) @@ -366,7 +366,12 @@ AddSeparatorItem(); +#ifdef __HAIKU__ + item = new BMenuItem("Restart" B_UTF8_ELLIPSIS, + new BMessage(CMD_REBOOT_SYSTEM)); +#else item = new BMenuItem("Restart", new BMessage(CMD_REBOOT_SYSTEM)); +#endif item->SetEnabled(!dragging); AddItem(item); @@ -378,7 +383,12 @@ } #endif +#ifdef __HAIKU__ + item = new BMenuItem("Shut Down" B_UTF8_ELLIPSIS, + new BMessage(CMD_SHUTDOWN_SYSTEM)); +#else item = new BMenuItem("Shut Down", new BMessage(CMD_SHUTDOWN_SYSTEM)); +#endif item->SetEnabled(!dragging); AddItem(item); From darkwyrm at earthlink.net Wed May 16 18:43:42 2007 From: darkwyrm at earthlink.net (DarkWyrm) Date: Wed, 16 May 2007 12:43:42 -0400 Subject: [Haiku-commits] r21156 - in haiku/trunk/src: add-ons/print/drivers/shared/libprint apps/cortex/RouteApp apps/deskbar apps/deskcalc apps/expander apps/mail apps/mediaplayer apps/networkstatus apps/people apps/poorman apps/processcontroller apps/pulse apps/stylededit apps/terminal apps/terminal/andrew apps/tv kits/interface preferences/datatranslations preferences/devices preferences/dun preferences/menu preferences/network In-Reply-To: <200705161634.l4GGYGcG001885@sheep.berlios.de> References: <200705161634.l4GGYGcG001885@sheep.berlios.de> Message-ID: <464B34BE.7060908@earthlink.net> axeld at BerliOS wrote: > - "Open...", > + "Open" B_UTF8_ELLIPSIS, Why this kind of change? Isn't it just simpler to use the UTF8 ellipsis already available in the keymap? The US mapping is Windows+. . Maybe it's just me, but I think the reference to the constant looks strange. --Jon From axeld at pinc-software.de Wed May 16 19:20:49 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Wed, 16 May 2007 19:20:49 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r21156_-_in_haiku/trunk/src=3A_ad?= =?iso-8859-15?q?d-ons/print/drivers/shared/libprint_apps/cortex/RouteApp_?= =?iso-8859-15?q?apps/deskbar_apps/deskcalc_apps/expander_apps/mail_apps/m?= =?iso-8859-15?q?ediaplayer__apps/networkstatus_apps/people_apps/poorman_a?= =?iso-8859-15?q?pps/processcontroller_apps/pulse_apps/stylededit_apps/ter?= =?iso-8859-15?q?minal_apps/terminal/andrew_apps/tv_kits/interface_prefere?= =?iso-8859-15?q?nces/datatranslations_preferences/devices_preferences/dun?= =?iso-8859-15?q?_preferences/menu_preferences/network?= In-Reply-To: <464B34BE.7060908@earthlink.net> Message-ID: <36047701987-BeMail@zon> DarkWyrm wrote: > axeld at BerliOS wrote: > > - "Open...", > > + "Open" B_UTF8_ELLIPSIS, > Why this kind of change? Isn't it just simpler to use the UTF8 > ellipsis > already available in the keymap? The US mapping is Windows+. . Maybe > it's just me, but I think the reference to the constant looks > strange. I don't know where it sits on the German keyboard, but that's exactly the point, I guess :-) At least this way it's clear it's UTF-8 and not whatever your text editor is using. Bye, Axel. From bonefish at cs.tu-berlin.de Wed May 16 19:35:16 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Wed, 16 May 2007 19:35:16 +0200 Subject: [Haiku-commits] r21156 - in haiku/trunk/src: add-ons/print/drivers/shared/libprint apps/cortex/RouteApp apps/deskbar apps/deskcalc apps/expander apps/mail apps/mediaplayer apps/networkstatus apps/people apps/poorman apps/processcontroller apps/pulse apps/stylededit apps/terminal apps/terminal/andrew apps/tv kits/interface preferences/datatranslations preferences/devices preferences/dun preferences/menu preferences/network In-Reply-To: <464B34BE.7060908@earthlink.net> References: <200705161634.l4GGYGcG001885@sheep.berlios.de> <464B34BE.7060908@earthlink.net> Message-ID: <20070516193516.6993.10@cs.tu-berlin.de> On 2007-05-16 at 18:43:42 [+0200], DarkWyrm wrote: > axeld at BerliOS wrote: > > - "Open...", > > + "Open" B_UTF8_ELLIPSIS, > Why this kind of change? Isn't it just simpler to use the UTF8 ellipsis > already available in the keymap? The US mapping is Windows+. . Maybe > it's just me, but I think the reference to the constant looks strange. It's just you. ;-) Seriously, besides that some people don't even have a Windows key (respectively have remapped it :-), I believe there were (still are?) reasons to keep non-ASCII chars out of the code, mainly to avoid problems with the SCM system and the compiler. Using the constant might not look exactly visually pleasing, but the occasions are relatively rare anyway. What I wonder, however, is that there's no space between the word and the ellipsis. Don't most English typographic standards require a space? CU, Ingo From leavengood at gmail.com Wed May 16 20:02:07 2007 From: leavengood at gmail.com (Ryan Leavengood) Date: Wed, 16 May 2007 14:02:07 -0400 Subject: [Haiku-commits] r21156 - in haiku/trunk/src: add-ons/print/drivers/shared/libprint apps/cortex/RouteApp apps/deskbar apps/deskcalc apps/expander apps/mail apps/mediaplayer apps/networkstatus apps/people apps/poorman apps/processcontroller apps/pu Message-ID: On 5/16/07, Ingo Weinhold wrote: > > What I wonder, however, is that there's no space between the word and the > ellipsis. Don't most English typographic standards require a space? In my experience there is rarely a space between a word and the ellipsis following it. Well that is how I type it... Most GUI's I've seen are the same in that sense: no space. I just did some research and if used within a sentence when removing material (especially in quotations) there are supposed to be spaces on both sides. If used at the end of a sentence there are no spaces and FOUR dots, hehehe (this actually is the ellipsis and then a period.) Crazy English grammar. I suggest leaving it as it is. Native English speaker, Ryan From colacoder at mail.berlios.de Wed May 16 23:43:15 2007 From: colacoder at mail.berlios.de (colacoder at BerliOS) Date: Wed, 16 May 2007 23:43:15 +0200 Subject: [Haiku-commits] r21158 - haiku/trunk/src/add-ons/kernel/drivers/audio/hda Message-ID: <200705162143.l4GLhFfA000561@sheep.berlios.de> Author: colacoder Date: 2007-05-16 23:43:15 +0200 (Wed, 16 May 2007) New Revision: 21158 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21158&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.c haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.c Log: * Count samples, not bytes, stupid :P * Don't try to bypass semaphore counting, it should just work(tm) * Minor cleanups. Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.c 2007-05-16 16:41:37 UTC (rev 21157) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.c 2007-05-16 21:43:15 UTC (rev 21158) @@ -7,7 +7,6 @@ const char** publish_devices(void); /* Just to silence compiler */ - status_t init_hardware(void) { Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2007-05-16 16:41:37 UTC (rev 21157) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2007-05-16 21:43:15 UTC (rev 21158) @@ -8,7 +8,7 @@ #include #include -#ifdef COMPILED_FOR_R5 +#ifdef COMPILE_FOR_R5 #define DEVFS_PATH_FORMAT "audio/multi/hda/%lu" #include #else Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c 2007-05-16 16:41:37 UTC (rev 21157) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c 2007-05-16 21:43:15 UTC (rev 21158) @@ -60,10 +60,8 @@ uint8 sts = OREG8(ctrlr,s->off,STS); if (sts) { cpu_status status; - int32 count; OREG8(ctrlr,s->off,STS) = sts; - status = disable_interrupts(); acquire_spinlock(&s->lock); @@ -74,9 +72,7 @@ release_spinlock(&s->lock); restore_interrupts(status); - get_sem_count(s->buffer_ready_sem, &count); - if (count <= 0) - release_sem_etc(s->buffer_ready_sem, 1, B_DO_NOT_RESCHEDULE); + release_sem_etc(s->buffer_ready_sem, 1, B_DO_NOT_RESCHEDULE); } } @@ -176,7 +172,7 @@ /* Setup BDL entries */ for (idx=0; idx < s->num_buffers; idx++, bdl++) { bdl->address = buffer_pa + (idx*buffer_size); - bdl->length = buffer_size; + bdl->length = s->sample_size * s->num_channels * s->buffer_length; bdl->ioc = 1; } @@ -208,7 +204,7 @@ OREG32(codec->ctrlr,s->off,BDPL) = s->bdl_pa; OREG32(codec->ctrlr,s->off,BDPU) = 0; OREG16(codec->ctrlr,s->off,LVI) = s->num_buffers -1; - OREG32(codec->ctrlr,s->off,CBL) = s->num_channels * s->num_buffers * s->sample_size; + OREG32(codec->ctrlr,s->off,CBL) = s->num_channels * s->num_buffers; OREG8(codec->ctrlr,s->off,CTL0) = CTL0_IOCE | CTL0_FEIE | CTL0_DEIE; OREG8(codec->ctrlr,s->off,CTL2) = s->id << 4; Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.c 2007-05-16 16:41:37 UTC (rev 21157) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.c 2007-05-16 21:43:15 UTC (rev 21158) @@ -216,9 +216,10 @@ hda_stream_start(codec->ctrlr, codec->playback_stream); /* do playback */ - rc=acquire_sem_etc(codec->playback_stream->buffer_ready_sem, 1, B_RELATIVE_TIMEOUT | B_CAN_INTERRUPT, 50000); + rc=acquire_sem(codec->playback_stream->buffer_ready_sem); if (rc != B_OK) { - dprintf("%s: Timeout waiting for playback buffer to finish!\n", __func__); + dprintf("%s: Error waiting for playback buffer to finish (%s)!\n", __func__, + strerror(rc)); return rc; } From colacoder at mail.berlios.de Thu May 17 04:43:13 2007 From: colacoder at mail.berlios.de (colacoder at BerliOS) Date: Thu, 17 May 2007 04:43:13 +0200 Subject: [Haiku-commits] r21159 - haiku/trunk/src/add-ons/kernel/drivers/audio/hda Message-ID: <200705170243.l4H2hDWn001124@sheep.berlios.de> Author: colacoder Date: 2007-05-17 04:43:12 +0200 (Thu, 17 May 2007) New Revision: 21159 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21159&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec.c haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.c Log: Fixed: * Prepare code for exposing multi_audio interface on Audio Function Group level * Some minor cleanups. Todo: * Publish devfs entries based on available Function Groups instead of HDA cards. * Publish all mixer controls / output busses through multi_audio interface. * Make recording work :) * Check why we need 4096 samples to play ok. * Figure out problems with driver on Haiku... currently only successfully tested on R5. As you can see, plenty of things left to do, but progressing nicely. At least people can have sound on R5 now! Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2007-05-16 21:43:15 UTC (rev 21158) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2007-05-17 02:43:12 UTC (rev 21159) @@ -24,13 +24,15 @@ /* values for the class_sub field for class_base = 0x04 (multimedia device) */ #define PCI_hd_audio 3 -#define MAXWORK 16 +#define HDA_MAXAFGS 15 #define HDA_MAXCODECS 15 #define HDA_MAXSTREAMS 16 #define MAX_CODEC_RESPONSES 10 #define MAXINPUTS 32 typedef struct hda_controller_s hda_controller; +typedef struct hda_codec_s hda_codec; +typedef struct hda_afg_s hda_afg; #define STRMAXBUF 10 #define STRMINBUF 2 @@ -40,6 +42,12 @@ STRM_RECORD }; +/* hda_stream_info + * + * This structure describes a single stream of audio data, + * which is can have multiple channels (for stereo or better). + */ + typedef struct hda_stream_info_s { uint32 id; /* HDA controller stream # */ uint32 off; /* HDA I/O/B descriptor offset */ @@ -68,27 +76,29 @@ uint32 bdl_pa; /* BDL physical address */ } hda_stream; -typedef struct hda_codec_s { - uint16 vendor_id; - uint16 product_id; - uint8 hda_rev; - uint16 rev_stepping; - uint8 addr; +/* hda_afg + * + * This structure describes a single Audio Function Group. An afg + * is a group of audio widgets which can be used to configure multiple + * streams of audio either from the HDA Link to an output device (= playback) + * or from an input device to the HDA link (= recording). + */ - sem_id response_sem; - uint32 responses[MAX_CODEC_RESPONSES]; - uint32 response_count; +struct hda_afg_s { + hda_codec* codec; /* Multi Audio API data */ - hda_stream* playback_stream; - hda_stream* record_stream; + hda_stream* playback_stream; + hda_stream* record_stream; + - /* Function Group Data */ - uint32 afg_nid; - uint32 afg_wid_start, afg_wid_count; - uint32 afg_deffmts; - uint32 afg_defrates; - uint32 afg_defpm; + uint32 root_nid, + wid_start, + wid_count; + + uint32 deffmts, + defrates, + defpm; struct { uint32 num_inputs; @@ -116,11 +126,44 @@ pin_dev_type device; } pin; } d; - } *afg_widgets; + } *widgets; +}; +/* hda_codec + * + * This structure describes a single codec module in the + * HDA compliant device. This is a discrete component, which + * can contain both Audio Function Groups, Modem Function Groups, + * and other customized (vendor specific) Function Groups. + * + * NOTE: Atm, only Audio Function Groups are supported. + */ + +struct hda_codec_s { + uint16 vendor_id; + uint16 product_id; + uint8 hda_rev; + uint16 rev_stepping; + uint8 addr; + + sem_id response_sem; + uint32 responses[MAX_CODEC_RESPONSES]; + uint32 response_count; + + hda_afg* afgs[HDA_MAXAFGS]; + uint32 num_afgs; + struct hda_controller_s* ctrlr; -} hda_codec; +}; +/* hda_controller + * + * This structure describes a single HDA compliant + * controller. It contains a list of available streams + * for use by the codecs contained, and the messaging queue + * (verb/response) buffers for communication. + */ + struct hda_controller_s { pci_info pcii; vuint32 opened; @@ -149,21 +192,27 @@ hda_stream* streams[HDA_MAXSTREAMS]; }; +/* driver.c */ extern device_hooks driver_hooks; - extern pci_module_info* pci; - extern hda_controller cards[MAXCARDS]; extern uint32 num_cards; +/* hda_codec.c */ +hda_codec* hda_codec_new(hda_controller* ctrlr, uint32 cad); + +/* hda_multi_audio.c */ +status_t multi_audio_control(void* cookie, uint32 op, void* arg, size_t len); + +/* hda_controller.c: Basic controller support */ status_t hda_hw_init(hda_controller* ctrlr); void hda_hw_stop(hda_controller* ctrlr); void hda_hw_uninit(hda_controller* ctrlr); -hda_codec* hda_codec_new(hda_controller* ctrlr, uint32 cad); status_t hda_send_verbs(hda_codec* codec, corb_t* verbs, uint32* responses, int count); -status_t multi_audio_control(void* cookie, uint32 op, void* arg, size_t len); + +/* hda_controller.c: Stream support */ hda_stream* hda_stream_alloc(hda_controller* ctrlr, int type); -status_t hda_stream_setup_buffers(hda_codec* codec, hda_stream* s, const char* desc); +status_t hda_stream_setup_buffers(hda_afg* afg, hda_stream* s, const char* desc); status_t hda_stream_start(hda_controller* ctrlr, hda_stream* s); status_t hda_stream_stop(hda_controller* ctrlr, hda_stream* s); status_t hda_stream_check_intr(hda_controller* ctrlr, hda_stream* s); Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec.c 2007-05-16 21:43:15 UTC (rev 21158) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec.c 2007-05-17 02:43:12 UTC (rev 21159) @@ -101,20 +101,20 @@ } static status_t -hda_codec_parse_afg(hda_codec* codec, uint32 afg_nid) +hda_codec_parse_afg(hda_afg* afg) { corb_t verbs[6]; uint32 resp[6]; uint32 widx; - hda_widget_get_stream_support(codec, afg_nid, &codec->afg_deffmts, &codec->afg_defrates); - hda_widget_get_pm_support(codec, afg_nid, &codec->afg_defpm); + hda_widget_get_stream_support(afg->codec, afg->root_nid, &afg->deffmts, &afg->defrates); + hda_widget_get_pm_support(afg->codec, afg->root_nid, &afg->defpm); - verbs[0] = MAKE_VERB(codec->addr,afg_nid,VID_GET_PARAM,PID_AUDIO_FG_CAP); - verbs[1] = MAKE_VERB(codec->addr,afg_nid,VID_GET_PARAM,PID_GPIO_COUNT); - verbs[2] = MAKE_VERB(codec->addr,afg_nid,VID_GET_PARAM,PID_SUBORD_NODE_COUNT); + verbs[0] = MAKE_VERB(afg->codec->addr,afg->root_nid,VID_GET_PARAM,PID_AUDIO_FG_CAP); + verbs[1] = MAKE_VERB(afg->codec->addr,afg->root_nid,VID_GET_PARAM,PID_GPIO_COUNT); + verbs[2] = MAKE_VERB(afg->codec->addr,afg->root_nid,VID_GET_PARAM,PID_SUBORD_NODE_COUNT); - if (hda_send_verbs(codec, verbs, resp, 3) == B_OK) { + if (hda_send_verbs(afg->codec, verbs, resp, 3) == B_OK) { dprintf("%s: Output delay: %ld samples, Input delay: %ld samples, Beep Generator: %s\n", __func__, resp[0] & 0xf, (resp[0] >> 8) & 0xf, (resp[0] & (1 << 16)) ? "yes" : "no"); @@ -123,30 +123,27 @@ (resp[1] & (1 << 30)) ? "yes" : "no", (resp[1] & (1 << 31)) ? "yes" : "no"); - codec->afg_wid_start = resp[2] >> 16; - codec->afg_wid_count = resp[2] & 0xFF; + afg->wid_start = resp[2] >> 16; + afg->wid_count = resp[2] & 0xFF; - codec->afg_widgets = calloc(sizeof(*codec->afg_widgets), codec->afg_wid_count); - if (codec->afg_widgets == NULL) { + afg->widgets = calloc(sizeof(*afg->widgets), afg->wid_count); + if (afg->widgets == NULL) { dprintf("ERROR: Not enough memory!\n"); return B_NO_MEMORY; } - /* Only now mark the AFG as found and used */ - codec->afg_nid = afg_nid; - /* Iterate over all Widgets and collect info */ - for (widx=0; widx < codec->afg_wid_count; widx++) { - uint32 wid = codec->afg_wid_start + widx; + for (widx=0; widx < afg->wid_count; widx++) { + uint32 wid = afg->wid_start + widx; char buf[256]; int off; - verbs[0] = MAKE_VERB(codec->addr,wid,VID_GET_PARAM,PID_AUDIO_WIDGET_CAP); - verbs[1] = MAKE_VERB(codec->addr,wid,VID_GET_PARAM,PID_CONNLIST_LEN); - hda_send_verbs(codec, verbs, resp, 2); + verbs[0] = MAKE_VERB(afg->codec->addr,wid,VID_GET_PARAM,PID_AUDIO_WIDGET_CAP); + verbs[1] = MAKE_VERB(afg->codec->addr,wid,VID_GET_PARAM,PID_CONNLIST_LEN); + hda_send_verbs(afg->codec, verbs, resp, 2); - codec->afg_widgets[widx].type = resp[0] >> 20; - codec->afg_widgets[widx].num_inputs = resp[1] & 0x7F; + afg->widgets[widx].type = resp[0] >> 20; + afg->widgets[widx].num_inputs = resp[1] & 0x7F; off = 0; if (resp[0] & (1 << 11)) off += sprintf(buf+off, "[L-R Swap] "); @@ -161,48 +158,48 @@ if (resp[0] & (1 << 1)) off += sprintf(buf+off, "[In Amp] "); if (resp[0] & (1 << 0)) off += sprintf(buf+off, "[Stereo] "); - switch(codec->afg_widgets[widx].type) { + switch(afg->widgets[widx].type) { case WT_AUDIO_OUTPUT: dprintf("%ld:\tAudio Output\n", wid); - hda_widget_get_stream_support(codec, wid, - &codec->afg_widgets[widx].d.input.formats, - &codec->afg_widgets[widx].d.input.rates); - hda_widget_get_amplifier_capabilities(codec, wid); + hda_widget_get_stream_support(afg->codec, wid, + &afg->widgets[widx].d.input.formats, + &afg->widgets[widx].d.input.rates); + hda_widget_get_amplifier_capabilities(afg->codec, wid); break; case WT_AUDIO_INPUT: dprintf("%ld:\tAudio Input\n", wid); - hda_widget_get_stream_support(codec, wid, - &codec->afg_widgets[widx].d.input.formats, - &codec->afg_widgets[widx].d.input.rates); - hda_widget_get_amplifier_capabilities(codec, wid); + hda_widget_get_stream_support(afg->codec, wid, + &afg->widgets[widx].d.input.formats, + &afg->widgets[widx].d.input.rates); + hda_widget_get_amplifier_capabilities(afg->codec, wid); break; case WT_AUDIO_MIXER: dprintf("%ld:\tAudio Mixer\n", wid); - hda_widget_get_amplifier_capabilities(codec, wid); + hda_widget_get_amplifier_capabilities(afg->codec, wid); break; case WT_AUDIO_SELECTOR: dprintf("%ld:\tAudio Selector\n", wid); - hda_widget_get_amplifier_capabilities(codec, wid); + hda_widget_get_amplifier_capabilities(afg->codec, wid); break; case WT_PIN_COMPLEX: dprintf("%ld:\tPin Complex\n", wid); - verbs[0] = MAKE_VERB(codec->addr,wid,VID_GET_PARAM,PID_PIN_CAP); - if (hda_send_verbs(codec, verbs, resp, 1) == B_OK) { - codec->afg_widgets[widx].d.pin.input = resp[0] & (1 << 5); - codec->afg_widgets[widx].d.pin.output = resp[0] & (1 << 4); + verbs[0] = MAKE_VERB(afg->codec->addr,wid,VID_GET_PARAM,PID_PIN_CAP); + if (hda_send_verbs(afg->codec, verbs, resp, 1) == B_OK) { + afg->widgets[widx].d.pin.input = resp[0] & (1 << 5); + afg->widgets[widx].d.pin.output = resp[0] & (1 << 4); } - verbs[0] = MAKE_VERB(codec->addr,wid,VID_GET_CFGDEFAULT,0); - if (hda_send_verbs(codec, verbs, resp, 1) == B_OK) { - codec->afg_widgets[widx].d.pin.device = (resp[0] >> 20) & 0xF; + verbs[0] = MAKE_VERB(afg->codec->addr,wid,VID_GET_CFGDEFAULT,0); + if (hda_send_verbs(afg->codec, verbs, resp, 1) == B_OK) { + afg->widgets[widx].d.pin.device = (resp[0] >> 20) & 0xF; dprintf("\t%s, %s, %s, %s\n", portcon[resp[0] >> 30], - defdev[codec->afg_widgets[widx].d.pin.device], + defdev[afg->widgets[widx].d.pin.device], conntype[(resp[0] >> 16) & 0xF], jcolor[(resp[0] >> 12) & 0xF]); } - hda_widget_get_amplifier_capabilities(codec, wid); + hda_widget_get_amplifier_capabilities(afg->codec, wid); break; case WT_POWER: dprintf("%ld:\tPower\n", wid); @@ -222,37 +219,37 @@ dprintf("\t%s\n", buf); - hda_widget_get_pm_support(codec, wid, &codec->afg_widgets[widx].pm); + hda_widget_get_pm_support(afg->codec, wid, &afg->widgets[widx].pm); - if (codec->afg_widgets[widx].num_inputs) { + if (afg->widgets[widx].num_inputs) { int idx; off = 0; - if (codec->afg_widgets[widx].num_inputs > 1) { - verbs[0] = MAKE_VERB(codec->addr,wid,VID_GET_CONNSEL,0); - if (hda_send_verbs(codec, verbs, resp, 1) == B_OK) - codec->afg_widgets[widx].active_input = resp[0] & 0xFF; + if (afg->widgets[widx].num_inputs > 1) { + verbs[0] = MAKE_VERB(afg->codec->addr,wid,VID_GET_CONNSEL,0); + if (hda_send_verbs(afg->codec, verbs, resp, 1) == B_OK) + afg->widgets[widx].active_input = resp[0] & 0xFF; else - codec->afg_widgets[widx].active_input = -1; + afg->widgets[widx].active_input = -1; } else - codec->afg_widgets[widx].active_input = -1; + afg->widgets[widx].active_input = -1; - for (idx=0; idx < codec->afg_widgets[widx].num_inputs; idx ++) { + for (idx=0; idx < afg->widgets[widx].num_inputs; idx ++) { if (!(idx % 4)) { - verbs[0] = MAKE_VERB(codec->addr,wid,VID_GET_CONNLENTRY,idx); - if (hda_send_verbs(codec, verbs, resp, 1) != B_OK) { + verbs[0] = MAKE_VERB(afg->codec->addr,wid,VID_GET_CONNLENTRY,idx); + if (hda_send_verbs(afg->codec, verbs, resp, 1) != B_OK) { dprintf("%s: Error parsing inputs for widget %ld!\n", __func__, wid); break; } } - if (idx != codec->afg_widgets[widx].active_input) + if (idx != afg->widgets[widx].active_input) off += sprintf(buf+off, "%ld ", (resp[0] >> (8*(idx%4))) & 0xFF); else off += sprintf(buf+off, "(%ld) ", (resp[0] >> (8*(idx%4))) & 0xFF); - codec->afg_widgets[widx].inputs[idx] = (resp[0] >> (8*(idx%4))) & 0xFF; + afg->widgets[widx].inputs[idx] = (resp[0] >> (8*(idx%4))) & 0xFF; } dprintf("\t[ %s]\n", buf); @@ -264,32 +261,32 @@ } static uint32 -hda_codec_afg_find_dac_path(hda_codec* codec, uint32 wid, uint32 depth) +hda_codec_afg_find_dac_path(hda_afg* afg, uint32 wid, uint32 depth) { - int widx = wid - codec->afg_wid_start; + int widx = wid - afg->wid_start; int idx; - switch(codec->afg_widgets[widx].type) { + switch(afg->widgets[widx].type) { case WT_AUDIO_OUTPUT: return wid; case WT_AUDIO_MIXER: - for (idx=0; idx < codec->afg_widgets[widx].num_inputs; idx++) { - if (hda_codec_afg_find_dac_path(codec, codec->afg_widgets[widx].inputs[idx], depth +1)) { - if (codec->afg_widgets[widx].active_input == -1) - codec->afg_widgets[widx].active_input = idx; + for (idx=0; idx < afg->widgets[widx].num_inputs; idx++) { + if (hda_codec_afg_find_dac_path(afg, afg->widgets[widx].inputs[idx], depth +1)) { + if (afg->widgets[widx].active_input == -1) + afg->widgets[widx].active_input = idx; - return codec->afg_widgets[widx].inputs[idx]; + return afg->widgets[widx].inputs[idx]; } } break; case WT_AUDIO_SELECTOR: { - int idx = codec->afg_widgets[widx].active_input; + int idx = afg->widgets[widx].active_input; if (idx != -1) { - uint32 wid = codec->afg_widgets[widx].inputs[idx]; - if (hda_codec_afg_find_dac_path(codec, wid, depth +1)) { + uint32 wid = afg->widgets[widx].inputs[idx]; + if (hda_codec_afg_find_dac_path(afg, wid, depth +1)) { return wid; } } @@ -303,41 +300,52 @@ return 0; } -static void -hda_codec_audiofg_new(hda_codec* codec, uint32 afg_nid) +static status_t +hda_codec_afg_new(hda_codec* codec, uint32 afg_nid) { + hda_afg* afg; + status_t rc; uint32 idx; - - /* FIXME: Bail if this isn't the first Audio Function Group we find... */ - if (codec->afg_nid != 0) { - dprintf("SORRY: This driver currently only supports a single Audio Function Group!\n"); - return; + + if ((afg=calloc(1, sizeof(hda_afg))) == NULL) { + rc = B_NO_MEMORY; + goto done; } + /* Setup minimal info needed by hda_codec_parse_afg */ + afg->root_nid = afg_nid; + afg->codec = codec; + /* Parse all widgets in Audio Function Group */ - hda_codec_parse_afg(codec, afg_nid); + rc = hda_codec_parse_afg(afg); + if (rc != B_OK) + goto free_afg; + /* Setup for worst-case scenario; + we cannot find any output Pin Widgets */ + rc = ENODEV; + /* Try to locate all output channels */ - for (idx=0; idx < codec->afg_wid_count; idx++) { + for (idx=0; idx < afg->wid_count; idx++) { uint32 iidx, output_wid = 0; - if (codec->afg_widgets[idx].type != WT_PIN_COMPLEX) + if (afg->widgets[idx].type != WT_PIN_COMPLEX) continue; - if (codec->afg_widgets[idx].d.pin.output) + if (afg->widgets[idx].d.pin.output) continue; - if (codec->afg_widgets[idx].d.pin.device != PIN_DEV_HP_OUT && - codec->afg_widgets[idx].d.pin.device != PIN_DEV_SPEAKER && - codec->afg_widgets[idx].d.pin.device != PIN_DEV_LINE_OUT) + if (afg->widgets[idx].d.pin.device != PIN_DEV_HP_OUT && + afg->widgets[idx].d.pin.device != PIN_DEV_SPEAKER && + afg->widgets[idx].d.pin.device != PIN_DEV_LINE_OUT) continue; - iidx = codec->afg_widgets[idx].active_input; + iidx = afg->widgets[idx].active_input; if (iidx != -1) { - output_wid = hda_codec_afg_find_dac_path(codec, codec->afg_widgets[idx].inputs[iidx], 0); + output_wid = hda_codec_afg_find_dac_path(afg, afg->widgets[idx].inputs[iidx], 0); } else { - for (iidx=0; iidx < codec->afg_widgets[idx].num_inputs; iidx++) { - output_wid = hda_codec_afg_find_dac_path(codec, codec->afg_widgets[idx].inputs[iidx], 0); + for (iidx=0; iidx < afg->widgets[idx].num_inputs; iidx++) { + output_wid = hda_codec_afg_find_dac_path(afg, afg->widgets[idx].inputs[iidx], 0); if (output_wid) { - corb_t verb = MAKE_VERB(codec->addr,idx+codec->afg_wid_start,VID_SET_CONNSEL,iidx); + corb_t verb = MAKE_VERB(codec->addr,idx+afg->wid_start,VID_SET_CONNSEL,iidx); if (hda_send_verbs(codec, &verb, NULL, 1) != B_OK) dprintf("%s: Setting output selector failed!\n", __func__); break; @@ -348,25 +356,43 @@ if (output_wid) { corb_t verb; - codec->playback_stream->pin_wid = idx + codec->afg_wid_start; - codec->playback_stream->io_wid = output_wid; + /* Setup playback/record streams for Multi Audio API */ + afg->playback_stream = hda_stream_alloc(afg->codec->ctrlr, STRM_PLAYBACK); + afg->record_stream = hda_stream_alloc(afg->codec->ctrlr, STRM_RECORD); + afg->playback_stream->pin_wid = idx + afg->wid_start; + afg->playback_stream->io_wid = output_wid; + dprintf("%s: Found output PIN (%s) connected to output CONV wid:%ld\n", - __func__, defdev[codec->afg_widgets[idx].d.pin.device], output_wid); + __func__, defdev[afg->widgets[idx].d.pin.device], output_wid); /* FIXME: Force Pin Widget to unmute */ - verb = MAKE_VERB(codec->addr, codec->playback_stream->pin_wid, + verb = MAKE_VERB(codec->addr, afg->playback_stream->pin_wid, VID_SET_AMPGAINMUTE, (1 << 15) | (1 << 13) | (1 << 12)); hda_send_verbs(codec, &verb, NULL, 1); + + rc = B_OK; break; } } + + /* If we found any valid output channels, we're in the clear */ + if (rc == B_OK) { + codec->afgs[codec->num_afgs++] = afg; + goto done; + } + +free_afg: + free(afg); + +done: + return rc; } hda_codec* hda_codec_new(hda_controller* ctrlr, uint32 cad) { - hda_codec* codec = calloc(sizeof(hda_codec),1); + hda_codec* codec = calloc(1, sizeof(hda_codec)); if (codec) { uint32 responses[3]; corb_t verbs[3]; @@ -377,13 +403,8 @@ codec->addr = cad; codec->response_count = 0; codec->response_sem = create_sem(0, "hda_codec_response_sem"); - codec->afg_nid = 0; ctrlr->codecs[cad] = codec; - /* Setup playback/record streams for Multi Audio API */ - codec->playback_stream = hda_stream_alloc(ctrlr, STRM_PLAYBACK); - codec->record_stream = hda_stream_alloc(ctrlr, STRM_RECORD); - verbs[0] = MAKE_VERB(cad,0,VID_GET_PARAM,PID_VENDORID); verbs[1] = MAKE_VERB(cad,0,VID_GET_PARAM,PID_REVISIONID); verbs[2] = MAKE_VERB(cad,0,VID_GET_PARAM,PID_SUBORD_NODE_COUNT); @@ -398,11 +419,13 @@ uint32 resp; verbs[0] = MAKE_VERB(cad,nid,VID_GET_PARAM,PID_FUNCGRP_TYPE); - if ((rc=hda_send_verbs(codec, verbs, &resp, 1)) == B_OK && (resp&0xFF) == 1) { + if ((rc=hda_send_verbs(codec, verbs, &resp, 1)) == B_OK && + (resp&0xFF) == 1 && + (rc=hda_codec_afg_new(codec, nid)) == B_OK) { /* Found an Audio Function Group! */ - hda_codec_audiofg_new(codec, nid); - } else + } else { dprintf("%s: FG %ld: %s\n", __func__, nid, strerror(rc)); + } } } } Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c 2007-05-16 21:43:15 UTC (rev 21158) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c 2007-05-17 02:43:12 UTC (rev 21159) @@ -93,7 +93,7 @@ } status_t -hda_stream_setup_buffers(hda_codec* codec, hda_stream* s, const char* desc) +hda_stream_setup_buffers(hda_afg* afg, hda_stream* s, const char* desc) { uint32 buffer_size, buffer_pa, alloc; uint32 response[2], idx; @@ -200,17 +200,17 @@ default: dprintf("%s: Invalid sample rate: 0x%lx\n", __func__, s->samplerate); break; } - OREG16(codec->ctrlr,s->off,FMT) = wfmt; - OREG32(codec->ctrlr,s->off,BDPL) = s->bdl_pa; - OREG32(codec->ctrlr,s->off,BDPU) = 0; - OREG16(codec->ctrlr,s->off,LVI) = s->num_buffers -1; - OREG32(codec->ctrlr,s->off,CBL) = s->num_channels * s->num_buffers; - OREG8(codec->ctrlr,s->off,CTL0) = CTL0_IOCE | CTL0_FEIE | CTL0_DEIE; - OREG8(codec->ctrlr,s->off,CTL2) = s->id << 4; + OREG16(afg->codec->ctrlr,s->off,FMT) = wfmt; + OREG32(afg->codec->ctrlr,s->off,BDPL) = s->bdl_pa; + OREG32(afg->codec->ctrlr,s->off,BDPU) = 0; + OREG16(afg->codec->ctrlr,s->off,LVI) = s->num_buffers -1; + OREG32(afg->codec->ctrlr,s->off,CBL) = s->num_channels * s->num_buffers; + OREG8(afg->codec->ctrlr,s->off,CTL0) = CTL0_IOCE | CTL0_FEIE | CTL0_DEIE; + OREG8(afg->codec->ctrlr,s->off,CTL2) = s->id << 4; - verb[0] = MAKE_VERB(codec->addr, s->io_wid, VID_SET_CONVFORMAT, wfmt); - verb[1] = MAKE_VERB(codec->addr, s->io_wid, VID_SET_CVTSTRCHN, s->id << 4); - rc = hda_send_verbs(codec, verb, response, 2); + verb[0] = MAKE_VERB(afg->codec->addr, s->io_wid, VID_SET_CONVFORMAT, wfmt); + verb[1] = MAKE_VERB(afg->codec->addr, s->io_wid, VID_SET_CVTSTRCHN, s->id << 4); + rc = hda_send_verbs(afg->codec, verb, response, 2); return rc; } Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.c 2007-05-16 21:43:15 UTC (rev 21158) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.c 2007-05-17 02:43:12 UTC (rev 21159) @@ -34,7 +34,7 @@ } static status_t -get_description(hda_codec* codec, multi_description* data) +get_description(hda_afg* afg, multi_description* data) { data->interface_version = B_CURRENT_INTERFACE_VERSION; data->interface_minimum = B_CURRENT_INTERFACE_VERSION; @@ -55,8 +55,8 @@ } /* determine output/input rates */ - data->output_rates = codec->afg_defrates; - data->input_rates = codec->afg_defrates; + data->output_rates = afg->defrates; + data->input_rates = afg->defrates; /* force existance of 48kHz if variable rates are not supported */ if (data->output_rates == 0) @@ -67,8 +67,8 @@ data->max_cvsr_rate = 0; data->min_cvsr_rate = 0; - data->output_formats = codec->afg_deffmts; - data->input_formats = codec->afg_deffmts; + data->output_formats = afg->deffmts; + data->input_formats = afg->deffmts; data->lock_sources = B_MULTI_LOCK_INTERNAL; data->timecode_sources = 0; data->interface_flags = B_MULTI_INTERFACE_PLAYBACK /* | B_MULTI_INTERFACE_RECORD */; @@ -80,7 +80,7 @@ } static status_t -get_enabled_channels(hda_codec* codec, multi_channel_enable* data) +get_enabled_channels(hda_afg* afg, multi_channel_enable* data) { B_SET_CHANNEL(data->enable_bits, 0, true); B_SET_CHANNEL(data->enable_bits, 1, true); @@ -92,59 +92,59 @@ } static status_t -get_global_format(hda_codec* codec, multi_format_info* data) +get_global_format(hda_afg* afg, multi_format_info* data) { data->output_latency = 0; data->input_latency = 0; data->timecode_kind = 0; - data->output.format = codec->playback_stream->sampleformat; - data->output.rate = codec->playback_stream->samplerate; + data->output.format = afg->playback_stream->sampleformat; + data->output.rate = afg->playback_stream->samplerate; - data->input.format = codec->record_stream->sampleformat; - data->input.rate = codec->record_stream->sampleformat; + data->input.format = afg->record_stream->sampleformat; + data->input.rate = afg->record_stream->sampleformat; return B_OK; } static status_t -set_global_format(hda_codec* codec, multi_format_info* data) +set_global_format(hda_afg* afg, multi_format_info* data) { - codec->playback_stream->sampleformat = data->output.format; - codec->playback_stream->samplerate = data->output.rate; - codec->playback_stream->sample_size = format2size(codec->playback_stream->sampleformat); + afg->playback_stream->sampleformat = data->output.format; + afg->playback_stream->samplerate = data->output.rate; + afg->playback_stream->sample_size = format2size(afg->playback_stream->sampleformat); - codec->record_stream->samplerate = data->input.rate; - codec->record_stream->sampleformat = data->input.format; - codec->record_stream->sample_size = format2size(codec->record_stream->sampleformat); + afg->record_stream->samplerate = data->input.rate; + afg->record_stream->sampleformat = data->input.format; + afg->record_stream->sample_size = format2size(afg->record_stream->sampleformat); return B_OK; } static status_t -list_mix_controls(hda_codec* codec, multi_mix_control_info * data) +list_mix_controls(hda_afg* afg, multi_mix_control_info * data) { return B_OK; } static status_t -list_mix_connections(hda_codec* codec, multi_mix_connection_info * data) +list_mix_connections(hda_afg* afg, multi_mix_connection_info * data) { data->actual_count = 0; return B_OK; } static status_t -list_mix_channels(hda_codec* codec, multi_mix_channel_info *data) +list_mix_channels(hda_afg* afg, multi_mix_channel_info *data) { return B_OK; } static status_t -get_buffers(hda_codec* codec, multi_buffer_list* data) +get_buffers(hda_afg* afg, multi_buffer_list* data) { - uint32 playback_sample_size = codec->playback_stream->sample_size; - uint32 record_sample_size = codec->record_stream->sample_size; + uint32 playback_sample_size = afg->playback_stream->sample_size; + uint32 record_sample_size = afg->record_stream->sample_size; uint32 cidx, bidx; status_t rc; @@ -163,18 +163,18 @@ data->flags = 0; /* Copy the requested settings into the streams */ - codec->playback_stream->num_buffers = data->request_playback_buffers; - codec->playback_stream->num_channels = data->request_playback_channels; - codec->playback_stream->buffer_length = data->request_playback_buffer_size; - if ((rc=hda_stream_setup_buffers(codec, codec->playback_stream, "Playback")) != B_OK) { + afg->playback_stream->num_buffers = data->request_playback_buffers; + afg->playback_stream->num_channels = data->request_playback_channels; + afg->playback_stream->buffer_length = data->request_playback_buffer_size; + if ((rc=hda_stream_setup_buffers(afg, afg->playback_stream, "Playback")) != B_OK) { dprintf("%s: Error setting up playback buffers (%s)\n", __func__, strerror(rc)); return rc; } - codec->record_stream->num_buffers = data->request_record_buffers; - codec->record_stream->num_channels = data->request_record_channels; - codec->record_stream->buffer_length = data->request_record_buffer_size; - if ((rc=hda_stream_setup_buffers(codec, codec->record_stream, "Recording")) != B_OK) { + afg->record_stream->num_buffers = data->request_record_buffers; + afg->record_stream->num_channels = data->request_record_channels; + afg->record_stream->buffer_length = data->request_record_buffer_size; + if ((rc=hda_stream_setup_buffers(afg, afg->record_stream, "Recording")) != B_OK) { dprintf("%s: Error setting up recording buffers (%s)\n", __func__, strerror(rc)); return rc; } @@ -186,7 +186,7 @@ for (bidx=0; bidx < data->return_playback_buffers; bidx++) { for (cidx=0; cidx < data->return_playback_channels; cidx++) { - data->playback_buffers[bidx][cidx].base = codec->playback_stream->buffers[bidx] + (playback_sample_size * cidx); + data->playback_buffers[bidx][cidx].base = afg->playback_stream->buffers[bidx] + (playback_sample_size * cidx); data->playback_buffers[bidx][cidx].stride = playback_sample_size * data->return_playback_channels; } } @@ -197,7 +197,7 @@ for (bidx=0; bidx < data->return_record_buffers; bidx++) { for (cidx=0; cidx < data->return_record_channels; cidx++) { - data->record_buffers[bidx][cidx].base = codec->record_stream->buffers[bidx] + (record_sample_size * cidx); + data->record_buffers[bidx][cidx].base = afg->record_stream->buffers[bidx] + (record_sample_size * cidx); data->record_buffers[bidx][cidx].stride = record_sample_size * data->return_record_channels; } } @@ -206,17 +206,17 @@ } static status_t -buffer_exchange(hda_codec* codec, multi_buffer_info* data) +buffer_exchange(hda_afg* afg, multi_buffer_info* data) { static int debug_buffers_exchanged = 0; cpu_status status; status_t rc; - if (!codec->playback_stream->running) - hda_stream_start(codec->ctrlr, codec->playback_stream); + if (!afg->playback_stream->running) + hda_stream_start(afg->codec->ctrlr, afg->playback_stream); /* do playback */ - rc=acquire_sem(codec->playback_stream->buffer_ready_sem); + rc=acquire_sem(afg->playback_stream->buffer_ready_sem); if (rc != B_OK) { dprintf("%s: Error waiting for playback buffer to finish (%s)!\n", __func__, strerror(rc)); @@ -224,13 +224,13 @@ } status = disable_interrupts(); - acquire_spinlock(&codec->playback_stream->lock); + acquire_spinlock(&afg->playback_stream->lock); - data->playback_buffer_cycle = codec->playback_stream->buffer_cycle; - data->played_real_time = codec->playback_stream->real_time; - data->played_frames_count = codec->playback_stream->frames_count; + data->playback_buffer_cycle = afg->playback_stream->buffer_cycle; + data->played_real_time = afg->playback_stream->real_time; + data->played_frames_count = afg->playback_stream->frames_count; - release_spinlock(&codec->playback_stream->lock); + release_spinlock(&afg->playback_stream->lock); restore_interrupts(status); debug_buffers_exchanged++; @@ -242,13 +242,13 @@ } static status_t -buffer_force_stop(hda_codec* codec) +buffer_force_stop(hda_afg* afg) { - hda_stream_stop(codec->ctrlr, codec->playback_stream); - hda_stream_stop(codec->ctrlr, codec->record_stream); + hda_stream_stop(afg->codec->ctrlr, afg->playback_stream); + hda_stream_stop(afg->codec->ctrlr, afg->record_stream); - delete_sem(codec->playback_stream->buffer_ready_sem); -// delete_sem(codec->record_stream->buffer_ready_sem); + delete_sem(afg->playback_stream->buffer_ready_sem); +// delete_sem(afg->record_stream->buffer_ready_sem); return B_OK; } @@ -257,28 +257,35 @@ multi_audio_control(void* cookie, uint32 op, void* arg, size_t len) { hda_codec* codec = (hda_codec*)cookie; + hda_afg* afg; + /* FIXME: Make sure we have a valid codec & afg... */ + if (!codec || codec->num_afgs == 0) + return ENODEV; + + afg = codec->afgs[0]; + switch(op) { - case B_MULTI_GET_DESCRIPTION: return get_description(codec, arg); + case B_MULTI_GET_DESCRIPTION: return get_description(afg, arg); case B_MULTI_GET_EVENT_INFO: return B_ERROR; case B_MULTI_SET_EVENT_INFO: return B_ERROR; case B_MULTI_GET_EVENT: return B_ERROR; - case B_MULTI_GET_ENABLED_CHANNELS: return get_enabled_channels(codec, arg); + case B_MULTI_GET_ENABLED_CHANNELS: return get_enabled_channels(afg, arg); case B_MULTI_SET_ENABLED_CHANNELS: return B_OK; - case B_MULTI_GET_GLOBAL_FORMAT: return get_global_format(codec, arg); - case B_MULTI_SET_GLOBAL_FORMAT: return set_global_format(codec, arg); + case B_MULTI_GET_GLOBAL_FORMAT: return get_global_format(afg, arg); + case B_MULTI_SET_GLOBAL_FORMAT: return set_global_format(afg, arg); case B_MULTI_GET_CHANNEL_FORMATS: return B_ERROR; case B_MULTI_SET_CHANNEL_FORMATS: return B_ERROR; case B_MULTI_GET_MIX: return B_ERROR; case B_MULTI_SET_MIX: return B_ERROR; - case B_MULTI_LIST_MIX_CHANNELS: return list_mix_channels(codec, arg); - case B_MULTI_LIST_MIX_CONTROLS: return list_mix_controls(codec, arg); - case B_MULTI_LIST_MIX_CONNECTIONS: return list_mix_connections(codec, arg); - case B_MULTI_GET_BUFFERS: return get_buffers(codec, arg); + case B_MULTI_LIST_MIX_CHANNELS: return list_mix_channels(afg, arg); + case B_MULTI_LIST_MIX_CONTROLS: return list_mix_controls(afg, arg); + case B_MULTI_LIST_MIX_CONNECTIONS: return list_mix_connections(afg, arg); + case B_MULTI_GET_BUFFERS: return get_buffers(afg, arg); case B_MULTI_SET_BUFFERS: return B_ERROR; case B_MULTI_SET_START_TIME: return B_ERROR; - case B_MULTI_BUFFER_EXCHANGE: return buffer_exchange(codec, arg); - case B_MULTI_BUFFER_FORCE_STOP: return buffer_force_stop(codec); + case B_MULTI_BUFFER_EXCHANGE: return buffer_exchange(afg, arg); + case B_MULTI_BUFFER_FORCE_STOP: return buffer_force_stop(afg); } return B_BAD_VALUE; From colacoder at mail.berlios.de Thu May 17 10:23:43 2007 From: colacoder at mail.berlios.de (colacoder at BerliOS) Date: Thu, 17 May 2007 10:23:43 +0200 Subject: [Haiku-commits] r21160 - haiku/trunk/src/add-ons/kernel/drivers/audio/hda Message-ID: <200705170823.l4H8Nhrc032561@sheep.berlios.de> Author: colacoder Date: 2007-05-17 10:23:42 +0200 (Thu, 17 May 2007) New Revision: 21160 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21160&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec.c haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c Log: * Made code more Coding Guidelines compliant * Fixed several sem/area leaks when restarting media services. Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2007-05-17 02:43:12 UTC (rev 21159) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2007-05-17 08:23:42 UTC (rev 21160) @@ -200,6 +200,7 @@ /* hda_codec.c */ hda_codec* hda_codec_new(hda_controller* ctrlr, uint32 cad); +void hda_codec_delete(hda_codec*); /* hda_multi_audio.c */ status_t multi_audio_control(void* cookie, uint32 op, void* arg, size_t len); @@ -211,7 +212,8 @@ status_t hda_send_verbs(hda_codec* codec, corb_t* verbs, uint32* responses, int count); /* hda_controller.c: Stream support */ -hda_stream* hda_stream_alloc(hda_controller* ctrlr, int type); +hda_stream* hda_stream_new(hda_controller* ctrlr, int type); +void hda_stream_delete(hda_stream* s); status_t hda_stream_setup_buffers(hda_afg* afg, hda_stream* s, const char* desc); status_t hda_stream_start(hda_controller* ctrlr, hda_stream* s); status_t hda_stream_stop(hda_controller* ctrlr, hda_stream* s); Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec.c 2007-05-17 02:43:12 UTC (rev 21159) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_codec.c 2007-05-17 08:23:42 UTC (rev 21160) @@ -300,6 +300,21 @@ return 0; } +static void +hda_afg_delete(hda_afg* afg) +{ + if (afg != NULL) { + if (afg->playback_stream != NULL) + hda_stream_delete(afg->playback_stream); + + if (afg->record_stream != NULL) + hda_stream_delete(afg->record_stream); + + free(afg->widgets); + free(afg); + } +} + static status_t hda_codec_afg_new(hda_codec* codec, uint32 afg_nid) { @@ -357,8 +372,8 @@ corb_t verb; /* Setup playback/record streams for Multi Audio API */ - afg->playback_stream = hda_stream_alloc(afg->codec->ctrlr, STRM_PLAYBACK); - afg->record_stream = hda_stream_alloc(afg->codec->ctrlr, STRM_RECORD); + afg->playback_stream = hda_stream_new(afg->codec->ctrlr, STRM_PLAYBACK); + afg->record_stream = hda_stream_new(afg->codec->ctrlr, STRM_RECORD); afg->playback_stream->pin_wid = idx + afg->wid_start; afg->playback_stream->io_wid = output_wid; @@ -389,6 +404,23 @@ return rc; } +void +hda_codec_delete(hda_codec* codec) +{ + if (codec != NULL) { + uint32 idx; + + delete_sem(codec->response_sem); + + for (idx=0; idx < codec->num_afgs; idx++) { + hda_afg_delete(codec->afgs[idx]); + codec->afgs[idx] = NULL; + } + + free(codec); + } +} + hda_codec* hda_codec_new(hda_controller* ctrlr, uint32 cad) { Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c 2007-05-17 02:43:12 UTC (rev 21159) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.c 2007-05-17 08:23:42 UTC (rev 21160) @@ -4,8 +4,23 @@ #include "driver.h" +void +hda_stream_delete(hda_stream* s) +{ + if (s->buffer_ready_sem >= B_OK) + delete_sem(s->buffer_ready_sem); + + if (s->buffer_area >= B_OK) + delete_area(s->buffer_area); + + if (s->bdl_area >= B_OK) + delete_area(s->bdl_area); + + free(s); +} + hda_stream* -hda_stream_alloc(hda_controller* ctrlr, int type) +hda_stream_new(hda_controller* ctrlr, int type) { hda_stream* s = calloc(1, sizeof(hda_stream)); if (s != NULL) { @@ -45,7 +60,7 @@ { OREG8(ctrlr,s->off,CTL0) |= CTL0_RUN; - while(!(OREG8(ctrlr,s->off,CTL0) & CTL0_RUN)) + while (!(OREG8(ctrlr,s->off,CTL0) & CTL0_RUN)) snooze(1); s->running = true; @@ -84,7 +99,7 @@ { OREG8(ctrlr,s->off,CTL0) &= ~CTL0_RUN; - while(OREG8(ctrlr,s->off,CTL0) & CTL0_RUN) + while (OREG8(ctrlr,s->off,CTL0) & CTL0_RUN) snooze(1); s->running = false; @@ -262,7 +277,7 @@ if (rirbsts & RIRBSTS_RINTFL) { uint16 rirbwp = REG16(ctrlr,RIRBWP); - while(ctrlr->rirbrp <= rirbwp) { + while (ctrlr->rirbrp <= rirbwp) { uint32 resp_ex = ctrlr->rirb[ctrlr->rirbrp].resp_ex; uint32 cad = resp_ex & HDA_MAXCODECS; hda_codec* codec = ctrlr->codecs[cad]; @@ -326,7 +341,7 @@ do { snooze(100); - } while(--timeout && !(REG32(ctrlr,GCTL) & GCTL_CRST)); + } while (--timeout && !(REG32(ctrlr,GCTL) & GCTL_CRST)); return timeout ? B_OK : B_TIMED_OUT; } @@ -383,7 +398,7 @@ if ((rc=get_memory_map(ctrlr->corb, memsz, &pe, 1)) != B_OK) { delete_area(ctrlr->rb_area); - return ctrlr->rb_area; + return rc; } /* Program CORB/RIRB for these locations */ @@ -395,7 +410,7 @@ REG16(ctrlr,CORBRP) = CORBRP_RST; do { snooze(10); - } while( !(REG16(ctrlr,CORBRP) & CORBRP_RST) ); + } while ( !(REG16(ctrlr,CORBRP) & CORBRP_RST) ); REG16(ctrlr,CORBRP) = 0; /* Reset RIRB write pointer */ @@ -522,6 +537,8 @@ hda_hw_uninit(hda_controller* ctrlr) { if (ctrlr != NULL) { + uint32 idx; + /* Stop all audio streams */ hda_hw_stop(ctrlr); @@ -535,6 +552,14 @@ remove_io_interrupt_handler(ctrlr->irq, (interrupt_handler)hda_interrupt_handler, ctrlr); + + /* Delete corb/rirb area */ + if (ctrlr->rb_area >= 0) { + delete_area(ctrlr->rb_area); + ctrlr->rb_area = B_ERROR; + ctrlr->corb = NULL; + ctrlr->rirb = NULL; + } /* Unmap registers */ if (ctrlr->regs_area >= 0) { @@ -542,5 +567,10 @@ ctrlr->regs_area = B_ERROR; ctrlr->regs = NULL; } + + /* Now delete all codecs */ + for (idx=0; idx < HDA_MAXCODECS; idx++) + if (ctrlr->codecs[idx] != NULL) + hda_codec_delete(ctrlr->codecs[idx]); } } From colacoder at mail.berlios.de Thu May 17 13:16:06 2007 From: colacoder at mail.berlios.de (colacoder at BerliOS) Date: Thu, 17 May 2007 13:16:06 +0200 Subject: [Haiku-commits] r21161 - haiku/trunk/src/add-ons/kernel/drivers/audio/hda Message-ID: <200705171116.l4HBG6Pt003734@sheep.berlios.de> Author: colacoder Date: 2007-05-17 13:16:05 +0200 (Thu, 17 May 2007) New Revision: 21161 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21161&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.c Log: Fixed the problem of not being able to work from Haiku. The main problem was that although the multi_audio API on BeOS hands the driver the settings as made in the Media prefs, the Haiku one just gives maximum values and assumes the driver will scale the values down. I didn't do that. If you run Haiku on HDA hardware, you should have sound now too! :) Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2007-05-17 08:23:42 UTC (rev 21160) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2007-05-17 11:16:05 UTC (rev 21161) @@ -30,6 +30,9 @@ #define MAX_CODEC_RESPONSES 10 #define MAXINPUTS 32 +/* FIXME: Find out why we need so much! */ +#define DEFAULT_FRAMESPERBUF 4096 + typedef struct hda_controller_s hda_controller; typedef struct hda_codec_s hda_codec; typedef struct hda_afg_s hda_afg; Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.c 2007-05-17 08:23:42 UTC (rev 21160) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.c 2007-05-17 11:16:05 UTC (rev 21161) @@ -153,13 +153,26 @@ dprintf("%s: record: %ld buffers, %ld channels, %ld samples\n", __func__, data->request_record_buffers, data->request_record_channels, data->request_record_buffer_size); + /* Workaround for Haiku multi_audio API, since it prefers to let the driver pick + values, while the BeOS multi_audio actually gives the user's defaults. */ if (data->request_playback_buffers > STRMAXBUF || - data->request_playback_buffers < STRMINBUF || - data->request_record_buffers > STRMAXBUF || + data->request_playback_buffers < STRMINBUF) { + data->request_playback_buffers = STRMINBUF; + } + + if (data->request_record_buffers > STRMAXBUF || data->request_record_buffers < STRMINBUF) { - return B_BAD_VALUE; + data->request_record_buffers = STRMINBUF; } + if (data->request_playback_buffer_size == 0) + data->request_playback_buffer_size = DEFAULT_FRAMESPERBUF; + + if (data->request_record_buffer_size == 0) + data->request_record_buffer_size = DEFAULT_FRAMESPERBUF; + + /* ... from here on, we can assume again that a reasonable request is being made */ + data->flags = 0; /* Copy the requested settings into the streams */ From stefano.ceccherini at gmail.com Thu May 17 13:32:43 2007 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Thu, 17 May 2007 13:32:43 +0200 Subject: [Haiku-commits] r21161 - haiku/trunk/src/add-ons/kernel/drivers/audio/hda In-Reply-To: <200705171116.l4HBG6Pt003734@sheep.berlios.de> References: <200705171116.l4HBG6Pt003734@sheep.berlios.de> Message-ID: <894b9700705170432h54d2f576r37720496e3cb173c@mail.gmail.com> 2007/5/17, colacoder at BerliOS : > Fixed the problem of not being able to work from Haiku. The main problem was that although the multi_audio API on BeOS hands the driver the settings as made in the Media prefs, the Haiku one just gives maximum values and assumes the driver will scale the values down. I didn't do that. Maybe we should fix our API to mimic what BeOS does, or is this intentional ? Jerome ? Marcus ? From nielx at mail.berlios.de Thu May 17 18:08:36 2007 From: nielx at mail.berlios.de (nielx at BerliOS) Date: Thu, 17 May 2007 18:08:36 +0200 Subject: [Haiku-commits] r21162 - haiku/trunk/docs/user/drivers Message-ID: <200705171608.l4HG8apV018897@sheep.berlios.de> Author: nielx Date: 2007-05-17 18:08:33 +0200 (Thu, 17 May 2007) New Revision: 21162 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21162&view=rev Modified: haiku/trunk/docs/user/drivers/USB3.dox haiku/trunk/docs/user/drivers/usb_modules.dox Log: First iteration of the documentation that describes how to write drivers that use the USB module. Modified: haiku/trunk/docs/user/drivers/USB3.dox =================================================================== --- haiku/trunk/docs/user/drivers/USB3.dox 2007-05-17 11:16:05 UTC (rev 21161) +++ haiku/trunk/docs/user/drivers/USB3.dox 2007-05-17 16:08:33 UTC (rev 21162) @@ -1,477 +1,669 @@ -/* - * Copyright 2007, Haiku, Inc. All Rights Reserved. - * Distributed under the terms of the MIT License. - * - * Documentation by: - * Niels Sascha Reedijk - * Corresponds to: - * /trunk/headers/os/drivers/USB3.h rev 19915 - */ - -/*! - \file USB3.h - \ingroup drivers - \brief Interface for the USB module. -*/ - -/*! - \typedef struct usb_module_info usb_module_info - \brief The main interface object. See the usb_module_info documentation. -*/ - -/*! - \typedef uint32 usb_id - \brief Uniquely identify various USB objects that are used in the module. -*/ - -/*! - \typedef usb_id usb_device - \brief Uniquely identify USB devices. -*/ - -/*! - \typedef usb_id usb_interface - \brief Uniquely identify USB interfaces. -*/ - -/*! - \typedef usb_id usb_pipe - \brief Uniquely identify USB pipes. -*/ - -/*! - \typedef struct usb_endpoint_info usb_endpoint_info - \brief Container for USB endpoint descriptors. - \see Documentation for usb_endpoint_info. -*/ - -/*! - \typedef struct usb_interface_info usb_interface_info - \brief Container for USB interface descriptors. - \see Documentation for usb_interface_info. -*/ - -/*! - \typedef usb_interface_list usb_interface_list - \brief Container that holds a list of USB interface descriptors. - \see Documentation for usb_interface_list. -*/ - -/*! - \typedef struct usb_configuration_info usb_configuration_info - \brief Container for USB configuration descriptors. - \see Documentation for usb_configuration_info. -*/ - -///// usb_notify_hooks ///// - -/*! - \struct usb_notify_hooks - \brief Hooks that the USB stack can callback in case of events. -*/ - -/*! - \fn status_t (*usb_notify_hooks::device_added)(usb_device device, void **cookie) - \brief Called by the stack in case a device is added. - - As soon as you have registered hooks using the - usb_module_info::install_notify() method, this hook will be called as soon as - a device is inserted that matches your provided usb_support_descriptor. - - \param device A unique id that identifies this USB device. - \param[in] cookie You can store a pointer to an object in this variable. - When the device is removed, this cookie will be provided to you. - \return You should return \c B_OK in case of success. If you return an error - value, the \a device id will become invalid and you will not be notified if - this device is removed. - \see device_removed() -*/ - -/*! - \var status_t (*usb_notify_hooks::device_removed)(void *cookie) - \brief Called by the stack in case a device you are using is removed. - - If you have accepted a device in the device_added() hook, this hook will - be called as soon as the device is removed. - - \param cookie The cookie you provided in the device_added() hook. Make sure - that you free the cookie, if necessary. - \return Currently the return value of this hook is ignored. It is recommended - to return \c B_OK though. -*/ - -///// usb_support_descriptor ///// - -/*! - \struct usb_support_descriptor - \brief Description of device descriptor that the driver can handle. - - Support descriptors can be used to match any form of class, subclass or - protocol, or a vendor and/or product. If any field has the value \c 0, it - is treated as a wildcard. - - For example, if you want to watch for all the hubs, which have a device - class of \c 0x09, you would pass this descriptor: - - \code - usb_support_descriptor hub_devs = { 9, 0, 0, 0, 0 }; - \endcode - - See usb_module_info::register_driver() for more information on how to use - this object. -*/ - -/*! - \var usb_support_descriptor::dev_class - \brief The supported device classes. -*/ - -/*! - \var usb_support_descriptor::dev_subclass - \brief The suported device subclasses. -*/ - -/*! - \var usb_support_descriptor::dev_protocol - \brief The supported device protocols. -*/ - -/*! - \var usb_support_descriptor::vendor - \brief The supported device vendor. -*/ - -/*! - \var usb_support_descriptor::product - \brief The supported device products. -*/ - -///// usb_endpoint_info ///// - -///// usb_interface_info ///// - -///// usb_interface_list ///// - -///// usb_configuration_info ///// - -///// usb_iso_packet_descriptor ///// - -///// usb_callback_func ///// - -/*! - \typedef typedef void (*usb_callback_func)(void *cookie, status_t status, void *data, size_t actualLength) - \brief Callback function for asynchronous transfers. - - \param cookie The cookie you supplied when you queued the transfer. - \param status The status of the transfer (whether it succeeded or not). - \param data The provided buffer. - \param actualLength The amount of bytes read or written during the transfer. -*/ - -///// usb_module_info ///// - -/*! - \struct usb_module_info - \brief Interface for drivers to interact with Haiku's USB stack. -*/ - -/*! - \var usb_module_info::binfo - \brief Instance of the bus_manager_info object. -*/ - -/*! - \fn status_t (*usb_module_info::register_driver)(const char *driverName, const usb_support_descriptor *supportDescriptors, size_t supportDescriptorCount, const char *optionalRepublishDriverName) - \brief Register your driver. - - To let the USB stack know that a driver is available to support devices, a - driver needs to register itself first. To let the stack know which devices - it needs to notify the driver of, have a look at usb_support_descriptor. - - It is possible to supply a list of support constructors. You should allocate - an array of support constructors, and give the amount of constructors in the - array using the \a supportDescriptorCount parameter. - - In case your driver supports all devices, or more likely, in case you want to - monitor all devices plugged in and removed, it is safe to pass \c NULL to the - \a supportDescriptors paramater and zero (0) to \a supportDescriptorCount. - - \param driverName A unique name that identifies your driver. Avoid names like - \c webcam or \c mouse, instead use vendor names and device types to avoid - nameclashes. The install_notify() and uninstall_notify() functions use the - driver name as an identifier. - \param supportDescriptors An array of the type usb_support_descriptor. Pass - the amount of objects in the next parameter. - \param supportDescriptorCount The number of objects in the array supplied in - the previous parameter. - \param optionalRepublishDriverName Undocumented parameter. It is safe to - pass \c NULL. - \retval B_OK The driver is registered. You can now call install_notify() - \retval B_BAD_VALUE You passed \c NULL as \a driverName. - \retval B_ERROR General internal error in the USB stack. You may retry the - request in this case. - \retval B_NO_MEMORY Error allocating some internal objects. The system is - out of memory. -*/ - -/*! - \fn status_t (*usb_module_info::install_notify)(const char *driverName, const usb_notify_hooks *hooks) - \brief Install notify hooks for your driver. - - After your driver is registered, you need to pass hooks to your driver that - are called whenever a device that matches your \link usb_support_descriptor - support descriptor \endlink . - - As soon as the hooks are installed you'll receive callbacks for devices that - are already attached, so make sure your driver is initialized properly when - calling this method. - - \param driverName The name you passed in register_driver(). - \param hooks The hooks the stack should call in case the status of devices - that match your support descriptor changes. - \retval B_OK Hooks are installed succesfully. - \retval B_NAME_NOT_FOUND Invalid \a driverName. - - \see usb_notify_hooks for information on how your hooks should behave. - \see uninstall_notify() -*/ - -/*! - \fn status_t (*usb_module_info::uninstall_notify)(const char *driverName) - \brief Uninstall notify hooks for your driver. - - If your driver needs to stop, you can uninstall the notifier hooks. This will - clear the stored hooks in the driver and you will not receive any - notifications when new devices are attached. This method will also call - usb_notify_hooks::device_removed() for all the devices that you are using and - all the stack's resources that are allocated to your driver are cleared. - - \param driverName The name you passed in register_driver(). - \retval B_OK Hooks are uninstalled. - \retval B_NAME_NOT_FOUND Invalid \a driverName. -*/ - -/*! - \fn const usb_device_descriptor *(*usb_module_info::get_device_descriptor)(usb_device device) - \brief Get the device descriptor. - - \param device The id of the device you want to query. - \return The standard usb_device_descriptor, or \c NULL in case of an error. -*/ - -/*! - \fn const usb_configuration_info *(*usb_module_info::get_nth_configuration)(usb_device device, uint index) - \brief Get a configuration descriptor by index. - - \param device The id of the device you want to query. - \param index The (zero based) offset of the list of configurations. - \return The usb_configuration_info with the standard usb configuration - descriptor, or \c NULL if the \a id is invalid or the \a index is out of - bounds. -*/ - -/*! - \fn const usb_configuration_info *(*usb_module_info::get_configuration)(usb_device device) - \brief Get the current configuration. - - \param id The id of the device you want to query. - \retval The usb_configuration_info with the standard usb configuration - descriptor, or \c NULL if the \a id is invalid. -*/ - -/*! - \fn status_t (*usb_module_info::set_configuration)(usb_device device, const usb_configuration_info *configuration) - \brief Change the current configuration. - - Changing the configuration will destroy all the current endpoints. If the - \a configuration points to the current configuration, the request will be - ignored and \c B_OK will be returned. - - \param device The id of the device you want to query. - \param configuration The pointer to the new configuration you want to set. - \retval B_OK The new configuration is set succesfully. - \retval B_DEV_INVALID_PIPE The \a device parameter is invalid. - \retval B_BAD_VALUE The configuration does not exist. - - \note This method also allows you to completely unconfigure the device, which - means that all the current endpoints, pipes and transfers will be freed. - Pass \c NULL to the parameter \a configuration if you want to do that. -*/ - -/*! - \fn status_t (*usb_module_info::set_alt_interface)(usb_device device, const usb_interface_info *interface) - \brief Set an alternative interface. Not implemented. - - This method currently always returns \c B_ERROR. -*/ - -/*! - \fn status_t (*usb_module_info::set_feature)(usb_id handle, uint16 selector) - \brief Convenience function for standard control pipe set feature requests. - - Both the set_feature() and clear_feature() requests work on all the Stack's - objects: devices, interfaces and pipes. - - \param handle The object you want to query. - \param selector The value you want to pass in the feature request. - \return \c B_OK in case the request succeeded and the device responded - positively, or an error code in case it failed. -*/ - -/*! - \fn status_t (*usb_module_info::clear_feature)(usb_id handle, uint16 selector) - \brief Convenience function for standard control pipe clear feature requests. - - \see set_feature() to see how this method works. -*/ - -/*! - \fn status_t (*usb_module_info::get_status)(usb_id handle, uint16 *status) - \brief Convenience function for standard usb status requests. - - \param[in] handle The object you want to query. - \param[out] status A variable in which the device can store it's status. - \return \c B_OK in case the request succeeded and the device responded - positively, or an error code in case it failed. -*/ - -/*! - \fn status_t (*usb_module_info::get_descriptor)(usb_device device, uint8 descriptorType, uint8 index, uint16 languageID, void *data, size_t dataLength, size_t *actualLength) - \brief Convenience function to get a descriptor from a device. - - \param[in] device The device you want to query. - \param[in] descriptorType The type of descriptor you are requesting. - \param[in] index In case there are multiple descriptors of this type, you - select which one you want. - \param[in] languageID The language you want the descriptor in (if applicable, - like with string_descriptors). - \param[out] data The buffer in which the descriptor can be written. - \param[in] dataLength The size of the buffer (in bytes). - \param[out] actualLength A pointer to a variable in which the actual number - of bytes written can be stored. - \retval B_OK The request succeeded, and the descriptor is written. - \retval B_DEV_INVALID_PIPE Invalid \a device parameter. - \retval "other errors" Request failed. -*/ - -/*! - \fn status_t (*usb_module_info::send_request)(usb_device device, uint8 requestType, uint8 request, uint16 value, uint16 index, uint16 length, void *data, size_t *actualLength) - \brief Send a generic, synchronous request over the default control pipe. - - See queue_request() for an asynchronous version of this method. - - Most of the standard values of a request are defined in USB_spec.h. - - \param[in] device The device you want to query. - \param[in] requestType The request type. - \param[in] request The request you want to perform. - \param[in] value The value of the request. - \param[in] index The index for the request. - \param[in] length The size of the buffer pointed by \a data - \param[out] data The buffer where to put the result in. - \param[out] actualLength The actual numbers of bytes written. - - \retval B_OK The request succeeded. - \retval B_DEV_INVALID_PIPE Invalid \a device parameter. - \retval "other errors" Request failed. -*/ - -/*! - \fn status_t (*usb_module_info::queue_interrupt)(usb_pipe pipe, void *data, size_t dataLength, usb_callback_func callback, void *callbackCookie) - \brief Asynchronously queue an interrupt transfer. - - \param pipe The id of the pipe you want to query. - \param data The data buffer you want to pass. - \param dataLength The size of the data buffer. - \param callback The callback function the stack should call after finishing. - \param callbackCookie A cookie that will be supplied to your callback - function when the transfer is finished. - - \return Whether or not the queueing of the transfer went well. The return - value won't tell you if the transfer actually succeeded. - \retval B_OK The interrupt transfer is queued. - \retval B_NO_MEMORY Error allocating objects. - \retval B_DEV_INVALID_PIPE The \a pipe is invalid. -*/ - -/*! - \fn status_t (*usb_module_info::queue_bulk)(usb_pipe pipe, void *data, size_t dataLength, usb_callback_func callback, void *callbackCookie) - \brief Asynchronously queue a bulk transfer. - - This method behaves like the queue_interrupt() method, except that it queues - a bulk transfer. -*/ - -/*! - \fn status_t (*usb_module_info::queue_bulk_v)(usb_pipe pipe, iovec *vector, size_t vectorCount, usb_callback_func callback, void *callbackCookie) - \brief Asynchronously queue a bulk vector. - - This method behaves like the queue_interrupt() method, except that it queues - bulk transfers and that it is based on an (array of) io vectors. - - \param vector One or more io vectors. IO vectors are standard POSIX entities. - \param vectorCount The number of elements in the \a vector array. -*/ - -/*! - \fn status_t (*usb_module_info::queue_isochronous)(usb_pipe pipe, void *data, size_t dataLength, usb_iso_packet_descriptor *packetDesc, uint32 packetCount, uint32 *startingFrameNumber, uint32 flags, usb_callback_func callback, void *callbackCookie) - \brief Asynchronously queue a isochronous transfer. Not implemented. - - Not implemented in the current Haiku USB Stack. -*/ - -/*! - \fn status_t (*usb_module_info::queue_request)(usb_device device, uint8 requestType, uint8 request, uint16 value, uint16 index, uint16 length, void *data, usb_callback_func callback, void *callbackCookie) - \brief Asynchronously queue a control pipe request. - - This method does roughly the same as send_request(), however, it works - asynchronously. This means that the method will return as soon as the - transfer is queued. - - \param callback The callback function for when the transfer is done. - \param callbackCookie The cookie that the stack should pass to your callback - function. - \return Whether or not the queueing of the transfer went well. The return - value won't tell you if the transfer actually succeeded. - \retval B_OK The control transfer is queued. - \retval B_NO_MEMORY Error allocating objects. - \retval B_DEV_INVALID_PIPE The \a callback is invalid. -*/ - -/*! - \fn status_t (*usb_module_info::set_pipe_policy)(usb_pipe pipe, uint8 maxNumQueuedPackets, uint16 maxBufferDurationMS, uint16 sampleSize) - \brief Set some pipe features. - - The USB standard specifies some properties that should be able to be set on - isochronous pipes. If your driver requires the properties to be changed, you - should use this method. - - \param pipe The id of the isochronous pipe you want to alter. - \param maxNumQueuedPackets The maximum number of queued packets allowed on - this pipe. - \param maxBufferDurationMS The maximum time in ms that the buffers are valid. - \param sampleSize The size of the samples through this pipe. - \retval B_OK Pipe policy changed. - \retval B_DEV_INVALID_PIPE The \a pipe argument is invalid or not an - isochronous pipe. -*/ - -/*! - \fn status_t (*usb_module_info::cancel_queued_transfers)(usb_pipe pipe) - \brief Cancel pending transfers. Not Implemented. - - Call this method to cancel pending transfers in a \a pipe. - - \warning This is currently not implemented! - - \param pipe The id of the pipe to clear. The method will always return - \c B_ERROR. -*/ - -/*! - \fn status_t (*usb_module_info::usb_ioctl)(uint32 opcode, void *buffer, size_t bufferSize) - \brief Low level commands to the USB stack. - - This method is used to give lowlevel commands to the Stack. There are - currently no uses documented. -*/ +/* + * Copyright 2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Documentation by: + * Niels Sascha Reedijk + * Corresponds to: + * /trunk/headers/os/drivers/USB3.h rev 19915 + */ + +/*! + \file USB3.h + \ingroup drivers + \brief Interface for the USB module. +*/ + +/*! + \typedef struct usb_module_info usb_module_info + \brief The main interface object. See the usb_module_info documentation. +*/ + +/*! + \typedef uint32 usb_id + \brief Uniquely identify various USB objects that are used in the module. +*/ + +/*! + \typedef usb_id usb_device + \brief Uniquely identify USB devices. +*/ + +/*! + \typedef usb_id usb_interface + \brief Uniquely identify USB interfaces. +*/ + +/*! + \typedef usb_id usb_pipe + \brief Uniquely identify USB pipes. +*/ + +/*! + \typedef struct usb_endpoint_info usb_endpoint_info + \brief Container for USB endpoint descriptors. + \see Documentation for usb_endpoint_info. +*/ + +/*! + \typedef struct usb_interface_info usb_interface_info + \brief Container for USB interface descriptors. + \see Documentation for usb_interface_info. +*/ + +/*! + \typedef usb_interface_list usb_interface_list + \brief Container that holds a list of USB interface descriptors. + \see Documentation for usb_interface_list. +*/ + +/*! + \typedef struct usb_configuration_info usb_configuration_info + \brief Container for USB configuration descriptors. + \see Documentation for usb_configuration_info. +*/ + +///// usb_notify_hooks ///// + +/*! + \struct usb_notify_hooks + \brief Hooks that the USB stack can callback in case of events. +*/ + +/*! + \fn status_t (*usb_notify_hooks::device_added)(usb_device device, void **cookie) + \brief Called by the stack in case a device is added. + + As soon as you have registered hooks using the + usb_module_info::install_notify() method, this hook will be called as soon as + a device is inserted that matches your provided usb_support_descriptor. + + \param device A unique id that identifies this USB device. + \param[in] cookie You can store a pointer to an object in this variable. + When the device is removed, this cookie will be provided to you. + \return You should return \c B_OK in case of success. The USB stack will then + request the kernel to republish your device names, so that the new device + will be shown in the \c /dev tree. If you return an error value, the + \a device id will become invalid and you will not be notified if this + device is removed. + \see device_removed() +*/ + +/*! + \var status_t (*usb_notify_hooks::device_removed)(void *cookie) + \brief Called by the stack in case a device you are using is removed. + + If you have accepted a device in the device_added() hook, this hook will + be called as soon as the device is removed. + + \param cookie The cookie you provided in the device_added() hook. Make sure + that you free the cookie, if necessary. + \return Currently the return value of this hook is ignored. It is recommended + to return \c B_OK though. +*/ + +///// usb_support_descriptor ///// + +/*! + \struct usb_support_descriptor + \brief Description of device descriptor that the driver can handle. + + Support descriptors can be used to match any form of class, subclass or + protocol, or a vendor and/or product. If any field has the value \c 0, it + is treated as a wildcard. + + For example, if you want to watch for all the hubs, which have a device + class of \c 0x09, you would pass this descriptor: + + \code + usb_support_descriptor hub_devs = { 9, 0, 0, 0, 0 }; + \endcode + + See usb_module_info::register_driver() for more information on how to use + this object. +*/ + +/*! + \var usb_support_descriptor::dev_class + \brief The supported device classes. +*/ + +/*! + \var usb_support_descriptor::dev_subclass + \brief The suported device subclasses. +*/ + +/*! + \var usb_support_descriptor::dev_protocol + \brief The supported device protocols. +*/ + +/*! + \var usb_support_descriptor::vendor + \brief The supported device vendor. +*/ + +/*! + \var usb_support_descriptor::product + \brief The supported device products. +*/ + +///// usb_endpoint_info ///// + +/*! + \struct usb_endpoint_info + \brief Container for endpoint descriptors and their Haiku USB stack + identifiers. +*/ + +/*! + \var usb_endpoint_descriptor *usb_endpoint_info::descr + \brief Pointer to the descriptor of the endpoint. +*/ + +/*! + \var usb_pipe usb_endpoint_info::handle + \brief Handle to use when using the stack to transfer data to and from this + endpoint. +*/ + +///// usb_interface_info ///// + +/*! + \struct usb_interface_info + \brief Container for interface descriptors and their Haiku USB stack + identifiers. +*/ + +//! @{ + +/*! + \var usb_interface_descriptor *usb_interface_info::descr + \brief Pointer to the descriptor of the interface. +*/ + +/*! + \var usb_interface usb_interface_info::handle + \brief Handle to use when using the stack to manipulate this interface. +*/ + +//! @} + +/*! + \name Endpoints +*/ + +//! @{ + +/*! + \var size_t usb_interface_info::endpoint_count + \brief The number of endpoints in this interface. +*/ + +/*! + \var usb_endpoint_info *usb_interface_info::endpoint + \brief An array of endpoints that are associated to this interface. +*/ + +//! @} + +/*! + \name Unparsed descriptors +*/ + +//! @{ + +/*! + \var size_t usb_interface_info::generic_count + \brief The number of unparsed descriptors in this interface. +*/ + +/*! + \var usb_descriptor **usb_interface_info::generic + \brief Unparsed descriptors in this interface. +*/ + +//! @} + +///// usb_interface_list ///// + +/*! + \struct usb_interface_list + \brief List of interfaces available to a configuration. +*/ + +/*! + \var size_t usb_interface_list::alt_count + \brief Number of available interfaces. +*/ + +/*! + \var usb_interface_info *usb_interface_list::alt + \brief Array of available interfaces. +*/ + +/*! + \var usb_interface_info *usb_interface_list::active + \brief Pointer to active interface. +*/ + +///// usb_configuration_info ///// + +/*! + \struct usb_configuration_info + \brief Container for a specific configuration descriptor of a device. +*/ + +/*! + \var usb_configuration_descriptor *usb_configuration_info::descr + \brief The configuration descriptor. +*/ + +/*! + \var size_t usb_configuration_info::interface_count + \brief The number of interfaces in this configuration. +*/ + +/*! + \var usb_interface_list *usb_configuration_info::interface + \brief The list of interfaces available to this configuration. +*/ + +///// usb_iso_packet_descriptor ///// + +/*! + \struct usb_iso_packet_descriptor + \brief The descriptor for data packets of isochronous transfers. +*/ + +/*! + \var int16 usb_iso_packet_descriptor::req_len + \brief Length of the request. +*/ + +/*! + \var int16 usb_iso_packet_descriptor::act_len + \brief The USB stack writes the actual transferred length in this variable. +*/ + +/*! + \var status_t usb_iso_packet_descriptor::status + \brief The status of the transfer. +*/ + +///// usb_callback_func ///// + +/*! + \typedef typedef void (*usb_callback_func)(void *cookie, status_t status, void *data, size_t actualLength) + \brief Callback function for asynchronous transfers. + + \param cookie The cookie you supplied when you queued the transfer. + \param status The status of the transfer. This is one of the following: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
B_OKTransfer succeeded.
B_CANCELEDTransfer cancelled by the user via a + usb_module_info::cancel_queued_transfers() call.
B_DEV_MULTIPLE_ERRORSMore than one of the errors + below. Unfortunately, the stack cannot give you more information.
B_DEV_STALLEDThe endpoint is stalled. You can use + usb_module_info::clear_feature() method with the associated pipe and + the USB_FEATURE_ENDPOINT_HALT arguments.
B_DEV_DATA_OVERRUNIncoming transfer: more data + flowing in than the size of the buffer.
B_DEV_DATA_UNDERRUNOutgoing transfer: more data + flowing out than the endpoint accepts.
B_DEV_CRC_ERRORThe internal data consistency + checks of the USB protocol failed. You are best to retry. If you keep + on getting this error, there might be something wrong with the + device.
B_DEV_UNEXPECTED_PIDInternal error. You should + retry your transfer.
B_DEV_FIFO_OVERRUNInternal error. You should + retry your transfer.
B_DEV_FIFO_UNDERRUNInternal error. You should + retry your transfer.
+ \param data The provided buffer. + \param actualLength The amount of bytes read or written during the transfer. +*/ + +///// usb_module_info ///// + +/*! + \struct usb_module_info + \brief Interface for drivers to interact with Haiku's USB stack. +*/ + +/*! + \var usb_module_info::binfo + \brief Instance of the bus_manager_info object. +*/ + +/*! + \fn status_t (*usb_module_info::register_driver)(const char *driverName, const usb_support_descriptor *supportDescriptors, size_t supportDescriptorCount, const char *optionalRepublishDriverName) + \brief Register your driver. + + To let the USB stack know that a driver is available to support devices, a + driver needs to register itself first. To let the stack know which devices + it needs to notify the driver of, have a look at usb_support_descriptor. + + It is possible to supply a list of support constructors. You should allocate + an array of support constructors, and give the amount of constructors in the + array using the \a supportDescriptorCount parameter. + + In case your driver supports all devices, or more likely, in case you want to + monitor all devices plugged in and removed, it is safe to pass \c NULL to the + \a supportDescriptors paramater and zero (0) to \a supportDescriptorCount. + + \param driverName A unique name that identifies your driver. Avoid names like + \c webcam or \c mouse, instead use vendor names and device types to avoid + nameclashes. The install_notify() and uninstall_notify() functions use the + driver name as an identifier. + \param supportDescriptors An array of the type usb_support_descriptor. Pass + the amount of objects in the next parameter. + \param supportDescriptorCount The number of objects in the array supplied in + the previous parameter. + \param optionalRepublishDriverName Unused parameter. You should pass \c NULL. + \retval B_OK The driver is registered. You can now call install_notify() + \retval B_BAD_VALUE You passed \c NULL as \a driverName. + \retval B_ERROR General internal error in the USB stack. You may retry the + request in this case. + \retval B_NO_MEMORY Error allocating some internal objects. The system is + out of memory. +*/ + +/*! + \fn status_t (*usb_module_info::install_notify)(const char *driverName, const usb_notify_hooks *hooks) + \brief Install notify hooks for your driver. + + After your driver is registered, you need to pass hooks to your driver that + are called whenever a device that matches your \link usb_support_descriptor + support descriptor \endlink . + + As soon as the hooks are installed you'll receive callbacks for devices that + are already attached, so make sure your driver is initialized properly when + calling this method. + + \param driverName The name you passed in register_driver(). + \param hooks The hooks the stack should call in case the status of devices + that match your support descriptor changes. + \retval B_OK Hooks are installed succesfully. + \retval B_NAME_NOT_FOUND Invalid \a driverName. + + \see usb_notify_hooks for information on how your hooks should behave. + \see uninstall_notify() +*/ + +/*! + \fn status_t (*usb_module_info::uninstall_notify)(const char *driverName) + \brief Uninstall notify hooks for your driver. + + If your driver needs to stop, you can uninstall the notifier hooks. This will + clear the stored hooks in the driver and you will not receive any + notifications when new devices are attached. This method will also call + usb_notify_hooks::device_removed() for all the devices that you are using and + all the stack's resources that are allocated to your driver are cleared. + + \param driverName The name you passed in register_driver(). + \retval B_OK Hooks are uninstalled. + \retval B_NAME_NOT_FOUND Invalid \a driverName. +*/ + +/*! + \fn const usb_device_descriptor *(*usb_module_info::get_device_descriptor)(usb_device device) + \brief Get the device descriptor. + + \param device The id of the device you want to query. + \return The standard usb_device_descriptor, or \c NULL in case of an error. +*/ + +/*! + \fn const usb_configuration_info *(*usb_module_info::get_nth_configuration)(usb_device device, uint index) + \brief Get a configuration descriptor by index. + + \param device The id of the device you want to query. + \param index The (zero based) offset of the list of configurations. + \return The usb_configuration_info with the standard usb configuration + descriptor, or \c NULL if the \a id is invalid or the \a index is out of + bounds. +*/ + +/*! + \fn const usb_configuration_info *(*usb_module_info::get_configuration)(usb_device device) + \brief Get the current configuration. + + \param id The id of the device you want to query. + \retval The usb_configuration_info with the standard usb configuration + descriptor, or \c NULL if the \a id is invalid. +*/ + +/*! + \fn status_t (*usb_module_info::set_configuration)(usb_device device, const usb_configuration_info *configuration) + \brief Change the current configuration. + + Changing the configuration will destroy all the current endpoints. If the + \a configuration points to the current configuration, the request will be + ignored and \c B_OK will be returned. + + \param device The id of the device you want to query. + \param configuration The pointer to the new configuration you want to set. + \retval B_OK The new configuration is set succesfully. + \retval B_DEV_INVALID_PIPE The \a device parameter is invalid. + \retval B_BAD_VALUE The configuration does not exist. + + \note This method also allows you to completely unconfigure the device, which + means that all the current endpoints, pipes and transfers will be freed. + Pass \c NULL to the parameter \a configuration if you want to do that. +*/ + +/*! + \fn status_t (*usb_module_info::set_alt_interface)(usb_device device, const usb_interface_info *interface) + \brief Set an alternative interface. Not implemented. + + This method currently always returns \c B_ERROR. +*/ + +/*! + \fn status_t (*usb_module_info::set_feature)(usb_id handle, uint16 selector) + \brief Convenience function for standard control pipe set feature requests. + + Both the set_feature() and clear_feature() requests work on all the Stack's + objects: devices, interfaces and pipes. + + \param handle The object you want to query. + \param selector The value you want to pass in the feature request. + \return \c B_OK in case the request succeeded and the device responded + positively, or an error code in case it failed. +*/ + +/*! + \fn status_t (*usb_module_info::clear_feature)(usb_id handle, uint16 selector) + \brief Convenience function for standard control pipe clear feature requests. + + \see set_feature() to see how this method works. +*/ + +/*! + \fn status_t (*usb_module_info::get_status)(usb_id handle, uint16 *status) + \brief Convenience function for standard usb status requests. + + \param[in] handle The object you want to query. + \param[out] status A variable in which the device can store it's status. + \return \c B_OK in case the request succeeded and the device responded + positively, or an error code in case it failed. +*/ + +/*! + \fn status_t (*usb_module_info::get_descriptor)(usb_device device, uint8 descriptorType, uint8 index, uint16 languageID, void *data, size_t dataLength, size_t *actualLength) + \brief Convenience function to get a descriptor from a device. [... truncated: 563 lines follow ...] From imker at mail.berlios.de Thu May 17 22:05:39 2007 From: imker at mail.berlios.de (imker at BerliOS) Date: Thu, 17 May 2007 22:05:39 +0200 Subject: [Haiku-commits] r21163 - haiku/trunk/src/add-ons/kernel/busses/scsi/usb Message-ID: <200705172005.l4HK5dm5018822@sheep.berlios.de> Author: imker Date: 2007-05-17 22:05:38 +0200 (Thu, 17 May 2007) New Revision: 21163 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21163&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/usb/usb_scsi.c Log: That's one small step for man... ;-) - module interface was changed to be compatible with Haiku API. Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/usb/usb_scsi.c =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/scsi/usb/usb_scsi.c 2007-05-17 16:08:33 UTC (rev 21162) +++ haiku/trunk/src/add-ons/kernel/busses/scsi/usb/usb_scsi.c 2007-05-17 20:05:38 UTC (rev 21163) @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include "device_info.h" #include "settings.h" #include "transform_procs.h" @@ -31,6 +33,8 @@ #include "fake_device.h" #include "sg_buffer.h" + +#if 0 status_t device_added(const usb_device device, void **cookie); status_t device_removed(void *cookie); @@ -52,7 +56,7 @@ static long path_id = -1; static int32 load_count = 0; -static char sim_vendor_name[] = "S.Zharski"; /* who wrote this driver */ +static char sim_vendor_name[] = "Haiku"; /* who wrote this driver */ static char hba_vendor_name[] = "USB"; /* who made the hardware */ static char controller_family[] = "USB SCSI"; /* what family of products */ @@ -893,6 +897,8 @@ } return status; } +#endif + /** \fn:std_ops \param op: operation to be performed on this module @@ -906,15 +912,16 @@ */ static status_t std_ops(int32 op, ...) { - int i; - status_t status = B_ERROR; - CAM_SIM_ENTRY entry; + //int i; + status_t status = B_OK;//B_ERROR; + //CAM_SIM_ENTRY entry; switch(op) { - case B_MODULE_INIT: - if(0 == atomic_add(&load_count, 1)){ - thread_info tinfo = {0}; + case B_MODULE_INIT: + TRACE_ALWAYS("std_ops: B_MODULE_INIT called!\n"); + /* if(0 == atomic_add(&load_count, 1)){ + thread_info tinfo = {0}; */ load_module_settings(); - get_thread_info(find_thread(0), &tinfo); +/* get_thread_info(find_thread(0), &tinfo); if(!b_ignore_sysinit2 || (0 != strcmp(tinfo.name, "sysinit2"))){ create_log(); if(get_module(B_USB_MODULE_NAME, (module_info **)&usb) == B_OK){ @@ -941,10 +948,11 @@ } } else { atomic_add(&load_count, -1); - } + }*/ break; case B_MODULE_UNINIT: - if(1 == atomic_add(&load_count, -1)){ + TRACE_ALWAYS("std_ops: B_MODULE_UNINIT called!\n"); + /* if(1 == atomic_add(&load_count, -1)){ (*usb->uninstall_notify)(MODULE_NAME); status = B_OK; if(path_id != -1){ @@ -956,23 +964,253 @@ put_module(B_CAM_FOR_SIM_MODULE_NAME); } else { atomic_add(&load_count, 1); - } + }*/ break; } return status; } /** + * \fn: + * \param : + * \return: + * TODO + */ +static float +supports_device(device_node_handle parent, bool *_noConnection) +{ + TRACE_ALWAYS("supports_device\n"); + return 0.f; +} + +/** + * \fn: + * \param : + * \return: + * TODO + */ +static status_t +register_device(device_node_handle parent) +{ + TRACE_ALWAYS("register_device\n"); + return B_OK; +} + +/** + * \fn: + * \param : + * \return: + * TODO + */ +static status_t +init_module(device_node_handle node, void *user_cookie, void **_cookie) +{ + TRACE_ALWAYS("inti_driver\n"); + return B_OK; +} + +/** + * \fn: + * \param : + * \return: + * TODO + */ +static status_t +uninit_module(void *cookie) +{ + TRACE_ALWAYS("uninit_driver\n"); + return B_OK; +} + +/** + * \fn: + * \param : + * TODO + */ +static void +device_removed(device_node_handle node, void *cookie) +{ + TRACE_ALWAYS("device_removed\n"); +} + +/** + * \fn: + * \param : + * TODO + */ +static void +device_cleanup(device_node_handle node) +{ + TRACE_ALWAYS("device_cleanup\n"); +} + +/** + * \fn: + * \param : + * TODO + */ +static void +get_supported_paths(const char ***_busses, const char ***_devices) +{ + TRACE_ALWAYS("get_supported_path\n"); +} + +/** + * \fn: + * \param : + * TODO + */ +static void +scsi_io( scsi_sim_cookie cookie, scsi_ccb *ccb ) +{ + TRACE_ALWAYS("scsi_io\n"); +} + +/** + * \fn: + * \param : + * \return: + * TODO + */ +static uchar +abort( scsi_sim_cookie cookie, scsi_ccb *ccb_to_abort ) +{ + TRACE_ALWAYS("scsi_sim\n"); + return 0; +} + +/** + * \fn: + * \param : + * \return: + * TODO + */ +static uchar +reset_device( scsi_sim_cookie cookie, uchar target_id, uchar target_lun ) +{ + TRACE_ALWAYS("supports_device\n"); + return 0; +} + +/** + * \fn: + * \param : + * \return: + * TODO + */ +static uchar +term_io( scsi_sim_cookie cookie, scsi_ccb *ccb_to_terminate ) +{ + TRACE_ALWAYS("term_io\n"); + return 0; +} + +/** + * \fn: + * \param : + * \return: + * TODO + */ +static uchar +path_inquiry( scsi_sim_cookie cookie, scsi_path_inquiry *inquiry_data ) +{ + TRACE_ALWAYS("path_inquiry\n"); + return 0; +} + +/** + * \fn: + * \param : + * \return: + * TODO + */ +static uchar +scan_bus( scsi_sim_cookie cookie ) +{ + TRACE_ALWAYS("scan_bus\n"); + return 0; +} + +/** + * \fn: + * \param : + * \return: + * TODO + */ +static uchar +reset_bus( scsi_sim_cookie cookie ) +{ + TRACE_ALWAYS("reset_bus\n"); + return 0; +} + +/** + * \fn: + * \param : + * TODO + */ +static void +get_restrictions(scsi_sim_cookie cookie, uchar target_id, bool *is_atapi, bool *no_autosense, uint32 *max_blocks ) +{ + TRACE_ALWAYS("get_restrictions\n"); +} + +/** + * \fn: + * \param : + * \return: + * TODO + */ +static status_t +module_ioctl(scsi_sim_cookie cookie, uint8 targetID, uint32 op, void *buffer, size_t length) +{ + TRACE_ALWAYS("ioctl\n"); + return B_ERROR; +} + + +/** Declare our module_info so we can be loaded as a kernel module */ -static sim_module_info sim_usb_module = { - { "busses/scsi/usb/v1", 0, &std_ops } +static scsi_sim_interface usb_scsi_sim = { + { //driver_module_info + { // module_info + "busses/scsi/usb/device_v1", // is device_v1 really required? or v1 is enough? + 0, + &std_ops + }, + + supports_device, + register_device, + + init_module, // init_driver, + uninit_module, // uninit_driver, + + device_removed, + device_cleanup, + + get_supported_paths, + }, + + scsi_io, + abort, + reset_device, + term_io, + + path_inquiry, + scan_bus, + reset_bus, + + get_restrictions, + + module_ioctl //ioctl }; + /** Export module_info-s list */ _EXPORT module_info *modules[] = { - (module_info *) &sim_usb_module, + (module_info *) &usb_scsi_sim, NULL }; From imker at mail.berlios.de Thu May 17 22:06:45 2007 From: imker at mail.berlios.de (imker at BerliOS) Date: Thu, 17 May 2007 22:06:45 +0200 Subject: [Haiku-commits] r21164 - haiku/trunk/src/add-ons/kernel/busses/scsi/usb Message-ID: <200705172006.l4HK6jNn018937@sheep.berlios.de> Author: imker Date: 2007-05-17 22:06:45 +0200 (Thu, 17 May 2007) New Revision: 21164 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21164&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/usb/tracing.c Log: ANSI color switches removed from the log. Looks like not supported now. Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/usb/tracing.c =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/scsi/usb/tracing.c 2007-05-17 20:05:38 UTC (rev 21163) +++ haiku/trunk/src/add-ons/kernel/busses/scsi/usb/tracing.c 2007-05-17 20:06:45 UTC (rev 21164) @@ -154,7 +154,7 @@ { if(b_force || b_log){ va_list arg_list; - static char *prefix = "\33[35m"MODULE_NAME":\33[0m"; + static char *prefix = MODULE_NAME":"; static char buf[1024]; char *buf_ptr = buf; port_id pid = find_port(log_port_name); From zharik at gmx.li Thu May 17 22:24:17 2007 From: zharik at gmx.li (Siarzhuk Zharski) Date: Thu, 17 May 2007 22:24:17 +0200 Subject: [Haiku-commits] r20951 - in haiku/trunk/src/tests/add-ons/kernel: . busses busses/scsi busses/scsi/example In-Reply-To: <13309368483-BeMail@primary> References: <13309368483-BeMail@primary> Message-ID: <464CB9F1.4030107@gmx.li> Hi, Michael, it's me again. Michael Lotz wrote: >> Commiting an example SCSI driver written to understand the new SCSI >> API. But the module isn't used even when installed and linked as a boot >> > driver. > > As stated in the commit log, the module isn't picked up at boot. Does > anyone have an insight on how to get a SCSI SIM module used by the SCSI > subsystem? > I'd like to port over the usb_scsi module to the new SCSI module API to > get USB boot working, but the driver simply isn't used by the bus > manager. Any comments welcome. > Looks like the problem was in the "name" variable of the module_info structure. Your sample has "busses/scsi/example/v1" in this variable. I have replaced it with "busses/scsi/example/device_v1" and this bus module was loaded successfully. BTW I have to create the "boot symlink" too. To All: Any comments about this "device_v1" issue? Kind Regards, S.Zharski From zharik at gmx.li Thu May 17 22:31:52 2007 From: zharik at gmx.li (Siarzhuk Zharski) Date: Thu, 17 May 2007 22:31:52 +0200 Subject: [Haiku-commits] (no subject) In-Reply-To: <2923083435-BeMail@zon> References: <2923083435-BeMail@zon> Message-ID: <464CBBB8.2000501@gmx.li> Hi, Axel! Axel D?rfler wrote: > AFAICT the SCSI bus module is a passive module, just like IDE. You need > a driver that opens it, not the other way around. > Which driver do you meant here? Last week I have investigated the sources trying to solve this issue with not loaded usb_scsi and found that both ide and scsi controllers are handled in the same (SCSI-like) way. Probably current support from IDE/SCSI bus managers is enough for my need. At least I have my usb_scsi module loaded now. Please look into my previous mail for details. Thanks! Kind Regards, S.Zharski From axeld at pinc-software.de Thu May 17 23:27:25 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Thu, 17 May 2007 23:27:25 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r21163_-_haiku/trunk/src/add-ons/?= =?iso-8859-15?q?kernel/busses/scsi/usb?= In-Reply-To: <200705172005.l4HK5dm5018822@sheep.berlios.de> Message-ID: <31637423364-BeMail@zon> imker at BerliOS wrote: > That's one small step for man... ;-) > - module interface was changed to be compatible with Haiku API. Nice! Can it still be built for R5? Bye, Axel. From axeld at pinc-software.de Thu May 17 23:48:54 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Thu, 17 May 2007 23:48:54 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r21164_-_haiku/trunk/src/add-ons/?= =?iso-8859-15?q?kernel/busses/scsi/usb?= In-Reply-To: <200705172006.l4HK6jNn018937@sheep.berlios.de> Message-ID: <32926713927-BeMail@zon> imker at BerliOS wrote: > Log: > ANSI color switches removed from the log. Looks like not supported > now. In what way is it not supported? Even the KDL blue screen supports these flags in Haiku. Otherwise, the Terminal where you see the output is supposed to parse them. Bye, Axel. From axeld at pinc-software.de Thu May 17 23:46:23 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Thu, 17 May 2007 23:46:23 +0200 CEST Subject: [Haiku-commits] r20951 - in haiku/trunk/src/tests/add-ons/kernel: . busses busses/scsi busses/scsi/example In-Reply-To: <464CB9F1.4030107@gmx.li> Message-ID: <32775941748-BeMail@zon> Siarzhuk Zharski wrote: > > As stated in the commit log, the module isn't picked up at boot. > > Does > > anyone have an insight on how to get a SCSI SIM module used by the > > SCSI > > subsystem? > > I'd like to port over the usb_scsi module to the new SCSI module > > API to > > get USB boot working, but the driver simply isn't used by the bus > > manager. Any comments welcome. > Looks like the problem was in the "name" variable of the module_info > structure. Your sample has "busses/scsi/example/v1" in this variable. > I > have replaced it with "busses/scsi/example/device_v1" and this bus > module was loaded successfully. BTW I have to create the "boot > symlink" > too. > > To All: Any comments about this "device_v1" issue? Yes, that's how the device manager recognizes device driver modules - the "device_v1" names the interface that the driver is using. > Axel D?rfler wrote: > > AFAICT the SCSI bus module is a passive module, just like IDE. You > > need > > a driver that opens it, not the other way around. > Which driver do you meant here? Last week I have investigated the > sources trying to solve this issue with not loaded usb_scsi and found > that both ide and scsi controllers are handled in the same (SCSI- > like) > way. Probably current support from IDE/SCSI bus managers is enough > for > my need. At least I have my usb_scsi module loaded now. Please look > into > my previous mail for details. Unlike the R5 SCSI bus manager (AFAICT), ours is passive - you need a driver that uses the SCSI bus manager. By adding your driver to "boot" and exporting a device module (ie. "device_v1") you make sure it's picked up on startup, otherwise the system wouldn't know where to look for. It's a bit hard to use the new driver architecture at this point, as it's not really finished, and is not as easy to use as it should be (oh, and not documented). Bye, Axel. From zharik at gmx.li Fri May 18 08:57:08 2007 From: zharik at gmx.li (Siarzhuk Zharski) Date: Fri, 18 May 2007 08:57:08 +0200 Subject: [Haiku-commits] r21164 - haiku/trunk/src/add-ons/kernel/busses/scsi/usb In-Reply-To: <32926713927-BeMail@zon> References: <32926713927-BeMail@zon> Message-ID: <464D4E44.90102@gmx.li> Hi, Axel, 17.05.2007 23:48 you wrote: > imker at BerliOS wrote: > >> Log: >> ANSI color switches removed from the log. Looks like not supported >> now. >> > > In what way is it not supported? Even the KDL blue screen supports > these flags in Haiku. > Otherwise, the Terminal where you see the output is supposed to parse > them. Ups. I have not checked it, sorry. Frankly speaking, I have overview the syslog with vim and see no colors. :-) From other side - is such decoration really significant now? BTW, vim -g is also functional under Haiku. Unfortunately vim configuration files are looks like missing in default build. So there are no menus and colors and default proportional font looks a bit strange. :-) Was this already discussed? Kind Regards, S.Zharski From zharik at gmx.li Fri May 18 08:57:18 2007 From: zharik at gmx.li (Siarzhuk Zharski) Date: Fri, 18 May 2007 08:57:18 +0200 Subject: [Haiku-commits] r21163 - haiku/trunk/src/add-ons/kernel/busses/scsi/usb In-Reply-To: <31637423364-BeMail@zon> References: <31637423364-BeMail@zon> Message-ID: <464D4E4E.7010208@gmx.li> Hi, Axel, 17.05.2007 23:27 you wrote: > imker at BerliOS wrote: > >> That's one small step for man... ;-) >> - module interface was changed to be compatible with Haiku API. >> > > Nice! Can it still be built for R5? > As soon as complete mass storage support environment (ide/scsi bus managers, busses, scsi_dsk and scsi_cd drivers etc) is functional under R5, this module should work too. But if you meant compatibility with old R5 scsi bus manager I think it is not good idea to spend a lot time to back compatibility. Many usb mass storage devices are very sensitive to SCSI command sequence. They are not standard-compatible but Windows-compatible. And I'm afraid that the way R5's scsi_dsk work with SIMs is different from Haiku's one. I already have such problem when tried to adapt usb_scsi to work with CD devices. The scsi_cd driver from R5 has his own meaning about "right ways to work with scsi devices". ;-) Kind Regards, S.Zharski From zharik at gmx.li Fri May 18 09:08:41 2007 From: zharik at gmx.li (Siarzhuk Zharski) Date: Fri, 18 May 2007 09:08:41 +0200 Subject: [Haiku-commits] r20951 - in haiku/trunk/src/tests/add-ons/kernel: . busses busses/scsi busses/scsi/example In-Reply-To: <32775941748-BeMail@zon> References: <32775941748-BeMail@zon> Message-ID: <464D50F9.1000101@gmx.li> Hi, Axel, 17.05.2007 23:46 you wrote: > Siarzhuk Zharski wrote: > >> Axel D?rfler wrote: >> >>> AFAICT the SCSI bus module is a passive module, just like IDE. You >>> need >>> a driver that opens it, not the other way around. >>> >> Which driver do you meant here? Last week I have investigated the >> sources trying to solve this issue with not loaded usb_scsi and found >> that both ide and scsi controllers are handled in the same (SCSI- >> like) >> way. Probably current support from IDE/SCSI bus managers is enough >> for >> my need. At least I have my usb_scsi module loaded now. Please look >> into >> my previous mail for details. >> > > Unlike the R5 SCSI bus manager (AFAICT), ours is passive - you need a > driver that uses the SCSI bus manager. By adding your driver to "boot" > and exporting a device module (ie. "device_v1") you make sure it's > picked up on startup, otherwise the system wouldn't know where to look > for. > Hm. The "scsi_sim_interface" anyway encapsulate the "driver_module_info". So by exporting first one we have automatically exported driver_module_info too. The question is how much driver functionality will be required from this SIM. But let discuss this later - as soon as I'll dig deeper, OK? :-) > It's a bit hard to use the new driver architecture at this point, as > it's not really finished, and is not as easy to use as it should be > (oh, and not documented). > That cannot to stop us. ;-) Kind Regards, S.Zharski From bonefish at mail.berlios.de Fri May 18 17:59:06 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Fri, 18 May 2007 17:59:06 +0200 Subject: [Haiku-commits] r21165 - in haiku/trunk: . build/jam build/scripts headers/build headers/build/host headers/build/host/darwin src/tools src/tools/gensyscalls src/tools/keymap src/tools/makebootable/platform/bios_ia32 src/tools/rc src/tools/resattr Message-ID: <200705181559.l4IFx6N0029748@sheep.berlios.de> Author: bonefish Date: 2007-05-18 17:59:04 +0200 (Fri, 18 May 2007) New Revision: 21165 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21165&view=rev Added: haiku/trunk/headers/build/host/darwin/ haiku/trunk/headers/build/host/darwin/endian.h haiku/trunk/headers/build/host/darwin/regex.h Modified: haiku/trunk/build/jam/BuildSetup haiku/trunk/build/jam/MainBuildRules haiku/trunk/build/scripts/build_haiku_image haiku/trunk/configure haiku/trunk/headers/build/BeOSBuildCompatibility.h haiku/trunk/src/tools/Jamfile haiku/trunk/src/tools/gensyscalls/Jamfile haiku/trunk/src/tools/keymap/Jamfile haiku/trunk/src/tools/makebootable/platform/bios_ia32/Jamfile haiku/trunk/src/tools/rc/Jamfile haiku/trunk/src/tools/resattr/Jamfile Log: Patch by Morgan Howe (slightly modified): Several changes to support building on Mac OS X (Darwin). A problem with makebootable remains. Modified: haiku/trunk/build/jam/BuildSetup =================================================================== --- haiku/trunk/build/jam/BuildSetup 2007-05-17 20:06:45 UTC (rev 21164) +++ haiku/trunk/build/jam/BuildSetup 2007-05-18 15:59:04 UTC (rev 21165) @@ -335,9 +335,11 @@ HOST_UNARFLAGS ?= x ; # check the host platform compatibility -SetPlatformCompatibilityFlagVariables HOST_PLATFORM : HOST : host : linux freebsd ; +SetPlatformCompatibilityFlagVariables HOST_PLATFORM : HOST : host + : linux freebsd darwin ; -if $(HOST_PLATFORM) = linux || $(HOST_PLATFORM) = freebsd { +if $(HOST_PLATFORM) = linux || $(HOST_PLATFORM) = freebsd + || $(HOST_PLATFORM) = darwin { # don't use lex: otherwise rc will not work correctly if $(LEX) = lex { LEX = flex ; @@ -404,6 +406,7 @@ case haiku : HOST_DEBUG_FLAGS ?= -ggdb ; case linux : HOST_DEBUG_FLAGS ?= -ggdb ; case freebsd : HOST_DEBUG_FLAGS ?= -ggdb ; + case darwin : HOST_DEBUG_FLAGS ?= -ggdb ; case * : HOST_DEBUG_FLAGS ?= -g ; } @@ -465,10 +468,17 @@ HOST_LIBSUPC++ = supc++ ; } + if $(HOST_PLATFORM) = darwin { + HOST_LIBSUPC++ = gcc_s.1 ; + } + # Unlike glibc FreeBSD's libc doesn't have built-in regex support. if $(HOST_PLATFORM) = freebsd { HOST_LIBROOT += /usr/lib/libgnuregex.so ; + } else if $(HOST_PLATFORM) = darwin { + HOST_LIBROOT += /opt/local/lib/libgnuregex.dylib ; } + # The BeOS compilers define __INTEL__ respectively __POWERPC__. On the # build platform we need to make sure, this is also defined. @@ -635,6 +645,7 @@ case haiku : TARGET_DEFINES += HAIKU_TARGET_PLATFORM_HAIKU ; case linux : TARGET_DEFINES += HAIKU_TARGET_PLATFORM_LINUX ; case freebsd : TARGET_DEFINES += HAIKU_TARGET_PLATFORM_FREEBSD ; + case darwin : TARGET_DEFINES += HAIKU_TARGET_PLATFORM_DARWIN ; case libbe_test : TARGET_DEFINES += HAIKU_TARGET_PLATFORM_LIBBE_TEST ; } @@ -646,6 +657,7 @@ case haiku : HOST_DEFINES += HAIKU_HOST_PLATFORM_HAIKU ; case linux : HOST_DEFINES += HAIKU_HOST_PLATFORM_LINUX ; case freebsd : HOST_DEFINES += HAIKU_HOST_PLATFORM_FREEBSD ; + case darwin : HOST_DEFINES += HAIKU_HOST_PLATFORM_DARWIN ; } Modified: haiku/trunk/build/jam/MainBuildRules =================================================================== --- haiku/trunk/build/jam/MainBuildRules 2007-05-17 20:06:45 UTC (rev 21164) +++ haiku/trunk/build/jam/MainBuildRules 2007-05-18 15:59:04 UTC (rev 21165) @@ -457,8 +457,14 @@ local libs = $(3) ; BuildPlatformMain $(target) : $(sources) : $(libs) ; - LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ] - -shared -Xlinker -soname=\"$(target:G=)\" ; + + if $(HOST_PLATFORM) = darwin { + LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ] + -dynamic -dynamiclib -Xlinker -flat_namespace ; + } else { + LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ] + -shared -Xlinker -soname=\"$(target:G=)\" ; + } } rule BuildPlatformMergeObject Modified: haiku/trunk/build/scripts/build_haiku_image =================================================================== --- haiku/trunk/build/scripts/build_haiku_image 2007-05-17 20:06:45 UTC (rev 21164) +++ haiku/trunk/build/scripts/build_haiku_image 2007-05-18 15:59:04 UTC (rev 21165) @@ -56,7 +56,7 @@ echo if [ ! $updateOnly ]; then echo "Creating image ..." - dd if=/dev/zero of=$imagePath bs=1M count=$imageSize + dd if=/dev/zero of=$imagePath bs=1048576 count=$imageSize $bfsShell --initialize $imagePath Haiku $makebootable $imagePath fi Modified: haiku/trunk/configure =================================================================== --- haiku/trunk/configure 2007-05-17 20:06:45 UTC (rev 21164) +++ haiku/trunk/configure 2007-05-18 15:59:04 UTC (rev 21165) @@ -272,6 +272,7 @@ ;; Linux) buildPlatform=linux ;; FreeBSD) buildPlatform=freebsd ;; + Darwin) buildPlatform=darwin ;; *) echo Unsupported platform: ${platform} exit 1 ;; esac Modified: haiku/trunk/headers/build/BeOSBuildCompatibility.h =================================================================== --- haiku/trunk/headers/build/BeOSBuildCompatibility.h 2007-05-17 20:06:45 UTC (rev 21164) +++ haiku/trunk/headers/build/BeOSBuildCompatibility.h 2007-05-18 15:59:04 UTC (rev 21165) @@ -16,7 +16,7 @@ extern size_t strlcpy(char *dest, const char *source, size_t length); extern size_t strlcat(char *dest, const char *source, size_t length); -#ifdef HAIKU_HOST_PLATFORM_FREEBSD +#if defined(HAIKU_HOST_PLATFORM_FREEBSD) || defined(HAIKU_HOST_PLATFORM_DARWIN) extern size_t strnlen(const char *string, size_t length); #endif Added: haiku/trunk/headers/build/host/darwin/endian.h =================================================================== --- haiku/trunk/headers/build/host/darwin/endian.h 2007-05-17 20:06:45 UTC (rev 21164) +++ haiku/trunk/headers/build/host/darwin/endian.h 2007-05-18 15:59:04 UTC (rev 21165) @@ -0,0 +1,10 @@ +#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_ENDIAN +#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_ENDIAN + +#include + +#define __LITTLE_ENDIAN LITTLE_ENDIAN +#define __BIG_ENDIAN BIG_ENDIAN +#define __PDP_ENDIAN PDP_ENDIAN + +#endif // _HAIKU_BUILD_COMPATIBILITY_DARWIN_ENDIAN Added: haiku/trunk/headers/build/host/darwin/regex.h =================================================================== --- haiku/trunk/headers/build/host/darwin/regex.h 2007-05-17 20:06:45 UTC (rev 21164) +++ haiku/trunk/headers/build/host/darwin/regex.h 2007-05-18 15:59:04 UTC (rev 21165) @@ -0,0 +1,16 @@ +#ifndef _HAIKU_BUILD_COMPATIBILITY_DARWIN_REGEX +#define _HAIKU_BUILD_COMPATIBILITY_DARWIN_REGEX + +// Include the darwin port of gnuregex + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#ifdef __cplusplus +} +#endif + +#endif // _HAIKU_BUILD_COMPATIBILITY_DARWIN_REGEX Modified: haiku/trunk/src/tools/Jamfile =================================================================== --- haiku/trunk/src/tools/Jamfile 2007-05-17 20:06:45 UTC (rev 21164) +++ haiku/trunk/src/tools/Jamfile 2007-05-18 15:59:04 UTC (rev 21165) @@ -22,7 +22,7 @@ BuildPlatformMain catattr : catattr.cpp : $(HOST_LIBBE) ; BuildPlatformMain copyattr : copyattr.cpp - : $(HOST_LIBBE) $(HOST_LIBSTDC++) ; + : $(HOST_LIBBE) $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) ; BuildPlatformMain listattr : listattr.cpp : $(HOST_LIBBE) ; @@ -35,7 +35,7 @@ database_support.cpp UpdateMimeInfoThread.cpp MimeUpdateThread.cpp - : $(HOST_LIBBE) + : $(HOST_LIBBE) $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) ; BuildPlatformMain mkindex : mkindex.cpp : $(HOST_LIBBE) ; @@ -43,13 +43,16 @@ BuildPlatformMain rmattr : rmattr.cpp : $(HOST_LIBBE) ; BuildPlatformMain set_haiku_revision : set_haiku_revision.cpp - : $(HOST_LIBSTDC++) ; + : $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) ; -BuildPlatformMain settype : settype.cpp : $(HOST_LIBBE) ; +BuildPlatformMain settype : settype.cpp : $(HOST_LIBBE) + $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) ; -BuildPlatformMain setversion : setversion.cpp : $(HOST_LIBBE) ; +BuildPlatformMain setversion : setversion.cpp : $(HOST_LIBBE) + $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) ; -BuildPlatformMain xres : xres.cpp : $(HOST_LIBBE) $(HOST_LIBSTDC++) ; +BuildPlatformMain xres : xres.cpp : $(HOST_LIBBE) $(HOST_LIBSTDC++) + $(HOST_LIBSUPC++) ; SEARCH on [ FGristFiles Mime.cpp Modified: haiku/trunk/src/tools/gensyscalls/Jamfile =================================================================== --- haiku/trunk/src/tools/gensyscalls/Jamfile 2007-05-17 20:06:45 UTC (rev 21164) +++ haiku/trunk/src/tools/gensyscalls/Jamfile 2007-05-18 15:59:04 UTC (rev 21165) @@ -62,7 +62,7 @@ BuildPlatformMain gensyscallinfos : gensyscallinfos.cpp - : $(HOST_LIBSTDC++) + : $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) ; @@ -88,7 +88,7 @@ # build gensyscalls BuildPlatformMain gensyscalls : gensyscalls.cpp $(syscallInfos) ; -LinkAgainst gensyscalls : $(HOST_LIBSTDC++) ; +LinkAgainst gensyscalls : $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) ; # Explicitly tell jam that gensyscalls.cpp includes the generated header. Includes [ FGristFiles gensyscalls.cpp ] : $(syscallsHeaderPP) ; Modified: haiku/trunk/src/tools/keymap/Jamfile =================================================================== --- haiku/trunk/src/tools/keymap/Jamfile 2007-05-17 20:06:45 UTC (rev 21164) +++ haiku/trunk/src/tools/keymap/Jamfile 2007-05-18 15:59:04 UTC (rev 21165) @@ -7,6 +7,7 @@ BuildPlatformMain keymap : main.cpp Keymap.cpp + : $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) ; LinkAgainst keymap : $(HOST_LIBBE) ; Modified: haiku/trunk/src/tools/makebootable/platform/bios_ia32/Jamfile =================================================================== --- haiku/trunk/src/tools/makebootable/platform/bios_ia32/Jamfile 2007-05-17 20:06:45 UTC (rev 21164) +++ haiku/trunk/src/tools/makebootable/platform/bios_ia32/Jamfile 2007-05-18 15:59:04 UTC (rev 21165) @@ -23,5 +23,5 @@ BuildPlatformMain makebootable : makebootable.cpp $(hostPlatformSources) - : $(HOST_LIBBE) + : $(HOST_LIBBE) $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) ; Modified: haiku/trunk/src/tools/rc/Jamfile =================================================================== --- haiku/trunk/src/tools/rc/Jamfile 2007-05-17 20:06:45 UTC (rev 21164) +++ haiku/trunk/src/tools/rc/Jamfile 2007-05-18 15:59:04 UTC (rev 21165) @@ -21,7 +21,7 @@ strlcat.c ; LinkAgainst rc - : librdef.a $(HOST_LIBSTDC++) $(HOST_LIBBE) ; + : librdef.a $(HOST_LIBSTDC++) $(HOST_LIBBE) $(HOST_LIBSUPC++) ; SEARCH on [ FGristFiles strlcat.c strlcpy.c Modified: haiku/trunk/src/tools/resattr/Jamfile =================================================================== --- haiku/trunk/src/tools/resattr/Jamfile 2007-05-17 20:06:45 UTC (rev 21164) +++ haiku/trunk/src/tools/resattr/Jamfile 2007-05-18 15:59:04 UTC (rev 21165) @@ -3,5 +3,5 @@ USES_BE_API on resattr = true ; BuildPlatformMain resattr : resattr.cpp ; -LinkAgainst resattr : $(HOST_LIBBE) ; +LinkAgainst resattr : $(HOST_LIBBE) $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) ; From bonefish at mail.berlios.de Fri May 18 18:50:50 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Fri, 18 May 2007 18:50:50 +0200 Subject: [Haiku-commits] r21166 - haiku/trunk/build/jam Message-ID: <200705181650.l4IGoo8M029450@sheep.berlios.de> Author: bonefish Date: 2007-05-18 18:50:47 +0200 (Fri, 18 May 2007) New Revision: 21166 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21166&view=rev Modified: haiku/trunk/build/jam/BeOSRules Log: Added rule AddFileDataAttribute to add an attribute to a file. The attribute value is read from another file. Modified: haiku/trunk/build/jam/BeOSRules =================================================================== --- haiku/trunk/build/jam/BeOSRules 2007-05-18 15:59:04 UTC (rev 21165) +++ haiku/trunk/build/jam/BeOSRules 2007-05-18 16:50:47 UTC (rev 21166) @@ -1,6 +1,49 @@ # BeOS specific rules +rule AddFileDataAttribute target : attrName : attrType : dataFile +{ + # AddFileAttribute : : : ; + # Adds a single attribute to a file, retrieving the attribute data from + # a separate file. + # : The file to which the attribute shall be added. + # : The name of the attribute. + # : Attribute type as supported by addattr (string, int, etc.) + # : The data to be written to the attribute will be read from + # that file. + # Note that this is supposed to be a build target, not a path + # name - if you need to add a data file in a different path, + # you have to locate it first. + # + # We need to create a temporary file in which we store the attribute name + # and type. Otherwise we wouldn't have these data available in the + # addattr actions. + local id = [ NextID ] ; + local attrMetaFile + = [ FGristFiles $(target:G=)-attr-$(attrName)-$(attrType)-$(id) ] ; + + ATTRIBUTE_NAME on $(attrMetaFile) = $(attrName) ; + ATTRIBUTE_TYPE on $(attrMetaFile) = $(attrType) ; + MakeLocateArch $(attrMetaFile) ; + CreateAttributeMetaFile $(attrMetaFile) ; + + Depends $(target) : addattr $(attrMetaFile) $(dataFile) ; + AddFileDataAttribute1 $(target) + : addattr $(attrMetaFile) $(dataFile) ; + + RmTemps $(target) : $(attrMetaFile) ; +} + +actions CreateAttributeMetaFile +{ + echo "-t $(ATTRIBUTE_TYPE)" "$(ATTRIBUTE_NAME)" > "$(1)" +} + +actions AddFileDataAttribute1 +{ + $(2[1]) -f $(2[3]) `cat $(2[2])` $(1) +} + rule AddStringDataResource { # AddStringDataResource : : @@ -37,7 +80,6 @@ $(2[1]) -o "$(1)" $(RESOURCE_STRINGS) } - rule AddFileDataResource { # AddFileDataResource : : [ ] From bonefish at mail.berlios.de Fri May 18 18:55:34 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Fri, 18 May 2007 18:55:34 +0200 Subject: [Haiku-commits] r21167 - in haiku/trunk/src/tools: . addattr Message-ID: <200705181655.l4IGtYr8002284@sheep.berlios.de> Author: bonefish Date: 2007-05-18 18:55:33 +0200 (Fri, 18 May 2007) New Revision: 21167 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=21167&view=rev Added: haiku/trunk/src/tools/addattr/ haiku/trunk/src/tools/addattr/Jamfile Modified: haiku/trunk/src/tools/Jamfile Log: Build addattr as a build tool as well. Needed for the new AddFileDataAttribute rule. Modified: haiku/trunk/src/tools/Jamfile =================================================================== --- haiku/trunk/src/tools/Jamfile 2007-05-18 16:50:47 UTC (rev 21166) +++ haiku/trunk/src/tools/Jamfile 2007-05-18 16:55:33 UTC (rev 21167) @@ -62,6 +62,7 @@ UpdateMimeInfoThread.cpp MimeUpdateThread.cpp database_support.cpp ] = [ FDirName $(HAIKU_TOP) src build libbe storage mime ] ; +SubInclude HAIKU_TOP src tools addattr ; SubInclude HAIKU_TOP src tools bfs_shell ; SubInclude HAIKU_TOP src tools copy_to_bfs_image ; SubInclude HAIKU_TOP src tools cppunit ; Added: haiku/trunk/src/tools/addattr/Jamfile =================================================================== --- haiku/trunk/src/tools/addattr/Jamfile 2007-05-18 16:50:47 UTC (rev 21166) +++ haiku/trunk/src/tools/addattr/Jamfile 2007-05-18 16:55:33 UTC (rev 21167) @@ -0,0 +1,10 @@